From e7254ae9451f170b656e640f529cd0555a211796 Mon Sep 17 00:00:00 2001 From: kavinbalagen <150852268+kavinbalagen@users.noreply.github.com> Date: Tue, 21 Jan 2025 06:03:55 -0800 Subject: [PATCH] used scan endpoint (#1474) * used scan endpoint * added --- ...esyscloud_externalcontacts_organization.go | 2 +- ...oud_externalcontacts_organization_proxy.go | 40 +++++++++---------- ...esyscloud_externalcontacts_organization.go | 34 ++++++++-------- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/genesyscloud/external_contacts_organization/data_source_genesyscloud_externalcontacts_organization.go b/genesyscloud/external_contacts_organization/data_source_genesyscloud_externalcontacts_organization.go index 1fd4b2683..611c440e5 100644 --- a/genesyscloud/external_contacts_organization/data_source_genesyscloud_externalcontacts_organization.go +++ b/genesyscloud/external_contacts_organization/data_source_genesyscloud_externalcontacts_organization.go @@ -50,7 +50,7 @@ func hydrateOrganizationCacheFn(c *rc.DataSourceCache, ctx context.Context) erro log.Printf("Hydrating cache for data source %s", ResourceType) - allExternalOrganization, resp, err := proxy.getAllExternalContactsOrganization(ctx, "") + allExternalOrganization, resp, err := proxy.getAllExternalContactsOrganization(ctx) if err != nil { return fmt.Errorf("failed to get external organization. Error: %s | API Response: %s", err.Error(), resp.String()) } diff --git a/genesyscloud/external_contacts_organization/genesyscloud_externalcontacts_organization_proxy.go b/genesyscloud/external_contacts_organization/genesyscloud_externalcontacts_organization_proxy.go index 9cae487e0..e89aaad32 100644 --- a/genesyscloud/external_contacts_organization/genesyscloud_externalcontacts_organization_proxy.go +++ b/genesyscloud/external_contacts_organization/genesyscloud_externalcontacts_organization_proxy.go @@ -20,7 +20,7 @@ var internalProxy *externalContactsOrganizationProxy // Type definitions for each func on our proxy so we can easily mock them out later type createExternalContactsOrganizationFunc func(ctx context.Context, p *externalContactsOrganizationProxy, externalOrganization *platformclientv2.Externalorganization) (*platformclientv2.Externalorganization, *platformclientv2.APIResponse, error) -type getAllExternalContactsOrganizationFunc func(ctx context.Context, p *externalContactsOrganizationProxy, query string) (*[]platformclientv2.Externalorganization, *platformclientv2.APIResponse, error) +type getAllExternalContactsOrganizationFunc func(ctx context.Context, p *externalContactsOrganizationProxy) (*[]platformclientv2.Externalorganization, *platformclientv2.APIResponse, error) type getExternalContactsOrganizationIdByNameFunc func(ctx context.Context, p *externalContactsOrganizationProxy, name string) (id string, retryable bool, apiResponse *platformclientv2.APIResponse, err error) type getExternalContactsOrganizationByIdFunc func(ctx context.Context, p *externalContactsOrganizationProxy, id string) (externalOrganization *platformclientv2.Externalorganization, apiResponse *platformclientv2.APIResponse, err error) type updateExternalContactsOrganizationFunc func(ctx context.Context, p *externalContactsOrganizationProxy, id string, externalOrganization *platformclientv2.Externalorganization) (*platformclientv2.Externalorganization, *platformclientv2.APIResponse, error) @@ -72,8 +72,8 @@ func (p *externalContactsOrganizationProxy) createExternalContactsOrganization(c } // getExternalContactsOrganization retrieves all Genesys Cloud external contacts organization -func (p *externalContactsOrganizationProxy) getAllExternalContactsOrganization(ctx context.Context, query string) (*[]platformclientv2.Externalorganization, *platformclientv2.APIResponse, error) { - return p.getAllExternalContactsOrganizationAttr(ctx, p, query) +func (p *externalContactsOrganizationProxy) getAllExternalContactsOrganization(ctx context.Context) (*[]platformclientv2.Externalorganization, *platformclientv2.APIResponse, error) { + return p.getAllExternalContactsOrganizationAttr(ctx, p) } // getExternalContactsOrganizationIdByName returns a single Genesys Cloud external contacts organization by a name @@ -102,31 +102,31 @@ func createExternalContactsOrganizationFn(ctx context.Context, p *externalContac } // getAllExternalContactsOrganizationFn is the implementation for retrieving all external contacts organization in Genesys Cloud -func getAllExternalContactsOrganizationFn(ctx context.Context, p *externalContactsOrganizationProxy, query string) (*[]platformclientv2.Externalorganization, *platformclientv2.APIResponse, error) { - var allExternalOrganizations []platformclientv2.Externalorganization - const pageSize = 100 +func getAllExternalContactsOrganizationFn(ctx context.Context, p *externalContactsOrganizationProxy) (*[]platformclientv2.Externalorganization, *platformclientv2.APIResponse, error) { + const cursorSize = 200 - externalOrganizations, response, err := p.externalContactsApi.GetExternalcontactsOrganizations(pageSize, 1, query, nil, "", nil, true) - if err != nil { - return nil, response, fmt.Errorf("failed to get external organization: %v", err) - } - if externalOrganizations.Entities == nil || len(*externalOrganizations.Entities) == 0 { - return &allExternalOrganizations, response, nil - } - allExternalOrganizations = append(allExternalOrganizations, *externalOrganizations.Entities...) + var allExternalOrganizations []platformclientv2.Externalorganization + var response *platformclientv2.APIResponse - for pageNum := 2; pageNum <= *externalOrganizations.PageCount; pageNum++ { - externalOrganizations, response, err := p.externalContactsApi.GetExternalcontactsOrganizations(pageSize, pageNum, query, nil, "", nil, true) + cursor := "" + for { + externalContactsOrganization, response, err := p.externalContactsApi.GetExternalcontactsScanOrganizations(cursorSize, cursor) if err != nil { return nil, response, fmt.Errorf("failed to get external organization: %v", err) } - - if externalOrganizations.Entities == nil || len(*externalOrganizations.Entities) == 0 { + if externalContactsOrganization.Entities == nil || len(*externalContactsOrganization.Entities) == 0 { break } - allExternalOrganizations = append(allExternalOrganizations, *externalOrganizations.Entities...) + allExternalOrganizations = append(allExternalOrganizations, *externalContactsOrganization.Entities...) + if externalContactsOrganization.Cursors == nil { + break + } + if externalContactsOrganization.Cursors.After == nil || (*externalContactsOrganization.Cursors.After) == "" { + break + } + cursor = *externalContactsOrganization.Cursors.After } // Cache the External Contacts resource into the p.externalContactsCache for later use for _, externalOrganization := range allExternalOrganizations { @@ -142,7 +142,7 @@ func getAllExternalContactsOrganizationFn(ctx context.Context, p *externalContac // getExternalContactsOrganizationIdByNameFn is an implementation of the function to get a Genesys Cloud external contacts organization by name func getExternalContactsOrganizationIdByNameFn(ctx context.Context, p *externalContactsOrganizationProxy, name string) (id string, retryable bool, apiResponse *platformclientv2.APIResponse, err error) { - externalOrganizations, response, err := p.getAllExternalContactsOrganization(ctx, name) + externalOrganizations, response, err := p.getAllExternalContactsOrganization(ctx) if err != nil { return "", false, response, err } diff --git a/genesyscloud/external_contacts_organization/resource_genesyscloud_externalcontacts_organization.go b/genesyscloud/external_contacts_organization/resource_genesyscloud_externalcontacts_organization.go index ded13591e..9a6519a6e 100644 --- a/genesyscloud/external_contacts_organization/resource_genesyscloud_externalcontacts_organization.go +++ b/genesyscloud/external_contacts_organization/resource_genesyscloud_externalcontacts_organization.go @@ -26,23 +26,23 @@ The resource_genesyscloud_external_contacts_organization.go contains all of the // getAllAuthExternalContactsOrganization retrieves all of the external contacts organization via Terraform in the Genesys Cloud and is used for the exporter func getAllAuthExternalContactsOrganizations(ctx context.Context, clientConfig *platformclientv2.Configuration) (resourceExporter.ResourceIDMetaMap, diag.Diagnostics) { - log.Println(ResourceType + " resources cannot be exported due to an API limitation.") - return nil, nil - - // TODO uncomment once DEVTOOLING-977 has been resolved - //proxy := newExternalContactsOrganizationProxy(clientConfig) - //resources := make(resourceExporter.ResourceIDMetaMap) - - //externalOrganizations, response, err := proxy.getAllExternalContactsOrganization(ctx, "") - //if err != nil { - // return nil, util.BuildAPIDiagnosticError(ResourceType, fmt.Sprintf("failed to get external organization error: %s", err), response) - //} - // - //for _, externalOrganization := range *externalOrganizations { - // resources[*externalOrganization.Id] = &resourceExporter.ResourceMeta{BlockLabel: *externalOrganization.Id} - //} - // - //return resources, nil + + proxy := getExternalContactsOrganizationProxy(clientConfig) + resources := make(resourceExporter.ResourceIDMetaMap) + + externalOrganizations, response, err := proxy.getAllExternalContactsOrganization(ctx) + if err != nil { + return nil, util.BuildAPIDiagnosticError(ResourceType, fmt.Sprintf("failed to get external organization error: %s", err), response) + } + + for _, externalOrganization := range *externalOrganizations { + if externalOrganization.Id == nil { + continue + } + resources[*externalOrganization.Id] = &resourceExporter.ResourceMeta{BlockLabel: *externalOrganization.Id} + } + + return resources, nil } // createExternalContactsOrganization is used by the external_contacts_organization resource to create Genesys cloud external contacts organization