Skip to content

Commit

Permalink
CodeClimate fix: refactor repeatableSecretsProvider function
Browse files Browse the repository at this point in the history
  • Loading branch information
john-odonnell committed Mar 20, 2023
1 parent 56704ba commit 8639050
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions pkg/entrypoint/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,29 @@ func StartSecretsProviderWithArguments(
return
}

// Gather secrets config and create a repeatable Secrets Provider
provideSecrets, _, err := repeatableSecretsProvider(
provideSecrets, secretsConfig, err := retryableSecretsProvider(
ctx,
tracer,
secretsBasePath,
templatesBasePath,
secretRetriever,
providerFactory,
statusUpdater,
)
if err != nil {
logError(err.Error())
return
}

repeatingProvideSecrets := repeatableSecretsProvider(
ctx,
tracer,
provideSecrets,
secretsConfig.SecretsRefreshInterval,
statusUpdater,
)

// Provide secrets
if err = provideSecrets(); err != nil {
if err = repeatingProvideSecrets(); err != nil {
logError(err.Error())
}
return
Expand Down Expand Up @@ -184,17 +190,15 @@ func secretRetriever(
return secretRetriever, nil
}

func repeatableSecretsProvider(
func retryableSecretsProvider(
ctx context.Context,
tracer trace.Tracer,
secretsBasePath string,
templatesBasePath string,
secretRetriever conjur.SecretRetriever,
providerFactory secrets.ProviderFactory,
statusUpdater secrets.StatusUpdater,
) (secrets.RepeatableProviderFunc, *secretsConfigProvider.Config, error) {

_, span := tracer.Start(ctx, "Create repeatable secrets provider")
) (secrets.ProviderFunc, *secretsConfigProvider.Config, error) {
_, span := tracer.Start(ctx, "Create retryable secrets provider")
defer span.End()

// Initialize Secrets Provider configuration
Expand Down Expand Up @@ -241,6 +245,19 @@ func repeatableSecretsProvider(
provideSecrets,
)

return provideSecrets, secretsConfig, nil
}

func repeatableSecretsProvider(
ctx context.Context,
tracer trace.Tracer,
provideSecrets secrets.ProviderFunc,
refreshInterval time.Duration,
statusUpdater secrets.StatusUpdater,
) secrets.RepeatableProviderFunc {
_, span := tracer.Start(ctx, "Create repeatable secrets provider")
defer span.End()

// Create a channel to send a quit signal to the periodic secret provider.
// TODO: Currently, this is just used for testing, but in the future we
// may want to create a SIGTERM or SIGHUP handler to catch a signal from
Expand All @@ -250,7 +267,7 @@ func repeatableSecretsProvider(

refreshConfig := secrets.ProviderRefreshConfig{
Mode: getContainerMode(),
SecretRefreshInterval: secretsConfig.SecretsRefreshInterval,
SecretRefreshInterval: refreshInterval,
ProviderQuit: providerQuit,
}

Expand All @@ -259,7 +276,7 @@ func repeatableSecretsProvider(
provideSecrets,
statusUpdater,
)
return repeatableProvideSecrets, secretsConfig, nil
return repeatableProvideSecrets
}

func customEnv(key string) string {
Expand Down

0 comments on commit 8639050

Please sign in to comment.