1- // Package strategy is a strategy pattern wrapper around the store implementations
2- //
3- // NOTE: this may be refactored out into the store package directly
1+ // Package strategy is a factory method wrapper around the backing store implementations
42package strategy
53
64import (
@@ -53,20 +51,17 @@ type strategyFnMap struct {
5351 funcMap StrategyFuncMap
5452}
5553
56- type RetrieveStrategy struct {
57- // mu *sync.Mutex
58- implementation store.Strategy
54+ type Strategy struct {
5955 config config.GenVarsConfig
6056 strategyFuncMap strategyFnMap
6157}
6258
63- type Opts func (* RetrieveStrategy )
59+ type Opts func (* Strategy )
6460
6561// New
66- func New (config config.GenVarsConfig , logger log.ILogger , opts ... Opts ) * RetrieveStrategy {
67- rs := & RetrieveStrategy {
68- config : config ,
69- // mu: &sync.Mutex{},
62+ func New (config config.GenVarsConfig , logger log.ILogger , opts ... Opts ) * Strategy {
63+ rs := & Strategy {
64+ config : config ,
7065 strategyFuncMap : strategyFnMap {mu : sync.Mutex {}, funcMap : defaultStrategyFuncMap (logger )},
7166 }
7267 // overwrite or add any options/defaults set above
@@ -82,7 +77,7 @@ func New(config config.GenVarsConfig, logger log.ILogger, opts ...Opts) *Retriev
8277// Mainly used for testing
8378// NOTE: this may lead to eventual optional configurations by users
8479func WithStrategyFuncMap (funcMap StrategyFuncMap ) Opts {
85- return func (rs * RetrieveStrategy ) {
80+ return func (rs * Strategy ) {
8681 rs .strategyFuncMap .mu .Lock ()
8782 defer rs .strategyFuncMap .mu .Unlock ()
8883 for prefix , implementation := range funcMap {
@@ -93,7 +88,7 @@ func WithStrategyFuncMap(funcMap StrategyFuncMap) Opts {
9388
9489// GetImplementation is a factory method returning the concrete implementation for the retrieval of the token value
9590// i.e. facilitating the exchange of the supplied token for the underlying value
96- func (rs * RetrieveStrategy ) GetImplementation (ctx context.Context , token * config.ParsedTokenConfig ) (store.Strategy , error ) {
91+ func (rs * Strategy ) GetImplementation (ctx context.Context , token * config.ParsedTokenConfig ) (store.Strategy , error ) {
9792 if token == nil {
9893 return nil , fmt .Errorf ("unable to get prefix, %w" , ErrTokenInvalid )
9994 }
@@ -114,24 +109,6 @@ func ExchangeToken(s store.Strategy, token *config.ParsedTokenConfig) *TokenResp
114109 return cr
115110}
116111
117- // func (rs *RetrieveStrategy) setImplementation(strategy store.Strategy) {
118- // rs.mu.Lock()
119- // defer rs.mu.Unlock()
120- // rs.implementation = strategy
121- // }
122-
123- // func (rs *RetrieveStrategy) setTokenVal(s *config.ParsedTokenConfig) {
124- // rs.mu.Lock()
125- // defer rs.mu.Unlock()
126- // rs.implementation.SetToken(s)
127- // }
128-
129- // func (rs *RetrieveStrategy) getTokenValue() (string, error) {
130- // rs.mu.Lock()
131- // defer rs.mu.Unlock()
132- // return rs.implementation.Token()
133- // }
134-
135112type TokenResponse struct {
136113 value string
137114 key * config.ParsedTokenConfig
0 commit comments