From 90eed6893d7a314062b055b513d631cc6f4a71ce Mon Sep 17 00:00:00 2001 From: John ODonnell Date: Mon, 20 Mar 2023 10:44:47 -0400 Subject: [PATCH] CodeClimate fix: refactor repeatableSecretsProvider function --- pkg/entrypoint/entrypoint.go | 39 ++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/pkg/entrypoint/entrypoint.go b/pkg/entrypoint/entrypoint.go index 066aee0b..cdc405ae 100644 --- a/pkg/entrypoint/entrypoint.go +++ b/pkg/entrypoint/entrypoint.go @@ -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 @@ -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 @@ -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 @@ -250,7 +267,7 @@ func repeatableSecretsProvider( refreshConfig := secrets.ProviderRefreshConfig{ Mode: getContainerMode(), - SecretRefreshInterval: secretsConfig.SecretsRefreshInterval, + SecretRefreshInterval: refreshInterval, ProviderQuit: providerQuit, } @@ -259,7 +276,7 @@ func repeatableSecretsProvider( provideSecrets, statusUpdater, ) - return repeatableProvideSecrets, secretsConfig, nil + return repeatableProvideSecrets } func customEnv(key string) string {