type Cache - AWS Secrets Manager

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

type Cache

适用于从 Secrets Manager 请求的密钥的内存中缓存。您使用 GetSecretStringGetSecretBinary 从缓存中检索密钥。

下面的示例演示了如何配置缓存设置。

// Create a custom secretsmanager client client := getCustomClient() // Create a custom CacheConfig struct config := secretcache. CacheConfig{ MaxCacheSize: secretcache.DefaultMaxCacheSize + 10, VersionStage: secretcache.DefaultVersionStage, CacheItemTTL: secretcache.DefaultCacheItemTTL, } // Instantiate the cache cache, _ := secretcache.New( func( c *secretcache.Cache) { c. CacheConfig = config }, func( c *secretcache.Cache) { c. Client = client }, )

有关包括示例在内的更多信息,请参阅 检索 Go 应用程序中的 AWS Secrets Manager 密钥

方法

New

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

New 使用功能选项构造密钥缓存,否则将使用默认值。在新会话中初始化 SecretsManager 客户端。将 CacheConfig 初始化为默认值。使用默认最大大小初始化 LRU 缓存。

GetSecretString

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

GetSecretString 从缓存中获取给定密钥 ID 的密钥字符串值。返回密钥字符串,如果操作失败则返回错误。

GetSecretStringWithStage

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

GetSecretStringWithStage 从缓存中获取给定密钥 ID 和版本阶段的密钥字符串值。返回密钥字符串,如果操作失败则返回错误。

GetSecretBinary

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

GetSecretBinary 从缓存中获取给定密钥 ID 的密钥二进制值。返回密钥二进制值,如果操作失败则返回错误。

GetSecretBinaryWithStage

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

GetSecretBinaryWithStage 从缓存中获取给定密钥 ID 和版本阶段的密钥二进制值。返回密钥二进制值,如果操作失败则返回错误。