Skip to content

Commit

Permalink
No jira: Fixed a few linting errors (#1444)
Browse files Browse the repository at this point in the history
* Fixed all architect package linting errors

* fixed linting errors as far as genesyscloud/conversations_*
  • Loading branch information
charliecon authored Dec 24, 2024
1 parent 105aa3e commit 3d6ad18
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func customizeDatatableRowDiff(ctx context.Context, diff *schema.ResourceDiff, m
if !diff.NewValueKnown("datatable_id") {
// datatable_id not yet in final state, but properties_json is marked as known.
// There may be computed defaults to set on properties_json that we do not know yet.
diff.SetNewComputed("properties_json")
_ = diff.SetNewComputed("properties_json")
return nil
}

Expand Down Expand Up @@ -109,7 +109,7 @@ func customizeDatatableRowDiff(ctx context.Context, diff *schema.ResourceDiff, m
return fmt.Errorf("Failure to marshal properties for %s: %s", id, err)
}

diff.SetNew("properties_json", string(result))
_ = diff.SetNew("properties_json", string(result))
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ func readArchitectDatatableRow(ctx context.Context, d *schema.ResourceData, meta
return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(ResourceType, fmt.Sprintf("Failed to read Datatable Row %s | error: %s", d.Id(), getErr), resp))
}

d.Set("datatable_id", tableId)
d.Set("key_value", keyStr)
_ = d.Set("datatable_id", tableId)
_ = d.Set("key_value", keyStr)

// The key value is exposed through a separate attribute, so it should be removed from the value map
delete(*row, "key")
Expand All @@ -131,7 +131,7 @@ func readArchitectDatatableRow(ctx context.Context, d *schema.ResourceData, meta
if err != nil {
return retry.NonRetryableError(fmt.Errorf("Failed to marshal row map %v: %v", *row, err))
}
d.Set("properties_json", string(valueBytes))
_ = d.Set("properties_json", string(valueBytes))

log.Printf("Read Datatable Row %s", d.Id())
return cc.CheckState(d)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (a *architectIvrProxy) uploadArchitectIvrWithChunkingLogic(ctx context.Cont
if !post {
// Get copy of ivr before this update
log.Printf("Reading IVR %s to save copy of the configuration before attempting an update", id)
ivrBeforeUpdate, resp, err = a.getArchitectIvr(ctx, id)
ivrBeforeUpdate, _, err = a.getArchitectIvr(ctx, id)
if err != nil {
log.Printf("Failed to save a copy of IVR %s before starting chunking logic: %v", id, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,28 +107,24 @@ func getAllArchitectSchedulegroupsFn(ctx context.Context, p *architectSchedulegr

scheduleGroups, apiResponse, err := p.architectApi.GetArchitectSchedulegroups(1, pageSize, "", "", "", "", nil)
if err != nil {
return nil, apiResponse, fmt.Errorf("Failed to get schedule group: %v", err)
return nil, apiResponse, fmt.Errorf("failed to get schedule group: %v", err)
}
if scheduleGroups.Entities == nil || len(*scheduleGroups.Entities) == 0 {
return &allScheduleGroups, apiResponse, nil
}
for _, scheduleGroup := range *scheduleGroups.Entities {
allScheduleGroups = append(allScheduleGroups, scheduleGroup)
}
allScheduleGroups = append(allScheduleGroups, *scheduleGroups.Entities...)

for pageNum := 2; pageNum <= *scheduleGroups.PageCount; pageNum++ {
scheduleGroups, apiResponse, err := p.architectApi.GetArchitectSchedulegroups(pageNum, pageSize, "", "", "", "", nil)
if err != nil {
return nil, apiResponse, fmt.Errorf("Failed to get schedule group: %v", err)
return nil, apiResponse, fmt.Errorf("failed to get schedule group: %v", err)
}

if scheduleGroups.Entities == nil || len(*scheduleGroups.Entities) == 0 {
break
}

for _, scheduleGroup := range *scheduleGroups.Entities {
allScheduleGroups = append(allScheduleGroups, scheduleGroup)
}
allScheduleGroups = append(allScheduleGroups, *scheduleGroups.Entities...)
}
return &allScheduleGroups, apiResponse, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
resourceExporter "terraform-provider-genesyscloud/genesyscloud/resource_exporter"
"terraform-provider-genesyscloud/genesyscloud/util"
"terraform-provider-genesyscloud/genesyscloud/util/constants"
"terraform-provider-genesyscloud/genesyscloud/util/resourcedata"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -79,34 +80,27 @@ func readArchitectSchedulegroups(ctx context.Context, d *schema.ResourceData, me
return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(ResourceType, fmt.Sprintf("Failed to read schedule group %s | error: %s", d.Id(), getErr), proxyResponse))
}

d.Set("name", *scheduleGroup.Name)
d.Set("division_id", *scheduleGroup.Division.Id)
d.Set("description", nil)
if scheduleGroup.Description != nil {
d.Set("description", *scheduleGroup.Description)
}

d.Set("time_zone", nil)
if scheduleGroup.TimeZone != nil {
d.Set("time_zone", *scheduleGroup.TimeZone)
}
resourcedata.SetNillableValue(d, "name", scheduleGroup.Name)
resourcedata.SetNillableValue(d, "description", scheduleGroup.Description)
resourcedata.SetNillableReferenceWritableDivision(d, "division_id", scheduleGroup.Division)
resourcedata.SetNillableValue(d, "time_zone", scheduleGroup.TimeZone)

if scheduleGroup.OpenSchedules != nil {
d.Set("open_schedules_id", util.SdkDomainEntityRefArrToSet(*scheduleGroup.OpenSchedules))
_ = d.Set("open_schedules_id", util.SdkDomainEntityRefArrToSet(*scheduleGroup.OpenSchedules))
} else {
d.Set("open_schedules_id", nil)
_ = d.Set("open_schedules_id", nil)
}

if scheduleGroup.ClosedSchedules != nil {
d.Set("closed_schedules_id", util.SdkDomainEntityRefArrToSet(*scheduleGroup.ClosedSchedules))
_ = d.Set("closed_schedules_id", util.SdkDomainEntityRefArrToSet(*scheduleGroup.ClosedSchedules))
} else {
d.Set("closed_schedules_id", nil)
_ = d.Set("closed_schedules_id", nil)
}

if scheduleGroup.HolidaySchedules != nil {
d.Set("holiday_schedules_id", util.SdkDomainEntityRefArrToSet(*scheduleGroup.HolidaySchedules))
_ = d.Set("holiday_schedules_id", util.SdkDomainEntityRefArrToSet(*scheduleGroup.HolidaySchedules))
} else {
d.Set("holiday_schedules_id", nil)
_ = d.Set("holiday_schedules_id", nil)
}

log.Printf("Read schedule group %s %s", d.Id(), *scheduleGroup.Name)
Expand Down
51 changes: 29 additions & 22 deletions genesyscloud/auth_role/data_source_genesyscloud_auth_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,49 @@ package auth_role
import (
"context"
"fmt"
"terraform-provider-genesyscloud/genesyscloud/provider"
"terraform-provider-genesyscloud/genesyscloud/util"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/mypurecloud/platform-client-sdk-go/v149/platformclientv2"
"terraform-provider-genesyscloud/genesyscloud/provider"
"terraform-provider-genesyscloud/genesyscloud/util"
"time"
)

/*
The data_source_genesyscloud_auth_role.go contains the data source implementation
for the resource.
*/

// dataSourceAuthRoleRead retrieves by name the id in question
// DataSourceAuthRoleRead retrieves by name the id in question
func DataSourceAuthRoleRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
sdkConfig := m.(*provider.ProviderMeta).ClientConfig
authAPI := platformclientv2.NewAuthorizationApiWithConfig(sdkConfig)

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

// Query role by name. Retry in case search has not yet indexed the role.
return util.WithRetries(ctx, 15*time.Second, func() *retry.RetryError {
const pageSize = 100
const pageNum = 1
roles, proxyResponse, getErr := authAPI.GetAuthorizationRoles(pageSize, pageNum, "", nil, "", "", name, nil, nil, false, nil)
if getErr != nil {
return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(ResourceType, fmt.Sprintf("Error requesting role %s | error: %s", name, getErr), proxyResponse))
}
var (
sdkConfig = m.(*provider.ProviderMeta).ClientConfig
proxy = getAuthRoleProxy(sdkConfig)

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

if roles.Entities == nil || len(*roles.Entities) == 0 {
return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(ResourceType, fmt.Sprintf("No authorization roles found with name %s", name), proxyResponse))
response *platformclientv2.APIResponse
id string
)

diagErr := util.WithRetries(ctx, 15*time.Second, func() *retry.RetryError {
roleId, retryable, resp, err := proxy.getAuthRoleIdByName(ctx, name)
if err != nil {
response = resp
if retryable {
return retry.RetryableError(err)
}
return retry.NonRetryableError(err)
}
role := (*roles.Entities)[0]
d.SetId(*role.Id)
id = roleId
return nil
})

if diagErr != nil {
return util.BuildAPIDiagnosticError(ResourceType, fmt.Sprintf("%v", diagErr), response)
}

d.SetId(id)
return nil
}
22 changes: 19 additions & 3 deletions genesyscloud/auth_role/genesyscloud_auth_role_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package auth_role
import (
"context"
"fmt"

rc "terraform-provider-genesyscloud/genesyscloud/resource_cache"

"github.com/mypurecloud/platform-client-sdk-go/v149/platformclientv2"
Expand Down Expand Up @@ -169,8 +168,25 @@ func getAllAuthRoleFn(ctx context.Context, p *authRoleProxy) (*[]platformclientv
}

// getAuthRoleIdByNameFn is an implementation of the function to get a Genesys Cloud auth role by name
func getAuthRoleIdByNameFn(ctx context.Context, p *authRoleProxy, name string) (id string, retryable bool, response *platformclientv2.APIResponse, err error) {
return "", false, nil, nil
func getAuthRoleIdByNameFn(_ context.Context, p *authRoleProxy, name string) (id string, retryable bool, response *platformclientv2.APIResponse, err error) {
const pageSize = 100
const pageNum = 1
roles, resp, getErr := p.authorizationApi.GetAuthorizationRoles(pageSize, pageNum, "", nil, "", "", name, nil, nil, false, nil)
if getErr != nil {
return "", false, resp, getErr
}

if roles.Entities == nil || len(*roles.Entities) == 0 {
return "", true, resp, fmt.Errorf("no authorization roles found with name %s", name)
}

for _, role := range *roles.Entities {
if *role.Name == name {
return *role.Id, false, resp, nil
}
}

return "", true, resp, fmt.Errorf("no authorization roles found with name %s", name)
}

// getAuthRoleByIdFn is an implementation of the function to get a Genesys Cloud auth role by Id
Expand Down
10 changes: 5 additions & 5 deletions genesyscloud/auth_role/resource_genesyscloud_auth_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,20 @@ func readAuthRole(ctx context.Context, d *schema.ResourceData, meta interface{})
return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(ResourceType, fmt.Sprintf("Failed to read role %s | error: %s", d.Id(), getErr), proxyResponse))
}

d.Set("name", *role.Name)
_ = d.Set("name", *role.Name)
resourcedata.SetNillableValue(d, "description", role.Description)
resourcedata.SetNillableValue(d, "default_role_id", role.DefaultRoleId)

if role.Permissions != nil {
d.Set("permissions", lists.StringListToSet(*role.Permissions))
_ = d.Set("permissions", lists.StringListToSet(*role.Permissions))
} else {
d.Set("permissions", nil)
_ = d.Set("permissions", nil)
}

if role.PermissionPolicies != nil {
d.Set("permission_policies", flattenRolePermissionPolicies(*role.PermissionPolicies))
_ = d.Set("permission_policies", flattenRolePermissionPolicies(*role.PermissionPolicies))
} else {
d.Set("permission_policies", nil)
_ = d.Set("permission_policies", nil)
}

log.Printf("Read role %s %s", d.Id(), *role.Name)
Expand Down
24 changes: 10 additions & 14 deletions genesyscloud/auth_role/resource_genesyscloud_auth_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,9 @@ func TestAccResourceAuthRoleConditions(t *testing.T) {
generateRolePermPolicyCondTerm(
varNameQueue,
opEq,
fmt.Sprintf(`
operands {
`operands {
type = "USER"
}
`),
}`,
),
),
),
Expand Down Expand Up @@ -304,11 +302,9 @@ func TestAccResourceAuthRoleConditions(t *testing.T) {
generateRolePermPolicyCondTerm(
varNameQueue,
opEq,
fmt.Sprintf(`
operands {
`operands {
type = "VARIABLE"
}
`),
}`,
),
),
),
Expand Down Expand Up @@ -398,10 +394,10 @@ func validateRolePermissions(roleResourcePath string, permissions ...string) res
return func(state *terraform.State) error {
roleResource, ok := state.RootModule().Resources[roleResourcePath]
if !ok {
return fmt.Errorf("Failed to find role %s in state", roleResourcePath)
return fmt.Errorf("failed to find role %s in state", roleResourcePath)
}

numPermsAttr, _ := roleResource.Primary.Attributes["permissions.#"]
numPermsAttr := roleResource.Primary.Attributes["permissions.#"]
numPerms, _ := strconv.Atoi(numPermsAttr)
configPerms := make([]string, numPerms)
for i := 0; i < numPerms; i++ {
Expand Down Expand Up @@ -431,13 +427,13 @@ func validatePermissionPolicyTest(roleResourcePath string, domain string, entity
}

roleAttrs := roleResource.Primary.Attributes
numPermsAttr, _ := roleAttrs["permission_policies.#"]
numPermsAttr := roleAttrs["permission_policies.#"]
numPerms, _ := strconv.Atoi(numPermsAttr)
for i := 0; i < numPerms; i++ {
if roleAttrs["permission_policies."+strconv.Itoa(i)+".domain"] == domain &&
roleAttrs["permission_policies."+strconv.Itoa(i)+".entity_name"] == entityName {

numActionsAttr, _ := roleAttrs["permission_policies."+strconv.Itoa(i)+".action_set.#"]
numActionsAttr := roleAttrs["permission_policies."+strconv.Itoa(i)+".action_set.#"]
numActions, _ := strconv.Atoi(numActionsAttr)
stateActions := make([]string, numActions)
for j := 0; j < numActions; j++ {
Expand Down Expand Up @@ -479,15 +475,15 @@ func validatePermPolicyCondition(
}

roleAttrs := roleResource.Primary.Attributes
numPermsAttr, _ := roleAttrs["permission_policies.#"]
numPermsAttr := roleAttrs["permission_policies.#"]
numPerms, _ := strconv.Atoi(numPermsAttr)
for i := 0; i < numPerms; i++ {
strNum := strconv.Itoa(i)
if roleAttrs["permission_policies."+strNum+".domain"] == domain &&
roleAttrs["permission_policies."+strNum+".entity_name"] == entityName {

// Check condition exists and matches
numCondAttr, _ := roleAttrs["permission_policies."+strNum+".conditions.#"]
numCondAttr := roleAttrs["permission_policies."+strNum+".conditions.#"]
numCond, _ := strconv.Atoi(numCondAttr)

if numCond == 0 {
Expand Down
15 changes: 0 additions & 15 deletions genesyscloud/consistency_checker/consistency_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,6 @@ func compareValues(oldValue, newValue interface{}, slice1Index, slice2Index int,
}
}

func (c *ConsistencyCheck) isComputed(d *schema.ResourceData, key string) bool {
schemaInterface := getUnexportedField(reflect.ValueOf(d).Elem().FieldByName("schema"))
resourceSchema := schemaInterface.(map[string]*schema.Schema)

k := key
if strings.Contains(key, ".") {
k = strings.Split(key, ".")[0]
}
if resourceSchema[k] == nil {
return false
}

return resourceSchema[k].Computed
}

func (c *ConsistencyCheck) CheckState(currentState *schema.ResourceData) *retry.RetryError {
if c.isEmptyState == nil {
panic("consistencyCheck must be initialized with NewConsistencyCheck")
Expand Down
Loading

0 comments on commit 3d6ad18

Please sign in to comment.