Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
fix: check response size before accessing the array
Browse files Browse the repository at this point in the history
this should partially solve #9
  • Loading branch information
eze-kiel authored and xakraz committed Jul 19, 2023
1 parent daafd89 commit b0381b1
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cloudflare/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ const (
ActiveCertificate = "active"
)

var ErrEmptyResponse = errors.New("cloudflare returned nothing")
var (
ErrEmptyResponse = errors.New("cloudflare returned nothing")
ErrNoResult = errors.New("cloudflare did not return any result in the response")
)

type Credentials struct {
Token string
Expand Down Expand Up @@ -65,6 +68,10 @@ func GetZoneID(name string, credz Credentials) (string, error) {
return "", ErrEmptyResponse
}

if len(holder.Result) < 1 {
return "", ErrNoResult
}

return holder.Result[0].ID, nil
}

Expand Down Expand Up @@ -108,6 +115,10 @@ func GetTXTValues(id string, credz Credentials) ([]ValidationRecords, error) {
return []ValidationRecords{}, ErrEmptyResponse
}

if len(holder.Result) < 1 {
return []ValidationRecords{}, ErrNoResult
}

return holder.Result[0].ValidationRecords, nil
}

Expand Down Expand Up @@ -150,6 +161,10 @@ func GetCertificatePacksStatus(id string, credz Credentials) (string, error) {
return "", ErrEmptyResponse
}

if len(holder.Result) < 1 {
return "", ErrNoResult
}

switch holder.Result[0].Status {
case "active":
return ActiveCertificate, nil
Expand Down

0 comments on commit b0381b1

Please sign in to comment.