Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Use hook to set map key after setter" #12

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type secretField struct {

type collector struct {
fields []*secretField
hooks []func()
err error
}

Expand Down Expand Up @@ -51,14 +50,10 @@ func (g *collector) collectSecretFields(v reflect.Value, path string) {
ptr := reflect.New(item.Type())
ptr.Elem().Set(item)

g.hooks = append(g.hooks, func() {
v.SetMapIndex(key, ptr.Elem())
})

g.collectSecretFields(ptr, fmt.Sprintf("%v[%v]", path, key))

// Set the modified struct back into the map

v.SetMapIndex(key, ptr.Elem())
} else {
g.collectSecretFields(item, fmt.Sprintf("%v[%v]", path, key))
}
Expand Down
10 changes: 1 addition & 9 deletions hydrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,5 @@ func hydrateConfig(ctx context.Context, provider secretsProvider, v reflect.Valu
})
}

if err := g.Wait(); err != nil {
return fmt.Errorf("failed to hydrate config: %w", err)
}

for _, hook := range c.hooks {
hook()
}

return nil
return g.Wait()
}
22 changes: 0 additions & 22 deletions hydrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ type config struct {
Analytics analytics
Pass string
JWTSecrets []string
Services map[string]service
}

type service struct {
URL string
Auth string
Pass string
}

type db struct {
Expand Down Expand Up @@ -59,7 +52,6 @@ func TestReplacePlaceholdersWithSecrets(t *testing.T) {
"pass": "secret",
"jwtSecretV1": "some-old-secret",
"jwtSecretV2": "changeme-now",
"auth": "auth-secret",
},
conf: &config{
Pass: "$SECRET:pass",
Expand All @@ -74,13 +66,6 @@ func TestReplacePlaceholdersWithSecrets(t *testing.T) {
AuthToken: "$SECRET:analyticsPassword",
},
JWTSecrets: []string{"$SECRET:jwtSecretV2", "$SECRET:jwtSecretV1"},
Services: map[string]service{
"a": {
URL: "http://localhost:8000",
Auth: "$SECRET:auth",
Pass: "$SECRET:jwtSecretV2",
},
},
},
wantErr: false,
wantConf: &config{
Expand All @@ -99,13 +84,6 @@ func TestReplacePlaceholdersWithSecrets(t *testing.T) {
"changeme-now",
"some-old-secret",
},
Services: map[string]service{
"a": {
URL: "http://localhost:8000",
Auth: "auth-secret",
Pass: "changeme-now",
},
},
},
},
{
Expand Down