secretcache

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2024 License: Apache-2.0 Imports: 10 Imported by: 2

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

Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at

http://aws.amazon.com/apache2.0/

or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

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

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	CacheConfig
	Client SecretsManagerAPIClient
	// 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 config.LoadDefaultConfig. 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

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

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

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

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

func (*Cache) RefreshNow

func (c *Cache) RefreshNow(secretId string)

Method to force the refresh of a secret inside the cache

func (*Cache) RefreshNowWithContext

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

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