@@ -57,7 +57,6 @@ type Generatoriface interface {
5757type GenVarsiface interface {
5858 Generatoriface
5959 Config () * GenVarsConfig
60- ConfigOutputPath () string
6160}
6261
6362type muRawMap struct {
@@ -76,15 +75,12 @@ type GenVars struct {
7675 ctx context.Context
7776 config GenVarsConfig
7877 outString []string
79- // rawMap is the internal object that holds the values of original token => retrieved value - decrypted in plain text
78+ // rawMap is the internal object that holds the values
79+ // of original token => retrieved value - decrypted in plain text
80+ // with a mutex RW locker
8081 rawMap muRawMap //ParsedMap
8182}
8283
83- // setValue implements GenVarsiface
84- func (* GenVars ) setValue (s string ) {
85- panic ("unimplemented" )
86- }
87-
8884// ParsedMap is the internal working object definition and
8985// the return type if results are not flushed to file
9086type ParsedMap map [string ]any
@@ -131,12 +127,6 @@ func (c *GenVars) Config() *GenVarsConfig {
131127 return & c .config
132128}
133129
134- // ConfigOutputPath returns the output path set on GenVars create
135- // withconfig or default value
136- func (c * GenVars ) ConfigOutputPath () string {
137- return c .config .outpath
138- }
139-
140130func (c * GenVars ) RawMap () ParsedMap {
141131 c .rawMap .RLock ()
142132 defer c .rawMap .RUnlock ()
@@ -154,41 +144,6 @@ func (c *GenVars) AddRawMap(key, val string) {
154144 c .rawMap .tokenMap [key ] = c .keySeparatorLookup (key , val )
155145}
156146
157- // GenVarsConfig defines the input config object to be passed
158- type GenVarsConfig struct {
159- outpath string
160- tokenSeparator string
161- keySeparator string
162- }
163-
164- // NewConfig
165- func NewConfig () * GenVarsConfig {
166- return & GenVarsConfig {
167- tokenSeparator : tokenSeparator ,
168- keySeparator : keySeparator ,
169- }
170- }
171-
172- // WithOutputPath
173- func (c * GenVarsConfig ) WithOutputPath (out string ) * GenVarsConfig {
174- c .outpath = out
175- return c
176- }
177-
178- // WithTokenSeparator adds a custom token separator
179- // token is the actual value of the parameter/secret in the
180- // provider store
181- func (c * GenVarsConfig ) WithTokenSeparator (tokenSeparator string ) * GenVarsConfig {
182- c .tokenSeparator = tokenSeparator
183- return c
184- }
185-
186- // WithKeySeparator adds a custom key separotor
187- func (c * GenVarsConfig ) WithKeySeparator (keySeparator string ) * GenVarsConfig {
188- c .keySeparator = keySeparator
189- return c
190- }
191-
192147// Generate generates a k/v map of the tokens with their corresponding secret/paramstore values
193148// the standard pattern of a token should follow a path like
194149func (c * GenVars ) Generate (tokens []string ) (ParsedMap , error ) {
@@ -215,7 +170,8 @@ type chanResp struct {
215170}
216171
217172type retrieveIface interface {
218- retrieveSpecificCh (ctx context.Context , prefix ImplementationPrefix , in string ) chanResp
173+ RetrieveByToken (ctx context.Context , impl genVarsStrategy , prefix ImplementationPrefix , in string ) chanResp
174+ SelectImplementation (ctx context.Context , prefix ImplementationPrefix , in string , config * GenVarsConfig ) (genVarsStrategy , error )
219175}
220176
221177// generate checks if any tokens found
@@ -238,7 +194,12 @@ func (c *GenVars) generate(rawMap map[string]string, rs retrieveIface) error {
238194 for token , prefix := range rawMap {
239195 go func (a string , p ImplementationPrefix ) {
240196 defer wg .Done ()
241- outCh <- rs .retrieveSpecificCh (c .ctx , p , a )
197+ strategy , err := rs .SelectImplementation (c .ctx , p , a , c .Config ())
198+ if err != nil {
199+ outCh <- chanResp {err : err }
200+ return
201+ }
202+ outCh <- rs .RetrieveByToken (c .ctx , strategy , p , a )
242203 }(token , ImplementationPrefix (prefix ))
243204 }
244205
0 commit comments