Skip to content

Commit

Permalink
Fix context passed when resolving secrets in config file
Browse files Browse the repository at this point in the history
I was passing the context incorrectly when resolving secrets in the
config file. This caused the trace spans to not be nested properly.

Signed-off-by: Carolyn Van Slyck <[email protected]>
Co-authored-by: Yingrong Zhao <[email protected]>
  • Loading branch information
carolynvs and VinozzZ committed May 17, 2022
1 parent 699cc38 commit 6b08440
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (c *Config) GetBuildDriver() string {
// Load loads the configuration file, rendering any templating used in the config file
// such as ${secret.NAME} or ${env.NAME}.
// Pass nil for resolveSecret to skip resolving secrets.
func (c *Config) Load(ctx context.Context, resolveSecret func(secretKey string) (string, error)) error {
func (c *Config) Load(ctx context.Context, resolveSecret func(ctx context.Context, secretKey string) (string, error)) error {
ctx, log := tracing.StartSpan(ctx)
defer log.EndSpan()

Expand Down Expand Up @@ -338,7 +338,7 @@ func (c *Config) loadFirstPass(ctx context.Context) error {
return c.loadData(ctx, templateData)
}

func (c *Config) loadFinalPass(ctx context.Context, resolveSecret func(secretKey string) (string, error)) error {
func (c *Config) loadFinalPass(ctx context.Context, resolveSecret func(ctx context.Context, secretKey string) (string, error)) error {
ctx, log := tracing.StartSpan(ctx)
defer log.EndSpan()

Expand All @@ -359,9 +359,9 @@ func (c *Config) loadFinalPass(ctx context.Context, resolveSecret func(secretKey

secretKey := variable[len(secretPrefix):]

_, childLog := log.StartSpanWithName("resolveSecret", attribute.String("porter.config.secret.key", secretKey))
ctx, childLog := log.StartSpanWithName("resolveSecret", attribute.String("porter.config.secret.key", secretKey))
defer childLog.EndSpan()
secretValue, err := resolveSecret(secretKey)
secretValue, err := resolveSecret(ctx, secretKey)
if err != nil {
return childLog.Error(errors.Wrapf(err, "could not render config file because ${secret.%s} could not be resolved", secretKey))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestData_Marshal(t *testing.T) {
c.TestContext.AddTestFile("testdata/config.toml", "/home/myuser/.porter/config.toml")

c.DataLoader = LoadFromEnvironment()
resolveTestSecrets := func(secretKey string) (string, error) {
resolveTestSecrets := func(ctx context.Context, secretKey string) (string, error) {
return "topsecret-connectionstring", nil
}
err := c.Load(context.Background(), resolveTestSecrets)
Expand Down

0 comments on commit 6b08440

Please sign in to comment.