Skip to content

Commit

Permalink
Revert "Refactor users package (MyPureCloud#1129)" (MyPureCloud#1191)
Browse files Browse the repository at this point in the history
This reverts commit ceaeeb1.
  • Loading branch information
carnellj-genesys authored Jul 31, 2024
1 parent ceaeeb1 commit db9af99
Show file tree
Hide file tree
Showing 47 changed files with 2,198 additions and 2,349 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
inboundCall:
name: Terraform Flow Test-e678ea2e-2f37-4376-ab79-d70e7c7359b7
name: Terraform Emergency Test Flow 7fa2e8a9-b1d9-4d78-93b8-05b4465314a7
defaultLanguage: en-us
startUpRef: ./menus/menu[mainMenu]
initialGreeting:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
inboundEmail:
name: Terraform Flow Test-dabfb12a-6e7e-4e8c-ab21-7f8549959c48
division: New Home1
name: Terraform Flow Test-d0c40522-88e4-4b66-aa48-f237afb819e0
division: New Home
startUpRef: "/inboundEmail/states/state[Initial State_10]"
defaultLanguage: en-us
supportedLanguages:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
inboundCall:
name: Terraform Flow Test-fa4dd927-bf74-4394-9b20-c3560a4b5f7f
name: Terraform Flow Test-e602c7ba-318e-4373-99bb-bdf69dcc7600
defaultLanguage: en-us
startUpRef: ./menus/menu[mainMenu]
initialGreeting:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ func getArchitectSchedulesIdByNameFn(ctx context.Context, p *architectSchedulesP
return "", true, apiResponse, fmt.Errorf("No architect schedules found with name %s", name)
}

for _, schedule := range *schedules {
if *schedule.Name == name {
log.Printf("Retrieved the architect schedules id %s by name %s", *schedule.Id, name)
return *schedule.Id, false, apiResponse, nil
for _, schedules := range *schedules {
if *schedules.Name == name {
log.Printf("Retrieved the architect schedules id %s by name %s", *schedules.Id, name)
return *schedules.Id, false, apiResponse, nil
}
}

Expand Down
54 changes: 54 additions & 0 deletions genesyscloud/data_source_genesyscloud_architect_schedules.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package genesyscloud

import (
"context"
"fmt"
"terraform-provider-genesyscloud/genesyscloud/provider"
"terraform-provider-genesyscloud/genesyscloud/util"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2"
)

func DataSourceSchedule() *schema.Resource {
return &schema.Resource{
Description: "Data source for Genesys Cloud Schedule. Select a schedule by name",
ReadContext: provider.ReadWithPooledClient(dataSourceScheduleRead),
Schema: map[string]*schema.Schema{
"name": {
Description: "Schedule name.",
Type: schema.TypeString,
Required: true,
},
},
}
}

func dataSourceScheduleRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
sdkConfig := m.(*provider.ProviderMeta).ClientConfig
archAPI := platformclientv2.NewArchitectApiWithConfig(sdkConfig)

name := d.Get("name").(string)

return util.WithRetries(ctx, 15*time.Second, func() *retry.RetryError {
const pageSize = 100
for pageNum := 1; ; pageNum++ {
schedule, resp, getErr := archAPI.GetArchitectSchedules(pageNum, pageSize, "", "", name, nil)

if getErr != nil {
return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError("genesyscloud_architect_schedules", fmt.Sprintf("Error requesting schedule %s | error: %s", name, getErr), resp))
}

if schedule.Entities == nil || len(*schedule.Entities) == 0 {
return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError("genesyscloud_architect_schedules", fmt.Sprintf("No schedule found with name %s", name), resp))
}

d.SetId(*(*schedule.Entities)[0].Id)
return nil
}
})
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package user
package genesyscloud

import (
"context"
"fmt"
"log"
"net/mail"
"terraform-provider-genesyscloud/genesyscloud/provider"
rc "terraform-provider-genesyscloud/genesyscloud/resource_cache"
"terraform-provider-genesyscloud/genesyscloud/util"
Expand All @@ -16,6 +17,25 @@ import (
"github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2"
)

func DataSourceUser() *schema.Resource {
return &schema.Resource{
Description: "Data source for Genesys Cloud Users. Select a user by email or name. If both email & name are specified, the name won't be used for user lookup",
ReadWithoutTimeout: provider.ReadWithPooledClient(DataSourceUserRead),
Schema: map[string]*schema.Schema{
"email": {
Description: "User email.",
Type: schema.TypeString,
Optional: true,
},
"name": {
Description: "User name.",
Type: schema.TypeString,
Optional: true,
},
},
}
}

var (
dataSourceUserCache *rc.DataSourceCache
)
Expand All @@ -33,14 +53,14 @@ func DataSourceUserRead(ctx context.Context, d *schema.ResourceData, m interface

}
if d.Get("name").(string) == "" && d.Get("email").(string) == "" {
return util.BuildDiagnosticError(resourceName, "no user search field specified", nil)
return util.BuildDiagnosticError("genesyscloud_user", "no user search field specified", nil)
}

if dataSourceUserCache == nil {
dataSourceUserCache = rc.NewDataSourceCache(sdkConfig, hydrateUserCacheFn, getUserByNameFn)
}

userId, err := rc.RetrieveId(dataSourceUserCache, resourceName, key, ctx)
userId, err := rc.RetrieveId(dataSourceUserCache, "genesyscloud_user", key, ctx)
if err != nil {
return err
}
Expand All @@ -50,7 +70,7 @@ func DataSourceUserRead(ctx context.Context, d *schema.ResourceData, m interface
}

func hydrateUserCacheFn(c *rc.DataSourceCache) error {
log.Printf("hydrating cache for data source %s", resourceName)
log.Printf("hydrating cache for data source genesyscloud_user")
const pageSize = 100
usersAPI := platformclientv2.NewUsersApiWithConfig(c.ClientConfig)

Expand All @@ -73,7 +93,7 @@ func hydrateUserCacheFn(c *rc.DataSourceCache) error {

users, response, err := usersAPI.GetUsers(pageSize, pageNum, nil, nil, "", nil, "", "")

log.Printf("hydrating cache for data source %s with page number: %v", resourceName, pageNum)
log.Printf("hydrating cache for data source genesyscloud_user with page number: %v", pageNum)
if err != nil {
return fmt.Errorf("failed to get page of users: %v %v", err, response)
}
Expand All @@ -88,7 +108,7 @@ func hydrateUserCacheFn(c *rc.DataSourceCache) error {
}
}

log.Printf("cache hydration completed for data source %s", resourceName)
log.Printf("cache hydration completed for data source genesyscloud_user")

return nil
}
Expand All @@ -115,11 +135,11 @@ func getUserByNameFn(c *rc.DataSourceCache, searchField string, ctx context.Cont
Query: &[]platformclientv2.Usersearchcriteria{searchCriteria},
})
if getErr != nil {
return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Error requesting users: %s", getErr), resp))
return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError("genesyscloud_user", fmt.Sprintf("Error requesting users: %s", getErr), resp))
}

if users.Results == nil || len(*users.Results) == 0 {
return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("No users found with search criteria %v", searchCriteria), resp))
return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError("genesyscloud_user", fmt.Sprintf("No users found with search criteria %v", searchCriteria), resp))
}

// Select first user in the list
Expand All @@ -129,3 +149,13 @@ func getUserByNameFn(c *rc.DataSourceCache, searchField string, ctx context.Cont
return userId, diag

}

func emailorNameDisambiguation(searchField string) (string, string) {
emailField := "email"
nameField := "name"
_, err := mail.ParseAddress(searchField)
if err == nil {
return searchField, emailField
}
return searchField, nameField
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package user
package genesyscloud

import (
"fmt"
Expand Down Expand Up @@ -35,16 +35,16 @@ func TestAccDataSourceUser(t *testing.T) {
userName,
) + generateUserDataSource(
userDataSource,
resourceName+"."+userResource+".email",
"genesyscloud_user."+userResource+".email",
util.NullValue,
resourceName+"."+userResource,
"genesyscloud_user."+userResource,
),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair("data."+resourceName+"."+userDataSource, "id", resourceName+"."+userResource, "id"),
resource.TestCheckResourceAttrPair("data.genesyscloud_user."+userDataSource, "id", "genesyscloud_user."+userResource, "id"),
func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName+"."+userResource]
rs, ok := s.RootModule().Resources["genesyscloud_user."+userResource]
if !ok {
return fmt.Errorf("not found: %s", resourceName+"."+userResource)
return fmt.Errorf("not found: %s", "genesyscloud_user."+userResource)
}
userID = rs.Primary.ID
log.Printf("User ID: %s\n", userID) // Print user ID
Expand All @@ -61,11 +61,11 @@ func TestAccDataSourceUser(t *testing.T) {
) + generateUserDataSource(
userDataSource,
util.NullValue,
resourceName+"."+userResource+".name",
resourceName+"."+userResource,
"genesyscloud_user."+userResource+".name",
"genesyscloud_user."+userResource,
),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair("data."+resourceName+"."+userDataSource, "id", resourceName+"."+userResource, "id"),
resource.TestCheckResourceAttrPair("data.genesyscloud_user."+userDataSource, "id", "genesyscloud_user."+userResource, "id"),
func(s *terraform.State) error {
time.Sleep(30 * time.Second) // Wait for 30 seconds for proper deletion
return nil
Expand All @@ -87,10 +87,10 @@ func generateUserDataSource(
// Must explicitly use depends_on in terraform v0.13 when a data source references a resource
// Fixed in v0.14 https://github.com/hashicorp/terraform/pull/26284
dependsOnResource string) string {
return fmt.Sprintf(`data "%s" "%s" {
return fmt.Sprintf(`data "genesyscloud_user" "%s" {
email = %s
name = %s
depends_on=[%s]
}
`, resourceName, resourceID, email, name, dependsOnResource)
`, resourceID, email, name, dependsOnResource)
}
7 changes: 3 additions & 4 deletions genesyscloud/group/genesyscloud_group_init_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package group

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"sync"
"terraform-provider-genesyscloud/genesyscloud/user"
"terraform-provider-genesyscloud/genesyscloud"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

var providerDataSources map[string]*schema.Resource
Expand All @@ -24,7 +23,7 @@ func (r *registerTestInstance) registerTestResources() {
defer r.resourceMapMutex.Unlock()

providerResources[resourceName] = ResourceGroup()
providerResources["genesyscloud_user"] = user.ResourceUser()
providerResources["genesyscloud_user"] = genesyscloud.ResourceUser()

}

Expand Down
2 changes: 1 addition & 1 deletion genesyscloud/group/resource_genesyscloud_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2"
)

func getAllGroups(ctx context.Context, clientConfig *platformclientv2.Configuration) (resourceExporter.ResourceIDMetaMap, diag.Diagnostics) {
func GetAllGroups(ctx context.Context, clientConfig *platformclientv2.Configuration) (resourceExporter.ResourceIDMetaMap, diag.Diagnostics) {
resources := make(resourceExporter.ResourceIDMetaMap)
groupProxy := getGroupProxy(clientConfig)

Expand Down
2 changes: 1 addition & 1 deletion genesyscloud/group/resource_genesyscloud_group_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func SetRegistrar(regInstance registrar.Registrar) {

func GroupExporter() *resourceExporter.ResourceExporter {
return &resourceExporter.ResourceExporter{
GetResourcesFunc: provider.GetAllWithPooledClient(getAllGroups),
GetResourcesFunc: provider.GetAllWithPooledClient(GetAllGroups),
RefAttrs: map[string]*resourceExporter.RefAttrSettings{
"owner_ids": {RefType: "genesyscloud_user"},
"member_ids": {RefType: "genesyscloud_user"},
Expand Down
10 changes: 4 additions & 6 deletions genesyscloud/group_roles/genesyscloud_group_roles_init_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package group_roles

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"sync"
"terraform-provider-genesyscloud/genesyscloud"
gcloud "terraform-provider-genesyscloud/genesyscloud"
authRole "terraform-provider-genesyscloud/genesyscloud/auth_role"
"terraform-provider-genesyscloud/genesyscloud/group"
"terraform-provider-genesyscloud/genesyscloud/user"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

/*
Expand All @@ -28,10 +26,10 @@ func (r *registerTestInstance) registerTestResources() {
defer r.resourceMapMutex.Unlock()

providerResources["genesyscloud_group_roles"] = ResourceGroupRoles()
providerResources["genesyscloud_user"] = user.ResourceUser()
providerResources["genesyscloud_user"] = gcloud.ResourceUser()
providerResources["genesyscloud_group"] = group.ResourceGroup()
providerResources["genesyscloud_auth_role"] = authRole.ResourceAuthRole()
providerResources["genesyscloud_auth_division"] = genesyscloud.ResourceAuthDivision()
providerResources["genesyscloud_auth_division"] = gcloud.ResourceAuthDivision()
}

// initTestResources initializes all test resources.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package integration
import (
"sync"
"terraform-provider-genesyscloud/genesyscloud/group"
integrationCred "terraform-provider-genesyscloud/genesyscloud/integration_credential"
"terraform-provider-genesyscloud/genesyscloud/user"
"testing"

gcloud "terraform-provider-genesyscloud/genesyscloud"
integrationCred "terraform-provider-genesyscloud/genesyscloud/integration_credential"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand Down Expand Up @@ -36,7 +37,7 @@ func (r *registerTestInstance) registerTestResources() {
providerResources["genesyscloud_integration"] = ResourceIntegration()
providerResources["genesyscloud_group"] = group.ResourceGroup()
providerResources["genesyscloud_integration_credential"] = integrationCred.ResourceIntegrationCredential()
providerResources["genesyscloud_user"] = user.ResourceUser()
providerResources["genesyscloud_user"] = gcloud.ResourceUser()
}

// registerTestDataSources registers all data sources used in the tests.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package journey_views

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"sync"
"terraform-provider-genesyscloud/genesyscloud/user"
"terraform-provider-genesyscloud/genesyscloud"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

//var providerDataSources map[string]*schema.Resource
Expand All @@ -23,7 +22,7 @@ func (r *registerTestInstance) registerTestResources() {
defer r.resourceMapMutex.Unlock()

providerResources[resourceName] = ResourceJourneyViews()
providerResources["genesyscloud_user"] = user.ResourceUser()
providerResources["genesyscloud_user"] = genesyscloud.ResourceUser()

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package orgauthorization_pairing

import (
"sync"
"terraform-provider-genesyscloud/genesyscloud"
"terraform-provider-genesyscloud/genesyscloud/group"
"terraform-provider-genesyscloud/genesyscloud/user"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -27,7 +27,7 @@ func (r *registerTestInstance) registerTestResources() {
defer r.resourceMapMutex.Unlock()

providerResources[resourceName] = ResourceOrgauthorizationPairing()
providerResources["genesyscloud_user"] = user.ResourceUser()
providerResources["genesyscloud_user"] = genesyscloud.ResourceUser()
providerResources["genesyscloud_group"] = group.ResourceGroup()
}

Expand Down
Loading

0 comments on commit db9af99

Please sign in to comment.