Documentation
¶
Overview ¶
Package secretly provides a client wrapper for popular secret management services.
The secretly package's client interface exposes convenience methods for retrieving secrets.
Index ¶
Constants ¶
const ( // Defaults. DefaultType = "text" DefaultVersion = "0" )
Default values for optional field tags.
Variables ¶
var ( ErrInvalidSpecification = errors.New("specification must be a struct pointer") ErrInvalidSecretType = errors.New("invalid secret type") ErrInvalidSecretVersion = errors.New("invalid secret version") ErrSecretTypeDoesNotSupportKey = errors.New("secret type does not support \"key\"") )
var ( ErrInvalidJSONSecret = errors.New("secret is not valid json") ErrInvalidYAMLSecret = errors.New("secret is not valid yaml") ErrSecretMissingKey = errors.New("secret is missing provided key") )
var ErrInvalidFileType = errors.New("invalid file type")
Functions ¶
func NewNoOpSecretCache ¶ added in v0.1.0
func NewNoOpSecretCache() noOpSecretCache
NewNoOpSecretCache constructs a no-op secret cache, meant to be used for disabling secret caching.
func NewSecretCache ¶ added in v0.1.0
func NewSecretCache() secretCache
NewSecretCache constructs a secretCache.
Types ¶
type Client ¶ added in v0.1.0
type Client interface { // Process resolves the provided specification. // ProcessOptions can be provided // to add additional processing for the fields, // like reading version info from the env or a file. // // (*Client).Process is a convenience // for calling secretly.Process with the Client. Process(spec any, opts ...ProcessOption) error // GetSecret retrieves the latest secret version for name // from the secret management service. GetSecret(ctx context.Context, name string) ([]byte, error) // GetSecretWithVersion retrieves the specific secret version for name // from the secret management service. GetSecretWithVersion(ctx context.Context, name, version string) ([]byte, error) }
Client describes a secretly secret manager client wrapper.
type Config ¶ added in v0.1.0
type Config struct { // DisableCaching disables the secret caching feature. // By default, secret caching is enabled. // With this set to true, // repeated gets to the same secret version will reach out // to the secret manager client. DisableCaching bool }
Config provides configuration to change the behavior of secretly client wrappers.
type Field ¶ added in v0.1.0
type Field struct { SecretType string SecretName string SecretVersion string MapKeyName string // NOTE: Only used when secretType is "json" or "yaml" SplitWords bool Value reflect.Value }
Field represents a field in a struct, exposing its secretly tag values and reference to the underlying value.
func NewField ¶ added in v0.1.0
NewField constructs a field referencing the provided reflect.Value with the tags from the reflect.StructField applied
type ProcessOption ¶
ProcessOptions are optional modifiers for secret processing.
func ApplyPatch ¶ added in v0.1.0
func ApplyPatch(filePath string) ProcessOption
ApplyPatch returns an ProcessOption which overwrites the specified/default field values with the provided patch. Can be used to overwrite any of the configurable field values.
Types of patch files are determined by their extensions. Accepted patch file types are:
- JSON (.json)
- YAML (.yaml,.yml)
func WithVersionsFromEnv ¶
func WithVersionsFromEnv(prefix string) ProcessOption
WithVersionsFromEnv returns an ProcessOption which overwrites the specified/default secret versions with versions from the environment. Environment variables are to be named with the following logic:
if prefix uppercase( prefix + "_" + field.Name() ) + "_VERSION" else uppercase( field.Name() ) + "_VERSION"
type SecretCache ¶ added in v0.1.0
type SecretCache interface { // Add adds a secret with its version to the cache. Add(name, version string, content []byte) // Get gets the secret version from the cache. // A bool is returned to indicate a cache hit or miss. Get(name, version string) ([]byte, bool) }
SecretCache describes a secret cache, which are used to limit calls to the upstream secret manager service.
type StructTagError ¶
StructTagError describes an error resulting from an issue with a struct tag.
func (StructTagError) Error ¶
func (e StructTagError) Error() string
func (StructTagError) Unwrap ¶
func (e StructTagError) Unwrap() error