Skip to content

Commit

Permalink
Add support for setting value type
Browse files Browse the repository at this point in the history
  • Loading branch information
apazzolini committed May 15, 2024
1 parent 4d5c938 commit 3dd8af8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
20 changes: 19 additions & 1 deletion pkg/cmd/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ func setSecrets(cmd *cobra.Command, args []string) {
localConfig := configuration.LocalConfig(cmd)
visibility := cmd.Flag("visibility").Value.String()
visibilityModified := visibility != ""
valueType := cmd.Flag("value-type").Value.String()
valueTypeModified := valueType != ""

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

Expand Down Expand Up @@ -320,6 +322,11 @@ func setSecrets(cmd *cobra.Command, args []string) {
if visibilityModified {
changeRequest.Visibility = &visibility
}
if valueTypeModified {
changeRequest.ValueType = &models.SecretValueType{
Type: valueType,
}
}
changeRequests = append(changeRequests, changeRequest)
} else if len(args) == 2 && !strings.Contains(args[0], "=") {
// format: 'doppler secrets set KEY value'
Expand All @@ -333,6 +340,11 @@ func setSecrets(cmd *cobra.Command, args []string) {
if visibilityModified {
changeRequest.Visibility = &visibility
}
if valueTypeModified {
changeRequest.ValueType = &models.SecretValueType{
Type: valueType,
}
}
changeRequests = append(changeRequests, changeRequest)
} else {
// format: 'doppler secrets set KEY=value'
Expand All @@ -353,6 +365,11 @@ func setSecrets(cmd *cobra.Command, args []string) {
if visibilityModified {
changeRequest.Visibility = &visibility
}
if valueTypeModified {
changeRequest.ValueType = &models.SecretValueType{
Type: valueType,
}
}
changeRequests = append(changeRequests, changeRequest)
}
}
Expand All @@ -363,7 +380,7 @@ func setSecrets(cmd *cobra.Command, args []string) {
}

if !utils.Silent {
printer.Secrets(response, keys, jsonFlag, false, raw, false, visibilityModified, false)
printer.Secrets(response, keys, jsonFlag, false, raw, false, visibilityModified, valueTypeModified)
}
}

Expand Down Expand Up @@ -659,6 +676,7 @@ func init() {
secretsSetCmd.Flags().Bool("raw", false, "print the raw secret value without processing variables")
secretsSetCmd.Flags().Bool("no-interactive", false, "do not allow entering secret value via interactive mode")
secretsSetCmd.Flags().String("visibility", "", "visibility (e.g. masked, unmasked, or restricted)")
secretsSetCmd.Flags().String("value-type", "", "value type (e.g. string, decimal, etc)")
secretsCmd.AddCommand(secretsSetCmd)

secretsUploadCmd.Flags().StringP("project", "p", "", "project (e.g. backend)")
Expand Down
20 changes: 11 additions & 9 deletions pkg/models/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ type ComputedSecret struct {

// ChangeRequest can be used to smartly update secrets
type ChangeRequest struct {
Name string `json:"name"`
OriginalName interface{} `json:"originalName"`
Value interface{} `json:"value"`
OriginalValue interface{} `json:"originalValue,omitempty"`
Visibility *string `json:"visibility,omitempty"`
OriginalVisibility *string `json:"originalVisibility,omitempty"`
ShouldPromote *bool `json:"shouldPromote,omitempty"`
ShouldDelete *bool `json:"shouldDelete,omitempty"`
ShouldConverge *bool `json:"shouldConverge,omitempty"`
Name string `json:"name"`
OriginalName interface{} `json:"originalName"`
Value interface{} `json:"value"`
OriginalValue interface{} `json:"originalValue,omitempty"`
Visibility *string `json:"visibility,omitempty"`
OriginalVisibility *string `json:"originalVisibility,omitempty"`
ValueType *SecretValueType `json:"valueType,omitempty"`
OriginalValueType *SecretValueType `json:"originalValueType,omitempty"`
ShouldPromote *bool `json:"shouldPromote,omitempty"`
ShouldDelete *bool `json:"shouldDelete,omitempty"`
ShouldConverge *bool `json:"shouldConverge,omitempty"`
}

// SecretNote contains a secret and its note
Expand Down

0 comments on commit 3dd8af8

Please sign in to comment.