-
Notifications
You must be signed in to change notification settings - Fork 6
/
api.go
39 lines (32 loc) · 985 Bytes
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package secretsmgr
import (
"sync"
"time"
"github.com/Cloud-Foundations/golib/pkg/log"
"github.com/aws/aws-sdk-go/aws/ec2metadata"
"github.com/aws/aws-sdk-go/service/secretsmanager"
)
type CachedSecret struct {
awsService *secretsmanager.SecretsManager
fetchTime time.Time
logger log.DebugLogger
maximumAge time.Duration
mutex sync.Mutex
secretId string
secrets map[string]string
}
func GetAwsSecret(metadataClient *ec2metadata.EC2Metadata,
secretId string, logger log.DebugLogger) (map[string]string, error) {
return getAwsSecret(metadataClient, secretId, logger)
}
func NewCachedSecret(metadataClient *ec2metadata.EC2Metadata,
secretId string, maximumAge time.Duration,
logger log.DebugLogger) (*CachedSecret, error) {
return newCachedSecret(metadataClient, secretId, maximumAge, logger)
}
func (cs *CachedSecret) GetSecret() (map[string]string, error) {
return cs.getSecret()
}
func (cs *CachedSecret) String() string {
return cs.secretId
}