open-vault/command/agent/sink/inmem/inmem_sink.go
Calvin Leung Huang c07253999c
agent/caching: enable caching of leases generated by autoauth token (#6293)
* agent/caching: enable caching of leases generated by autoauth token

* add test for auth/token/create path

* update error message log

* Some minor updates

* add sleep timer for renewal logic to process
2019-02-27 13:14:58 -08:00

44 lines
880 B
Go

package inmem
import (
"errors"
hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/command/agent/cache"
"github.com/hashicorp/vault/command/agent/sink"
)
// inmemSink retains the auto-auth token in memory and exposes it via
// sink.SinkReader interface.
type inmemSink struct {
logger hclog.Logger
token 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,
}, nil
}
func (s *inmemSink) WriteToken(token string) error {
s.token = token
if s.leaseCache != nil {
s.leaseCache.RegisterAutoAuthToken(token)
}
return nil
}
func (s *inmemSink) Token() string {
return s.token
}