Skip to content

Commit

Permalink
Refactor repeatableSecretsProvider function
Browse files Browse the repository at this point in the history
  • Loading branch information
john-odonnell committed Mar 30, 2023
1 parent 02f247a commit ba78a42
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions pkg/entrypoint/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,33 @@ func startSecretsProviderWithDeps(
return
}

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

provideSecretsFunc = secrets.RetryableSecretProvider(
time.Duration(secretsConfig.RetryIntervalSec)*time.Second,
secretsConfig.RetryCountLimit,
provideSecretsFunc,
)

provideSecrets := repeatableSecretsProvider(
ctx,
tracer,
secretsConfig.SecretsRefreshInterval,
provideSecretsFunc,
statusUpdaterFactory,
)

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

func repeatableSecretsProvider(
func secretsProvider(
ctx context.Context,
tracer trace.Tracer,
secretsBasePath string,
templatesBasePath string,
secretRetriever conjur.RetrieveSecretsFunc,
providerFactory secrets.ProviderFactory,
statusUpdaterFactory secrets.StatusUpdaterFactory,
) (secrets.RepeatableProviderFunc, *secretsConfigProvider.Config, error) {

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

// Initialize Secrets Provider configuration
Expand Down Expand Up @@ -218,11 +228,18 @@ func repeatableSecretsProvider(
return nil, nil, err
}

provideSecrets = secrets.RetryableSecretProvider(
time.Duration(secretsConfig.RetryIntervalSec)*time.Second,
secretsConfig.RetryCountLimit,
provideSecrets,
)
return provideSecrets, secretsConfig, nil
}

func repeatableSecretsProvider(
ctx context.Context,
tracer trace.Tracer,
refreshInterval time.Duration,
provideSecrets secrets.ProviderFunc,
statusUpdaterFactory secrets.StatusUpdaterFactory,
) 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
Expand All @@ -233,16 +250,15 @@ func repeatableSecretsProvider(

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

repeatableProvideSecrets := secrets.RepeatableSecretProvider(
return secrets.RepeatableSecretProvider(
refreshConfig,
provideSecrets,
statusUpdaterFactory(),
)
return repeatableProvideSecrets, secretsConfig, nil
}

func customEnv(key string) string {
Expand Down

0 comments on commit ba78a42

Please sign in to comment.