Skip to content
Closed
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
4 changes: 2 additions & 2 deletions temporalcloudcli/commands.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
23 changes: 20 additions & 3 deletions temporalcloudcli/commands.namespace.encryption_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 2 additions & 0 deletions temporalcloudcli/commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
Loading