Documentation
¶
Index ¶
- Constants
- func AddRoute(rc config.KeeperConfig, keeper string, locations ...string)
- func Builder(ctx context.Context, c any) (secrets.Keeper, error)
- func RemoveLocationsAndRoutes(rc config.KeeperConfig, removeLocations ...string)
- func Validator(ctx context.Context, c any) error
- type Config
- type RouteConfig
- type Router
- func (r *Router) AddKeeper(keeper secrets.Keeper, locations ...string) error
- func (r *Router) CopySecret(ctx context.Context, id string, location string) (secrets.Secret, error)
- func (r *Router) DeleteSecret(ctx context.Context, id string) error
- func (r *Router) GetSecret(ctx context.Context, id string) (secrets.Secret, error)
- func (r *Router) GetSecretsByName(ctx context.Context, name string) ([]secrets.Secret, error)
- func (r *Router) ListLocations(ctx context.Context) ([]string, error)
- func (r *Router) ListSecrets(ctx context.Context, location string) ([]string, error)
- func (r *Router) MoveSecret(ctx context.Context, id string, location string) (secrets.Secret, error)
- func (r *Router) SetSecret(ctx context.Context, sec secrets.Secret) (secrets.Secret, error)
- type Secret
Constants ¶
const ConfigType = "router"
ConfigType is the name of the config type for the router secret keeper.
Variables ¶
This section is empty.
Functions ¶
func AddRoute ¶
func AddRoute(rc config.KeeperConfig, keeper string, locations ...string)
AddRoute adds a route to the router configuration.
func RemoveLocationsAndRoutes ¶
func RemoveLocationsAndRoutes(rc config.KeeperConfig, removeLocations ...string)
RemoveLocationsAndRoutes removes the given locations from the router configuration.
Types ¶
type Config ¶
type Config struct { // Routes is the list of routes to use for the router. Routes []RouteConfig `mapstructure:"routes" yaml:"routes"` // DefaultRoute is the name of the default route to use for the router. DefaultRoute string `mapstructure:"default" yaml:"default,omitempty"` }
Config is the configuration for the router secret keeper.
type RouteConfig ¶
type RouteConfig struct { // Locations is the list of locations to route to the keeper. Locations []string `mapstructure:"locations" yaml:"locations"` // Keeper is the name of the keeper to use for the route. Keeper string `mapstructure:"keeper" yaml:"keeper"` }
RouteConfig is the configuration for a route in the router.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router is a Keeper that maps locations to other Keepers. Keepers are added to the Router using the AddKeeper method.
The added secrets.Keepers are associated with this secrets.Keeper operate as peers, rather than children. That is, if you add another keeper for locations "Personal" and "Work", then whenever a secret is gotten or saved for "Personal" or for "Work", that keeper will be used. This is NOT a parent-child relationship with pathing or anything of that sort.
Whenever secrets are fetched, saved, etc. The location of the secret will match those associated with a Keeper. For example, if GetSecretsByName is called, secrets that match that name, but are not in an associated location will not be returned.
The IDs used by this library will differ from those returned by each associated keeper.
func (*Router) AddKeeper ¶
AddKeeper adds a new Keeper, which will be used for storing at the given locations. The same location may not be used for more than one Keeper.
func (*Router) CopySecret ¶
func (r *Router) CopySecret( ctx context.Context, id string, location string, ) (secrets.Secret, error)
CopySecret will copy the secret from one location to another, possibly moving it into another secrets.Keeper store.
As of this writing, it will not use CopySecret even if a single secrets.Keeper store is used for both location. Instead, it copies the secrets.Password in memory with a blank ID and the new location and uses SetSecret to create it.
func (*Router) DeleteSecret ¶
DeleteSecret finds the store that holds the identified secret and deletes it.
func (*Router) GetSecret ¶
GetSecret will retrieve the identified secret from one of the available secrets.Keeper stores. This will return secrets.ErrNotFound if no secret matches the given ID.
func (*Router) GetSecretsByName ¶
GetSecretsByName will retrieve every secret in every secret store with the the given name.
func (*Router) ListLocations ¶
ListLocations returns all the locations that this secrets.Keeper provides.
func (*Router) ListSecrets ¶
ListSecrets will list all secrets from the secrets.Keeper store that owns the given location.
func (*Router) MoveSecret ¶
func (r *Router) MoveSecret( ctx context.Context, id string, location string, ) (secrets.Secret, error)
MoveSecret will move the secret from one location to another, possibly moving it into another secrets.Keeper store.
As of this writing, this operation does not perform MoveSecret when the operation is moving between locations on the same store. Instead, this uses SetSecret to create a secret in the new location and then uses DeleteSecret to delete the secret from the old location. It is done in this order so that the accidental failure mode is more likely to end up with duplicated secrets than deleted secrets if this operation should fail in the middle.