@@ -15,33 +15,27 @@ const (
1515 tokenSeparator = "#"
1616 // keySeparator used for accessing nested
1717 // objects within the retrieved map
18- keySeparator = "|"
19- secretMgrPrefix = "AWSSECRETS"
20- paramStorePrefix = "AWSPARAMSTR "
21-
18+ keySeparator = "|"
19+ //
20+ // secretMgrPrefix = "AWSSECRETS "
21+ // paramStorePrefix = "AWSPARAMSTR"
2222 SecretMgrPrefix = "AWSSECRETS"
2323 ParamStorePrefix = "AWSPARAMSTR"
2424)
2525
26- // // VarPrefix maps implementation to prefix
27- // type VarPrefix struct {
28- // secretsMgr string
29- // paramStore string
30- // }
31-
3226var (
33- // varPrefix = VarPrefix{secretsMgr: secretMgrPrefix, paramStore: paramStorePrefix}
3427 // default varPrefix
3528 VarPrefix = map [string ]bool {SecretMgrPrefix : true , ParamStorePrefix : true }
3629)
3730
38- type genVarsStrategy interface {
39- getTokenValue ( c * genVars ) (s string , e error )
40- setToken ( s string )
41- setValue ( s string )
31+ type Generatoriface interface {
32+ Generate ( tokens [] string ) (ParsedMap , error )
33+ ConvertToExportVar ( )
34+ FlushToFile () ( string , error )
4235}
4336
44- type genVars struct {
37+ type GenVars struct {
38+ Generatoriface
4539 implementation genVarsStrategy
4640 token string
4741 ctx context.Context
@@ -56,18 +50,18 @@ type genVars struct {
5650type ParsedMap map [string ]any
5751
5852// NewGenerator returns a new instance
59- func NewGenerator () * genVars {
53+ func NewGenerator () * GenVars {
6054 defaultStrategy := NewDefatultStrategy ()
6155 return newGenVars (defaultStrategy )
6256}
6357
64- func newGenVars (e genVarsStrategy ) * genVars {
58+ func newGenVars (e genVarsStrategy ) * GenVars {
6559 m := ParsedMap {}
6660 defaultConf := GenVarsConfig {
6761 tokenSeparator : tokenSeparator ,
6862 keySeparator : keySeparator ,
6963 }
70- return & genVars {
64+ return & GenVars {
7165 implementation : e ,
7266 rawMap : m ,
7367 // return using default config
@@ -76,7 +70,7 @@ func newGenVars(e genVarsStrategy) *genVars {
7670}
7771
7872// WithConfig uses custom config
79- func (c * genVars ) WithConfig (cfg * GenVarsConfig ) * genVars {
73+ func (c * GenVars ) WithConfig (cfg * GenVarsConfig ) * GenVars {
8074 // backwards compatibility
8175 if cfg != nil {
8276 c .config = * cfg
@@ -121,30 +115,13 @@ func (c *GenVarsConfig) WithKeySeparator(keySeparator string) *GenVarsConfig {
121115 return c
122116}
123117
124- func (c * genVars ) setImplementation (strategy genVarsStrategy ) {
125- c .implementation = strategy
126- }
127-
128- func (c * genVars ) setToken (s string ) {
129- c .implementation .setToken (s )
130- }
131-
132- func (c * genVars ) setVaule (s string ) {
133- c .implementation .setValue (s )
134- }
135-
136- func (c * genVars ) getTokenValue () (string , error ) {
137- log .Info ("Strategy implementation" )
138- return c .implementation .getTokenValue (c )
139- }
140-
141- func (c * genVars ) stripPrefix (in , prefix string ) string {
118+ func (c * GenVars ) stripPrefix (in , prefix string ) string {
142119 return strings .Replace (in , fmt .Sprintf ("%s%s" , prefix , c .config .tokenSeparator ), "" , 1 )
143120}
144121
145122// Generate generates a k/v map of the tokens with their corresponding secret/paramstore values
146123// the standard pattern of a token should follow a path like
147- func (c * genVars ) Generate (tokens []string ) (ParsedMap , error ) {
124+ func (c * GenVars ) Generate (tokens []string ) (ParsedMap , error ) {
148125
149126 for _ , token := range tokens {
150127 prefix := strings .Split (token , c .config .tokenSeparator )[0 ]
@@ -160,9 +137,9 @@ func (c *genVars) Generate(tokens []string) (ParsedMap, error) {
160137 return c .rawMap , nil
161138}
162139
163- func (c * genVars ) retrieveSpecific (prefix , in string ) (string , error ) {
140+ func (c * GenVars ) retrieveSpecific (prefix , in string ) (string , error ) {
164141 switch prefix {
165- case secretMgrPrefix :
142+ case SecretMgrPrefix :
166143 // default strategy paramstore
167144 scrtMgr , err := NewSecretsMgr (c .ctx )
168145 if err != nil {
@@ -171,7 +148,7 @@ func (c *genVars) retrieveSpecific(prefix, in string) (string, error) {
171148 c .setImplementation (scrtMgr )
172149 c .setToken (in )
173150 return c .getTokenValue ()
174- case paramStorePrefix :
151+ case ParamStorePrefix :
175152 paramStr , err := NewParamStore (c .ctx )
176153 if err != nil {
177154 return "" , err
@@ -199,7 +176,7 @@ func isParsed(res any, trm *ParsedMap) bool {
199176}
200177
201178// ConvertToExportVar
202- func (c * genVars ) ConvertToExportVar () {
179+ func (c * GenVars ) ConvertToExportVar () {
203180 for k , v := range c .rawMap {
204181 rawKeyToken := strings .Split (k , "/" ) // assumes a path like token was used
205182 topLevelKey := rawKeyToken [len (rawKeyToken )- 1 ]
@@ -223,7 +200,7 @@ func envVarNormalize(pmap ParsedMap) ParsedMap {
223200 return normalizedMap
224201}
225202
226- func (c * genVars ) exportVars (exportMap ParsedMap ) {
203+ func (c * GenVars ) exportVars (exportMap ParsedMap ) {
227204
228205 for k , v := range exportMap {
229206 // NOTE: \n line ending is not totally cross platform
@@ -244,7 +221,7 @@ func normalizeKey(k string) string {
244221 return strings .ToUpper (string (r ))
245222}
246223
247- func (c * genVars ) FlushToFile () (string , error ) {
224+ func (c * GenVars ) FlushToFile () (string , error ) {
248225
249226 // moved up to
250227 joinedStr := listToString (c .outString )
0 commit comments