Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
78 changes: 44 additions & 34 deletions cmd/kas-registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,24 @@ func policy_getKeyAccessRegistry(cmd *cobra.Command, args []string) {
}

keyType := "Local"
key := kas.PublicKey.GetLocal()
key := kas.GetPublicKey().GetLocal()
if kas.PublicKey.GetRemote() != "" {
keyType = "Remote"
key = kas.PublicKey.GetRemote()
key = kas.GetPublicKey().GetRemote()
}

t := cli.NewTabular(
[]string{"Id", kas.Id},
// TODO: render labels [https://github.com/opentdf/otdfctl/issues/73]
[]string{"URI", kas.Uri},
[]string{"PublicKey Type", keyType},
[]string{"PublicKey", key},
)
HandleSuccess(cmd, kas.Id, t, kas)
rows := [][]string{
{"Id", kas.GetId()},
{"URI", kas.GetUri()},
{"PublicKey Type", keyType},
{"PublicKey", key},
}
if mdRows := getMetadataRows(kas.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}

t := cli.NewTabular(rows...)
HandleSuccess(cmd, kas.GetId(), t, kas)
}

func policy_listKeyAccessRegistries(cmd *cobra.Command, args []string) {
Expand All @@ -60,15 +64,15 @@ func policy_listKeyAccessRegistries(cmd *cobra.Command, args []string) {
rows := []table.Row{}
for _, kas := range list {
keyType := "Local"
key := kas.PublicKey.GetLocal()
if kas.PublicKey.GetRemote() != "" {
key := kas.GetPublicKey().GetLocal()
if kas.GetPublicKey().GetRemote() != "" {
keyType = "Remote"
key = kas.PublicKey.GetRemote()
key = kas.GetPublicKey().GetRemote()
}

rows = append(rows, table.NewRow(table.RowData{
"id": kas.Id,
"uri": kas.Uri,
"id": kas.GetId(),
"uri": kas.GetUri(),
"pk_loc": keyType,
"pk": key,
}))
Expand All @@ -88,15 +92,15 @@ func policy_createKeyAccessRegistry(cmd *cobra.Command, args []string) {
metadataLabels := flagHelper.GetStringSlice("label", metadataLabels, cli.FlagHelperStringSliceOptions{Min: 0})

if local == "" && remote == "" {
e := fmt.Errorf("A public key is required. Please pass either a local or remote public key")
e := fmt.Errorf("a public key is required. Please pass either a local or remote public key")
cli.ExitWithError("Issue with create flags 'public-key-local' and 'public-key-remote': ", e)
}

key := &policy.PublicKey{}
keyType := "Local"
if local != "" {
if remote != "" {
e := fmt.Errorf("Only one public key is allowed. Please pass either a local or remote public key but not both")
e := fmt.Errorf("only one public key is allowed. Please pass either a local or remote public key but not both")
cli.ExitWithError("Issue with create flags 'public-key-local' and 'public-key-remote': ", e)
}
key.PublicKey = &policy.PublicKey_Local{Local: local}
Expand All @@ -114,15 +118,18 @@ func policy_createKeyAccessRegistry(cmd *cobra.Command, args []string) {
cli.ExitWithError("Failed to create KAS registry entry", err)
}

t := cli.NewTabular(
[]string{"Id", created.Id},
[]string{"URI", created.Uri},
[]string{"PublicKey Type", keyType},
[]string{"PublicKey", local},
// TODO: render labels [https://github.com/opentdf/otdfctl/issues/73]
)
rows := [][]string{
{"Id", created.GetId()},
{"URI", created.GetUri()},
{"PublicKey Type", keyType},
{"PublicKey", local},
}
if mdRows := getMetadataRows(created.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}
t := cli.NewTabular(rows...)

HandleSuccess(cmd, created.Id, t, created)
HandleSuccess(cmd, created.GetId(), t, created)
}

func policy_updateKeyAccessRegistry(cmd *cobra.Command, args []string) {
Expand All @@ -144,7 +151,7 @@ func policy_updateKeyAccessRegistry(cmd *cobra.Command, args []string) {
// TODO: should update of a type of key be a dangerous mutation or cause a need for confirmation in the CLI?
var pubKey *policy.PublicKey
if local != "" && remote != "" {
e := fmt.Errorf("Only one public key is allowed. Please pass either a local or remote public key but not both")
e := fmt.Errorf("only one public key is allowed. Please pass either a local or remote public key but not both")
cli.ExitWithError("Issue with update flags 'public-key-local' and 'public-key-remote': ", e)
} else if local != "" {
pubKey = &policy.PublicKey{PublicKey: &policy.PublicKey_Local{Local: local}}
Expand All @@ -162,11 +169,14 @@ func policy_updateKeyAccessRegistry(cmd *cobra.Command, args []string) {
if err != nil {
cli.ExitWithError(fmt.Sprintf("Failed to update KAS registry entry (%s)", id), err)
}
t := cli.NewTabular(
[]string{"Id", id},
[]string{"URI", uri},
// TODO: render labels [https://github.com/opentdf/otdfctl/issues/73]
)
rows := [][]string{
{"Id", id},
{"URI", uri},
}
if mdRows := getMetadataRows(updated.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}
t := cli.NewTabular(rows...)
HandleSuccess(cmd, id, t, updated)
}

Expand All @@ -191,11 +201,11 @@ func policy_deleteKeyAccessRegistry(cmd *cobra.Command, args []string) {
}

t := cli.NewTabular(
[]string{"Id", "URI"},
[]string{kas.Id, kas.Uri},
[]string{"Id", kas.GetId()},
[]string{"URI", kas.GetUri()},
)

HandleSuccess(cmd, kas.Id, t, kas)
HandleSuccess(cmd, kas.GetId(), t, kas)
}

func init() {
Expand Down
10 changes: 4 additions & 6 deletions cmd/policy-attributeNamespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"github.com/spf13/cobra"
)

// TODO: add metadata to outputs once [https://github.com/opentdf/otdfctl/issues/73] is addressed

var (
policy_attributeNamespacesCmd = man.Docs.GetCommand("policy/attributes/namespaces")

Expand All @@ -34,7 +32,7 @@ func policy_getAttributeNamespace(cmd *cobra.Command, args []string) {
{"Id", ns.Id},
{"Name", ns.Name},
}
if mdRows := getMetadataRows(ns.Metadata); mdRows != nil {
if mdRows := getMetadataRows(ns.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}
t := cli.NewTabular(rows...)
Expand Down Expand Up @@ -92,7 +90,7 @@ func policy_createAttributeNamespace(cmd *cobra.Command, args []string) {
{"Name", name},
{"Id", created.Id},
}
if mdRows := getMetadataRows(created.Metadata); mdRows != nil {
if mdRows := getMetadataRows(created.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}

Expand Down Expand Up @@ -124,7 +122,7 @@ func policy_deactivateAttributeNamespace(cmd *cobra.Command, args []string) {
{"Id", ns.Id},
{"Name", ns.Name},
}
if mdRows := getMetadataRows(d.Metadata); mdRows != nil {
if mdRows := getMetadataRows(d.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}
t := cli.NewTabular(rows...)
Expand All @@ -151,7 +149,7 @@ func policy_updateAttributeNamespace(cmd *cobra.Command, args []string) {
{"Id", ns.Id},
{"Name", ns.Name},
}
if mdRows := getMetadataRows(ns.Metadata); mdRows != nil {
if mdRows := getMetadataRows(ns.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}

Expand Down
4 changes: 1 addition & 3 deletions cmd/policy-attributeValues.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"github.com/spf13/cobra"
)

// TODO: add metadata to outputs once [https://github.com/opentdf/otdfctl/issues/73] is addressed

var policy_attributeValuesCmd *cobra.Command

func policy_createAttributeValue(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -345,7 +343,7 @@ func handleValueSuccess(cmd *cobra.Command, v *policy.Value) {
{"FQN", v.GetFqn()},
{"Value", v.GetValue()},
}
if mdRows := getMetadataRows(v.Metadata); mdRows != nil {
if mdRows := getMetadataRows(v.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}

Expand Down
16 changes: 7 additions & 9 deletions cmd/policy-attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/spf13/cobra"
)

// TODO: add metadata to outputs once [https://github.com/opentdf/otdfctl/issues/73] is addressed

var (
attrValues []string
metadataLabels []string
Expand Down Expand Up @@ -50,7 +48,7 @@ func policy_createAttribute(cmd *cobra.Command, args []string) {
{"Values", cli.CommaSeparated(a.Values)},
{"Namespace", a.Namespace},
}
if mdRows := getMetadataRows(attr.Metadata); mdRows != nil {
if mdRows := getMetadataRows(attr.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}

Expand Down Expand Up @@ -80,7 +78,7 @@ func policy_getAttribute(cmd *cobra.Command, args []string) {
{"Values", cli.CommaSeparated(a.Values)},
{"Namespace", a.Namespace},
}
if mdRows := getMetadataRows(attr.Metadata); mdRows != nil {
if mdRows := getMetadataRows(attr.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}
t := cli.NewTabular(rows...)
Expand Down Expand Up @@ -155,7 +153,7 @@ func policy_deactivateAttribute(cmd *cobra.Command, args []string) {
{"Values", cli.CommaSeparated(a.Values)},
{"Namespace", a.Namespace},
}
if mdRows := getMetadataRows(attr.Metadata); mdRows != nil {
if mdRows := getMetadataRows(attr.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}
t := cli.NewTabular(rows...)
Expand All @@ -177,7 +175,7 @@ func policy_updateAttribute(cmd *cobra.Command, args []string) {
{"Id", a.Id},
{"Name", a.Name},
}
if mdRows := getMetadataRows(a.Metadata); mdRows != nil {
if mdRows := getMetadataRows(a.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}
t := cli.NewTabular(rows...)
Expand Down Expand Up @@ -209,7 +207,7 @@ func policy_unsafeReactivateAttribute(cmd *cobra.Command, args []string) {
{"Id", a.Id},
{"Name", a.Name},
}
if mdRows := getMetadataRows(a.Metadata); mdRows != nil {
if mdRows := getMetadataRows(a.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}
t := cli.NewTabular(rows...)
Expand Down Expand Up @@ -255,7 +253,7 @@ func policy_unsafeUpdateAttribute(cmd *cobra.Command, args []string) {
{"Values", cli.CommaSeparated(values)},
{"Value IDs", cli.CommaSeparated(valueIDs)},
}
if mdRows := getMetadataRows(a.Metadata); mdRows != nil {
if mdRows := getMetadataRows(a.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}
t := cli.NewTabular(rows...)
Expand Down Expand Up @@ -288,7 +286,7 @@ func policy_unsafeDeleteAttribute(cmd *cobra.Command, args []string) {
{"Id", a.Id},
{"Name", a.Name},
}
if mdRows := getMetadataRows(a.Metadata); mdRows != nil {
if mdRows := getMetadataRows(a.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}
t := cli.NewTabular(rows...)
Expand Down
8 changes: 3 additions & 5 deletions cmd/policy-resourceMappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/spf13/cobra"
)

// TODO: add metadata to outputs once [https://github.com/opentdf/otdfctl/issues/73] is addressed

var (
policy_resource_mappingsTerms []string
policy_resourceMappingsCmd *cobra.Command
Expand All @@ -39,7 +37,7 @@ func policy_createResourceMapping(cmd *cobra.Command, args []string) {
{"Attribute Value", resourceMapping.AttributeValue.Value},
{"Terms", strings.Join(resourceMapping.Terms, ", ")},
}
if mdRows := getMetadataRows(resourceMapping.Metadata); mdRows != nil {
if mdRows := getMetadataRows(resourceMapping.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}
t := cli.NewTabular(rows...)
Expand All @@ -63,7 +61,7 @@ func policy_getResourceMapping(cmd *cobra.Command, args []string) {
{"Attribute Value", resourceMapping.AttributeValue.Value},
{"Terms", strings.Join(resourceMapping.Terms, ", ")},
}
if mdRows := getMetadataRows(resourceMapping.Metadata); mdRows != nil {
if mdRows := getMetadataRows(resourceMapping.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}
t := cli.NewTabular(rows...)
Expand Down Expand Up @@ -125,7 +123,7 @@ func policy_updateResourceMapping(cmd *cobra.Command, args []string) {
{"Attribute Value", resourceMapping.AttributeValue.Value},
{"Terms", strings.Join(resourceMapping.Terms, ", ")},
}
if mdRows := getMetadataRows(resourceMapping.Metadata); mdRows != nil {
if mdRows := getMetadataRows(resourceMapping.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}
t := cli.NewTabular(rows...)
Expand Down
8 changes: 4 additions & 4 deletions cmd/policy-subjectConditionSets.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func policy_createSubjectConditionSet(cmd *cobra.Command, args []string) {
{"SubjectSets", string(subjectSetsJSON)},
}

if mdRows := getMetadataRows(scs.Metadata); mdRows != nil {
if mdRows := getMetadataRows(scs.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}

Expand Down Expand Up @@ -130,7 +130,7 @@ func policy_getSubjectConditionSet(cmd *cobra.Command, args []string) {
{"Id", scs.Id},
{"SubjectSets", string(subjectSetsJSON)},
}
if mdRows := getMetadataRows(scs.Metadata); mdRows != nil {
if mdRows := getMetadataRows(scs.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}

Expand Down Expand Up @@ -233,7 +233,7 @@ func policy_updateSubjectConditionSet(cmd *cobra.Command, args []string) {
{"SubjectSets", string(subjectSetsJSON)},
}

if mdRows := getMetadataRows(scs.Metadata); mdRows != nil {
if mdRows := getMetadataRows(scs.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}

Expand Down Expand Up @@ -269,7 +269,7 @@ func policy_deleteSubjectConditionSet(cmd *cobra.Command, args []string) {
{"SubjectSets", string(subjectSetsJSON)},
}

if mdRows := getMetadataRows(scs.Metadata); mdRows != nil {
if mdRows := getMetadataRows(scs.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}

Expand Down
10 changes: 4 additions & 6 deletions cmd/policy-subject_mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"github.com/spf13/cobra"
)

// TODO: add metadata to outputs once [https://github.com/opentdf/otdfctl/issues/73] is addressed

var (
standardActions []string
customActions []string
Expand Down Expand Up @@ -50,7 +48,7 @@ func policy_getSubjectMapping(cmd *cobra.Command, args []string) {
{"Subject Condition Set: Id", mapping.SubjectConditionSet.Id},
{"Subject Condition Set", string(subjectSetsJSON)},
}
if mdRows := getMetadataRows(mapping.Metadata); mdRows != nil {
if mdRows := getMetadataRows(mapping.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}

Expand Down Expand Up @@ -171,7 +169,7 @@ func policy_createSubjectMapping(cmd *cobra.Command, args []string) {
{"Attribute Value Id", mapping.AttributeValue.Id},
}

if mdRows := getMetadataRows(mapping.Metadata); mdRows != nil {
if mdRows := getMetadataRows(mapping.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}

Expand Down Expand Up @@ -200,7 +198,7 @@ func policy_deleteSubjectMapping(cmd *cobra.Command, args []string) {
cli.ExitWithError(errMsg, err)
}
rows := [][]string{{"Id", sm.Id}}
if mdRows := getMetadataRows(deleted.Metadata); mdRows != nil {
if mdRows := getMetadataRows(deleted.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}
t := cli.NewTabular(rows...)
Expand Down Expand Up @@ -239,7 +237,7 @@ func policy_updateSubjectMapping(cmd *cobra.Command, args []string) {
cli.ExitWithError("Failed to update subject mapping", err)
}
rows := [][]string{{"Id", id}}
if mdRows := getMetadataRows(updated.Metadata); mdRows != nil {
if mdRows := getMetadataRows(updated.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}
t := cli.NewTabular(rows...)
Expand Down