-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
inmem_sink.go
45 lines (36 loc) · 958 Bytes
/
inmem_sink.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
40
41
42
43
44
45
package inmem
import (
"errors"
hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/command/agent/cache"
"github.com/hashicorp/vault/command/agent/sink"
"go.uber.org/atomic"
)
// inmemSink retains the auto-auth token in memory and exposes it via
// sink.SinkReader interface.
type inmemSink struct {
logger hclog.Logger
token *atomic.String
leaseCache *cache.LeaseCache
}
// New creates a new instance of inmemSink.
func New(conf *sink.SinkConfig, leaseCache *cache.LeaseCache) (sink.Sink, error) {
if conf.Logger == nil {
return nil, errors.New("nil logger provided")
}
return &inmemSink{
logger: conf.Logger,
leaseCache: leaseCache,
token: atomic.NewString(""),
}, nil
}
func (s *inmemSink) WriteToken(token string) error {
s.token.Store(token)
if s.leaseCache != nil {
s.leaseCache.RegisterAutoAuthToken(token)
}
return nil
}
func (s *inmemSink) Token() string {
return s.token.Load()
}