router

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
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 Builder

func Builder(ctx context.Context, c any) (secrets.Keeper, error)

Builder constructs a new router secret keeper.

func RemoveLocationsAndRoutes

func RemoveLocationsAndRoutes(rc config.KeeperConfig, removeLocations ...string)

RemoveLocationsAndRoutes removes the given locations from the router configuration.

func Validator

func Validator(ctx context.Context, c any) error

Validator validates 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 NewRouter

func NewRouter(defaultKeeper secrets.Keeper) *Router

NewRouter returns a new router with the given Keeper as the default Keeper.

func (*Router) AddKeeper

func (r *Router) AddKeeper(keeper secrets.Keeper, locations ...string) error

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

func (r *Router) DeleteSecret(
	ctx context.Context,
	id string,
) error

DeleteSecret finds the store that holds the identified secret and deletes it.

func (*Router) GetSecret

func (r *Router) GetSecret(
	ctx context.Context,
	id string,
) (secrets.Secret, error)

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

func (r *Router) GetSecretsByName(
	ctx context.Context,
	name string,
) ([]secrets.Secret, error)

GetSecretsByName will retrieve every secret in every secret store with the the given name.

func (*Router) ListLocations

func (r *Router) ListLocations(ctx context.Context) ([]string, error)

ListLocations returns all the locations that this secrets.Keeper provides.

func (*Router) ListSecrets

func (r *Router) ListSecrets(
	ctx context.Context,
	location string,
) ([]string, error)

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.

func (*Router) SetSecret

func (r *Router) SetSecret(
	ctx context.Context,
	sec secrets.Secret,
) (secrets.Secret, error)

SetSecret will find the secrets.Keeper store used for the new secret's location. It will then add the secret to that Keeper.

type Secret

type Secret struct {
	secrets.Secret
	// contains filtered or unexported fields
}

Secret is a special wrapper around secrets returned from Router that manages the ID.

func (*Secret) ID

func (s *Secret) ID() string

ID returns the ID of the secret.

Jump to

Keyboard shortcuts

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