op

package
v1.18.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

README

1Password secret store

Read secrets from 1Password using the op CLI.

URL format

op://<vault>/<item>/<field>

Example:

op://Private/e2e-account.json/notesPlain

The vault name is parsed as the URL host (Private). The item and field path follow the host (e2e-account.json/notesPlain).

Usage

import (
	"context"
	"github.com/viant/afs"
	_ "github.com/viant/afsc/op"
)

func main() {
	fs := afs.New()
	data, err := fs.DownloadWithURL(context.Background(), "op://Private/my-item/password")
	// ...
}

Requirements

  • op must be installed and on PATH, or set OP_CLI to the binary location
  • The user must be signed in (op signin) or otherwise authenticated for CLI access

Testing

Unit tests (no 1Password, safe for CI and Cursor):

cd ~/project/afsc
go test ./op/... -count=1 -v

These tests use an in-memory stub CLI and a testdata/fake-op.sh script. They never call your real op binary or open a 1Password session.

Optional integration test (you run locally with 1Password):

op signin
export OP_INTEGRATION_REF='op://Private/e2e-account.json/notesPlain'
go test ./op/... -tags=integration -run TestIntegrationDownloadWithURL -count=1 -v

Do not run -tags=integration from automation that should not access 1Password.

Notes

  • Read-only: upload, create, copy, and move are not supported
  • Secret bytes are returned in memory; this connector does not write credentials to disk

Documentation

Index

Constants

View Source
const Scheme = "op"

Scheme represents 1Password secret references read via the op CLI.

Variables

This section is empty.

Functions

func New

func New(options ...storage.Option) storage.Manager

New creates a 1Password secret manager.

func Provider

func Provider(options ...storage.Option) (storage.Manager, error)

Provider returns a 1Password secret manager.

Types

type CLI

type CLI interface {
	Read(ctx context.Context, reference string) ([]byte, error)
}

CLI reads secrets from 1Password.

func NewCLI

func NewCLI() CLI

NewCLI creates a CLI backed by the op binary.

type CLIOption

type CLIOption struct {
	CLI CLI
}

CLIOption injects a 1Password CLI implementation (primarily for tests).

func (*CLIOption) Init

func (o *CLIOption) Init() error

Init validates the option.

func (*CLIOption) Validate

func (o *CLIOption) Validate() error

Validate validates the option.

type Storager

type Storager struct {
	// contains filtered or unexported fields
}

Storager reads 1Password secrets for a vault base URL such as op://Private.

func NewStorager

func NewStorager(ctx context.Context, baseURL string, options ...storage.Option) (*Storager, error)

NewStorager creates a new 1Password storager.

func (*Storager) Close

func (s *Storager) Close() error

Close closes the storager.

func (*Storager) Create

func (s *Storager) Create(ctx context.Context, resourceID string, mode os.FileMode, reader io.Reader, isDir bool, options ...storage.Option) error

Create is not supported.

func (*Storager) Delete

func (s *Storager) Delete(ctx context.Context, location string, options ...storage.Option) error

Delete is not supported.

func (*Storager) Exists

func (s *Storager) Exists(ctx context.Context, resourceID string, options ...storage.Option) (bool, error)

Exists returns true when op read succeeds for the supplied reference.

func (*Storager) Get

func (s *Storager) Get(ctx context.Context, location string, options ...storage.Option) (os.FileInfo, error)

Get returns file info for a readable secret reference.

func (*Storager) List

func (s *Storager) List(ctx context.Context, resourceID string, options ...storage.Option) ([]os.FileInfo, error)

List returns file info for a readable secret reference.

func (*Storager) Open

func (s *Storager) Open(ctx context.Context, resourceID string, options ...storage.Option) (io.ReadCloser, error)

Open returns a reader for the supplied 1Password secret reference.

func (*Storager) Upload

func (s *Storager) Upload(ctx context.Context, resourceID string, mode os.FileMode, reader io.Reader, options ...storage.Option) error

Upload is not supported.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL