Skip to content

Commit 2584732

Browse files
committed
fix: experiment with WASI
NOTE: it is a no go - but still valuable insight into sandboxing by the runtime
1 parent c467ce9 commit 2584732

File tree

17 files changed

+1173
-82
lines changed

17 files changed

+1173
-82
lines changed

cmd/configmanager/configmanager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func cmdutilsInit(rootCmd *Root, cmd *cobra.Command, path string) (*cmdutils.Cmd
7373

7474
cm := configmanager.New(cmd.Context())
7575
cm.Config.WithTokenSeparator(rootCmd.rootFlags.tokenSeparator).WithOutputPath(path).WithKeySeparator(rootCmd.rootFlags.keySeparator).WithEnvSubst(rootCmd.rootFlags.enableEnvSubst)
76-
gnrtr := generator.NewGenerator(cmd.Context(), func(gv *generator.GenVars) {
76+
gnrtr := generator.New(cmd.Context(), func(gv *generator.Generator) {
7777
if rootCmd.rootFlags.verbose {
7878
rootCmd.logger.SetLevel(log.DebugLvl)
7979
}

configmanager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type ConfigManager struct {
4646
func New(ctx context.Context) *ConfigManager {
4747
cm := &ConfigManager{}
4848
cm.Config = config.NewConfig()
49-
cm.generator = generator.NewGenerator(ctx).WithConfig(cm.Config)
49+
cm.generator = generator.New(ctx).WithConfig(cm.Config)
5050
cm.logger = log.New(io.Discard)
5151
return cm
5252
}

generator/generator.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,32 @@ import (
1717
"github.com/DevLabFoundry/configmanager/v3/internal/strategy"
1818
)
1919

20-
// GenVars is the main struct holding the
20+
// Generator is the main struct holding the
2121
// strategy patterns iface
2222
// any initialised config if overridded with withers
2323
// as well as the final outString and the initial rawMap
2424
// which wil be passed in a loop into a goroutine to perform the
2525
// relevant strategy network calls to the config store implementations
26-
type GenVars struct {
26+
type Generator struct {
2727
Logger log.ILogger
2828
strategy strategy.StrategyFuncMap
2929
ctx context.Context
3030
config config.GenVarsConfig
3131
}
3232

33-
type Opts func(*GenVars)
33+
type Opts func(*Generator)
3434

35-
// NewGenerator returns a new instance of Generator
35+
// New returns a new instance of Generator
3636
// with a default strategy pattern wil be overwritten
3737
// during the first run of a found tokens map
38-
func NewGenerator(ctx context.Context, opts ...Opts) *GenVars {
38+
func New(ctx context.Context, opts ...Opts) *Generator {
3939
// defaultStrategy := NewDefatultStrategy()
40-
return newGenVars(ctx, opts...)
40+
return new(ctx, opts...)
4141
}
4242

43-
func newGenVars(ctx context.Context, opts ...Opts) *GenVars {
43+
func new(ctx context.Context, opts ...Opts) *Generator {
4444
conf := config.NewConfig()
45-
g := &GenVars{
45+
g := &Generator{
4646
Logger: log.New(io.Discard),
4747
ctx: ctx,
4848
// return using default config
@@ -61,13 +61,13 @@ func newGenVars(ctx context.Context, opts ...Opts) *GenVars {
6161
// WithStrategyMap
6262
//
6363
// Adds addtional funcs for storageRetrieval used for testing only
64-
func (c *GenVars) WithStrategyMap(sm strategy.StrategyFuncMap) *GenVars {
64+
func (c *Generator) WithStrategyMap(sm strategy.StrategyFuncMap) *Generator {
6565
c.strategy = sm
6666
return c
6767
}
6868

6969
// WithConfig uses custom config
70-
func (c *GenVars) WithConfig(cfg *config.GenVarsConfig) *GenVars {
70+
func (c *Generator) WithConfig(cfg *config.GenVarsConfig) *Generator {
7171
// backwards compatibility
7272
if cfg != nil {
7373
c.config = *cfg
@@ -76,21 +76,21 @@ func (c *GenVars) WithConfig(cfg *config.GenVarsConfig) *GenVars {
7676
}
7777

7878
// WithContext uses caller passed context
79-
func (c *GenVars) WithContext(ctx context.Context) *GenVars {
79+
func (c *Generator) WithContext(ctx context.Context) *Generator {
8080
c.ctx = ctx
8181
return c
8282
}
8383

8484
// Config gets Config on the GenVars
85-
func (c *GenVars) Config() *config.GenVarsConfig {
85+
func (c *Generator) Config() *config.GenVarsConfig {
8686
return &c.config
8787
}
8888

8989
// Generate generates a k/v map of the tokens with their corresponding secret/paramstore values
9090
// the standard pattern of a token should follow a path like string
9191
//
9292
// Called only from a slice of tokens
93-
func (c *GenVars) Generate(tokens []string) (ReplacedToken, error) {
93+
func (c *Generator) Generate(tokens []string) (ReplacedToken, error) {
9494

9595
ntm, err := c.DiscoverTokens(strings.Join(tokens, "\n"))
9696
if err != nil {
@@ -112,7 +112,7 @@ var ErrTokenDiscovery = errors.New("failed to discover tokens")
112112
// the standard pattern of a token should follow a path like string
113113
//
114114
// Called only from a slice of tokens
115-
func (c *GenVars) DiscoverTokens(text string) (NormalizedTokenSafe, error) {
115+
func (c *Generator) DiscoverTokens(text string) (NormalizedTokenSafe, error) {
116116

117117
rtm := NewRawTokenConfig()
118118

@@ -144,7 +144,7 @@ func IsParsed(v any, trm ReplacedToken) bool {
144144
// Captures the response/error in TokenResponse struct
145145
// It then denormalizes the NormalizedTokenSafe back to a ReplacedToken map
146146
// which stores the values for each token to be returned to the caller
147-
func (c *GenVars) generate(ntm NormalizedTokenSafe) (ReplacedToken, error) {
147+
func (c *Generator) generate(ntm NormalizedTokenSafe) (ReplacedToken, error) {
148148
if len(ntm.normalizedTokenMap) < 1 {
149149
c.Logger.Debug("no replaceable tokens found in input")
150150
return nil, nil
@@ -232,7 +232,7 @@ func (n NormalizedTokenSafe) GetMap() map[string]*NormalizedToken {
232232
return n.normalizedTokenMap
233233
}
234234

235-
func (c *GenVars) NormalizeRawToken(rtm *RawTokenConfig) NormalizedTokenSafe {
235+
func (c *Generator) NormalizeRawToken(rtm *RawTokenConfig) NormalizedTokenSafe {
236236
ntm := NormalizedTokenSafe{mu: &sync.Mutex{}, normalizedTokenMap: make(map[string]*NormalizedToken)}
237237

238238
for _, r := range rtm.RawTokenMap() {

generator/generator_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestGenerate(t *testing.T) {
3434
return m, nil
3535
}
3636

37-
g := generator.NewGenerator(context.TODO(), func(gv *generator.GenVars) {
37+
g := generator.New(context.TODO(), func(gv *generator.Generator) {
3838
gv.Logger = log.New(&bytes.Buffer{})
3939
})
4040
g.WithStrategyMap(strategy.StrategyFuncMap{config.ParamStorePrefix: custFunc})
@@ -54,7 +54,7 @@ func TestGenerate(t *testing.T) {
5454
return m, nil
5555
}
5656

57-
g := generator.NewGenerator(context.TODO())
57+
g := generator.New(context.TODO())
5858
g.WithStrategyMap(strategy.StrategyFuncMap{config.ParamStorePrefix: custFunc})
5959
got, err := g.Generate([]string{"AWSPARAMSTR://mountPath/token"})
6060

@@ -72,7 +72,7 @@ func TestGenerate(t *testing.T) {
7272
return m, nil
7373
}
7474

75-
g := generator.NewGenerator(context.TODO())
75+
g := generator.New(context.TODO())
7676
g.WithStrategyMap(strategy.StrategyFuncMap{config.ParamStorePrefix: custFunc})
7777
got, err := g.Generate([]string{"AWSPARAMSTR://mountPath/token|key1.key2"})
7878

@@ -129,7 +129,7 @@ func TestGenerate_withKeys_lookup(t *testing.T) {
129129
}
130130
for name, tt := range ttests {
131131
t.Run(name, func(t *testing.T) {
132-
g := generator.NewGenerator(context.TODO())
132+
g := generator.New(context.TODO())
133133
g.WithStrategyMap(strategy.StrategyFuncMap{config.ParamStorePrefix: tt.custFunc})
134134
got, err := g.Generate([]string{tt.token})
135135

@@ -175,7 +175,7 @@ func Test_IsParsed(t *testing.T) {
175175
func TestGenVars_NormalizeRawToken(t *testing.T) {
176176

177177
t.Run("multiple tokens", func(t *testing.T) {
178-
g := generator.NewGenerator(context.TODO())
178+
g := generator.New(context.TODO())
179179

180180
input := `GCPSECRETS:///djsfsdkjvfjkhfdvibdfinjdsfnjvdsflj
181181
GCPSECRETS:///djsfsdkjvfjkhfdvibdfinjdsfnjvdsflj|a
@@ -298,7 +298,7 @@ func Test_ConfigManager_DiscoverTokens(t *testing.T) {
298298
for name, tt := range ttests {
299299
t.Run(name, func(t *testing.T) {
300300
config.VarPrefix = map[config.ImplementationPrefix]bool{"AWSPARAMSTR": true}
301-
g := generator.NewGenerator(context.TODO())
301+
g := generator.New(context.TODO())
302302
g.Config().WithTokenSeparator(tt.separator)
303303
gdt, err := g.DiscoverTokens(tt.input)
304304
if err != nil {
@@ -319,7 +319,7 @@ func Test_ConfigManager_DiscoverTokens(t *testing.T) {
319319
}
320320

321321
func Test_Generate_EnsureRaceFree(t *testing.T) {
322-
g := generator.NewGenerator(context.TODO())
322+
g := generator.New(context.TODO())
323323

324324
input := `
325325
fg

generator/generatorvars.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,6 @@ func (rtm *RawTokenConfig) RawTokenMap() map[string]*config.ParsedTokenConfig {
4343
return rtm.tokenMap
4444
}
4545

46-
// type tokenMapSafe struct {
47-
// mu *sync.Mutex
48-
// tokenMap ReplacedToken
49-
// }
50-
51-
// func (tms *tokenMapSafe) getTokenMap() ReplacedToken {
52-
// tms.mu.Lock()
53-
// defer tms.mu.Unlock()
54-
// return tms.tokenMap
55-
// }
56-
57-
// func (tms *tokenMapSafe) addKeyVal(key *config.ParsedTokenConfig, val string) {
58-
// tms.mu.Lock()
59-
// defer tms.mu.Unlock()
60-
// // NOTE: still use the metadata in the key
61-
// // there could be different versions / labels for the same token and hence different values
62-
// // However the JSONpath look up
63-
// tms.tokenMap[key.String()] = keySeparatorLookup(key, val)
64-
// }
65-
6646
// keySeparatorLookup checks if the key contains
6747
// keySeparator character
6848
// If it does contain one then it tries to parse

go.mod

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
module github.com/DevLabFoundry/configmanager/v3
22

3-
go 1.25.3
3+
go 1.25.4
44

55
require (
66
cloud.google.com/go/secretmanager v1.16.0
7-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.19.1
8-
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.13.0
7+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.20.0
8+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.13.1
99
github.com/Azure/azure-sdk-for-go/sdk/data/azappconfig v1.2.0
10-
github.com/Azure/azure-sdk-for-go/sdk/data/aztables v1.4.0
10+
github.com/Azure/azure-sdk-for-go/sdk/data/aztables v1.4.1
1111
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azsecrets v1.4.0
12-
github.com/aws/aws-sdk-go-v2 v1.39.6
13-
github.com/aws/aws-sdk-go-v2/config v1.31.17
14-
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.39.11
15-
github.com/aws/aws-sdk-go-v2/service/ssm v1.66.4
12+
github.com/aws/aws-sdk-go-v2 v1.40.0
13+
github.com/aws/aws-sdk-go-v2/config v1.32.0
14+
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.40.1
15+
github.com/aws/aws-sdk-go-v2/service/ssm v1.67.3
1616
github.com/go-test/deep v1.1.1
1717
github.com/googleapis/gax-go/v2 v2.15.0
1818
github.com/hashicorp/vault/api v1.22.0
@@ -22,6 +22,8 @@ require (
2222
gopkg.in/yaml.v3 v3.0.1
2323
)
2424

25+
require github.com/aws/aws-sdk-go-v2/service/signin v1.0.1 // indirect
26+
2527
require (
2628
cloud.google.com/go/auth v0.17.0 // indirect
2729
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
@@ -32,16 +34,16 @@ require (
3234
github.com/AzureAD/microsoft-authentication-library-for-go v1.6.0 // indirect
3335
github.com/a8m/envsubst v1.4.3
3436
github.com/aws/aws-sdk-go v1.55.8 // indirect
35-
github.com/aws/aws-sdk-go-v2/credentials v1.18.21 // indirect
36-
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.13 // indirect
37-
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.13 // indirect
38-
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.13 // indirect
37+
github.com/aws/aws-sdk-go-v2/credentials v1.19.0 // indirect
38+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.14 // indirect
39+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.14 // indirect
40+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.14 // indirect
3941
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 // indirect
4042
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.3 // indirect
41-
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.13 // indirect
42-
github.com/aws/aws-sdk-go-v2/service/sso v1.30.1 // indirect
43-
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.5 // indirect
44-
github.com/aws/aws-sdk-go-v2/service/sts v1.39.1 // indirect
43+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.14 // indirect
44+
github.com/aws/aws-sdk-go-v2/service/sso v1.30.4 // indirect
45+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.8 // indirect
46+
github.com/aws/aws-sdk-go-v2/service/sts v1.41.1 // indirect
4547
github.com/aws/smithy-go v1.23.2 // indirect
4648
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
4749
github.com/fatih/color v1.18.0 // indirect
@@ -76,23 +78,24 @@ require (
7678
github.com/pkg/errors v0.9.1 // indirect
7779
github.com/ryanuber/go-glob v1.0.0 // indirect
7880
github.com/spf13/pflag v1.0.10 // indirect
81+
github.com/tetratelabs/wazero v1.10.1
7982
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
8083
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.63.0 // indirect
8184
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0 // indirect
8285
go.opentelemetry.io/otel v1.38.0 // indirect
8386
go.opentelemetry.io/otel/metric v1.38.0 // indirect
8487
go.opentelemetry.io/otel/trace v1.38.0 // indirect
85-
golang.org/x/crypto v0.43.0 // indirect
86-
golang.org/x/net v0.46.0 // indirect
87-
golang.org/x/oauth2 v0.32.0 // indirect
88-
golang.org/x/sync v0.17.0 // indirect
89-
golang.org/x/sys v0.37.0 // indirect
90-
golang.org/x/text v0.30.0 // indirect
88+
golang.org/x/crypto v0.45.0 // indirect
89+
golang.org/x/net v0.47.0 // indirect
90+
golang.org/x/oauth2 v0.33.0 // indirect
91+
golang.org/x/sync v0.18.0 // indirect
92+
golang.org/x/sys v0.38.0 // indirect
93+
golang.org/x/text v0.31.0 // indirect
9194
golang.org/x/time v0.14.0 // indirect
92-
google.golang.org/api v0.255.0 // indirect
93-
google.golang.org/genproto v0.0.0-20251103181224-f26f9409b101 // indirect
94-
google.golang.org/genproto/googleapis/api v0.0.0-20251103181224-f26f9409b101 // indirect
95-
google.golang.org/genproto/googleapis/rpc v0.0.0-20251103181224-f26f9409b101 // indirect
96-
google.golang.org/grpc v1.76.0 // indirect
95+
google.golang.org/api v0.256.0 // indirect
96+
google.golang.org/genproto v0.0.0-20251111163417-95abcf5c77ba // indirect
97+
google.golang.org/genproto/googleapis/api v0.0.0-20251111163417-95abcf5c77ba // indirect
98+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251111163417-95abcf5c77ba // indirect
99+
google.golang.org/grpc v1.77.0 // indirect
97100
google.golang.org/protobuf v1.36.10 // indirect
98101
)

0 commit comments

Comments
 (0)