diff --git a/temporalcloudcli/commands.gen.go b/temporalcloudcli/commands.gen.go index 7bb14ff..c1c13c4 100644 --- a/temporalcloudcli/commands.gen.go +++ b/temporalcloudcli/commands.gen.go @@ -2721,9 +2721,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.\nAn unset metadata key or values are shown with the server defaults\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.\nAn unset metadata key or values are shown with the server defaults\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()) diff --git a/temporalcloudcli/commands.namespace.encryption_validation.go b/temporalcloudcli/commands.namespace.encryption_validation.go index 41b4d87..a56ba55 100644 --- a/temporalcloudcli/commands.namespace.encryption_validation.go +++ b/temporalcloudcli/commands.namespace.encryption_validation.go @@ -19,9 +19,19 @@ const ( encryptionValidationModeDeny = "deny" alreadyInDesiredStateMessage = "Resource already in desired state" + + // Default the server applies when the metadata key is unset, per the cloud-api + // EncryptionValidationSpec docs. + defaultEncryptionValidationMetadataKey = "encoding" ) -var encryptionValidationSetFlags = []string{"mode", "metadata-key", "metadata-value", "inspect-header", "inspect-failure"} +var ( + encryptionValidationSetFlags = []string{"mode", "metadata-key", "metadata-value", "inspect-header", "inspect-failure"} + + // Default the server applies when the metadata values are unset, per the cloud-api + // EncryptionValidationSpec docs. + defaultEncryptionValidationMetadataValues = []string{"binary/encrypted"} +) func (c *CloudNamespaceEncryptionValidationGetCommand) run(cctx *CommandContext, _ []string) error { client, err := cctx.GetCloudClient(c.ClientOptions) @@ -34,8 +44,15 @@ func (c *CloudNamespaceEncryptionValidationGetCommand) run(cctx *CommandContext, } var spec *namespacev1.EncryptionValidationSpec - if res.Namespace.Spec != nil { - spec = res.Namespace.Spec.EncryptionValidation + if res.Namespace.Spec != nil && res.Namespace.Spec.EncryptionValidation != nil { + // Show the metadata key and values the server enforces, not just the stored ones. + spec = proto.Clone(res.Namespace.Spec.EncryptionValidation).(*namespacev1.EncryptionValidationSpec) + if spec.MetadataKey == "" { + spec.MetadataKey = defaultEncryptionValidationMetadataKey + } + if len(spec.MetadataValues) == 0 { + spec.MetadataValues = slices.Clone(defaultEncryptionValidationMetadataValues) + } } return cctx.Printer.PrintResource(struct { Namespace string `json:"namespace"` diff --git a/temporalcloudcli/commands.namespace.encryption_validation_test.go b/temporalcloudcli/commands.namespace.encryption_validation_test.go index cf6931e..62afed1 100644 --- a/temporalcloudcli/commands.namespace.encryption_validation_test.go +++ b/temporalcloudcli/commands.namespace.encryption_validation_test.go @@ -60,6 +60,53 @@ func TestNamespaceEncryptionValidationGet(t *testing.T) { }, }, }, + { + name: "UnsetMetadataShowsDefaults", + cmd: temporalcloudcli.CloudNamespaceEncryptionValidationGetCommand{ + NamespaceOptions: temporalcloudcli.NamespaceOptions{Namespace: "my-ns.my-acct"}, + }, + cloudClientExpectations: func(c *cloudmock.MockCloudServiceClient) { + c.EXPECT(). + GetNamespace(mock.Anything, &cloudservice.GetNamespaceRequest{Namespace: "my-ns.my-acct"}, mock.Anything). + Return(&cloudservice.GetNamespaceResponse{Namespace: namespaceWithEncryptionValidation( + &namespacev1.EncryptionValidationSpec{ + Mode: namespacev1.EncryptionValidationSpec_ENCRYPTION_VALIDATION_MODE_DENY, + }, + )}, nil) + }, + expectedJsonOutput: map[string]any{ + "namespace": "my-ns.my-acct", + "spec": map[string]any{ + "mode": "ENCRYPTION_VALIDATION_MODE_DENY", + "metadataKey": "encoding", + "metadataValues": []any{"binary/encrypted"}, + }, + }, + }, + { + name: "UnsetMetadataKeyOnly", + cmd: temporalcloudcli.CloudNamespaceEncryptionValidationGetCommand{ + NamespaceOptions: temporalcloudcli.NamespaceOptions{Namespace: "my-ns.my-acct"}, + }, + cloudClientExpectations: func(c *cloudmock.MockCloudServiceClient) { + c.EXPECT(). + GetNamespace(mock.Anything, &cloudservice.GetNamespaceRequest{Namespace: "my-ns.my-acct"}, mock.Anything). + Return(&cloudservice.GetNamespaceResponse{Namespace: namespaceWithEncryptionValidation( + &namespacev1.EncryptionValidationSpec{ + Mode: namespacev1.EncryptionValidationSpec_ENCRYPTION_VALIDATION_MODE_WARN, + MetadataValues: []string{"binary/aes256"}, + }, + )}, nil) + }, + expectedJsonOutput: map[string]any{ + "namespace": "my-ns.my-acct", + "spec": map[string]any{ + "mode": "ENCRYPTION_VALIDATION_MODE_WARN", + "metadataKey": "encoding", + "metadataValues": []any{"binary/aes256"}, + }, + }, + }, { name: "NilSpec", cmd: temporalcloudcli.CloudNamespaceEncryptionValidationGetCommand{ diff --git a/temporalcloudcli/commands.yml b/temporalcloudcli/commands.yml index c4a947f..d23d2c2 100644 --- a/temporalcloudcli/commands.yml +++ b/temporalcloudcli/commands.yml @@ -774,6 +774,8 @@ commands: summary: '[Experimental] Get namespace payload encryption validation configuration' description: | Retrieve the current payload encryption validation configuration for a Temporal Cloud namespace. + An unset metadata key or values are shown with the server defaults + (metadata-key=encoding, metadata-values=[binary/encrypted]). Example: