Skip to content

Commit

Permalink
used scan endpoint (#1474)
Browse files Browse the repository at this point in the history
* used scan endpoint

* added
  • Loading branch information
kavinbalagen authored Jan 21, 2025
1 parent d357ba1 commit e7254ae
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e7254ae

Please sign in to comment.