Skip to content

Commit

Permalink
fix(core): metadata rendering cleanup (#293)
Browse files Browse the repository at this point in the history
Remainder of #73
  • Loading branch information
jakedoublev authored Aug 27, 2024
1 parent d2a3cb9 commit ed21f81
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 56 deletions.
56 changes: 33 additions & 23 deletions cmd/kas-registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ func policy_getKeyAccessRegistry(cmd *cobra.Command, args []string) {
keyType = "Remote"
key.PublicKey = &policy.PublicKey_Remote{Remote: kas.GetPublicKey().GetRemote()}
}
rows := [][]string{
{"Id", kas.GetId()},
{"URI", kas.GetUri()},
{"PublicKey Type", keyType},
{"PublicKey", kas.GetPublicKey().String()},
}

if mdRows := getMetadataRows(kas.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}
t := cli.NewTabular(rows...)

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", kas.GetPublicKey().String()},
)
HandleSuccess(cmd, kas.Id, t, kas)
}

Expand Down Expand Up @@ -122,15 +126,18 @@ func policy_createKeyAccessRegistry(cmd *cobra.Command, args []string) {
cli.ExitWithError("Failed to create Registered KAS entry", err)
}

t := cli.NewTabular(
[]string{"Id", created.Id},
[]string{"URI", created.Uri},
[]string{"PublicKey Type", keyType},
[]string{"PublicKey", cachedJSON},
// TODO: render labels [https://github.com/opentdf/otdfctl/issues/73]
)
rows := [][]string{
{"Id", created.GetId()},
{"URI", created.GetUri()},
{"PublicKey Type", keyType},
{"PublicKey", key.String()},
}
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 Down Expand Up @@ -174,11 +181,14 @@ func policy_updateKeyAccessRegistry(cmd *cobra.Command, args []string) {
if err != nil {
cli.ExitWithError(fmt.Sprintf("Failed to update Registered KAS entry (%s)", id), err)
}
t := cli.NewTabular(
[]string{"Id", id},
[]string{"URI", updated.GetUri()},
// TODO: render labels [https://github.com/opentdf/otdfctl/issues/73]
)
rows := [][]string{
{"Id", id},
{"URI", updated.GetUri()},
}
if mdRows := getMetadataRows(updated.GetMetadata()); mdRows != nil {
rows = append(rows, mdRows...)
}
t := cli.NewTabular(rows...)
HandleSuccess(cmd, id, t, updated)
}

Expand Down Expand Up @@ -206,11 +216,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

0 comments on commit ed21f81

Please sign in to comment.