aws

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 20 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager stores credentials as secrets in AWS Secrets Manager, one for each key, which AWS encrypts with KMS

func New

func New(ctx context.Context, opts ...Opt) (_ *Manager, err error)

New returns a manager for credentials in AWS Secrets Manager. The region, credentials and endpoint are from the AWS environment variables, such as AWS_REGION, AWS_PROFILE, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, and the shared configuration files, unless they are set with options.

func (*Manager) Delete

func (self *Manager) Delete(ctx context.Context, key string) (err error)

Delete schedules the key's secret for deletion, after the recovery window set with WithRecoveryWindow, or AWS's default of 30 days, or deletes it at once when the window is zero. A secret with the key can't be created again until the deletion is complete. Returns ErrNotFound when there isn't one.

func (*Manager) Describe

func (self *Manager) Describe(ctx context.Context, key, description string) (err error)

Describe sets the description of the key's secret, which AWS keeps beside it, unencrypted, or removes it, when it's empty, without changing its value, and returns ErrNotFound when there isn't one

func (*Manager) Expand

func (self *Manager) Expand(ctx context.Context, value string) (_ string, err error)

Expand replaces each $KEY or ${KEY} placeholder in the value with the credential for the key, which must be a string, or with the environment variable, with WithEnv, when there is no secret for it. Keys containing "-" must use the ${KEY} form. Each secret is read once, however many times it's used. Returns an error, rather than a partly expanded value, if a placeholder is not a valid key, or its credential does not exist or is not a string.

func (*Manager) Get

func (self *Manager) Get(ctx context.Context, key string) (_ json.RawMessage, err error)

Get returns the credential for the key, as JSON, or the environment variable's value, with WithEnv, when there is no secret for it. A secret which isn't JSON is returned as a JSON string. Returns an error if the key isn't valid, or the credential doesn't exist.

func (*Manager) List

func (self *Manager) List(ctx context.Context) (_ []credential.Credential, err error)

List returns the stored credentials, in key order, without their values: the secrets whose names start with the prefix, and the rest of which is a key. Secrets which are scheduled for deletion aren't listed.

func (*Manager) Set

func (self *Manager) Set(ctx context.Context, key string, value json.RawMessage) (err error)

Set stores the credential for the key as a new version of its secret, creating the secret when it doesn't exist. Returns an error if the key isn't valid, or the value isn't JSON.

type Opt

type Opt func(*opt) error

Opt is a functional option for the AWS credential manager

func WithCredentials

func WithCredentials(accessKeyID, secretAccessKey, sessionToken string) Opt

WithCredentials sets static credentials, in place of AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN, or the profile's. The session token is optional.

func WithEndpoint

func WithEndpoint(endpoint string) Opt

WithEndpoint sets the endpoint URL, in place of AWS_ENDPOINT_URL, such as for a local emulator

func WithEnv

func WithEnv() Opt

WithEnv reads a credential from the environment when there is no secret for it, so $KEY is expanded from the environment variable KEY. The environment is read-only, so credentials are still stored as secrets.

func WithKMSKey

func WithKMSKey(keyID string) Opt

WithKMSKey sets the KMS key which new secrets are encrypted with, in place of the account's default key for Secrets Manager

func WithPrefix

func WithPrefix(prefix string) Opt

WithPrefix sets a prefix for the secret names, such as "myapp/", so the credential for key KEY is the secret "myapp/KEY"

func WithProfile

func WithProfile(profile string) Opt

WithProfile sets the shared configuration profile, in place of AWS_PROFILE

func WithRecoveryWindow

func WithRecoveryWindow(days int) Opt

WithRecoveryWindow sets the number of days, from 7 to 30, that a deleted secret can be recovered for, in place of AWS's default of 30 days, or 0 to delete secrets at once, without recovery

func WithRegion

func WithRegion(region string) Opt

WithRegion sets the AWS region, in place of AWS_REGION or the profile's

func WithTracer

func WithTracer(tracer trace.Tracer) Opt

WithTracer sets the tracer used for tracing operations

Jump to

Keyboard shortcuts

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