secretcache

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: Apache-2.0 Imports: 11 Imported by: 30

Documentation

Overview

Package secretcache provides the Cache struct for in-memory caching of secrets stored in AWS Secrets Manager Also exports a CacheHook, for pre-store and post-fetch processing of cached values

Index

Constants

View Source
const (
	DefaultMaxCacheSize = 1024
	DefaultCacheItemTTL = 3600000000000 // 1 hour in nanoseconds
	DefaultVersionStage = "AWSCURRENT"
)
View Source
const (
	VersionNumber        = "1"
	MajorRevisionNumber  = "1"
	MinorRevisionNumber  = "2"
	BugfixRevisionNumber = "0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	CacheConfig
	Client secretsmanageriface.SecretsManagerAPI
	// contains filtered or unexported fields
}

Cache client for AWS Secrets Manager secrets.

func New

func New(optFns ...func(*Cache)) (*Cache, error)

New constructs a secret cache using functional options, uses defaults otherwise. Initialises a SecretsManager Client from a new session.Session. Initialises CacheConfig to default values. Initialises lru cache with a default max size.

func (*Cache) GetSecretBinary

func (c *Cache) GetSecretBinary(secretId string) ([]byte, error)

GetSecretBinary gets the secret binary value from the cache for given secret id and a default version stage. Returns the secret binary and an error if operation failed.

func (*Cache) GetSecretBinaryWithContext added in v1.1.1

func (c *Cache) GetSecretBinaryWithContext(ctx context.Context, secretId string) ([]byte, error)

func (*Cache) GetSecretBinaryWithStage

func (c *Cache) GetSecretBinaryWithStage(secretId string, versionStage string) ([]byte, error)

GetSecretBinaryWithStage gets the secret binary value from the cache for given secret id and version stage. Returns the secret binary and an error if operation failed.

func (*Cache) GetSecretBinaryWithStageWithContext added in v1.1.1

func (c *Cache) GetSecretBinaryWithStageWithContext(ctx context.Context, secretId string, versionStage string) ([]byte, error)

func (*Cache) GetSecretString

func (c *Cache) GetSecretString(secretId string) (string, error)

GetSecretString gets the secret string value from the cache for given secret id and a default version stage. Returns the secret string and an error if operation failed.

func (*Cache) GetSecretStringWithContext added in v1.1.1

func (c *Cache) GetSecretStringWithContext(ctx context.Context, secretId string) (string, error)

func (*Cache) GetSecretStringWithStage

func (c *Cache) GetSecretStringWithStage(secretId string, versionStage string) (string, error)

GetSecretStringWithStage gets the secret string value from the cache for given secret id and version stage. Returns the secret string and an error if operation failed.

func (*Cache) GetSecretStringWithStageWithContext added in v1.1.1

func (c *Cache) GetSecretStringWithStageWithContext(ctx context.Context, secretId string, versionStage string) (string, error)

type CacheConfig

type CacheConfig struct {
	//The maximum number of cached secrets to maintain before evicting secrets that
	//have not been accessed recently.
	MaxCacheSize int

	//The number of nanoseconds that a cached item is considered valid before
	// requiring a refresh of the secret state.  Items that have exceeded this
	// TTL will be refreshed synchronously when requesting the secret value.  If
	// the synchronous refresh failed, the stale secret will be returned.
	CacheItemTTL int64

	//The version stage that will be used when requesting the secret values for
	//this cache.
	VersionStage string

	//Used to hook in-memory cache updates.
	Hook CacheHook
}

CacheConfig is the config object passed to the Cache struct

type CacheHook

type CacheHook interface {
	// Put prepares the object for storing in the cache.
	Put(data interface{}) interface{}

	// Get derives the object from the cached object.
	Get(data interface{}) interface{}
}

CacheHook is an interface to hook into the local in-memory cache. This interface will allow users to perform actions on the items being stored in the in-memory cache. One example would be encrypting/decrypting items stored in the in-memory cache.

type InvalidConfigError

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

func (*InvalidConfigError) Error

func (i *InvalidConfigError) Error() string

type InvalidOperationError

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

func (*InvalidOperationError) Error

func (i *InvalidOperationError) Error() string

type VersionNotFoundError

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

func (*VersionNotFoundError) Error

func (v *VersionNotFoundError) Error() string

Jump to

Keyboard shortcuts

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