Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 7 additions & 43 deletions temporalcloudcli/commands.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2633,7 +2633,6 @@ func NewCloudNamespaceEncryptionValidationCommand(cctx *CommandContext, parent *
s.Command.Long = "Commands for managing payload encryption validation configuration of Temporal Cloud namespaces."
s.Command.Args = cobra.NoArgs
s.Command.AddCommand(&NewCloudNamespaceEncryptionValidationDisableCommand(cctx, &s).Command)
s.Command.AddCommand(&NewCloudNamespaceEncryptionValidationEnableCommand(cctx, &s).Command)
s.Command.AddCommand(&NewCloudNamespaceEncryptionValidationGetCommand(cctx, &s).Command)
s.Command.AddCommand(&NewCloudNamespaceEncryptionValidationSetCommand(cctx, &s).Command)
return &s
Expand All @@ -2655,9 +2654,9 @@ func NewCloudNamespaceEncryptionValidationDisableCommand(cctx *CommandContext, p
s.Command.Use = "disable [flags]"
s.Command.Short = "[Experimental] Disable payload encryption validation for a namespace"
if hasHighlighting {
s.Command.Long = "Disable payload encryption validation for a Temporal Cloud namespace.\nExisting metadata and inspect settings are kept. If validation is not\nconfigured or is already disabled, nothing is changed.\n\nExample:\n\n\x1b[1mtemporal cloud namespace encryption-validation disable --namespace my-namespace.my-account\x1b[0m"
s.Command.Long = "Disable payload encryption validation for a Temporal Cloud namespace.\nExisting metadata and inspect settings are kept. To turn validation back\non, use \x1b[1mset --mode warn\x1b[0m or \x1b[1mset --mode deny\x1b[0m. If validation is not\nconfigured or is already disabled, the command errors unless\n--idempotent is set.\n\nExample:\n\n\x1b[1mtemporal cloud namespace encryption-validation disable --namespace my-namespace.my-account\x1b[0m"
} else {
s.Command.Long = "Disable payload encryption validation for a Temporal Cloud namespace.\nExisting metadata and inspect settings are kept. If validation is not\nconfigured or is already disabled, nothing is changed.\n\nExample:\n\n```\ntemporal cloud namespace encryption-validation disable --namespace my-namespace.my-account\n```"
s.Command.Long = "Disable payload encryption validation for a Temporal Cloud namespace.\nExisting metadata and inspect settings are kept. To turn validation back\non, use `set --mode warn` or `set --mode deny`. If validation is not\nconfigured or is already disabled, the command errors unless\n--idempotent is set.\n\nExample:\n\n```\ntemporal cloud namespace encryption-validation disable --namespace my-namespace.my-account\n```"
}
s.Command.Args = cobra.NoArgs
s.ClientOptions.BuildFlags(s.Command.Flags())
Expand All @@ -2672,41 +2671,6 @@ func NewCloudNamespaceEncryptionValidationDisableCommand(cctx *CommandContext, p
return &s
}

type CloudNamespaceEncryptionValidationEnableCommand struct {
Parent *CloudNamespaceEncryptionValidationCommand
Command cobra.Command
ClientOptions
NamespaceOptions
AsyncOperationOptions
ResourceVersionOptions
Deny bool
}

func NewCloudNamespaceEncryptionValidationEnableCommand(cctx *CommandContext, parent *CloudNamespaceEncryptionValidationCommand) *CloudNamespaceEncryptionValidationEnableCommand {
var s CloudNamespaceEncryptionValidationEnableCommand
s.Parent = parent
s.Command.DisableFlagsInUseLine = true
s.Command.Use = "enable [flags]"
s.Command.Short = "[Experimental] Enable payload encryption validation for a namespace"
if hasHighlighting {
s.Command.Long = "Enable payload encryption validation for a Temporal Cloud namespace.\nIf validation has not been configured, it is enabled in warn mode with\nno metadata key or values, so the defaults apply\n(metadata-key=encoding, metadata-values=[binary/encrypted]).\nIf validation is disabled, the existing configuration is re-enabled.\nUse --deny to enable in deny mode; this also switches a namespace that\nis already in warn mode to deny. Without --deny, a namespace that is\nalready in warn or deny mode is left unchanged.\n\nExample:\n\n\x1b[1mtemporal cloud namespace encryption-validation enable --namespace my-namespace.my-account\x1b[0m"
} else {
s.Command.Long = "Enable payload encryption validation for a Temporal Cloud namespace.\nIf validation has not been configured, it is enabled in warn mode with\nno metadata key or values, so the defaults apply\n(metadata-key=encoding, metadata-values=[binary/encrypted]).\nIf validation is disabled, the existing configuration is re-enabled.\nUse --deny to enable in deny mode; this also switches a namespace that\nis already in warn mode to deny. Without --deny, a namespace that is\nalready in warn or deny mode is left unchanged.\n\nExample:\n\n```\ntemporal cloud namespace encryption-validation enable --namespace my-namespace.my-account\n```"
}
s.Command.Args = cobra.NoArgs
s.Command.Flags().BoolVar(&s.Deny, "deny", false, "Enable validation in deny mode instead of warn. Switches warn mode to deny.")
s.ClientOptions.BuildFlags(s.Command.Flags())
s.NamespaceOptions.BuildFlags(s.Command.Flags())
s.AsyncOperationOptions.BuildFlags(s.Command.Flags())
s.ResourceVersionOptions.BuildFlags(s.Command.Flags())
s.Command.Run = func(c *cobra.Command, args []string) {
if err := s.run(cctx, args); err != nil {
cctx.Options.Fail(err)
}
}
return &s
}

type CloudNamespaceEncryptionValidationGetCommand struct {
Parent *CloudNamespaceEncryptionValidationCommand
Command cobra.Command
Expand All @@ -2721,9 +2685,9 @@ func NewCloudNamespaceEncryptionValidationGetCommand(cctx *CommandContext, paren
s.Command.Use = "get [flags]"
s.Command.Short = "[Experimental] Get namespace payload encryption validation configuration"
if hasHighlighting {
s.Command.Long = "Retrieve the current payload encryption validation configuration for a Temporal Cloud namespace.\n\nExample:\n\n\x1b[1mtemporal cloud namespace encryption-validation get --namespace my-namespace.my-account\x1b[0m"
s.Command.Long = "Retrieve the current payload encryption validation configuration for a Temporal Cloud namespace.\nIf the metadata key or values are not set, the server defaults that apply are shown\n(metadata-key=encoding, metadata-values=[binary/encrypted]).\n\nExample:\n\n\x1b[1mtemporal cloud namespace encryption-validation get --namespace my-namespace.my-account\x1b[0m"
} else {
s.Command.Long = "Retrieve the current payload encryption validation configuration for a Temporal Cloud namespace.\n\nExample:\n\n```\ntemporal cloud namespace encryption-validation get --namespace my-namespace.my-account\n```"
s.Command.Long = "Retrieve the current payload encryption validation configuration for a Temporal Cloud namespace.\nIf the metadata key or values are not set, the server defaults that apply are shown\n(metadata-key=encoding, metadata-values=[binary/encrypted]).\n\nExample:\n\n```\ntemporal cloud namespace encryption-validation get --namespace my-namespace.my-account\n```"
}
s.Command.Args = cobra.NoArgs
s.ClientOptions.BuildFlags(s.Command.Flags())
Expand Down Expand Up @@ -2757,14 +2721,14 @@ func NewCloudNamespaceEncryptionValidationSetCommand(cctx *CommandContext, paren
s.Command.Use = "set [flags]"
s.Command.Short = "[Experimental] Set namespace payload encryption validation configuration"
if hasHighlighting {
s.Command.Long = "Update the payload encryption validation configuration for a Temporal Cloud\nnamespace. At least one flag must be set. Omitted flags keep the\nexisting values. An empty metadata key or values means the server\ndefaults apply (metadata-key=encoding, metadata-values=[binary/encrypted]).\n\nExample:\n\n\x1b[1mtemporal cloud namespace encryption-validation set --namespace my-namespace.my-account --mode warn --metadata-key encoding --metadata-value binary/encrypted\x1b[0m"
s.Command.Long = "Configure payload encryption validation for a Temporal Cloud namespace.\nUse this command to turn validation on (--mode warn or --mode deny) and to\nchange its settings. At least one flag must be set. Omitted flags keep the\nexisting values. An empty metadata key means the server default applies\n(metadata-key=encoding); omit --metadata-value to keep the existing values,\nwhich default to [binary/encrypted]. If nothing would change, the command\nerrors unless --idempotent is set.\n\nExamples:\n\n\x1b[1mtemporal cloud namespace encryption-validation set --namespace my-namespace.my-account --mode warn\ntemporal cloud namespace encryption-validation set --namespace my-namespace.my-account --mode deny --metadata-key encoding --metadata-value binary/encrypted\x1b[0m"
} else {
s.Command.Long = "Update the payload encryption validation configuration for a Temporal Cloud\nnamespace. At least one flag must be set. Omitted flags keep the\nexisting values. An empty metadata key or values means the server\ndefaults apply (metadata-key=encoding, metadata-values=[binary/encrypted]).\n\nExample:\n\n```\ntemporal cloud namespace encryption-validation set --namespace my-namespace.my-account --mode warn --metadata-key encoding --metadata-value binary/encrypted\n```"
s.Command.Long = "Configure payload encryption validation for a Temporal Cloud namespace.\nUse this command to turn validation on (--mode warn or --mode deny) and to\nchange its settings. At least one flag must be set. Omitted flags keep the\nexisting values. An empty metadata key means the server default applies\n(metadata-key=encoding); omit --metadata-value to keep the existing values,\nwhich default to [binary/encrypted]. If nothing would change, the command\nerrors unless --idempotent is set.\n\nExamples:\n\n```\ntemporal cloud namespace encryption-validation set --namespace my-namespace.my-account --mode warn\ntemporal cloud namespace encryption-validation set --namespace my-namespace.my-account --mode deny --metadata-key encoding --metadata-value binary/encrypted\n```"
}
s.Command.Args = cobra.NoArgs
s.Command.Flags().StringVar(&s.Mode, "mode", "", "Payload encryption validation mode. Valid values: disabled, warn, deny. If omitted, the existing mode is kept. Required when encryption validation is not configured yet.")
s.Command.Flags().StringVar(&s.MetadataKey, "metadata-key", "", "Payload metadata key used to identify encrypted payloads. If omitted, the existing key is kept.")
s.Command.Flags().StringArrayVar(&s.MetadataValue, "metadata-value", nil, "Payload metadata value used to identify encrypted payloads. Repeat to add additional values. Replaces the existing values. If omitted, the existing values are kept.")
s.Command.Flags().StringArrayVar(&s.MetadataValue, "metadata-value", nil, "Payload metadata value used to identify encrypted payloads. Repeat to add additional values. Replaces the existing values. Values cannot be blank. If omitted, the existing values are kept.")
s.Command.Flags().BoolVar(&s.InspectHeader, "inspect-header", false, "Inspect workflow headers for encryption validation. If omitted, the existing value is kept.")
s.Command.Flags().BoolVar(&s.InspectFailure, "inspect-failure", false, "Inspect Failure payloads for encryption validation. If omitted, the existing value is kept.")
s.ClientOptions.BuildFlags(s.Command.Flags())
Expand Down
90 changes: 37 additions & 53 deletions temporalcloudcli/commands.namespace.encryption_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const (
encryptionValidationModeWarn = "warn"
encryptionValidationModeDeny = "deny"

alreadyInDesiredStateMessage = "Resource already in desired state"
// Server-side defaults applied when the metadata key or values are left empty.
defaultEncryptionValidationMetadataKey = "encoding"
defaultEncryptionValidationMetadataValue = "binary/encrypted"
)

var encryptionValidationSetFlags = []string{"mode", "metadata-key", "metadata-value", "inspect-header", "inspect-failure"}
Expand All @@ -35,7 +37,7 @@ func (c *CloudNamespaceEncryptionValidationGetCommand) run(cctx *CommandContext,

var spec *namespacev1.EncryptionValidationSpec
if res.Namespace.Spec != nil {
spec = res.Namespace.Spec.EncryptionValidation
spec = withEncryptionValidationDefaults(res.Namespace.Spec.EncryptionValidation)
}
return cctx.Printer.PrintResource(struct {
Namespace string `json:"namespace"`
Expand All @@ -52,6 +54,9 @@ func (c *CloudNamespaceEncryptionValidationSetCommand) run(cctx *CommandContext,
return errors.New("at least one of --mode, --metadata-key, --metadata-value, --inspect-header, " +
"or --inspect-failure must be set")
}
if flags.Changed("metadata-value") && slices.ContainsFunc(c.MetadataValue, isBlank) {
return errors.New("--metadata-value cannot be blank")
}
var mode namespacev1.EncryptionValidationSpec_EncryptionValidationMode
if flags.Changed("mode") {
var err error
Expand Down Expand Up @@ -94,8 +99,7 @@ func (c *CloudNamespaceEncryptionValidationSetCommand) run(cctx *CommandContext,
newSpec.EncryptionValidation.InspectFailure = c.InspectFailure
}
if proto.Equal(ns.Spec, newSpec) {
cctx.Printer.Println(alreadyInDesiredStateMessage)
return nil
return encryptionValidationNothingChanged(cctx, c.Idempotent)
}

yes, err := cctx.GetPrompter().PromptApply(ns.Spec, newSpec, false)
Expand All @@ -119,7 +123,7 @@ func (c *CloudNamespaceEncryptionValidationSetCommand) run(cctx *CommandContext,
return cctx.GetPoller(client, c.AsyncOperationOptions).HandleUpdateOperation(cctx, resp, err)
}

func (c *CloudNamespaceEncryptionValidationEnableCommand) run(cctx *CommandContext, _ []string) error {
func (c *CloudNamespaceEncryptionValidationDisableCommand) run(cctx *CommandContext, _ []string) error {
client, err := cctx.GetCloudClient(c.ClientOptions)
if err != nil {
return err
Expand All @@ -130,29 +134,21 @@ func (c *CloudNamespaceEncryptionValidationEnableCommand) run(cctx *CommandConte
}

ns := res.Namespace
newSpec := proto.Clone(ns.Spec).(*namespacev1.NamespaceSpec)
if newSpec.EncryptionValidation == nil {
newSpec.EncryptionValidation = &namespacev1.EncryptionValidationSpec{}
}
ev := newSpec.EncryptionValidation
// --deny always results in deny mode. Without it, an existing warn/deny mode is kept.
if c.Deny {
ev.Mode = namespacev1.EncryptionValidationSpec_ENCRYPTION_VALIDATION_MODE_DENY
} else if ev.Mode == namespacev1.EncryptionValidationSpec_ENCRYPTION_VALIDATION_MODE_UNSPECIFIED ||
ev.Mode == namespacev1.EncryptionValidationSpec_ENCRYPTION_VALIDATION_MODE_DISABLED {
ev.Mode = namespacev1.EncryptionValidationSpec_ENCRYPTION_VALIDATION_MODE_WARN
if ns.Spec.EncryptionValidation == nil {
return encryptionValidationNothingChanged(cctx, c.Idempotent)
}
newSpec := proto.Clone(ns.Spec).(*namespacev1.NamespaceSpec)
newSpec.EncryptionValidation.Mode = namespacev1.EncryptionValidationSpec_ENCRYPTION_VALIDATION_MODE_DISABLED
if proto.Equal(ns.Spec, newSpec) {
cctx.Printer.Println(alreadyInDesiredStateMessage)
return nil
return encryptionValidationNothingChanged(cctx, c.Idempotent)
}

yes, err := cctx.GetPrompter().PromptApply(ns.Spec, newSpec, false)
if err != nil {
return err
}
if !yes {
return errors.New("Aborting enable.")
return errors.New("Aborting disable.")
}

rv := ns.ResourceVersion
Expand All @@ -168,47 +164,35 @@ func (c *CloudNamespaceEncryptionValidationEnableCommand) run(cctx *CommandConte
return cctx.GetPoller(client, c.AsyncOperationOptions).HandleUpdateOperation(cctx, resp, err)
}

func (c *CloudNamespaceEncryptionValidationDisableCommand) run(cctx *CommandContext, _ []string) error {
client, err := cctx.GetCloudClient(c.ClientOptions)
if err != nil {
return err
}
res, err := client.GetNamespace(cctx, &cloudservice.GetNamespaceRequest{Namespace: c.Namespace})
if err != nil {
return err
// encryptionValidationNothingChanged handles a request that would not change the namespace.
// It matches the server's "nothing to change" handling used by other commands: an error by
// default, or an "unchanged" result when --idempotent is set.
func encryptionValidationNothingChanged(cctx *CommandContext, idempotent bool) error {
if idempotent {
return cctx.Printer.PrintStructured(newUnchangedResult(), printer.StructuredOptions{})
}
return errors.New("nothing to change: encryption validation is already in the requested state " +
"(use --idempotent to succeed without changes)")
}

ns := res.Namespace
if ns.Spec.EncryptionValidation == nil {
cctx.Printer.Println(alreadyInDesiredStateMessage)
// withEncryptionValidationDefaults returns a copy of spec with the server defaults filled in
// for an empty metadata key or empty metadata values, so `get` shows what is actually enforced.
func withEncryptionValidationDefaults(spec *namespacev1.EncryptionValidationSpec) *namespacev1.EncryptionValidationSpec {
if spec == nil {
return nil
}
newSpec := proto.Clone(ns.Spec).(*namespacev1.NamespaceSpec)
newSpec.EncryptionValidation.Mode = namespacev1.EncryptionValidationSpec_ENCRYPTION_VALIDATION_MODE_DISABLED
if proto.Equal(ns.Spec, newSpec) {
cctx.Printer.Println(alreadyInDesiredStateMessage)
return nil
}

yes, err := cctx.GetPrompter().PromptApply(ns.Spec, newSpec, false)
if err != nil {
return err
out := proto.Clone(spec).(*namespacev1.EncryptionValidationSpec)
if out.MetadataKey == "" {
out.MetadataKey = defaultEncryptionValidationMetadataKey
}
if !yes {
return errors.New("Aborting disable.")
if len(out.MetadataValues) == 0 {
out.MetadataValues = []string{defaultEncryptionValidationMetadataValue}
}
return out
}

rv := ns.ResourceVersion
if c.ResourceVersion != "" {
rv = c.ResourceVersion
}
resp, err := client.UpdateNamespace(cctx, &cloudservice.UpdateNamespaceRequest{
Namespace: c.Namespace,
Spec: newSpec,
ResourceVersion: rv,
AsyncOperationId: c.AsyncOperationId,
})
return cctx.GetPoller(client, c.AsyncOperationOptions).HandleUpdateOperation(cctx, resp, err)
func isBlank(s string) bool {
return strings.TrimSpace(s) == ""
}

func parseEncryptionValidationMode(value string) (namespacev1.EncryptionValidationSpec_EncryptionValidationMode, error) {
Expand Down
Loading
Loading