Skip to content

Commit e199688

Browse files
committed
fix: add more interim init changes
1 parent dcdc163 commit e199688

9 files changed

Lines changed: 269 additions & 35 deletions

File tree

cmd/configmanager/init.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package cmd
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
type initFlags struct {
8+
}
9+
10+
func newInitCmd(rootCmd *Root) {
11+
12+
// f := &initFlags{}
13+
14+
initCmd := &cobra.Command{
15+
Use: "init",
16+
Aliases: []string{},
17+
Short: ``,
18+
Long: ``,
19+
RunE: func(cmd *cobra.Command, args []string) error {
20+
// c := generator.New(cmd.Context(), func(gv *generator.Generator) {
21+
// if rootCmd.rootFlags.verbose {
22+
// rootCmd.logger.SetLevel(log.DebugLvl)
23+
// }
24+
// gv.Logger = rootCmd.logger
25+
// }).WithConfig(config.NewConfig().WithTokenSeparator(rootCmd.rootFlags.tokenSeparator).WithKeySeparator(rootCmd.rootFlags.keySeparator))
26+
27+
// // ntm, err := c.DiscoverTokens("")
28+
// if err != nil {
29+
// return err
30+
// }
31+
32+
// initialise pugins here based on discovered tokens
33+
// //
34+
// // this can only be done once the tokens are known
35+
// if err := c.store.Init(cmd.Context(), ntm.TokenSet()); err != nil {
36+
// return nil, fmt.Errorf("%w, %v", ErrProvidersNotFound, err)
37+
// }
38+
// defer c.store.PluginCleanUp()
39+
return nil
40+
},
41+
}
42+
43+
rootCmd.Cmd.AddCommand(initCmd)
44+
}

configmanager.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ import (
1515
"github.com/a8m/envsubst"
1616
)
1717

18-
const (
19-
TERMINATING_CHAR string = `[^\'\"\s\n\\\,]` // :\@\?\/
20-
)
21-
2218
// generateAPI
2319
type generateAPI interface {
2420
Generate(tokens []string) (generator.ReplacedToken, error)

generator/generator.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var ErrProvidersNotFound = errors.New("providers not initialised")
2323
type storeIface interface {
2424
GetValue(implemenation *config.ParsedTokenConfig) (string, error)
2525
Init(ctx context.Context, implt []string) error
26+
PluginCleanUp()
2627
}
2728

2829
// Generator is the main struct holding the
@@ -95,6 +96,8 @@ func (c *Generator) Config() *config.GenVarsConfig {
9596
return &c.config
9697
}
9798

99+
func (c *Generator) InitPlugins()
100+
98101
// Generate generates a k/v map of the tokens with their corresponding secret/paramstore values
99102
// the standard pattern of a token should follow a path like string
100103
//
@@ -112,7 +115,7 @@ func (c *Generator) Generate(tokens []string) (ReplacedToken, error) {
112115
if err := c.store.Init(c.ctx, ntm.TokenSet()); err != nil {
113116
return nil, fmt.Errorf("%w, %v", ErrProvidersNotFound, err)
114117
}
115-
118+
defer c.store.PluginCleanUp()
116119
// pass in default initialised retrieveStrategy
117120
// input should be
118121
rt, err := c.generate(ntm)

generator/generator_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ func (m mockStore) Init(ctx context.Context, implt []string) error {
2828
return nil
2929
}
3030

31+
func (m mockStore) PluginCleanUp() {}
32+
3133
func Test_Generate(t *testing.T) {
3234

3335
t.Run("succeeds", func(t *testing.T) {

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ require (
1717
github.com/golang/protobuf v1.5.4 // indirect
1818
github.com/hashicorp/yamux v0.1.2 // indirect
1919
github.com/kr/pretty v0.3.1 // indirect
20+
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
2021
github.com/oklog/run v1.2.0 // indirect
22+
github.com/rivo/uniseg v0.4.7 // indirect
2123
github.com/rogpeppe/go-internal v1.14.1 // indirect
2224
github.com/stretchr/testify v1.11.1 // indirect
25+
golang.org/x/term v0.41.0 // indirect
2326
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
2427
)
2528

@@ -31,6 +34,7 @@ require (
3134
github.com/inconshreveable/mousetrap v1.1.0 // indirect
3235
github.com/mattn/go-colorable v0.1.14 // indirect
3336
github.com/mattn/go-isatty v0.0.20 // indirect
37+
github.com/schollz/progressbar/v3 v3.19.0
3438
github.com/spf13/pflag v1.0.10 // indirect
3539
golang.org/x/net v0.52.0 // indirect
3640
golang.org/x/sys v0.42.0 // indirect

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,21 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
4949
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
5050
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
5151
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
52+
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
53+
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
5254
github.com/oklog/run v1.2.0 h1:O8x3yXwah4A73hJdlrwo/2X6J62gE5qTMusH0dvz60E=
5355
github.com/oklog/run v1.2.0/go.mod h1:mgDbKRSwPhJfesJ4PntqFUbKQRZ50NgmZTSPlFA0YFk=
5456
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
5557
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5658
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
59+
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
60+
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
5761
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
5862
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
5963
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
6064
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
65+
github.com/schollz/progressbar/v3 v3.19.0 h1:Ea18xuIRQXLAUidVDox3AbwfUhD0/1IvohyTutOIFoc=
66+
github.com/schollz/progressbar/v3 v3.19.0/go.mod h1:IsO3lpbaGuzh8zIMzgY3+J8l4C8GjO0Y9S69eFvNsec=
6167
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
6268
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
6369
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
@@ -92,6 +98,8 @@ golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBc
9298
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9399
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
94100
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
101+
golang.org/x/term v0.41.0 h1:QCgPso/Q3RTJx2Th4bDLqML4W6iJiaXFq2/ftQF13YU=
102+
golang.org/x/term v0.41.0/go.mod h1:3pfBgksrReYfZ5lvYM0kSO0LIkAl4Yl2bXOkKP7Ec2A=
95103
golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8=
96104
golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA=
97105
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=

internal/store/plugin.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,29 @@ func (p *Plugin) GetValue(token *config.ParsedTokenConfig) (string, error) {
6868
}
6969
return result, nil
7070
}
71+
72+
type PluginDownloadInfo struct {
73+
BaseUrl string
74+
Name string
75+
}
76+
77+
const corePluginBaseUrl = "https://github.com/DevLabFoundry/configmanager/releases"
78+
79+
type PluginDownloadInfoMap map[string]*PluginDownloadInfo
80+
81+
// corePluginMap are the configmanager maintained plugins
82+
var corePluginMap PluginDownloadInfoMap = map[string]*PluginDownloadInfo{
83+
"empty": {
84+
BaseUrl: corePluginBaseUrl,
85+
Name: "",
86+
},
87+
"awsparamstr": {
88+
BaseUrl: corePluginBaseUrl,
89+
Name: "",
90+
},
91+
"awssecrets": {
92+
BaseUrl: corePluginBaseUrl,
93+
Name: "",
94+
},
95+
// ...
96+
}

0 commit comments

Comments
 (0)