Skip to content

Commit

Permalink
Merge pull request #215 from DopplerHQ/andre/error-on-missing-secrets
Browse files Browse the repository at this point in the history
Throw an error if a non-existent secret is requested from secrets get
  • Loading branch information
Piccirello authored May 19, 2021
2 parents 7c1837b + cc6c0a8 commit 65f41dc
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/cmd/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func getSecrets(cmd *cobra.Command, args []string) {
plain := utils.GetBoolFlag(cmd, "plain")
copy := utils.GetBoolFlag(cmd, "copy")
raw := utils.GetBoolFlag(cmd, "raw")
exitOnMissingSecret := !utils.GetBoolFlag(cmd, "no-exit-on-missing-secret")
localConfig := configuration.LocalConfig(cmd)

utils.RequireValue("token", localConfig.Token.Value)
Expand All @@ -151,6 +152,24 @@ func getSecrets(cmd *cobra.Command, args []string) {
utils.HandleError(parseErr, "Unable to parse API response")
}

if exitOnMissingSecret && len(args) > 0 {
var missingSecrets []string

for _, name := range args {
if secrets[name] == (models.ComputedSecret{}) {
missingSecrets = append(missingSecrets, name)
}
}

if len(missingSecrets) > 0 {
pluralized := "secrets"
if len(missingSecrets) == 1 {
pluralized = "secret"
}
utils.HandleError(fmt.Errorf("Could not find requested %s: %s", pluralized, strings.Join(missingSecrets, ", ")))
}
}

printer.Secrets(secrets, args, jsonFlag, plain, raw, copy)
}

Expand Down Expand Up @@ -372,6 +391,7 @@ func init() {
secretsGetCmd.Flags().Bool("plain", false, "print values without formatting")
secretsGetCmd.Flags().Bool("copy", false, "copy the value(s) to your clipboard")
secretsGetCmd.Flags().Bool("raw", false, "print the raw secret value without processing variables")
secretsGetCmd.Flags().Bool("no-exit-on-missing-secret", false, "do not exit if unable to find a requested secret")
secretsCmd.AddCommand(secretsGetCmd)

secretsSetCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
Expand Down

0 comments on commit 65f41dc

Please sign in to comment.