Skip to content

Commit

Permalink
Fixed bug in dnclist package
Browse files Browse the repository at this point in the history
  • Loading branch information
charliecon committed Aug 7, 2024
1 parent ec11b4f commit 1e6facd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ func (p *outboundDnclistProxy) uploadPhoneEntriesToDncList(dncList *platformclie
}

func createOutboundDnclistFn(ctx context.Context, p *outboundDnclistProxy, dnclist *platformclientv2.Dnclistcreate) (*platformclientv2.Dnclist, *platformclientv2.APIResponse, error) {
list, resp, err := p.outboundApi.PostOutboundDnclists(*dnclist)
if err != nil {
return nil, resp, fmt.Errorf("failed to create dnclist: %s", err)
}
return list, resp, nil
return p.outboundApi.PostOutboundDnclists(*dnclist)
}

func getAllOutboundDnclistFn(ctx context.Context, p *outboundDnclistProxy) (*[]platformclientv2.Dnclist, *platformclientv2.APIResponse, error) {
Expand All @@ -105,47 +101,33 @@ func getAllOutboundDnclistFn(ctx context.Context, p *outboundDnclistProxy) (*[]p

dnclists, resp, err := p.outboundApi.GetOutboundDnclists(false, false, pageSize, 1, true, "", "", "", []string{}, "", "")
if err != nil {
return nil, resp, fmt.Errorf("Failed to get dnclists: %v", err)
return nil, resp, fmt.Errorf("failed to get dnclists: %v", err)
}

if dnclists.Entities == nil || len(*dnclists.Entities) == 0 {
return &allDnclists, resp, nil
}

for _, dnclist := range *dnclists.Entities {
allDnclists = append(allDnclists, dnclist)
}
allDnclists = append(allDnclists, *dnclists.Entities...)

var response *platformclientv2.APIResponse
for pageNum := 2; pageNum <= *dnclists.PageCount; pageNum++ {
dnclists, resp, err := p.outboundApi.GetOutboundDnclists(false, false, pageSize, pageNum, true, "", "", "", []string{}, "", "")
if err != nil {
return nil, resp, fmt.Errorf("Failed to get dnclists: %v", err)
return nil, resp, fmt.Errorf("failed to get dnclists: %v", err)
}
response = resp
if dnclists.Entities == nil || len(*dnclists.Entities) == 0 {
break
}

for _, dnclist := range *dnclists.Entities {
log.Printf("Dealing with dnclist: %s", *dnclist.Id)
allDnclists = append(allDnclists, dnclist)
}
allDnclists = append(allDnclists, *dnclists.Entities...)
}
return &allDnclists, response, nil
}

func updateOutboundDnclistFn(ctx context.Context, p *outboundDnclistProxy, dnclistId string, dnclist *platformclientv2.Dnclist) (*platformclientv2.Dnclist, *platformclientv2.APIResponse, error) {
dnclist, resp, err := p.outboundApi.GetOutboundDnclist(dnclistId, false, false)
if err != nil {
return nil, resp, fmt.Errorf("failed to get dnc list by id %s", err)
}

outboundDncList, resp, err := p.outboundApi.PutOutboundDnclist(dnclistId, *dnclist)
if err != nil {
return nil, resp, fmt.Errorf("error updating outbound dnc list %s", err)
}
return outboundDncList, resp, nil
return p.outboundApi.PutOutboundDnclist(dnclistId, *dnclist)
}

func uploadPhoneEntriesToDncListFn(p *outboundDnclistProxy, dncList *platformclientv2.Dnclist, entry interface{}) (*platformclientv2.APIResponse, diag.Diagnostics) {
Expand All @@ -170,34 +152,23 @@ func uploadPhoneEntriesToDncListFn(p *outboundDnclistProxy, dncList *platformcli
}

func deleteOutboundDnclistFn(ctx context.Context, p *outboundDnclistProxy, dnclistId string) (*platformclientv2.APIResponse, error) {
resp, err := p.outboundApi.DeleteOutboundDnclist(dnclistId)
if err != nil {
return resp, fmt.Errorf("failed to delete dnc list %s", err)
}
return resp, nil
return p.outboundApi.DeleteOutboundDnclist(dnclistId)
}

func getOutboundDnclistByIdFn(ctx context.Context, p *outboundDnclistProxy, dnclistId string) (*platformclientv2.Dnclist, *platformclientv2.APIResponse, error) {
dnclist, resp, err := p.outboundApi.GetOutboundDnclist(dnclistId, false, false)
if err != nil {
return nil, resp, fmt.Errorf("failed to retrieve dnc list by id %s: %s", dnclistId, err)
}
return dnclist, resp, nil
return p.outboundApi.GetOutboundDnclist(dnclistId, false, false)
}

func getOutboundDnclistByNameFn(ctx context.Context, p *outboundDnclistProxy, name string) (dnclistId string, retryable bool, response *platformclientv2.APIResponse, err error) {
dnclists, resp, err := getAllOutboundDnclistFn(ctx, p)
if err != nil {
return "", false, resp, fmt.Errorf("Error searching outbound dnc list %s: %s", name, err)
return "", false, resp, fmt.Errorf("error searching outbound dnc list %s: %s", name, err)
}

var dnclist platformclientv2.Dnclist
for _, dnclistSdk := range *dnclists {
if *dnclistSdk.Name == name {
log.Printf("Retrieved the dnc list id %s by name %s", *dnclistSdk.Id, name)
dnclist = dnclistSdk
return *dnclist.Id, false, resp, nil
return *dnclistSdk.Id, false, resp, nil
}
}
return "", true, resp, fmt.Errorf("Unable to find dnc list with name %s", name)
return "", true, resp, fmt.Errorf("unable to find dnc list with name %s", name)
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func createOutboundDncList(ctx context.Context, d *schema.ResourceData, meta int
}
}
} else {
return util.BuildDiagnosticError(resourceName, fmt.Sprintf("Phone numbers can only be uploaded to internal DNC lists."), fmt.Errorf("phone numbers can only be uploaded to internal DNC Lists"))
return util.BuildDiagnosticError(resourceName, "Phone numbers can only be uploaded to internal DNC lists.", fmt.Errorf("phone numbers can only be uploaded to internal DNC Lists"))
}
}
log.Printf("Created Outbound DNC list %s %s", name, *outboundDncList.Id)
Expand Down Expand Up @@ -153,7 +153,7 @@ func updateOutboundDncList(ctx context.Context, d *schema.ResourceData, meta int
}
}
} else {
return nil, util.BuildDiagnosticError(resourceName, fmt.Sprintf("Phone numbers can only be uploaded to internal DNC lists"), fmt.Errorf("phone numbers can only be uploaded to internal DNC lists"))
return nil, util.BuildDiagnosticError(resourceName, "Phone numbers can only be uploaded to internal DNC lists", fmt.Errorf("phone numbers can only be uploaded to internal DNC lists"))
}
}
return nil, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,7 @@ func TestAccResourceOutboundDncListDncListType(t *testing.T) {
func TestAccResourceOutboundDncListGryphonListType(t *testing.T) {
t.Parallel()
var gryphonLicense string
var present bool

present = false
present := false

if v := os.Getenv("GENESYSCLOUD_REGION"); v == "tca" {
gryphonLicense, present = os.LookupEnv("TEST_DNC_GRYPHON_LICENSE_KEY")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func deleteRoutingWrapupCode(ctx context.Context, d *schema.ResourceData, meta i
return util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to delete wrapupcode %s error: %s", name, err), proxyDelResponse)
}

return util.WithRetries(ctx, 180*time.Second, func() *retry.RetryError {
return util.WithRetries(ctx, 30*time.Second, func() *retry.RetryError {
_, proxyGetResponse, err := proxy.getRoutingWrapupcodeById(ctx, d.Id())
if err != nil {
if util.IsStatus404(proxyGetResponse) {
Expand Down

0 comments on commit 1e6facd

Please sign in to comment.