patch secret override for run/export command

This commit is contained in:
Maidul Islam
2023-01-19 17:05:18 -08:00
parent 0613e1115d
commit 3fc68ffc50
3 changed files with 46 additions and 19 deletions

View File

@@ -51,11 +51,22 @@ var exportCmd = &cobra.Command{
util.HandleError(err)
}
secretOverriding, err := cmd.Flags().GetBool("secret-overriding")
if err != nil {
util.HandleError(err, "Unable to parse flag")
}
secrets, err := util.GetAllEnvironmentVariables(envName)
if err != nil {
util.HandleError(err, "Unable to fetch secrets")
}
if secretOverriding {
secrets = util.OverrideSecrets(secrets, util.SECRET_TYPE_PERSONAL)
} else {
secrets = util.OverrideSecrets(secrets, util.SECRET_TYPE_SHARED)
}
var output string
if shouldExpandSecrets {
substitutions := util.SubstituteSecrets(secrets)
@@ -79,6 +90,7 @@ func init() {
exportCmd.Flags().StringP("env", "e", "dev", "Set the environment (dev, prod, etc.) from which your secrets should be pulled from")
exportCmd.Flags().Bool("expand", true, "Parse shell parameter expansions in your secrets")
exportCmd.Flags().StringP("format", "f", "dotenv", "Set the format of the output file (dotenv, json, csv)")
exportCmd.Flags().Bool("secret-overriding", true, "Prioritizes personal secrets, if any, with the same name over shared secrets")
}
// Format according to the format flag

View File

@@ -77,12 +77,14 @@ var runCmd = &cobra.Command{
util.HandleError(err, "Could not fetch secrets", "If you are using a service token to fetch secrets, please ensure it is valid")
}
if shouldExpandSecrets {
secrets = util.SubstituteSecrets(secrets)
if secretOverriding {
secrets = util.OverrideSecrets(secrets, util.SECRET_TYPE_PERSONAL)
} else {
secrets = util.OverrideSecrets(secrets, util.SECRET_TYPE_SHARED)
}
if secretOverriding {
secrets = util.OverrideWithPersonalSecrets(secrets)
if shouldExpandSecrets {
secrets = util.SubstituteSecrets(secrets)
}
secretsByKey := getSecretsByKeys(secrets)