Violet Hynes 6b4b0f7aaf
VAULT-15547 First pass at agent/proxy decoupling (#20548)
* VAULT-15547 First pass at agent/proxy decoupling

* VAULT-15547 Fix some imports

* VAULT-15547 cases instead of string.Title

* VAULT-15547 changelog

* VAULT-15547 Fix some imports

* VAULT-15547 some more dependency updates

* VAULT-15547 More dependency paths

* VAULT-15547 godocs for tests

* VAULT-15547 godocs for tests

* VAULT-15547 test package updates

* VAULT-15547 test packages

* VAULT-15547 add proxy to test packages

* VAULT-15547 gitignore

* VAULT-15547 address comments

* VAULT-15547 Some typos and small fixes
2023-05-17 09:38:34 -04:00

49 lines
1.0 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package inmem
import (
"errors"
hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/command/agentproxyshared/cache"
"github.com/hashicorp/vault/command/agentproxyshared/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()
}