From 9f9ea646231b70cac7ad78d7c4c2847165dac964 Mon Sep 17 00:00:00 2001 From: shphadnis <134159681+shphadnis@users.noreply.github.com> Date: Thu, 26 Oct 2023 18:11:41 -0700 Subject: [PATCH 1/2] list all pages of app profiles --- client/application_profile.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/client/application_profile.go b/client/application_profile.go index 50eb403e..07ab8971 100644 --- a/client/application_profile.go +++ b/client/application_profile.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/pkg/errors" - "github.com/spectrocloud/hapi/apiutil/transport" hashboardC "github.com/spectrocloud/hapi/hashboard/client/v1" "github.com/spectrocloud/hapi/models" @@ -105,7 +104,7 @@ func (h *V1Client) GetApplicationProfileTierManifestContent(applicationProfileUI return success.Payload.Spec.Published.Content, nil } -func (h *V1Client) SearchAppProfileSummaries(scope string, filter *models.V1AppProfileFilterSpec, sortBy []*models.V1AppProfileSortSpec) ([]*models.V1AppProfileSummary, error) { +func (h *V1Client) SearchAppProfileSummaries(scope string, filter *models.V1AppProfileFilterSpec, sortBy []*models.V1AppProfileSortSpec, getAllPages bool) ([]*models.V1AppProfileSummary, error) { client, err := h.GetHashboardClient() if err != nil { return nil, err @@ -122,14 +121,29 @@ func (h *V1Client) SearchAppProfileSummaries(scope string, filter *models.V1AppP Filter: filter, Sort: sortBy, } - + var appProfile []*models.V1AppProfileSummary resp, err := client.V1DashboardAppProfiles(params) if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 { return nil, nil } else if err != nil { return nil, err } - return resp.Payload.AppProfiles, nil + appProfile = append(appProfile, resp.Payload.AppProfiles...) + for len(resp.Payload.Listmeta.Continue) != 0 && getAllPages { + params.Offset = &resp.Payload.Listmeta.Offset + resp, err := client.V1DashboardAppProfiles(params) + if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 { + return nil, nil + } else if err != nil { + return nil, err + } + appProfile = append(appProfile, resp.Payload.AppProfiles...) + if len(resp.Payload.Listmeta.Continue) == 0 { + break + } + getAllPages = true + } + return appProfile, nil } func (h *V1Client) PatchApplicationProfile(appProfileUID string, metadata *models.V1AppProfileMetaEntity, ProfileContext string) error { @@ -137,7 +151,6 @@ func (h *V1Client) PatchApplicationProfile(appProfileUID string, metadata *model if err != nil { return err } - var params *clusterC.V1AppProfilesUIDMetadataUpdateParams switch ProfileContext { case "project": From 69523e892fe8d5f36b413a91e6fa96ea0b80f536 Mon Sep 17 00:00:00 2001 From: shphadnis <134159681+shphadnis@users.noreply.github.com> Date: Fri, 27 Oct 2023 15:00:32 -0700 Subject: [PATCH 2/2] Review changes --- client/application_profile.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/client/application_profile.go b/client/application_profile.go index 07ab8971..77f1c59e 100644 --- a/client/application_profile.go +++ b/client/application_profile.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/pkg/errors" + "github.com/spectrocloud/hapi/apiutil/transport" hashboardC "github.com/spectrocloud/hapi/hashboard/client/v1" "github.com/spectrocloud/hapi/models" @@ -104,7 +105,7 @@ func (h *V1Client) GetApplicationProfileTierManifestContent(applicationProfileUI return success.Payload.Spec.Published.Content, nil } -func (h *V1Client) SearchAppProfileSummaries(scope string, filter *models.V1AppProfileFilterSpec, sortBy []*models.V1AppProfileSortSpec, getAllPages bool) ([]*models.V1AppProfileSummary, error) { +func (h *V1Client) SearchAppProfileSummaries(scope string, filter *models.V1AppProfileFilterSpec, sortBy []*models.V1AppProfileSortSpec) ([]*models.V1AppProfileSummary, error) { client, err := h.GetHashboardClient() if err != nil { return nil, err @@ -122,16 +123,12 @@ func (h *V1Client) SearchAppProfileSummaries(scope string, filter *models.V1AppP Sort: sortBy, } var appProfile []*models.V1AppProfileSummary - resp, err := client.V1DashboardAppProfiles(params) - if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 { - return nil, nil - } else if err != nil { - return nil, err - } - appProfile = append(appProfile, resp.Payload.AppProfiles...) - for len(resp.Payload.Listmeta.Continue) != 0 && getAllPages { - params.Offset = &resp.Payload.Listmeta.Offset - resp, err := client.V1DashboardAppProfiles(params) + var resp *hashboardC.V1DashboardAppProfilesOK + for { + if resp != nil { + params.Offset = &resp.Payload.Listmeta.Offset + } + resp, err = client.V1DashboardAppProfiles(params) if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 { return nil, nil } else if err != nil { @@ -141,7 +138,6 @@ func (h *V1Client) SearchAppProfileSummaries(scope string, filter *models.V1AppP if len(resp.Payload.Listmeta.Continue) == 0 { break } - getAllPages = true } return appProfile, nil }