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
16 changes: 16 additions & 0 deletions cmd/policy/kasKeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"github.com/opentdf/platform/protocol/go/policy"
"github.com/opentdf/platform/protocol/go/policy/kasregistry"
"github.com/spf13/cobra"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

const (
Expand Down Expand Up @@ -419,6 +421,16 @@ func policyListKasKeys(cmd *cobra.Command, args []string) {
cli.ExitWithError("Invalid kas identifier", err)
}

if kasIdentifier != "" {
_, err := h.GetKasRegistryEntry(c.Context(), kasLookup)
if err != nil {
if status.Code(err) == codes.NotFound {
cli.ExitWithError(kasRegistryMissingErrorMessage(kasIdentifier), nil)
}
cli.ExitWithError("Failed to resolve KAS registry entry", err)
}
}

// Get the list of keys.
resp, err := h.ListKasKeys(c.Context(), limit, offset, alg, kasLookup, legacy)
if err != nil {
Expand Down Expand Up @@ -466,6 +478,10 @@ func policyListKasKeys(cmd *cobra.Command, args []string) {
common.HandleSuccess(cmd, "", t, resp)
}

func kasRegistryMissingErrorMessage(kas string) string {
return fmt.Sprintf("KAS %q is not registered; create one with `policy kas-registry create`", kas)
}

func policyListKeyMappings(cmd *cobra.Command, args []string) {
c := cli.New(cmd, args)
h := common.NewHandler(c)
Expand Down
10 changes: 10 additions & 0 deletions e2e/kas-keys.bats
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,16 @@ format_kas_name_as_uri() {
delete_kas_registry "$KAS_ID_LIST"
}

@test "kas-keys: list keys (kas not registered)" {
MISSING_KAS_NAME=$(generate_kas_name)
MISSING_KAS_URI=$(format_kas_name_as_uri "${MISSING_KAS_NAME}")

run_otdfctl_key list --kas "${MISSING_KAS_URI}"
assert_failure
assert_output --partial "is not registered"
assert_output --partial "policy kas-registry create"
}


@test "kas-keys: list legacy keys" {
KAS_NAME_LIST=$(generate_kas_name)
Expand Down
Loading