From 7cf43747d00c852a7a6a07fd2bad36e04c27a4cf Mon Sep 17 00:00:00 2001 From: jakedoublev Date: Tue, 3 Dec 2024 14:27:37 -0800 Subject: [PATCH 01/14] feat(core): pagination of LIST commands --- docs/man/policy/attributes/list.md | 6 ++++++ docs/man/policy/attributes/namespaces/list.md | 6 ++++++ docs/man/policy/attributes/values/list.md | 6 ++++++ docs/man/policy/kas-grants/list.md | 6 ++++++ docs/man/policy/kas-registry/list.md | 7 +++++++ docs/man/policy/resource-mappings/list.md | 7 +++++++ docs/man/policy/subject-condition-sets/list.md | 7 +++++++ docs/man/policy/subject-mappings/list.md | 7 +++++++ 8 files changed, 52 insertions(+) diff --git a/docs/man/policy/attributes/list.md b/docs/man/policy/attributes/list.md index e7a19908..7ee1337c 100644 --- a/docs/man/policy/attributes/list.md +++ b/docs/man/policy/attributes/list.md @@ -13,6 +13,12 @@ command: - inactive - any default: active + - name: limit + shorthand: l + description: Limit retrieved count (default set by platform if not provided) + - name: offset + shorthand: o + description: Offset quantity from start of the list (page) --- By default, the list will only provide `active` attributes if unspecified, but the filter can be controlled with the `--state` flag. diff --git a/docs/man/policy/attributes/namespaces/list.md b/docs/man/policy/attributes/namespaces/list.md index 3f58d76e..b3ba2978 100644 --- a/docs/man/policy/attributes/namespaces/list.md +++ b/docs/man/policy/attributes/namespaces/list.md @@ -9,6 +9,12 @@ command: - name: state shorthand: s description: Filter by state [active, inactive, any] + - name: limit + shorthand: l + description: Limit retrieved count (default set by platform if not provided) + - name: offset + shorthand: o + description: Offset quantity from start of the list (page) --- For more general information, see the `namespaces` subcommand. diff --git a/docs/man/policy/attributes/values/list.md b/docs/man/policy/attributes/values/list.md index 95484e88..dbf9512e 100644 --- a/docs/man/policy/attributes/values/list.md +++ b/docs/man/policy/attributes/values/list.md @@ -17,6 +17,12 @@ command: - inactive - any default: active + - name: limit + shorthand: l + description: Limit retrieved count (default set by platform if not provided) + - name: offset + shorthand: o + description: Offset quantity from start of the list (page) --- By default, the list will only provide `active` values if unspecified, but the filter can be controlled with the `--state` flag. diff --git a/docs/man/policy/kas-grants/list.md b/docs/man/policy/kas-grants/list.md index dba055e0..992f8b53 100644 --- a/docs/man/policy/kas-grants/list.md +++ b/docs/man/policy/kas-grants/list.md @@ -10,6 +10,12 @@ command: - name: kas shorthand: k description: The optional ID or URI of a KAS to filter the list + - name: limit + shorthand: l + description: Limit retrieved count (default set by platform if not provided) + - name: offset + shorthand: o + description: Offset quantity from start of the list (page) --- List the Grants of Registered Key Access Servers (KASes) to attribute namespaces, definitions, diff --git a/docs/man/policy/kas-registry/list.md b/docs/man/policy/kas-registry/list.md index c7b2ce44..2972a9fa 100644 --- a/docs/man/policy/kas-registry/list.md +++ b/docs/man/policy/kas-registry/list.md @@ -4,6 +4,13 @@ command: name: list aliases: - l + flags: + - name: limit + shorthand: l + description: Limit retrieved count (default set by platform if not provided) + - name: offset + shorthand: o + description: Offset quantity from start of the list (page) --- For more information about registration of Key Access Servers, see the manual for `kas-registry`. diff --git a/docs/man/policy/resource-mappings/list.md b/docs/man/policy/resource-mappings/list.md index 57a1186c..f5af896a 100644 --- a/docs/man/policy/resource-mappings/list.md +++ b/docs/man/policy/resource-mappings/list.md @@ -4,6 +4,13 @@ command: name: list aliases: - l + flags: + - name: limit + shorthand: l + description: Limit retrieved count (default set by platform if not provided) + - name: offset + shorthand: o + description: Offset quantity from start of the list (page) --- For more information about resource mappings, see the `resource-mappings` subcommand. diff --git a/docs/man/policy/subject-condition-sets/list.md b/docs/man/policy/subject-condition-sets/list.md index 4ab11705..a0c58961 100644 --- a/docs/man/policy/subject-condition-sets/list.md +++ b/docs/man/policy/subject-condition-sets/list.md @@ -5,6 +5,13 @@ command: name: list aliases: - l + flags: + - name: limit + shorthand: l + description: Limit retrieved count (default set by platform if not provided) + - name: offset + shorthand: o + description: Offset quantity from start of the list (page) --- For more information about subject condition sets, see the `subject-condition-sets` subcommand. diff --git a/docs/man/policy/subject-mappings/list.md b/docs/man/policy/subject-mappings/list.md index e433bb6b..ba021b80 100644 --- a/docs/man/policy/subject-mappings/list.md +++ b/docs/man/policy/subject-mappings/list.md @@ -4,6 +4,13 @@ command: name: list aliases: - l + flags: + - name: limit + shorthand: l + description: Limit retrieved count (default set by platform if not provided) + - name: offset + shorthand: o + description: Offset quantity from start of the list (page) --- For more information about subject mappings, see the `subject-mappings` subcommand. From 9b4f020f7c9f75f2e3cd8a194d77d280f77e1090 Mon Sep 17 00:00:00 2001 From: jakedoublev Date: Tue, 3 Dec 2024 14:43:49 -0800 Subject: [PATCH 02/14] add list pagination flags to list commands --- cmd/dev.go | 22 +++++++++++++++++++++- cmd/kas-grants.go | 2 ++ cmd/kas-registry.go | 1 + cmd/policy-attributeNamespaces.go | 1 + cmd/policy-attributeValues.go | 1 + cmd/policy-attributes.go | 1 + cmd/policy-resourceMappings.go | 1 + cmd/policy-subjectConditionSets.go | 1 + cmd/policy-subjectMappings.go | 1 + 9 files changed, 30 insertions(+), 1 deletion(-) diff --git a/cmd/dev.go b/cmd/dev.go index ff79d882..8dff64e7 100644 --- a/cmd/dev.go +++ b/cmd/dev.go @@ -18,7 +18,11 @@ import ( // devCmd is the command for playground-style development var devCmd = man.Docs.GetCommand("dev") -var metadataLabels []string +var ( + metadataLabels []string + defaultListFlagLimit int32 = 300 + defaultListFlagOffset int32 = 0 +) func dev_designSystem(cmd *cobra.Command, args []string) { fmt.Print("Design system\n=============\n\n") @@ -116,6 +120,22 @@ func injectLabelFlags(cmd *cobra.Command, isUpdate bool) { } } +// Adds reusable limit/offset flags to a Policy LIST command +func injectListPaginationFlags(listDoc *man.Doc) { + listDoc.Flags().Int32P( + listDoc.GetDocFlag("limit").Name, + listDoc.GetDocFlag("limit").Shorthand, + defaultListFlagLimit, + listDoc.GetDocFlag("limit").Description, + ) + listDoc.Flags().Int32P( + listDoc.GetDocFlag("offset").Name, + listDoc.GetDocFlag("offset").Shorthand, + defaultListFlagOffset, + listDoc.GetDocFlag("offset").Description, + ) +} + // Read bytes from stdin without blocking by checking size first func readPipedStdin() []byte { stat, err := os.Stdin.Stat() diff --git a/cmd/kas-grants.go b/cmd/kas-grants.go index 9c60bc95..fb4aca41 100644 --- a/cmd/kas-grants.go +++ b/cmd/kas-grants.go @@ -304,6 +304,8 @@ func init() { listCmd.GetDocFlag("kas").Default, listCmd.GetDocFlag("kas").Description, ) + injectListPaginationFlags(listCmd) + cmd := man.Docs.GetCommand("policy/kas-grants", man.WithSubcommands(assignCmd, unassignCmd, listCmd), ) diff --git a/cmd/kas-registry.go b/cmd/kas-registry.go index 44d4175b..7d096e47 100644 --- a/cmd/kas-registry.go +++ b/cmd/kas-registry.go @@ -268,6 +268,7 @@ func init() { listDoc := man.Docs.GetCommand("policy/kas-registry/list", man.WithRun(policy_listKeyAccessRegistries), ) + injectListPaginationFlags(listDoc) createDoc := man.Docs.GetCommand("policy/kas-registry/create", man.WithRun(policy_createKeyAccessRegistry), diff --git a/cmd/policy-attributeNamespaces.go b/cmd/policy-attributeNamespaces.go index ed3db7df..1f21d509 100644 --- a/cmd/policy-attributeNamespaces.go +++ b/cmd/policy-attributeNamespaces.go @@ -281,6 +281,7 @@ func init() { listCmd.GetDocFlag("state").Default, listCmd.GetDocFlag("state").Description, ) + injectListPaginationFlags(listCmd) createDoc := man.Docs.GetCommand("policy/attributes/namespaces/create", man.WithRun(policy_createAttributeNamespace), diff --git a/cmd/policy-attributeValues.go b/cmd/policy-attributeValues.go index d3ddac34..b6e13fdd 100644 --- a/cmd/policy-attributeValues.go +++ b/cmd/policy-attributeValues.go @@ -264,6 +264,7 @@ func init() { listCmd.GetDocFlag("state").Default, listCmd.GetDocFlag("state").Description, ) + injectListPaginationFlags(listCmd) updateCmd := man.Docs.GetCommand("policy/attributes/values/update", man.WithRun(policy_updateAttributeValue), diff --git a/cmd/policy-attributes.go b/cmd/policy-attributes.go index 9a855f4f..95d68cb8 100644 --- a/cmd/policy-attributes.go +++ b/cmd/policy-attributes.go @@ -349,6 +349,7 @@ func init() { listDoc.GetDocFlag("state").Default, listDoc.GetDocFlag("state").Description, ) + injectListPaginationFlags(listDoc) // Update an attribute updateDoc := man.Docs.GetCommand("policy/attributes/update", diff --git a/cmd/policy-resourceMappings.go b/cmd/policy-resourceMappings.go index 52a0ce4b..546ce0ef 100644 --- a/cmd/policy-resourceMappings.go +++ b/cmd/policy-resourceMappings.go @@ -189,6 +189,7 @@ func init() { listDoc := man.Docs.GetCommand("policy/resource-mappings/list", man.WithRun(policy_listResourceMappings), ) + injectListPaginationFlags(listDoc) updateDoc := man.Docs.GetCommand("policy/resource-mappings/update", man.WithRun(policy_updateResourceMapping), diff --git a/cmd/policy-subjectConditionSets.go b/cmd/policy-subjectConditionSets.go index 10e5b77e..93263f52 100644 --- a/cmd/policy-subjectConditionSets.go +++ b/cmd/policy-subjectConditionSets.go @@ -340,6 +340,7 @@ func init() { listDoc := man.Docs.GetCommand("policy/subject-condition-sets/list", man.WithRun(policy_listSubjectConditionSets), ) + injectListPaginationFlags(listDoc) updateDoc := man.Docs.GetCommand("policy/subject-condition-sets/update", man.WithRun(policy_updateSubjectConditionSet), diff --git a/cmd/policy-subjectMappings.go b/cmd/policy-subjectMappings.go index be0f7b49..d56e9b78 100644 --- a/cmd/policy-subjectMappings.go +++ b/cmd/policy-subjectMappings.go @@ -353,6 +353,7 @@ func init() { listDoc := man.Docs.GetCommand("policy/subject-mappings/list", man.WithRun(policy_listSubjectMappings), ) + injectListPaginationFlags(listDoc) createDoc := man.Docs.GetCommand("policy/subject-mappings/create", man.WithRun(policy_createSubjectMapping), From 09802e1210c8c39fde6023ad51dd414baa148d71 Mon Sep 17 00:00:00 2001 From: jakedoublev Date: Tue, 3 Dec 2024 14:49:35 -0800 Subject: [PATCH 03/14] clean up docs --- docs/man/policy/attributes/list.md | 4 ++-- docs/man/policy/attributes/namespaces/list.md | 4 ++-- docs/man/policy/attributes/values/list.md | 4 ++-- docs/man/policy/kas-grants/list.md | 4 ++-- docs/man/policy/kas-registry/list.md | 4 ++-- docs/man/policy/resource-mappings/list.md | 4 ++-- docs/man/policy/subject-condition-sets/list.md | 4 ++-- docs/man/policy/subject-mappings/list.md | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/man/policy/attributes/list.md b/docs/man/policy/attributes/list.md index 7ee1337c..422041d0 100644 --- a/docs/man/policy/attributes/list.md +++ b/docs/man/policy/attributes/list.md @@ -15,10 +15,10 @@ command: default: active - name: limit shorthand: l - description: Limit retrieved count (default set by platform if not provided) + description: Limit retrieved count (default 300 if not provided) - name: offset shorthand: o - description: Offset quantity from start of the list (page) + description: Offset (page) quantity from start of the list --- By default, the list will only provide `active` attributes if unspecified, but the filter can be controlled with the `--state` flag. diff --git a/docs/man/policy/attributes/namespaces/list.md b/docs/man/policy/attributes/namespaces/list.md index b3ba2978..4fcc1295 100644 --- a/docs/man/policy/attributes/namespaces/list.md +++ b/docs/man/policy/attributes/namespaces/list.md @@ -11,10 +11,10 @@ command: description: Filter by state [active, inactive, any] - name: limit shorthand: l - description: Limit retrieved count (default set by platform if not provided) + description: Limit retrieved count - name: offset shorthand: o - description: Offset quantity from start of the list (page) + description: Offset (page) quantity from start of the list --- For more general information, see the `namespaces` subcommand. diff --git a/docs/man/policy/attributes/values/list.md b/docs/man/policy/attributes/values/list.md index dbf9512e..892c72e6 100644 --- a/docs/man/policy/attributes/values/list.md +++ b/docs/man/policy/attributes/values/list.md @@ -19,10 +19,10 @@ command: default: active - name: limit shorthand: l - description: Limit retrieved count (default set by platform if not provided) + description: Limit retrieved count (default 300 if not provided) - name: offset shorthand: o - description: Offset quantity from start of the list (page) + description: Offset (page) quantity from start of the list --- By default, the list will only provide `active` values if unspecified, but the filter can be controlled with the `--state` flag. diff --git a/docs/man/policy/kas-grants/list.md b/docs/man/policy/kas-grants/list.md index 992f8b53..f6e67d89 100644 --- a/docs/man/policy/kas-grants/list.md +++ b/docs/man/policy/kas-grants/list.md @@ -12,10 +12,10 @@ command: description: The optional ID or URI of a KAS to filter the list - name: limit shorthand: l - description: Limit retrieved count (default set by platform if not provided) + description: Limit retrieved count (default 300 if not provided) - name: offset shorthand: o - description: Offset quantity from start of the list (page) + description: Offset (page) quantity from start of the list --- List the Grants of Registered Key Access Servers (KASes) to attribute namespaces, definitions, diff --git a/docs/man/policy/kas-registry/list.md b/docs/man/policy/kas-registry/list.md index 2972a9fa..9412a63b 100644 --- a/docs/man/policy/kas-registry/list.md +++ b/docs/man/policy/kas-registry/list.md @@ -7,10 +7,10 @@ command: flags: - name: limit shorthand: l - description: Limit retrieved count (default set by platform if not provided) + description: Limit retrieved count (default 300 if not provided) - name: offset shorthand: o - description: Offset quantity from start of the list (page) + description: Offset (page) quantity from start of the list --- For more information about registration of Key Access Servers, see the manual for `kas-registry`. diff --git a/docs/man/policy/resource-mappings/list.md b/docs/man/policy/resource-mappings/list.md index f5af896a..8e3aaa52 100644 --- a/docs/man/policy/resource-mappings/list.md +++ b/docs/man/policy/resource-mappings/list.md @@ -7,10 +7,10 @@ command: flags: - name: limit shorthand: l - description: Limit retrieved count (default set by platform if not provided) + description: Limit retrieved count (default 300 if not provided) - name: offset shorthand: o - description: Offset quantity from start of the list (page) + description: Offset (page) quantity from start of the list --- For more information about resource mappings, see the `resource-mappings` subcommand. diff --git a/docs/man/policy/subject-condition-sets/list.md b/docs/man/policy/subject-condition-sets/list.md index a0c58961..b94034b9 100644 --- a/docs/man/policy/subject-condition-sets/list.md +++ b/docs/man/policy/subject-condition-sets/list.md @@ -8,10 +8,10 @@ command: flags: - name: limit shorthand: l - description: Limit retrieved count (default set by platform if not provided) + description: Limit retrieved count (default 300 if not provided) - name: offset shorthand: o - description: Offset quantity from start of the list (page) + description: Offset (page) quantity from start of the list --- For more information about subject condition sets, see the `subject-condition-sets` subcommand. diff --git a/docs/man/policy/subject-mappings/list.md b/docs/man/policy/subject-mappings/list.md index ba021b80..95515854 100644 --- a/docs/man/policy/subject-mappings/list.md +++ b/docs/man/policy/subject-mappings/list.md @@ -7,10 +7,10 @@ command: flags: - name: limit shorthand: l - description: Limit retrieved count (default set by platform if not provided) + description: Limit retrieved count (default 300 if not provided) - name: offset shorthand: o - description: Offset quantity from start of the list (page) + description: Offset (page) quantity from start of the list --- For more information about subject mappings, see the `subject-mappings` subcommand. From 011f7b85ee2436b3ce7f94b574798d1ffa546dfd Mon Sep 17 00:00:00 2001 From: jakedoublev Date: Wed, 4 Dec 2024 08:03:16 -0800 Subject: [PATCH 04/14] handlers --- pkg/handlers/attribute.go | 14 ++++++++++---- pkg/handlers/attributeValues.go | 15 +++++++++++---- pkg/handlers/kas-grants.go | 11 ++++++++--- pkg/handlers/kas-registry.go | 13 +++++++++---- pkg/handlers/namespaces.go | 14 ++++++++++---- pkg/handlers/resourceMappings.go | 13 +++++++++---- pkg/handlers/subjectConditionSets.go | 13 +++++++++---- pkg/handlers/subjectmappings.go | 15 +++++++++++---- 8 files changed, 77 insertions(+), 31 deletions(-) diff --git a/pkg/handlers/attribute.go b/pkg/handlers/attribute.go index 81ca4ec4..3596bef1 100644 --- a/pkg/handlers/attribute.go +++ b/pkg/handlers/attribute.go @@ -42,12 +42,18 @@ func (h Handler) GetAttribute(id string) (*policy.Attribute, error) { return resp.GetAttribute(), nil } -func (h Handler) ListAttributes(state common.ActiveStateEnum) ([]*policy.Attribute, error) { - resp, err := h.sdk.Attributes.ListAttributes(h.ctx, &attributes.ListAttributesRequest{State: state}) +func (h Handler) ListAttributes(state common.ActiveStateEnum, limit, offset int32) ([]*policy.Attribute, *policy.PageResponse, error) { + resp, err := h.sdk.Attributes.ListAttributes(h.ctx, &attributes.ListAttributesRequest{ + State: state, + Pagination: &policy.PageRequest{ + Limit: limit, + Offset: offset, + }, + }) if err != nil { - return nil, err + return nil, nil, err } - return resp.GetAttributes(), err + return resp.GetAttributes(), resp.GetPagination(), nil } // Creates and returns the created attribute diff --git a/pkg/handlers/attributeValues.go b/pkg/handlers/attributeValues.go index 9b4f1dc2..a62ff7d6 100644 --- a/pkg/handlers/attributeValues.go +++ b/pkg/handlers/attributeValues.go @@ -7,12 +7,19 @@ import ( "github.com/opentdf/platform/protocol/go/policy/unsafe" ) -func (h *Handler) ListAttributeValues(attributeId string, state common.ActiveStateEnum) ([]*policy.Value, error) { - resp, err := h.sdk.Attributes.ListAttributeValues(h.ctx, &attributes.ListAttributeValuesRequest{AttributeId: attributeId, State: state}) +func (h *Handler) ListAttributeValues(attributeId string, state common.ActiveStateEnum, limit, offset int32) ([]*policy.Value, *policy.PageResponse, error) { + resp, err := h.sdk.Attributes.ListAttributeValues(h.ctx, &attributes.ListAttributeValuesRequest{ + AttributeId: attributeId, + State: state, + Pagination: &policy.PageRequest{ + Limit: limit, + Offset: offset, + }, + }) if err != nil { - return nil, err + return nil, nil, err } - return resp.GetValues(), err + return resp.GetValues(), resp.GetPagination(), err } // Creates and returns the created value diff --git a/pkg/handlers/kas-grants.go b/pkg/handlers/kas-grants.go index a32dd0fb..256e36ed 100644 --- a/pkg/handlers/kas-grants.go +++ b/pkg/handlers/kas-grants.go @@ -3,6 +3,7 @@ package handlers import ( "context" + "github.com/opentdf/platform/protocol/go/policy" "github.com/opentdf/platform/protocol/go/policy/attributes" "github.com/opentdf/platform/protocol/go/policy/kasregistry" "github.com/opentdf/platform/protocol/go/policy/namespaces" @@ -98,13 +99,17 @@ func (h Handler) DeleteKasGrantFromNamespace(ctx context.Context, ns_id string, return resp.GetNamespaceKeyAccessServer(), nil } -func (h Handler) ListKasGrants(ctx context.Context, kas_id, kas_uri string) ([]*kasregistry.KeyAccessServerGrants, error) { +func (h Handler) ListKasGrants(ctx context.Context, kas_id, kas_uri string, limit, offset int32) ([]*kasregistry.KeyAccessServerGrants, *policy.PageResponse, error) { resp, err := h.sdk.KeyAccessServerRegistry.ListKeyAccessServerGrants(ctx, &kasregistry.ListKeyAccessServerGrantsRequest{ KasId: kas_id, KasUri: kas_uri, + Pagination: &policy.PageRequest{ + Limit: limit, + Offset: offset, + }, }) if err != nil { - return nil, err + return nil, nil, err } - return resp.GetGrants(), nil + return resp.GetGrants(), resp.GetPagination(), nil } diff --git a/pkg/handlers/kas-registry.go b/pkg/handlers/kas-registry.go index 5249c5d1..7c0fbe0d 100644 --- a/pkg/handlers/kas-registry.go +++ b/pkg/handlers/kas-registry.go @@ -17,13 +17,18 @@ func (h Handler) GetKasRegistryEntry(id string) (*policy.KeyAccessServer, error) return resp.GetKeyAccessServer(), nil } -func (h Handler) ListKasRegistryEntries() ([]*policy.KeyAccessServer, error) { - resp, err := h.sdk.KeyAccessServerRegistry.ListKeyAccessServers(h.ctx, &kasregistry.ListKeyAccessServersRequest{}) +func (h Handler) ListKasRegistryEntries(limit, offset int32) ([]*policy.KeyAccessServer, *policy.PageResponse, error) { + resp, err := h.sdk.KeyAccessServerRegistry.ListKeyAccessServers(h.ctx, &kasregistry.ListKeyAccessServersRequest{ + Pagination: &policy.PageRequest{ + Limit: limit, + Offset: offset, + }, + }) if err != nil { - return nil, err + return nil, nil, err } - return resp.GetKeyAccessServers(), nil + return resp.GetKeyAccessServers(), resp.GetPagination(), nil } // Creates the KAS registry and then returns the KAS diff --git a/pkg/handlers/namespaces.go b/pkg/handlers/namespaces.go index 232c4ba2..fe773472 100644 --- a/pkg/handlers/namespaces.go +++ b/pkg/handlers/namespaces.go @@ -18,13 +18,19 @@ func (h Handler) GetNamespace(id string) (*policy.Namespace, error) { return resp.GetNamespace(), nil } -func (h Handler) ListNamespaces(state common.ActiveStateEnum) ([]*policy.Namespace, error) { - resp, err := h.sdk.Namespaces.ListNamespaces(h.ctx, &namespaces.ListNamespacesRequest{State: state}) +func (h Handler) ListNamespaces(state common.ActiveStateEnum, limit, offset int32) ([]*policy.Namespace, *policy.PageResponse, error) { + resp, err := h.sdk.Namespaces.ListNamespaces(h.ctx, &namespaces.ListNamespacesRequest{ + State: state, + Pagination: &policy.PageRequest{ + Limit: limit, + Offset: offset, + }, + }) if err != nil { - return nil, err + return nil, nil, err } - return resp.GetNamespaces(), nil + return resp.GetNamespaces(), resp.GetPagination(), nil } // Creates and returns the created n diff --git a/pkg/handlers/resourceMappings.go b/pkg/handlers/resourceMappings.go index 28ba0436..a2930d67 100644 --- a/pkg/handlers/resourceMappings.go +++ b/pkg/handlers/resourceMappings.go @@ -39,13 +39,18 @@ func (h *Handler) GetResourceMapping(id string) (*policy.ResourceMapping, error) return res.GetResourceMapping(), nil } -func (h *Handler) ListResourceMappings() ([]*policy.ResourceMapping, error) { - res, err := h.sdk.ResourceMapping.ListResourceMappings(context.Background(), &resourcemapping.ListResourceMappingsRequest{}) +func (h *Handler) ListResourceMappings(limit, offset int32) ([]*policy.ResourceMapping, *policy.PageResponse, error) { + res, err := h.sdk.ResourceMapping.ListResourceMappings(context.Background(), &resourcemapping.ListResourceMappingsRequest{ + Pagination: &policy.PageRequest{ + Limit: limit, + Offset: offset, + }, + }) if err != nil { - return nil, err + return nil, nil, err } - return res.GetResourceMappings(), nil + return res.GetResourceMappings(), res.GetPagination(), nil } // TODO: verify updation behavior diff --git a/pkg/handlers/subjectConditionSets.go b/pkg/handlers/subjectConditionSets.go index ea8dbd8d..d702a683 100644 --- a/pkg/handlers/subjectConditionSets.go +++ b/pkg/handlers/subjectConditionSets.go @@ -17,12 +17,17 @@ func (h Handler) GetSubjectConditionSet(id string) (*policy.SubjectConditionSet, return resp.GetSubjectConditionSet(), nil } -func (h Handler) ListSubjectConditionSets() ([]*policy.SubjectConditionSet, error) { - resp, err := h.sdk.SubjectMapping.ListSubjectConditionSets(h.ctx, &subjectmapping.ListSubjectConditionSetsRequest{}) +func (h Handler) ListSubjectConditionSets(limit, offset int32) ([]*policy.SubjectConditionSet, *policy.PageResponse, error) { + resp, err := h.sdk.SubjectMapping.ListSubjectConditionSets(h.ctx, &subjectmapping.ListSubjectConditionSetsRequest{ + Pagination: &policy.PageRequest{ + Limit: limit, + Offset: offset, + }, + }) if err != nil { - return nil, err + return nil, nil, err } - return resp.GetSubjectConditionSets(), err + return resp.GetSubjectConditionSets(), resp.GetPagination(), err } // Creates and returns the created subject condition set diff --git a/pkg/handlers/subjectmappings.go b/pkg/handlers/subjectmappings.go index 82b98098..06043d37 100644 --- a/pkg/handlers/subjectmappings.go +++ b/pkg/handlers/subjectmappings.go @@ -22,10 +22,17 @@ func (h Handler) GetSubjectMapping(id string) (*policy.SubjectMapping, error) { return resp.GetSubjectMapping(), err } -func (h Handler) ListSubjectMappings() ([]*policy.SubjectMapping, error) { - resp, err := h.sdk.SubjectMapping.ListSubjectMappings(h.ctx, &subjectmapping.ListSubjectMappingsRequest{}) - - return resp.GetSubjectMappings(), err +func (h Handler) ListSubjectMappings(limit, offset int32) ([]*policy.SubjectMapping, *policy.PageResponse, error) { + resp, err := h.sdk.SubjectMapping.ListSubjectMappings(h.ctx, &subjectmapping.ListSubjectMappingsRequest{ + Pagination: &policy.PageRequest{ + Limit: limit, + Offset: offset, + }, + }) + if err != nil { + return nil, nil, err + } + return resp.GetSubjectMappings(), resp.GetPagination(), err } // Creates and returns the created subject mapping From 0ac031c4d4bdf9b20367f2cb38fc5e37b2afa50f Mon Sep 17 00:00:00 2001 From: jakedoublev Date: Wed, 4 Dec 2024 09:23:38 -0800 Subject: [PATCH 05/14] add pagination to printed table output --- cmd/dev.go | 14 ++++++++++++++ cmd/kas-grants.go | 5 ++++- cmd/kas-registry.go | 6 +++++- cmd/policy-attributeNamespaces.go | 6 +++++- cmd/policy-attributeValues.go | 7 ++++++- cmd/policy-attributes.go | 6 +++++- cmd/policy-resourceMappings.go | 6 +++++- cmd/policy-subjectConditionSets.go | 6 +++++- cmd/policy-subjectMappings.go | 6 +++++- tui/attributeList.go | 18 +++++++++++------- 10 files changed, 65 insertions(+), 15 deletions(-) diff --git a/cmd/dev.go b/cmd/dev.go index 8dff64e7..4a2e42c5 100644 --- a/cmd/dev.go +++ b/cmd/dev.go @@ -12,6 +12,7 @@ import ( "github.com/opentdf/otdfctl/pkg/config" "github.com/opentdf/otdfctl/pkg/man" "github.com/opentdf/platform/protocol/go/common" + "github.com/opentdf/platform/protocol/go/policy" "github.com/spf13/cobra" ) @@ -63,6 +64,19 @@ func renderDSMessages() string { return cli.SuccessMessage("Success message") + "\n" + cli.ErrorMessage("Error message", nil) } +func printListPaginationTable(p *policy.PageResponse) { + rows := [][]string{ + {"Current Offset", fmt.Sprintf("%d", p.GetCurrentOffset())}, + } + if p.GetNextOffset() > 0 { + rows = append(rows, []string{"Next Offset", fmt.Sprintf("%d", p.GetNextOffset())}) + } + rows = append(rows, []string{"Total", fmt.Sprintf("%d", p.GetTotal())}) + for _, r := range rows { + fmt.Printf("%-20s %s\n", r[0], r[1]) + } +} + func getMetadataRows(m *common.Metadata) [][]string { if m != nil { metadata := cli.ConstructMetadata(m) diff --git a/cmd/kas-grants.go b/cmd/kas-grants.go index fb4aca41..48524449 100644 --- a/cmd/kas-grants.go +++ b/cmd/kas-grants.go @@ -162,6 +162,8 @@ func policy_listKasGrants(cmd *cobra.Command, args []string) { h := NewHandler(c) defer h.Close() kasF := c.Flags.GetOptionalString("kas") + limit := c.Flags.GetRequiredInt32("limit") + offset := c.Flags.GetRequiredInt32("offset") var ( kasID string kasURI string @@ -177,7 +179,7 @@ func policy_listKasGrants(cmd *cobra.Command, args []string) { } } - grants, err := h.ListKasGrants(cmd.Context(), kasID, kasURI) + grants, page, err := h.ListKasGrants(cmd.Context(), kasID, kasURI, limit, offset) if err != nil { cli.ExitWithError("Failed to list assigned KAS Grants", err) } @@ -229,6 +231,7 @@ func policy_listKasGrants(cmd *cobra.Command, args []string) { // with no individual ID. cmd.Use = "" HandleSuccess(cmd, "", t, grants) + printListPaginationTable(page) } func init() { diff --git a/cmd/kas-registry.go b/cmd/kas-registry.go index 7d096e47..38d59f32 100644 --- a/cmd/kas-registry.go +++ b/cmd/kas-registry.go @@ -57,7 +57,10 @@ func policy_listKeyAccessRegistries(cmd *cobra.Command, args []string) { h := NewHandler(c) defer h.Close() - list, err := h.ListKasRegistryEntries() + limit := c.Flags.GetRequiredInt32("limit") + offset := c.Flags.GetRequiredInt32("offset") + + list, page, err := h.ListKasRegistryEntries(limit, offset) if err != nil { cli.ExitWithError("Failed to list Registered KAS entries", err) } @@ -85,6 +88,7 @@ func policy_listKeyAccessRegistries(cmd *cobra.Command, args []string) { } t = t.WithRows(rows) HandleSuccess(cmd, "", t, list) + printListPaginationTable(page) } func policy_createKeyAccessRegistry(cmd *cobra.Command, args []string) { diff --git a/cmd/policy-attributeNamespaces.go b/cmd/policy-attributeNamespaces.go index 1f21d509..f43bfce7 100644 --- a/cmd/policy-attributeNamespaces.go +++ b/cmd/policy-attributeNamespaces.go @@ -45,7 +45,10 @@ func policy_listAttributeNamespaces(cmd *cobra.Command, args []string) { defer h.Close() state := cli.GetState(cmd) - list, err := h.ListNamespaces(state) + limit := c.Flags.GetRequiredInt32("limit") + offset := c.Flags.GetRequiredInt32("offset") + + list, page, err := h.ListNamespaces(state, limit, offset) if err != nil { cli.ExitWithError("Failed to list namespaces", err) } @@ -73,6 +76,7 @@ func policy_listAttributeNamespaces(cmd *cobra.Command, args []string) { } t = t.WithRows(rows) HandleSuccess(cmd, "", t, list) + printListPaginationTable(page) } func policy_createAttributeNamespace(cmd *cobra.Command, args []string) { diff --git a/cmd/policy-attributeValues.go b/cmd/policy-attributeValues.go index b6e13fdd..01b59eee 100644 --- a/cmd/policy-attributeValues.go +++ b/cmd/policy-attributeValues.go @@ -53,9 +53,13 @@ func policy_listAttributeValue(cmd *cobra.Command, args []string) { c := cli.New(cmd, args) h := NewHandler(c) defer h.Close() + attrId := c.FlagHelper.GetRequiredID("attribute-id") state := cli.GetState(cmd) - vals, err := h.ListAttributeValues(attrId, state) + limit := c.Flags.GetRequiredInt32("limit") + offset := c.Flags.GetRequiredInt32("offset") + + vals, page, err := h.ListAttributeValues(attrId, state, limit, offset) if err != nil { cli.ExitWithError("Failed to list attribute values", err) } @@ -81,6 +85,7 @@ func policy_listAttributeValue(cmd *cobra.Command, args []string) { } t = t.WithRows(rows) HandleSuccess(cmd, "", t, vals) + printListPaginationTable(page) } func policy_updateAttributeValue(cmd *cobra.Command, args []string) { diff --git a/cmd/policy-attributes.go b/cmd/policy-attributes.go index 95d68cb8..113efe63 100644 --- a/cmd/policy-attributes.go +++ b/cmd/policy-attributes.go @@ -91,7 +91,10 @@ func policy_listAttributes(cmd *cobra.Command, args []string) { defer h.Close() state := cli.GetState(cmd) - attrs, err := h.ListAttributes(state) + limit := c.Flags.GetRequiredInt32("limit") + offset := c.Flags.GetRequiredInt32("offset") + + attrs, page, err := h.ListAttributes(state, limit, offset) if err != nil { cli.ExitWithError("Failed to list attributes", err) } @@ -124,6 +127,7 @@ func policy_listAttributes(cmd *cobra.Command, args []string) { } t = t.WithRows(rows) HandleSuccess(cmd, "", t, attrs) + printListPaginationTable(page) } func policy_deactivateAttribute(cmd *cobra.Command, args []string) { diff --git a/cmd/policy-resourceMappings.go b/cmd/policy-resourceMappings.go index 546ce0ef..c46a30bf 100644 --- a/cmd/policy-resourceMappings.go +++ b/cmd/policy-resourceMappings.go @@ -73,7 +73,10 @@ func policy_listResourceMappings(cmd *cobra.Command, args []string) { h := NewHandler(c) defer h.Close() - rmList, err := h.ListResourceMappings() + limit := c.Flags.GetRequiredInt32("limit") + offset := c.Flags.GetRequiredInt32("offset") + + rmList, page, err := h.ListResourceMappings(limit, offset) if err != nil { cli.ExitWithError("Failed to list resource mappings", err) } @@ -102,6 +105,7 @@ func policy_listResourceMappings(cmd *cobra.Command, args []string) { } t = t.WithRows(rows) HandleSuccess(cmd, "", t, rmList) + printListPaginationTable(page) } func policy_updateResourceMapping(cmd *cobra.Command, args []string) { diff --git a/cmd/policy-subjectConditionSets.go b/cmd/policy-subjectConditionSets.go index 93263f52..599ef26b 100644 --- a/cmd/policy-subjectConditionSets.go +++ b/cmd/policy-subjectConditionSets.go @@ -143,7 +143,10 @@ func policy_listSubjectConditionSets(cmd *cobra.Command, args []string) { h := NewHandler(c) defer h.Close() - scsList, err := h.ListSubjectConditionSets() + limit := c.Flags.GetRequiredInt32("limit") + offset := c.Flags.GetRequiredInt32("offset") + + scsList, page, err := h.ListSubjectConditionSets(limit, offset) if err != nil { cli.ExitWithError("Error listing subject condition sets", err) } @@ -172,6 +175,7 @@ func policy_listSubjectConditionSets(cmd *cobra.Command, args []string) { } t = t.WithRows(rows) HandleSuccess(cmd, "", t, scsList) + printListPaginationTable(page) } func policy_updateSubjectConditionSet(cmd *cobra.Command, args []string) { diff --git a/cmd/policy-subjectMappings.go b/cmd/policy-subjectMappings.go index d56e9b78..f0521d3b 100644 --- a/cmd/policy-subjectMappings.go +++ b/cmd/policy-subjectMappings.go @@ -64,7 +64,10 @@ func policy_listSubjectMappings(cmd *cobra.Command, args []string) { h := NewHandler(c) defer h.Close() - list, err := h.ListSubjectMappings() + limit := c.Flags.GetRequiredInt32("limit") + offset := c.Flags.GetRequiredInt32("offset") + + list, page, err := h.ListSubjectMappings(limit, offset) if err != nil { cli.ExitWithError("Failed to get subject mappings", err) } @@ -99,6 +102,7 @@ func policy_listSubjectMappings(cmd *cobra.Command, args []string) { } t = t.WithRows(rows) HandleSuccess(cmd, "", t, list) + printListPaginationTable(page) } func policy_createSubjectMapping(cmd *cobra.Command, args []string) { diff --git a/tui/attributeList.go b/tui/attributeList.go index ee54c9b5..b4997950 100644 --- a/tui/attributeList.go +++ b/tui/attributeList.go @@ -11,7 +11,7 @@ import ( type AttributeList struct { list list.Model - sdk handlers.Handler + h handlers.Handler } type AttributeItem struct { @@ -31,10 +31,14 @@ func (m AttributeItem) Description() string { return m.id } -func InitAttributeList(id string, sdk handlers.Handler) (tea.Model, tea.Cmd) { +func InitAttributeList(id string, h handlers.Handler) (tea.Model, tea.Cmd) { l := list.New([]list.Item{}, list.NewDefaultDelegate(), constants.WindowSize.Width, constants.WindowSize.Height) - // TODO: handle and return error view - res, _ := sdk.ListAttributes(common.ActiveStateEnum_ACTIVE_STATE_ENUM_ANY) + // TODO: handle and return error view and use real command flags limit/offset + var ( + limit int32 = 100 + offset int32 = 0 + ) + res, _, _ := h.ListAttributes(common.ActiveStateEnum_ACTIVE_STATE_ENUM_ANY, limit, offset) var attrs []list.Item selectIdx := 0 for i, attr := range res { @@ -56,7 +60,7 @@ func InitAttributeList(id string, sdk handlers.Handler) (tea.Model, tea.Cmd) { l.Title = "Attributes" l.SetItems(attrs) l.Select(selectIdx) - m := AttributeList{sdk: sdk, list: l} + m := AttributeList{h: h, list: l} return m.Update(WindowMsg()) } @@ -89,7 +93,7 @@ func (m AttributeList) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case "ctrl+c", "q": return m, tea.Quit case "ctrl+[", "backspace": - am, _ := InitAppMenu(m.sdk) + am, _ := InitAppMenu(m.h) // make enum for Attributes idx in AppMenu am.list.Select(0) return am.Update(WindowMsg()) @@ -97,7 +101,7 @@ func (m AttributeList) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // create new attribute // return InitAttributeView(m.list.Items(), len(m.list.Items())) case "enter", "e": - return InitAttributeView(m.list.Items()[m.list.Index()].(AttributeItem).id, m.sdk) + return InitAttributeView(m.list.Items()[m.list.Index()].(AttributeItem).id, m.h) // case "ctrl+d": // m.list.RemoveItem(m.list.Index()) // newIndex := m.list.Index() - 1 From b40367b6a1816aab85e8d94b4a0773727a141810 Mon Sep 17 00:00:00 2001 From: jakedoublev Date: Wed, 4 Dec 2024 09:30:13 -0800 Subject: [PATCH 06/14] cleanup --- cmd/dev.go | 1 + cmd/kas-grants.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/dev.go b/cmd/dev.go index 4a2e42c5..69e6430a 100644 --- a/cmd/dev.go +++ b/cmd/dev.go @@ -64,6 +64,7 @@ func renderDSMessages() string { return cli.SuccessMessage("Success message") + "\n" + cli.ErrorMessage("Error message", nil) } +// Prints out the page information in simplified aligned format func printListPaginationTable(p *policy.PageResponse) { rows := [][]string{ {"Current Offset", fmt.Sprintf("%d", p.GetCurrentOffset())}, diff --git a/cmd/kas-grants.go b/cmd/kas-grants.go index 48524449..30cb1650 100644 --- a/cmd/kas-grants.go +++ b/cmd/kas-grants.go @@ -308,7 +308,7 @@ func init() { listCmd.GetDocFlag("kas").Description, ) injectListPaginationFlags(listCmd) - + cmd := man.Docs.GetCommand("policy/kas-grants", man.WithSubcommands(assignCmd, unassignCmd, listCmd), ) From 5cd57d548a8fde9fcdd0e972037806c4f08f16b5 Mon Sep 17 00:00:00 2001 From: jakedoublev Date: Wed, 4 Dec 2024 09:34:57 -0800 Subject: [PATCH 07/14] rm extraneous help output --- docs/man/policy/attributes/list.md | 2 +- docs/man/policy/attributes/values/list.md | 2 +- docs/man/policy/kas-grants/list.md | 2 +- docs/man/policy/kas-registry/list.md | 2 +- docs/man/policy/resource-mappings/list.md | 2 +- docs/man/policy/subject-condition-sets/list.md | 2 +- docs/man/policy/subject-mappings/list.md | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/man/policy/attributes/list.md b/docs/man/policy/attributes/list.md index 422041d0..ef8e3440 100644 --- a/docs/man/policy/attributes/list.md +++ b/docs/man/policy/attributes/list.md @@ -15,7 +15,7 @@ command: default: active - name: limit shorthand: l - description: Limit retrieved count (default 300 if not provided) + description: Limit retrieved count - name: offset shorthand: o description: Offset (page) quantity from start of the list diff --git a/docs/man/policy/attributes/values/list.md b/docs/man/policy/attributes/values/list.md index 892c72e6..7e7a142c 100644 --- a/docs/man/policy/attributes/values/list.md +++ b/docs/man/policy/attributes/values/list.md @@ -19,7 +19,7 @@ command: default: active - name: limit shorthand: l - description: Limit retrieved count (default 300 if not provided) + description: Limit retrieved count - name: offset shorthand: o description: Offset (page) quantity from start of the list diff --git a/docs/man/policy/kas-grants/list.md b/docs/man/policy/kas-grants/list.md index f6e67d89..e3c27db7 100644 --- a/docs/man/policy/kas-grants/list.md +++ b/docs/man/policy/kas-grants/list.md @@ -12,7 +12,7 @@ command: description: The optional ID or URI of a KAS to filter the list - name: limit shorthand: l - description: Limit retrieved count (default 300 if not provided) + description: Limit retrieved count - name: offset shorthand: o description: Offset (page) quantity from start of the list diff --git a/docs/man/policy/kas-registry/list.md b/docs/man/policy/kas-registry/list.md index 9412a63b..9d2101fd 100644 --- a/docs/man/policy/kas-registry/list.md +++ b/docs/man/policy/kas-registry/list.md @@ -7,7 +7,7 @@ command: flags: - name: limit shorthand: l - description: Limit retrieved count (default 300 if not provided) + description: Limit retrieved count - name: offset shorthand: o description: Offset (page) quantity from start of the list diff --git a/docs/man/policy/resource-mappings/list.md b/docs/man/policy/resource-mappings/list.md index 8e3aaa52..6dbd6d92 100644 --- a/docs/man/policy/resource-mappings/list.md +++ b/docs/man/policy/resource-mappings/list.md @@ -7,7 +7,7 @@ command: flags: - name: limit shorthand: l - description: Limit retrieved count (default 300 if not provided) + description: Limit retrieved count - name: offset shorthand: o description: Offset (page) quantity from start of the list diff --git a/docs/man/policy/subject-condition-sets/list.md b/docs/man/policy/subject-condition-sets/list.md index b94034b9..77b9bc26 100644 --- a/docs/man/policy/subject-condition-sets/list.md +++ b/docs/man/policy/subject-condition-sets/list.md @@ -8,7 +8,7 @@ command: flags: - name: limit shorthand: l - description: Limit retrieved count (default 300 if not provided) + description: Limit retrieved count - name: offset shorthand: o description: Offset (page) quantity from start of the list diff --git a/docs/man/policy/subject-mappings/list.md b/docs/man/policy/subject-mappings/list.md index 95515854..1e13e6af 100644 --- a/docs/man/policy/subject-mappings/list.md +++ b/docs/man/policy/subject-mappings/list.md @@ -7,7 +7,7 @@ command: flags: - name: limit shorthand: l - description: Limit retrieved count (default 300 if not provided) + description: Limit retrieved count - name: offset shorthand: o description: Offset (page) quantity from start of the list From cc66874830f39981d0065f3c8be437f173e681ed Mon Sep 17 00:00:00 2001 From: jakedoublev Date: Wed, 4 Dec 2024 09:47:42 -0800 Subject: [PATCH 08/14] bats simple tests --- e2e/attributes.bats | 6 ++++++ e2e/kas-grants.bats | 6 ++++-- e2e/kas-registry.bats | 14 +++++++++----- e2e/namespaces.bats | 7 +++++-- e2e/resource-mapping.bats | 2 ++ e2e/subject-condition-sets.bats | 26 ++++++++++++++------------ e2e/subject-mapping.bats | 2 ++ 7 files changed, 42 insertions(+), 21 deletions(-) diff --git a/e2e/attributes.bats b/e2e/attributes.bats index c7ee214a..a786aa90 100755 --- a/e2e/attributes.bats +++ b/e2e/attributes.bats @@ -111,14 +111,20 @@ teardown_file() { run_otdfctl_attr list assert_success assert_output --partial "$ATTR_ID" + assert_output --partial "Total" + assert_output --regexp "Current Offset 0" run_otdfctl_attr list --state active assert_success assert_output --partial "$ATTR_ID" + assert_output --partial "Total" + assert_output --regexp "Current Offset 0" run_otdfctl_attr list --state inactive assert_success refute_output --partial "$ATTR_ID" + assert_output --partial "Total" + assert_output --regexp "Current Offset 0" } @test "Deactivate then unsafe reactivate an attribute definition" { diff --git a/e2e/kas-grants.bats b/e2e/kas-grants.bats index 7e3c24ea..704fde82 100755 --- a/e2e/kas-grants.bats +++ b/e2e/kas-grants.bats @@ -140,10 +140,12 @@ teardown_file() { # unfiltered # json run_otdfctl_kasg list --json - refute_output --partial "$ATTR_ID" + refute_output --partial "$ATTR_ID" # table run_otdfctl_kasg list - refute_output --regexp "$KAS_URI.*Definition.*$ATTR_ID" + refute_output --regexp "$KAS_URI.*Definition.*$ATTR_ID" + assert_output --partial "Total" + assert_output --regexp "Current Offset 0" } @test "value: assign grant then unassign it" { diff --git a/e2e/kas-registry.bats b/e2e/kas-registry.bats index c5f77693..ec5e84b0 100755 --- a/e2e/kas-registry.bats +++ b/e2e/kas-registry.bats @@ -195,9 +195,13 @@ teardown() { export CREATED=$(./otdfctl $HOST $DEBUG_LEVEL $WITH_CREDS policy kas-registry create --uri "$URI" -c "$CACHED_KEY" -n "$NAME" --json) ID=$(echo "$CREATED" | jq -r '.id') run_otdfctl_kasr list --json - assert_output --partial "$ID" - assert_output --partial "uri" - assert_output --partial "$URI" - assert_output --partial "name" - assert_output --partial "$NAME" + assert_output --partial "$ID" + assert_output --partial "uri" + assert_output --partial "$URI" + assert_output --partial "name" + assert_output --partial "$NAME" + + run_otdfctl_kasr list + assert_output --partial "Total" + assert_output --regexp "Current Offset 0" } diff --git a/e2e/namespaces.bats b/e2e/namespaces.bats index 310f7ac6..ddd5b876 100755 --- a/e2e/namespaces.bats +++ b/e2e/namespaces.bats @@ -94,10 +94,13 @@ teardown_file() { echo $output | jq --arg id "$NS_ID" '.[] | select(.[]? | type == "object" and .id == $id)' run_otdfctl_ns list --state inactive --json - echo $output | refute_output --partial "$NS_ID" + refute_output --partial "$NS_ID" run_otdfctl_ns list --state active - echo $output | assert_output --partial "$NS_ID" + assert_output --partial "$NS_ID" + assert_output --partial "Total" + assert_output --regexp "Current Offset 0" + } @test "Update namespace - Safe" { diff --git a/e2e/resource-mapping.bats b/e2e/resource-mapping.bats index 110aed16..23240696 100755 --- a/e2e/resource-mapping.bats +++ b/e2e/resource-mapping.bats @@ -110,6 +110,8 @@ teardown_file() { assert_output --partial "$RM1_ID" assert_output --partial "$VAL1_ID" assert_output --partial "valueone, valuefirst, first" + assert_output --partial "Total" + assert_output --regexp "Current Offset 0" } @test "Delete resource mapping" { diff --git a/e2e/subject-condition-sets.bats b/e2e/subject-condition-sets.bats index f6ae5e3c..01f49ddd 100755 --- a/e2e/subject-condition-sets.bats +++ b/e2e/subject-condition-sets.bats @@ -106,23 +106,25 @@ teardown_file() { CREATED_ID=$(./otdfctl $HOST $WITH_CREDS policy scs create --subject-sets "$SCS_2" -l fromfile=false --json | jq -r '.id') run_otdfctl_scs list - assert_success - assert_output --partial "$CREATED_ID" + assert_success + assert_output --partial "$CREATED_ID" + assert_output --partial "Total" + assert_output --regexp "Current Offset 0" run_otdfctl_scs list --json - assert_success - assert_output --partial ".department" - assert_output --partial ".emailAddress" - assert_output --partial ".team.name" - assert_output --partial ".org.name" - [ $(echo "$output" | jq -r '.[-1].subject_sets[0].condition_groups[0].conditions[0].subject_external_values[0]') = "piedpiper.com" ] - [ $(echo "$output" | jq -r '.[-1].id') = "$CREATED_ID" ] - [ $(echo "$output" | jq -r '.[-1].metadata.labels.fromfile') = "false" ] + assert_success + assert_output --partial ".department" + assert_output --partial ".emailAddress" + assert_output --partial ".team.name" + assert_output --partial ".org.name" + [ $(echo "$output" | jq -r '.[-1].subject_sets[0].condition_groups[0].conditions[0].subject_external_values[0]') = "piedpiper.com" ] + [ $(echo "$output" | jq -r '.[-1].id') = "$CREATED_ID" ] + [ $(echo "$output" | jq -r '.[-1].metadata.labels.fromfile') = "false" ] # validate deletion run_delete_scs "$CREATED_ID" - assert_success - assert_output --partial "$CREATED_ID" + assert_success + assert_output --partial "$CREATED_ID" } @test "Prune SCS - deletes unmapped SCS alone" { diff --git a/e2e/subject-mapping.bats b/e2e/subject-mapping.bats index 99c2742f..d436df92 100755 --- a/e2e/subject-mapping.bats +++ b/e2e/subject-mapping.bats @@ -133,6 +133,8 @@ teardown_file() { run_otdfctl_sm list assert_success assert_output --partial "$created" + assert_output --partial "Total" + assert_output --regexp "Current Offset 0" run_otdfctl_sm list --json [ "$(echo $output | jq -r ".[] | select(.id == \"$created\") | .attribute_value.fqn")" == "https://subject-mappings.net/attr/attr1/value/val1" ] From b52cc1e167189efda75a1ed1051c033a29fe96c4 Mon Sep 17 00:00:00 2001 From: jakedoublev Date: Wed, 4 Dec 2024 10:33:38 -0800 Subject: [PATCH 09/14] improve e2e tests regexp matching --- e2e/attributes.bats | 39 ++++++++++++++++++++++++++++----- e2e/kas-grants.bats | 20 ++++++++--------- e2e/kas-registry.bats | 2 +- e2e/namespaces.bats | 38 ++++++++++++++++---------------- e2e/profile.bats | 8 +++---- e2e/resource-mapping.bats | 16 +++++++------- e2e/subject-condition-sets.bats | 6 ++--- e2e/subject-mapping.bats | 14 ++++++------ 8 files changed, 85 insertions(+), 58 deletions(-) diff --git a/e2e/attributes.bats b/e2e/attributes.bats index a786aa90..7ad3fbc7 100755 --- a/e2e/attributes.bats +++ b/e2e/attributes.bats @@ -67,10 +67,10 @@ teardown_file() { run_otdfctl_attr get --id "$ATTR_ID" assert_success - assert_output --regexp "Id.*$ATTR_ID" - assert_output --regexp "Name.*$LOWERED" + assert_line --regexp "Id.*$ATTR_ID" + assert_line --regexp "Name.*$LOWERED" assert_output --partial "ANY_OF" - assert_output --regexp "Namespace.*$NS_NAME" + assert_line --regexp "Namespace.*$NS_NAME" run_otdfctl_attr get --id "$ATTR_ID" --json assert_success @@ -112,19 +112,46 @@ teardown_file() { assert_success assert_output --partial "$ATTR_ID" assert_output --partial "Total" - assert_output --regexp "Current Offset 0" + assert_line --regexp "Current Offset.*0" run_otdfctl_attr list --state active assert_success assert_output --partial "$ATTR_ID" assert_output --partial "Total" - assert_output --regexp "Current Offset 0" + assert_line --regexp "Current Offset.*0" run_otdfctl_attr list --state inactive assert_success refute_output --partial "$ATTR_ID" assert_output --partial "Total" - assert_output --regexp "Current Offset 0" + assert_line --regexp "Current Offset.*0" +} + +@test "List - comprehensive pagination tests" { + # create 10 random attributes so we have confidence there are >= 10 attribute definitions + for i in {1..10}; do + random_name=$(LC_ALL=C tr -dc 'A-Za-z0-9' Date: Wed, 4 Dec 2024 10:39:47 -0800 Subject: [PATCH 10/14] fix previously bad tests --- e2e/namespaces.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/namespaces.bats b/e2e/namespaces.bats index 88e77751..dcb0ee99 100755 --- a/e2e/namespaces.bats +++ b/e2e/namespaces.bats @@ -135,7 +135,7 @@ teardown_file() { run_otdfctl_ns deactivate "$NS_ID_FLAG" --force assert_success assert_line --regexp "Id.*$NS_ID" - assert_line --regexp "Id.*$NS_NAME_UPDATE" + assert_line --regexp "Name.*$NS_NAME_UPDATE" } @test "List namespaces - when inactive" { @@ -177,7 +177,7 @@ teardown_file() { run_otdfctl_ns unsafe delete "$NS_ID_FLAG" --force assert_success assert_line --regexp "Id.*$NS_ID" - assert_line --regexp "Id.*$NS_NAME_UPDATE" + assert_line --regexp "Name.*$NS_NAME_UPDATE" } @test "List namespaces - when deleted" { From 747326032c098876c212751d6c738b77614b21da Mon Sep 17 00:00:00 2001 From: jakedoublev Date: Wed, 4 Dec 2024 10:40:46 -0800 Subject: [PATCH 11/14] fix other previously broken test --- e2e/subject-mapping.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/subject-mapping.bats b/e2e/subject-mapping.bats index 9ccc404e..cfb7b437 100755 --- a/e2e/subject-mapping.bats +++ b/e2e/subject-mapping.bats @@ -100,7 +100,7 @@ teardown_file() { assert_line --regexp "Id.*$created" assert_line --regexp "Attribute Value: Id.*$VAL2_ID" assert_line --regexp "Attribute Value: Value.*value2" - assert_line --regexp "Subject Condition Set: Id.*$created" + assert_line --regexp "Subject Condition Set: Id.*$new_scs" # json run_otdfctl_sm get --id "$created" --json From 9a859cefba01a2f44bb0e2d7f7eaaeec321ebd23 Mon Sep 17 00:00:00 2001 From: jakedoublev Date: Wed, 4 Dec 2024 13:01:37 -0800 Subject: [PATCH 12/14] style wip --- cmd/dev.go | 21 +++-------- cmd/kas-grants.go | 2 +- cmd/kas-registry.go | 2 +- cmd/policy-attributeNamespaces.go | 2 +- cmd/policy-attributeValues.go | 2 +- cmd/policy-attributes.go | 5 +-- cmd/policy-resourceMappings.go | 2 +- cmd/policy-subjectConditionSets.go | 2 +- cmd/policy-subjectMappings.go | 2 +- pkg/cli/messages.go | 4 ++- pkg/cli/style.go | 9 +++-- pkg/cli/table.go | 56 ++++++++++++++++++++++++++++++ pkg/cli/tabular.go | 15 +++++--- 13 files changed, 90 insertions(+), 34 deletions(-) diff --git a/cmd/dev.go b/cmd/dev.go index 69e6430a..c86e0b99 100644 --- a/cmd/dev.go +++ b/cmd/dev.go @@ -12,7 +12,6 @@ import ( "github.com/opentdf/otdfctl/pkg/config" "github.com/opentdf/otdfctl/pkg/man" "github.com/opentdf/platform/protocol/go/common" - "github.com/opentdf/platform/protocol/go/policy" "github.com/spf13/cobra" ) @@ -64,20 +63,6 @@ func renderDSMessages() string { return cli.SuccessMessage("Success message") + "\n" + cli.ErrorMessage("Error message", nil) } -// Prints out the page information in simplified aligned format -func printListPaginationTable(p *policy.PageResponse) { - rows := [][]string{ - {"Current Offset", fmt.Sprintf("%d", p.GetCurrentOffset())}, - } - if p.GetNextOffset() > 0 { - rows = append(rows, []string{"Next Offset", fmt.Sprintf("%d", p.GetNextOffset())}) - } - rows = append(rows, []string{"Total", fmt.Sprintf("%d", p.GetTotal())}) - for _, r := range rows { - fmt.Printf("%-20s %s\n", r[0], r[1]) - } -} - func getMetadataRows(m *common.Metadata) [][]string { if m != nil { metadata := cli.ConstructMetadata(m) @@ -119,12 +104,14 @@ func getMetadataUpdateBehavior() common.MetadataUpdateEnum { } // HandleSuccess prints a success message according to the configured format (styled table or JSON) -func HandleSuccess(command *cobra.Command, id string, t table.Model, policyObject interface{}) { +func HandleSuccess(command *cobra.Command, id string, t table.Model, policyObject interface{}, joinable ...table.Model) { c := cli.New(command, []string{}) if OtdfctlCfg.Output.Format == config.OutputJSON || configFlagOverrides.OutputFormatJSON { c.ExitWithJSON(policyObject) } - cli.PrintSuccessTable(command, id, t) + tables := []table.Model{t} + tables = append(tables, joinable...) + cli.PrintSuccessTable(command, id, tables...) } // Adds reusable create/update label flags to a Policy command and the optional force-replace-labels flag for updates only diff --git a/cmd/kas-grants.go b/cmd/kas-grants.go index 30cb1650..b0bd6037 100644 --- a/cmd/kas-grants.go +++ b/cmd/kas-grants.go @@ -226,12 +226,12 @@ func policy_listKasGrants(cmd *cobra.Command, args []string) { } } t = t.WithRows(rows) + t = cli.WithListPaginationFooter(t, page) // Do not supporting printing the 'get --id=...' helper message as grants are atypical // with no individual ID. cmd.Use = "" HandleSuccess(cmd, "", t, grants) - printListPaginationTable(page) } func init() { diff --git a/cmd/kas-registry.go b/cmd/kas-registry.go index 38d59f32..ee67e46d 100644 --- a/cmd/kas-registry.go +++ b/cmd/kas-registry.go @@ -87,8 +87,8 @@ func policy_listKeyAccessRegistries(cmd *cobra.Command, args []string) { })) } t = t.WithRows(rows) + t = cli.WithListPaginationFooter(t, page) HandleSuccess(cmd, "", t, list) - printListPaginationTable(page) } func policy_createKeyAccessRegistry(cmd *cobra.Command, args []string) { diff --git a/cmd/policy-attributeNamespaces.go b/cmd/policy-attributeNamespaces.go index f43bfce7..16dfde76 100644 --- a/cmd/policy-attributeNamespaces.go +++ b/cmd/policy-attributeNamespaces.go @@ -75,8 +75,8 @@ func policy_listAttributeNamespaces(cmd *cobra.Command, args []string) { ) } t = t.WithRows(rows) + t = cli.WithListPaginationFooter(t, page) HandleSuccess(cmd, "", t, list) - printListPaginationTable(page) } func policy_createAttributeNamespace(cmd *cobra.Command, args []string) { diff --git a/cmd/policy-attributeValues.go b/cmd/policy-attributeValues.go index 01b59eee..633ede4c 100644 --- a/cmd/policy-attributeValues.go +++ b/cmd/policy-attributeValues.go @@ -84,8 +84,8 @@ func policy_listAttributeValue(cmd *cobra.Command, args []string) { })) } t = t.WithRows(rows) + t = cli.WithListPaginationFooter(t, page) HandleSuccess(cmd, "", t, vals) - printListPaginationTable(page) } func policy_updateAttributeValue(cmd *cobra.Command, args []string) { diff --git a/cmd/policy-attributes.go b/cmd/policy-attributes.go index 113efe63..2dde47ea 100644 --- a/cmd/policy-attributes.go +++ b/cmd/policy-attributes.go @@ -126,8 +126,9 @@ func policy_listAttributes(cmd *cobra.Command, args []string) { })) } t = t.WithRows(rows) - HandleSuccess(cmd, "", t, attrs) - printListPaginationTable(page) + footer := cli.WithListPaginationFooter(t, page) + HandleSuccess(cmd, "", t, attrs, footer) + // cli.WithListPaginationFooter(t, page) } func policy_deactivateAttribute(cmd *cobra.Command, args []string) { diff --git a/cmd/policy-resourceMappings.go b/cmd/policy-resourceMappings.go index c46a30bf..fab0e69a 100644 --- a/cmd/policy-resourceMappings.go +++ b/cmd/policy-resourceMappings.go @@ -104,8 +104,8 @@ func policy_listResourceMappings(cmd *cobra.Command, args []string) { })) } t = t.WithRows(rows) + t = cli.WithListPaginationFooter(t, page) HandleSuccess(cmd, "", t, rmList) - printListPaginationTable(page) } func policy_updateResourceMapping(cmd *cobra.Command, args []string) { diff --git a/cmd/policy-subjectConditionSets.go b/cmd/policy-subjectConditionSets.go index 599ef26b..f41f96c8 100644 --- a/cmd/policy-subjectConditionSets.go +++ b/cmd/policy-subjectConditionSets.go @@ -174,8 +174,8 @@ func policy_listSubjectConditionSets(cmd *cobra.Command, args []string) { })) } t = t.WithRows(rows) + t = cli.WithListPaginationFooter(t, page) HandleSuccess(cmd, "", t, scsList) - printListPaginationTable(page) } func policy_updateSubjectConditionSet(cmd *cobra.Command, args []string) { diff --git a/cmd/policy-subjectMappings.go b/cmd/policy-subjectMappings.go index f0521d3b..8230a89c 100644 --- a/cmd/policy-subjectMappings.go +++ b/cmd/policy-subjectMappings.go @@ -101,8 +101,8 @@ func policy_listSubjectMappings(cmd *cobra.Command, args []string) { })) } t = t.WithRows(rows) + t = cli.WithListPaginationFooter(t, page) HandleSuccess(cmd, "", t, list) - printListPaginationTable(page) } func policy_createSubjectMapping(cmd *cobra.Command, args []string) { diff --git a/pkg/cli/messages.go b/pkg/cli/messages.go index 036869af..5baba3b7 100644 --- a/pkg/cli/messages.go +++ b/pkg/cli/messages.go @@ -1,6 +1,8 @@ package cli -import "github.com/charmbracelet/lipgloss" +import ( + "github.com/charmbracelet/lipgloss" +) func SuccessMessage(msg string) string { return lipgloss.JoinHorizontal(lipgloss.Left, styleSuccessStatusBar.Render("SUCCESS"), msg) diff --git a/pkg/cli/style.go b/pkg/cli/style.go index a4cdd166..91d8c23c 100644 --- a/pkg/cli/style.go +++ b/pkg/cli/style.go @@ -340,7 +340,8 @@ var styleTableBorder = lipgloss.CompleteAdaptiveColor{ Dark: colorIndigo.Background.Light, } -var styleTable = lipgloss.NewStyle(). +var styleTable = lipgloss. + NewStyle(). Foreground(lipgloss.CompleteAdaptiveColor{ Light: colorBlack.Foreground.Light, Dark: colorWhite.Foreground.Dark, @@ -350,14 +351,16 @@ var styleTable = lipgloss.NewStyle(). // Text //lint:ignore U1000 // not used yet -var styleText = lipgloss.NewStyle(). +var styleText = lipgloss. + NewStyle(). Foreground(lipgloss.CompleteAdaptiveColor{ Light: colorBlack.Foreground.Light, Dark: colorWhite.Foreground.Dark, }) //lint:ignore U1000 // not used yet -var styleTextBold = lipgloss.NewStyle(). +var styleTextBold = lipgloss. + NewStyle(). Foreground(lipgloss.CompleteAdaptiveColor{ Light: colorBlack.Foreground.Light, Dark: colorWhite.Foreground.Dark, diff --git a/pkg/cli/table.go b/pkg/cli/table.go index 3a77525e..bfb58d41 100644 --- a/pkg/cli/table.go +++ b/pkg/cli/table.go @@ -1,7 +1,12 @@ package cli import ( + "fmt" + "strings" + + "github.com/charmbracelet/lipgloss" "github.com/evertras/bubble-table/table" + "github.com/opentdf/platform/protocol/go/policy" ) const ( @@ -23,3 +28,54 @@ func NewTable(cols ...table.Column) table.Model { func NewUUIDColumn() table.Column { return table.NewFlexColumn("id", "ID", FlexColumnWidthFive) } + +// Adds the page information to the table footer +func WithListPaginationFooter(t table.Model, p *policy.PageResponse) table.Model { + info := []string{ + fmt.Sprintf("Total: %d", p.GetTotal()), + fmt.Sprintf("Current Offset: %d", p.GetCurrentOffset()), + } + if p.GetNextOffset() > 0 { + info = append(info, fmt.Sprintf("Next Offset: %d", p.GetNextOffset())) + } + + columns := []table.Column{} + for _, c := range info { + columns = append(columns, table.NewFlexColumn(c, c, FlexColumnWidthOne)) + } + + content := strings.Join(info, " | ") + // content := table.New(columns). + // WithBaseStyle(styleTable). + // BorderRounded(). + // WithTargetWidth(len(info) * 20). + // WithNoPagination().View() + + leftAligned := lipgloss.NewStyle().Align(lipgloss.Left) + return t.WithStaticFooter(content).WithBaseStyle(leftAligned) +} + +// func WithListPaginationFooter(t table.Model, p *policy.PageResponse) table.Model { +// info := []string{ +// fmt.Sprintf("Total: %d", p.GetTotal()), +// fmt.Sprintf("Current Offset: %d", p.GetCurrentOffset()), +// } +// if p.GetNextOffset() > 0 { +// info = append(info, fmt.Sprintf("Next Offset: %d", p.GetNextOffset())) +// } + +// columns := []table.Column{} +// for _, c := range info { +// columns = append(columns, table.NewFlexColumn(c, c, FlexColumnWidthOne)) +// } + +// // content := strings.Join(info, " | ") +// content := table.New(columns). +// WithBaseStyle(styleTable). +// BorderRounded(). +// WithTargetWidth(len(info) * 20). +// WithNoPagination() + +// // fmt.Println(lipgloss.JoinVertical(lipgloss.Left, t.View(), content.View())) +// return content +// } diff --git a/pkg/cli/tabular.go b/pkg/cli/tabular.go index 9a9343c6..7038573e 100644 --- a/pkg/cli/tabular.go +++ b/pkg/cli/tabular.go @@ -47,7 +47,7 @@ func getJSONHelper(command string) string { return fmt.Sprintf("Use '%s --json' to see all properties", command) } -func PrintSuccessTable(cmd *cobra.Command, id string, t table.Model) { +func PrintSuccessTable(cmd *cobra.Command, id string, joinableTables ...table.Model) { parent := cmd.Parent() resourceShort := parent.Use resource := parent.Use @@ -88,11 +88,18 @@ func PrintSuccessTable(cmd *cobra.Command, id string, t table.Model) { successMessage := SuccessMessage(msg.verb) jsonDirections := FooterMessage(msg.helper) - ts := t.View() - if ts == "" { + if len(joinableTables) == 0 { fmt.Println(lipgloss.JoinVertical(lipgloss.Top, successMessage, jsonDirections)) return } - fmt.Println(lipgloss.JoinVertical(lipgloss.Top, successMessage, ts, jsonDirections)) + printable := []string{ + successMessage, + } + for _, t := range joinableTables { + printable = append(printable, t.View()) + } + printable = append(printable, jsonDirections) + + fmt.Println(lipgloss.JoinVertical(lipgloss.Top, printable...)) } From 40b508507164536d9486d6cbcd82f26fab5f79ed Mon Sep 17 00:00:00 2001 From: jakedoublev Date: Wed, 4 Dec 2024 13:15:18 -0800 Subject: [PATCH 13/14] use footer for pagination info --- cmd/dev.go | 6 ++---- cmd/policy-attributes.go | 5 ++--- pkg/cli/table.go | 35 ----------------------------------- pkg/cli/tabular.go | 15 ++++----------- 4 files changed, 8 insertions(+), 53 deletions(-) diff --git a/cmd/dev.go b/cmd/dev.go index c86e0b99..8dff64e7 100644 --- a/cmd/dev.go +++ b/cmd/dev.go @@ -104,14 +104,12 @@ func getMetadataUpdateBehavior() common.MetadataUpdateEnum { } // HandleSuccess prints a success message according to the configured format (styled table or JSON) -func HandleSuccess(command *cobra.Command, id string, t table.Model, policyObject interface{}, joinable ...table.Model) { +func HandleSuccess(command *cobra.Command, id string, t table.Model, policyObject interface{}) { c := cli.New(command, []string{}) if OtdfctlCfg.Output.Format == config.OutputJSON || configFlagOverrides.OutputFormatJSON { c.ExitWithJSON(policyObject) } - tables := []table.Model{t} - tables = append(tables, joinable...) - cli.PrintSuccessTable(command, id, tables...) + cli.PrintSuccessTable(command, id, t) } // Adds reusable create/update label flags to a Policy command and the optional force-replace-labels flag for updates only diff --git a/cmd/policy-attributes.go b/cmd/policy-attributes.go index 2dde47ea..8a3dfc74 100644 --- a/cmd/policy-attributes.go +++ b/cmd/policy-attributes.go @@ -126,9 +126,8 @@ func policy_listAttributes(cmd *cobra.Command, args []string) { })) } t = t.WithRows(rows) - footer := cli.WithListPaginationFooter(t, page) - HandleSuccess(cmd, "", t, attrs, footer) - // cli.WithListPaginationFooter(t, page) + t = cli.WithListPaginationFooter(t, page) + HandleSuccess(cmd, "", t, attrs) } func policy_deactivateAttribute(cmd *cobra.Command, args []string) { diff --git a/pkg/cli/table.go b/pkg/cli/table.go index bfb58d41..7564bf9a 100644 --- a/pkg/cli/table.go +++ b/pkg/cli/table.go @@ -39,43 +39,8 @@ func WithListPaginationFooter(t table.Model, p *policy.PageResponse) table.Model info = append(info, fmt.Sprintf("Next Offset: %d", p.GetNextOffset())) } - columns := []table.Column{} - for _, c := range info { - columns = append(columns, table.NewFlexColumn(c, c, FlexColumnWidthOne)) - } - content := strings.Join(info, " | ") - // content := table.New(columns). - // WithBaseStyle(styleTable). - // BorderRounded(). - // WithTargetWidth(len(info) * 20). - // WithNoPagination().View() leftAligned := lipgloss.NewStyle().Align(lipgloss.Left) return t.WithStaticFooter(content).WithBaseStyle(leftAligned) } - -// func WithListPaginationFooter(t table.Model, p *policy.PageResponse) table.Model { -// info := []string{ -// fmt.Sprintf("Total: %d", p.GetTotal()), -// fmt.Sprintf("Current Offset: %d", p.GetCurrentOffset()), -// } -// if p.GetNextOffset() > 0 { -// info = append(info, fmt.Sprintf("Next Offset: %d", p.GetNextOffset())) -// } - -// columns := []table.Column{} -// for _, c := range info { -// columns = append(columns, table.NewFlexColumn(c, c, FlexColumnWidthOne)) -// } - -// // content := strings.Join(info, " | ") -// content := table.New(columns). -// WithBaseStyle(styleTable). -// BorderRounded(). -// WithTargetWidth(len(info) * 20). -// WithNoPagination() - -// // fmt.Println(lipgloss.JoinVertical(lipgloss.Left, t.View(), content.View())) -// return content -// } diff --git a/pkg/cli/tabular.go b/pkg/cli/tabular.go index 7038573e..9a9343c6 100644 --- a/pkg/cli/tabular.go +++ b/pkg/cli/tabular.go @@ -47,7 +47,7 @@ func getJSONHelper(command string) string { return fmt.Sprintf("Use '%s --json' to see all properties", command) } -func PrintSuccessTable(cmd *cobra.Command, id string, joinableTables ...table.Model) { +func PrintSuccessTable(cmd *cobra.Command, id string, t table.Model) { parent := cmd.Parent() resourceShort := parent.Use resource := parent.Use @@ -88,18 +88,11 @@ func PrintSuccessTable(cmd *cobra.Command, id string, joinableTables ...table.Mo successMessage := SuccessMessage(msg.verb) jsonDirections := FooterMessage(msg.helper) - if len(joinableTables) == 0 { + ts := t.View() + if ts == "" { fmt.Println(lipgloss.JoinVertical(lipgloss.Top, successMessage, jsonDirections)) return } - printable := []string{ - successMessage, - } - for _, t := range joinableTables { - printable = append(printable, t.View()) - } - printable = append(printable, jsonDirections) - - fmt.Println(lipgloss.JoinVertical(lipgloss.Top, printable...)) + fmt.Println(lipgloss.JoinVertical(lipgloss.Top, successMessage, ts, jsonDirections)) } From 0e81ede759037b6d95b4e0578b0f7c6d3218e944 Mon Sep 17 00:00:00 2001 From: jakedoublev Date: Thu, 5 Dec 2024 09:21:30 -0800 Subject: [PATCH 14/14] fix LIST RM context usage --- cmd/policy-resourceMappings.go | 2 +- pkg/handlers/resourceMappings.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/policy-resourceMappings.go b/cmd/policy-resourceMappings.go index fab0e69a..180d99c1 100644 --- a/cmd/policy-resourceMappings.go +++ b/cmd/policy-resourceMappings.go @@ -76,7 +76,7 @@ func policy_listResourceMappings(cmd *cobra.Command, args []string) { limit := c.Flags.GetRequiredInt32("limit") offset := c.Flags.GetRequiredInt32("offset") - rmList, page, err := h.ListResourceMappings(limit, offset) + rmList, page, err := h.ListResourceMappings(cmd.Context(), limit, offset) if err != nil { cli.ExitWithError("Failed to list resource mappings", err) } diff --git a/pkg/handlers/resourceMappings.go b/pkg/handlers/resourceMappings.go index a2930d67..563b3f16 100644 --- a/pkg/handlers/resourceMappings.go +++ b/pkg/handlers/resourceMappings.go @@ -39,8 +39,8 @@ func (h *Handler) GetResourceMapping(id string) (*policy.ResourceMapping, error) return res.GetResourceMapping(), nil } -func (h *Handler) ListResourceMappings(limit, offset int32) ([]*policy.ResourceMapping, *policy.PageResponse, error) { - res, err := h.sdk.ResourceMapping.ListResourceMappings(context.Background(), &resourcemapping.ListResourceMappingsRequest{ +func (h *Handler) ListResourceMappings(ctx context.Context, limit, offset int32) ([]*policy.ResourceMapping, *policy.PageResponse, error) { + res, err := h.sdk.ResourceMapping.ListResourceMappings(ctx, &resourcemapping.ListResourceMappingsRequest{ Pagination: &policy.PageRequest{ Limit: limit, Offset: offset,