Skip to content

Commit

Permalink
Merge pull request #297 from DopplerHQ/nic/dynamic-ttl
Browse files Browse the repository at this point in the history
Change `--expire-dynamics` to `--dynamic-ttl`
  • Loading branch information
nmanoogian authored Feb 1, 2022
2 parents 9ca5da2 + c2169c0 commit 8ed090e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/enclave_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func init() {
enclaveSecretsDownloadCmd.Flags().String("passphrase", "", "passphrase to use for encrypting the secrets file. the default passphrase is computed using your current configuration.")
enclaveSecretsDownloadCmd.Flags().Bool("no-file", false, "print the response to stdout")
enclaveSecretsDownloadCmd.Flags().String("name-transformer", "", fmt.Sprintf("(BETA) output name transformer. one of %v", validNameTransformersList))
enclaveSecretsDownloadCmd.Flags().Duration("expire-dynamics", 0, "(BETA) dynamic secrets will expire after specified duration, (e.g. '3h', '15m')")
enclaveSecretsDownloadCmd.Flags().Duration("dynamic-ttl", 0, "(BETA) dynamic secrets will expire after specified duration, (e.g. '3h', '15m')")
// fallback flags
enclaveSecretsDownloadCmd.Flags().String("fallback", "", "path to the fallback file. encrypted secrets are written to this file after each successful fetch. secrets will be read from this file if subsequent connections are unsuccessful.")
enclaveSecretsDownloadCmd.Flags().Bool("no-cache", false, "disable using the fallback file to speed up fetches. the fallback file is only used when the API indicates that it's still current.")
Expand Down
10 changes: 5 additions & 5 deletions pkg/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ doppler run --command "YOUR_COMMAND && YOUR_OTHER_COMMAND"`,
preserveEnv := utils.GetBoolFlag(cmd, "preserve-env")
forwardSignals := utils.GetBoolFlag(cmd, "forward-signals")
localConfig := configuration.LocalConfig(cmd)
dynamicSecretsExpire := utils.GetDurationFlag(cmd, "expire-dynamics")
dynamicSecretsTTL := utils.GetDurationFlag(cmd, "dynamic-ttl")

utils.RequireValue("token", localConfig.Token.Value)

Expand Down Expand Up @@ -112,7 +112,7 @@ doppler run --command "YOUR_COMMAND && YOUR_OTHER_COMMAND"`,
}
}

secrets := fetchSecrets(localConfig, enableCache, enableFallback, fallbackPath, legacyFallbackPath, metadataPath, fallbackReadonly, fallbackOnly, exitOnWriteFailure, passphrase, nameTransformer, dynamicSecretsExpire)
secrets := fetchSecrets(localConfig, enableCache, enableFallback, fallbackPath, legacyFallbackPath, metadataPath, fallbackReadonly, fallbackOnly, exitOnWriteFailure, passphrase, nameTransformer, dynamicSecretsTTL)

if preserveEnv {
utils.LogWarning("Ignoring Doppler secrets already defined in the environment due to --preserve-env flag")
Expand Down Expand Up @@ -251,7 +251,7 @@ var runCleanCmd = &cobra.Command{
}

// fetchSecrets fetches secrets, including all reading and writing of fallback files
func fetchSecrets(localConfig models.ScopedOptions, enableCache bool, enableFallback bool, fallbackPath string, legacyFallbackPath string, metadataPath string, fallbackReadonly bool, fallbackOnly bool, exitOnWriteFailure bool, passphrase string, nameTransformer *models.SecretsNameTransformer, dynamicSecretsExpire time.Duration) map[string]string {
func fetchSecrets(localConfig models.ScopedOptions, enableCache bool, enableFallback bool, fallbackPath string, legacyFallbackPath string, metadataPath string, fallbackReadonly bool, fallbackOnly bool, exitOnWriteFailure bool, passphrase string, nameTransformer *models.SecretsNameTransformer, dynamicSecretsTTL time.Duration) map[string]string {
if fallbackOnly {
if !enableFallback {
utils.HandleError(errors.New("Conflict: unable to specify --no-fallback with --fallback-only"))
Expand All @@ -269,7 +269,7 @@ func fetchSecrets(localConfig models.ScopedOptions, enableCache bool, enableFall
etag = getCacheFileETag(metadataPath, fallbackPath)
}

statusCode, respHeaders, response, httpErr := http.DownloadSecrets(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value, localConfig.EnclaveProject.Value, localConfig.EnclaveConfig.Value, models.JSON, nameTransformer, etag, dynamicSecretsExpire)
statusCode, respHeaders, response, httpErr := http.DownloadSecrets(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value, localConfig.EnclaveProject.Value, localConfig.EnclaveConfig.Value, models.JSON, nameTransformer, etag, dynamicSecretsTTL)
if !httpErr.IsNil() {
if enableFallback {
utils.Log("Unable to fetch secrets from the Doppler API")
Expand Down Expand Up @@ -561,7 +561,7 @@ func init() {
runCmd.Flags().String("command", "", "command to execute (e.g. \"echo hi\")")
runCmd.Flags().Bool("preserve-env", false, "ignore any Doppler secrets that are already defined in the environment. this has potential security implications, use at your own risk.")
runCmd.Flags().String("name-transformer", "", fmt.Sprintf("(BETA) output name transformer. one of %v", validEnvCompatNameTransformersList))
runCmd.Flags().Duration("expire-dynamics", 0, "(BETA) dynamic secrets will expire after specified duration, (e.g. '3h', '15m')")
runCmd.Flags().Duration("dynamic-ttl", 0, "(BETA) dynamic secrets will expire after specified duration, (e.g. '3h', '15m')")
// fallback flags
runCmd.Flags().String("fallback", "", "path to the fallback file. encrypted secrets are written to this file after each successful fetch. secrets will be read from this file if subsequent connections are unsuccessful.")
// TODO rename this to 'fallback-passphrase' in CLI v4 (DPLR-435)
Expand Down
14 changes: 7 additions & 7 deletions pkg/cmd/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func downloadSecrets(cmd *cobra.Command, args []string) {
fallbackReadonly := utils.GetBoolFlag(cmd, "fallback-readonly")
fallbackOnly := utils.GetBoolFlag(cmd, "fallback-only")
exitOnWriteFailure := !utils.GetBoolFlag(cmd, "no-exit-on-write-failure")
dynamicSecretsExpire := utils.GetDurationFlag(cmd, "expire-dynamics")
dynamicSecretsTTL := utils.GetDurationFlag(cmd, "dynamic-ttl")

utils.RequireValue("token", localConfig.Token.Value)

Expand Down Expand Up @@ -449,7 +449,7 @@ func downloadSecrets(cmd *cobra.Command, args []string) {
if enableCache {
metadataPath = controllers.MetadataFilePath(localConfig.Token.Value, localConfig.EnclaveProject.Value, localConfig.EnclaveConfig.Value)
}
secrets := fetchSecrets(localConfig, enableCache, enableFallback, fallbackPath, legacyFallbackPath, metadataPath, fallbackReadonly, fallbackOnly, exitOnWriteFailure, fallbackPassphrase, nameTransformer, dynamicSecretsExpire)
secrets := fetchSecrets(localConfig, enableCache, enableFallback, fallbackPath, legacyFallbackPath, metadataPath, fallbackReadonly, fallbackOnly, exitOnWriteFailure, fallbackPassphrase, nameTransformer, dynamicSecretsTTL)

var err error
body, err = json.Marshal(secrets)
Expand All @@ -468,7 +468,7 @@ func downloadSecrets(cmd *cobra.Command, args []string) {
}

var apiError http.Error
_, _, body, apiError = http.DownloadSecrets(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value, localConfig.EnclaveProject.Value, localConfig.EnclaveConfig.Value, format, nameTransformer, "", dynamicSecretsExpire)
_, _, body, apiError = http.DownloadSecrets(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value, localConfig.EnclaveProject.Value, localConfig.EnclaveConfig.Value, format, nameTransformer, "", dynamicSecretsTTL)
if !apiError.IsNil() {
utils.HandleError(apiError.Unwrap(), apiError.Message)
}
Expand Down Expand Up @@ -556,8 +556,8 @@ func substituteSecrets(cmd *cobra.Command, args []string) {
utils.HandleError(err, "Unable to parse template text")
}

dynamicSecretsExpire := utils.GetDurationFlag(cmd, "expire-dynamics")
response, responseErr := http.GetSecrets(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value, localConfig.EnclaveProject.Value, localConfig.EnclaveConfig.Value, nil, true, dynamicSecretsExpire)
dynamicSecretsTTL := utils.GetDurationFlag(cmd, "dynamic-ttl")
response, responseErr := http.GetSecrets(localConfig.APIHost.Value, utils.GetBool(localConfig.VerifyTLS.Value, true), localConfig.Token.Value, localConfig.EnclaveProject.Value, localConfig.EnclaveConfig.Value, nil, true, dynamicSecretsTTL)
if !responseErr.IsNil() {
utils.HandleError(responseErr.Unwrap(), responseErr.Message)
}
Expand Down Expand Up @@ -640,7 +640,7 @@ func init() {
secretsDownloadCmd.Flags().String("name-transformer", "", fmt.Sprintf("(BETA) output name transformer. one of %v", validNameTransformersList))
secretsDownloadCmd.Flags().String("passphrase", "", "passphrase to use for encrypting the secrets file. the default passphrase is computed using your current configuration.")
secretsDownloadCmd.Flags().Bool("no-file", false, "print the response to stdout")
secretsDownloadCmd.Flags().Duration("expire-dynamics", 0, "(BETA) dynamic secrets will expire after specified duration, (e.g. '3h', '15m')")
secretsDownloadCmd.Flags().Duration("dynamic-ttl", 0, "(BETA) dynamic secrets will expire after specified duration, (e.g. '3h', '15m')")
// fallback flags
secretsDownloadCmd.Flags().String("fallback", "", "path to the fallback file. encrypted secrets are written to this file after each successful fetch. secrets will be read from this file if subsequent connections are unsuccessful.")
secretsDownloadCmd.Flags().Bool("no-cache", false, "disable using the fallback file to speed up fetches. the fallback file is only used when the API indicates that it's still current.")
Expand All @@ -654,7 +654,7 @@ func init() {
secretsSubstituteCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
secretsSubstituteCmd.Flags().StringP("config", "c", "", "config (e.g. dev)")
secretsSubstituteCmd.Flags().String("output", "", "path to the output file. by default the rendered text will be written to stdout.")
secretsSubstituteCmd.Flags().Duration("expire-dynamics", 0, "(BETA) dynamic secrets will expire after specified duration, (e.g. '3h', '15m')")
secretsSubstituteCmd.Flags().Duration("dynamic-ttl", 0, "(BETA) dynamic secrets will expire after specified duration, (e.g. '3h', '15m')")
secretsCmd.AddCommand(secretsSubstituteCmd)

rootCmd.AddCommand(secretsCmd)
Expand Down
12 changes: 6 additions & 6 deletions pkg/http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ func RevokeAuthToken(host string, verifyTLS bool, token string) (map[string]inte
}

// DownloadSecrets for specified project and config
func DownloadSecrets(host string, verifyTLS bool, apiKey string, project string, config string, format models.SecretsFormat, nameTransformer *models.SecretsNameTransformer, etag string, dynamicSecretsExpire time.Duration) (int, http.Header, []byte, Error) {
func DownloadSecrets(host string, verifyTLS bool, apiKey string, project string, config string, format models.SecretsFormat, nameTransformer *models.SecretsNameTransformer, etag string, dynamicSecretsTTL time.Duration) (int, http.Header, []byte, Error) {
var params []queryParam
params = append(params, queryParam{Key: "project", Value: project})
params = append(params, queryParam{Key: "config", Value: config})
params = append(params, queryParam{Key: "format", Value: format.String()})
params = append(params, queryParam{Key: "include_dynamic_secrets", Value: "true"})

if dynamicSecretsExpire > 0 {
ttlSeconds := int(dynamicSecretsExpire.Seconds())
if dynamicSecretsTTL > 0 {
ttlSeconds := int(dynamicSecretsTTL.Seconds())
params = append(params, queryParam{Key: "dynamic_secrets_ttl_sec", Value: strconv.Itoa(ttlSeconds)})
}
if nameTransformer != nil {
Expand All @@ -167,7 +167,7 @@ func DownloadSecrets(host string, verifyTLS bool, apiKey string, project string,
}

// GetSecrets for specified project and config
func GetSecrets(host string, verifyTLS bool, apiKey string, project string, config string, secrets []string, includeDynamicSecrets bool, dynamicSecretsExpire time.Duration) ([]byte, Error) {
func GetSecrets(host string, verifyTLS bool, apiKey string, project string, config string, secrets []string, includeDynamicSecrets bool, dynamicSecretsTTL time.Duration) ([]byte, Error) {
var params []queryParam
params = append(params, queryParam{Key: "project", Value: project})
params = append(params, queryParam{Key: "config", Value: config})
Expand All @@ -182,8 +182,8 @@ func GetSecrets(host string, verifyTLS bool, apiKey string, project string, conf
}
params = append(params, queryParam{Key: "include_dynamic_secrets", Value: includeDynamicSecretsOption})

if dynamicSecretsExpire > 0 {
ttlSeconds := int(dynamicSecretsExpire.Seconds())
if dynamicSecretsTTL > 0 {
ttlSeconds := int(dynamicSecretsTTL.Seconds())
params = append(params, queryParam{Key: "dynamic_secrets_ttl_sec", Value: strconv.Itoa(ttlSeconds)})
}

Expand Down

0 comments on commit 8ed090e

Please sign in to comment.