Skip to content

Commit

Permalink
Merge pull request #175 from Edgio/bugFix_dnstxt_nilexception
Browse files Browse the repository at this point in the history
[DEN-479] fixed array out of bounds exception when getting dns txt token
  • Loading branch information
stevenpaz authored Apr 28, 2023
2 parents ad1b589 + 0f8ebe4 commit 3f3c40a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions edgecast/resources/cps/data_source_dns_txt_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func DataSourceDNSTXTTokenRead(

// No token found.
retryErr := CheckForDCVTokenRetry(retry, metadata, statusresp)
if retryErr == nil {
if retryErr == nil && IsDNSTxtTokenPresent(metadata) {
// All of the domains have the same token, so take the first.
log.Printf("setting token to %s", metadata[0].DcvToken.Token)
d.Set("value", metadata[0].DcvToken.Token)
Expand All @@ -162,8 +162,7 @@ func CheckForDCVTokenRetry(
// if token is available, and status is not processing, no retry is needed.
if statusresp.Status != "" &&
strings.ToLower(statusresp.Status) != "processing" &&
metadata != nil && len(metadata) > 0 &&
metadata[0].DcvToken != nil && len(metadata[0].DcvToken.Token) > 0 {
IsDNSTxtTokenPresent(metadata) {
return nil
}

Expand All @@ -180,3 +179,10 @@ func CheckForDCVTokenRetry(
log.Println("not retrying")
return nil
}

func IsDNSTxtTokenPresent(metadata []*models.DomainDcvFull) bool {
return metadata != nil &&
len(metadata) > 0 &&
metadata[0].DcvToken != nil &&
len(metadata[0].DcvToken.Token) > 0
}

0 comments on commit 3f3c40a

Please sign in to comment.