Documentation
¶
Overview ¶
Package variables keeps the variables of services where they live: in shed.db, or, while 1Password is connected, in one item per service in a vault of the operator's. Callers read and write variables through a Keeper and never ask which.
Index ¶
- Variables
- type Item
- type Keeper
- func (k *Keeper) Archive(ctx context.Context, item Item) error
- func (k *Keeper) Connect(ctx context.Context, token, vaultID string) error
- func (k *Keeper) Disconnect(ctx context.Context) error
- func (k *Keeper) Get(ctx context.Context, svc store.Service) (map[string]string, error)
- func (k *Keeper) Items(ctx context.Context, services ...store.Service) ([]Item, error)
- func (k *Keeper) Preload(ctx context.Context) error
- func (k *Keeper) Retitle(ctx context.Context, project store.Project, services []store.Service) error
- func (k *Keeper) Set(ctx context.Context, svc store.Service, vars map[string]string) error
- func (k *Keeper) Status(ctx context.Context) (Status, error)
- func (k *Keeper) Vaults(ctx context.Context, token string) ([]onepassword.Vault, error)
- type OnePassword
- type Status
- type Store
Constants ¶
This section is empty.
Variables ¶
var ( // ErrConnected is returned when connecting while 1Password is connected. ErrConnected = errors.New("variables: 1Password is already connected") // ErrVault is wrapped by errors for a vault the token cannot connect to: // one it cannot access, or none or one of several when none was chosen. ErrVault = errors.New("variables: no vault to connect to") )
Functions ¶
This section is empty.
Types ¶
type Keeper ¶
type Keeper struct {
// contains filtered or unexported fields
}
Keeper reads and writes the variables of services. It is safe for concurrent use.
func (*Keeper) Archive ¶
Archive archives an item. While 1Password is not connected it does nothing.
func (*Keeper) Connect ¶
Connect moves every service's variables from shed.db to items in the vault with ID vaultID, or, if vaultID is empty, the only vault token can access, and keeps variables there from then on. An error matching ErrVault means there is no such vault. Items are recorded as they are created, and a service that has one from an earlier attempt gets its fields replaced, so after a failure Connect can be retried; until it succeeds, shed.db keeps the variables. An error matching onepassword.ErrInvalidToken means 1Password rejected the token. Connecting while connected returns ErrConnected.
func (*Keeper) Disconnect ¶
Disconnect reads every service's item, saves the variables in shed.db, and forgets the token, the vault, and the items, which stay in 1Password. If a read fails, nothing changes. Disconnecting while not connected changes nothing.
func (*Keeper) Get ¶
Get returns a service's variables, with references unexpanded. While 1Password is connected they are read from the service's item; if it has none, or 1Password no longer has it, the error matches onepassword.ErrItemMissing.
func (*Keeper) Items ¶
Items returns the items of services, none while 1Password is not connected. Deleting a service forgets its item, so the items of services being deleted are looked up first and archived with Archive once the deletion succeeds.
func (*Keeper) Preload ¶
Preload loads 1Password in the background if it is connected, so that the first read does not wait for it.
func (*Keeper) Retitle ¶
func (k *Keeper) Retitle(ctx context.Context, project store.Project, services []store.Service) error
Retitle gives the items of services of a project the project's and services' current names. Services without an item are skipped.
func (*Keeper) Set ¶
Set replaces a service's variables. While 1Password is connected they are written to the service's item, which is created if the service has none or 1Password no longer has it; a new service gets its item this way.
type OnePassword ¶
type OnePassword interface {
Preload(ctx context.Context, token string)
SignIn(ctx context.Context, token string) error
Vaults(ctx context.Context, token string) ([]onepassword.Vault, error)
CreateItem(ctx context.Context, token, vaultID string, item onepassword.Item) (string, error)
Variables(ctx context.Context, token, vaultID string, itemIDs []string) (map[string]map[string]string, error)
SetVariables(ctx context.Context, token, vaultID, itemID string, vars map[string]string) error
Retitle(ctx context.Context, token, vaultID, itemID, title string, tags []string) error
Archive(ctx context.Context, token, vaultID, itemID string) error
}
OnePassword reads and writes vault items. *onepassword.Client implements it.
type Status ¶
type Status struct {
Connected bool
// Vault is the name of the vault, empty while not connected.
Vault string
// Items is how many services have an item, zero while not connected.
Items int
}
Status describes the 1Password connection.
type Store ¶
type Store interface {
Project(ctx context.Context, id string) (store.Project, error)
Projects(ctx context.Context) ([]store.Project, error)
AllServices(ctx context.Context) ([]store.Service, error)
Variables(ctx context.Context, serviceID string) (map[string]string, error)
SetVariables(ctx context.Context, serviceID string, vars map[string]string) error
// OnePassword returns the connection, or store.ErrNotFound while
// 1Password is not connected.
OnePassword(ctx context.Context) (store.OnePasswordConnection, error)
// ConnectOnePassword deletes every service's variables and saves the
// connection, atomically.
ConnectOnePassword(ctx context.Context, c store.OnePasswordConnection) error
// DisconnectOnePassword saves the variables of services by service ID
// and deletes the connection and every service's item, atomically.
DisconnectOnePassword(ctx context.Context, vars map[string]map[string]string) error
// OnePasswordItem returns the ID of a service's item, or
// store.ErrNotFound if it has none.
OnePasswordItem(ctx context.Context, serviceID string) (string, error)
// OnePasswordItems returns the item IDs of services by service ID.
OnePasswordItems(ctx context.Context) (map[string]string, error)
SetOnePasswordItem(ctx context.Context, serviceID, itemID string) error
}
Store holds the variables while 1Password is not connected, the connection, and the item of each service. *store.Store implements it.