From ed21f81863450fd6167106711392e713a43c55be Mon Sep 17 00:00:00 2001 From: Jake Van Vorhis <83739412+jakedoublev@users.noreply.github.com> Date: Tue, 27 Aug 2024 08:40:03 -0700 Subject: [PATCH] fix(core): metadata rendering cleanup (#293) Remainder of #73 --- cmd/kas-registry.go | 56 ++++++++++++++++++------------ cmd/policy-attributeNamespaces.go | 10 +++--- cmd/policy-attributeValues.go | 4 +-- cmd/policy-attributes.go | 16 ++++----- cmd/policy-resourceMappings.go | 8 ++--- cmd/policy-subjectConditionSets.go | 8 ++--- cmd/policy-subject_mappings.go | 10 +++--- 7 files changed, 56 insertions(+), 56 deletions(-) diff --git a/cmd/kas-registry.go b/cmd/kas-registry.go index 8c3058a5..3fb0fe53 100644 --- a/cmd/kas-registry.go +++ b/cmd/kas-registry.go @@ -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) } @@ -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) { @@ -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) } @@ -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() { diff --git a/cmd/policy-attributeNamespaces.go b/cmd/policy-attributeNamespaces.go index 0e44a2db..bbbdd0c1 100644 --- a/cmd/policy-attributeNamespaces.go +++ b/cmd/policy-attributeNamespaces.go @@ -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") @@ -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...) @@ -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...) } @@ -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...) @@ -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...) } diff --git a/cmd/policy-attributeValues.go b/cmd/policy-attributeValues.go index a6373e4f..3aadc12c 100644 --- a/cmd/policy-attributeValues.go +++ b/cmd/policy-attributeValues.go @@ -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) { @@ -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...) } diff --git a/cmd/policy-attributes.go b/cmd/policy-attributes.go index 8e161b86..7553e22d 100644 --- a/cmd/policy-attributes.go +++ b/cmd/policy-attributes.go @@ -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 @@ -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...) } @@ -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...) @@ -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...) @@ -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...) @@ -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...) @@ -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...) @@ -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...) diff --git a/cmd/policy-resourceMappings.go b/cmd/policy-resourceMappings.go index 912dfe23..edffba26 100644 --- a/cmd/policy-resourceMappings.go +++ b/cmd/policy-resourceMappings.go @@ -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 @@ -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...) @@ -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...) @@ -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...) diff --git a/cmd/policy-subjectConditionSets.go b/cmd/policy-subjectConditionSets.go index c25125a0..1d6c32c3 100644 --- a/cmd/policy-subjectConditionSets.go +++ b/cmd/policy-subjectConditionSets.go @@ -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...) } @@ -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...) } @@ -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...) } @@ -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...) } diff --git a/cmd/policy-subject_mappings.go b/cmd/policy-subject_mappings.go index 5c51ecdd..2511f42f 100644 --- a/cmd/policy-subject_mappings.go +++ b/cmd/policy-subject_mappings.go @@ -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 @@ -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...) } @@ -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...) } @@ -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...) @@ -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...)