这是indexloc提供的服务,不要输入任何密码
Skip to content

Add backoff if rate limits are hit #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions client/alias_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package client
import (
"context"
"fmt"
"net/http"
"strings"

"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand All @@ -28,22 +26,18 @@ func (c *Client) CreateAlias(ctx context.Context, request CreateAliasRequest, de
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(teamID))
}
payload := string(mustMarshal(request))
req, err := http.NewRequestWithContext(
ctx,
"POST",
url,
strings.NewReader(payload),
)
if err != nil {
return r, err
}

tflog.Trace(ctx, "creating alias", map[string]interface{}{
"url": url,
"payload": payload,
})
var aliasResponse createAliasResponse
err = c.doRequest(req, &aliasResponse)
err = c.doRequest(clientRequest{
ctx: ctx,
method: "POST",
url: url,
body: payload,
}, &aliasResponse)
if err != nil {
return r, err
}
Expand Down
16 changes: 6 additions & 10 deletions client/alias_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"context"
"fmt"
"net/http"

"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand All @@ -19,18 +18,15 @@ func (c *Client) DeleteAlias(ctx context.Context, aliasUID string, teamID string
if c.teamID(teamID) != "" {
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(teamID))
}
req, err := http.NewRequest(
"DELETE",
url,
nil,
)
if err != nil {
return r, err
}

tflog.Trace(ctx, "deleting alias", map[string]interface{}{
"url": url,
})
err = c.doRequest(req, &r)
err = c.doRequest(clientRequest{
ctx: ctx,
method: "DELETE",
url: url,
body: "",
}, &r)
return r, err
}
17 changes: 6 additions & 11 deletions client/alias_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"context"
"fmt"
"net/http"

"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand All @@ -22,19 +21,15 @@ func (c *Client) GetAlias(ctx context.Context, alias, teamID string) (r AliasRes
if c.teamID(teamID) != "" {
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(teamID))
}
req, err := http.NewRequestWithContext(
ctx,
"GET",
url,
nil,
)
if err != nil {
return r, fmt.Errorf("creating request: %s", err)
}
tflog.Trace(ctx, "getting alias", map[string]interface{}{
"url": url,
})
err = c.doRequest(req, &r)
err = c.doRequest(clientRequest{
ctx: ctx,
method: "GET",
url: url,
body: "",
}, &r)
r.TeamID = c.teamID(teamID)
return r, err
}
17 changes: 6 additions & 11 deletions client/deployment_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"log"
"net/http"
"strings"
"time"

Expand Down Expand Up @@ -201,21 +200,17 @@ func (c *Client) CreateDeployment(ctx context.Context, request CreateDeploymentR
url = fmt.Sprintf("%s&teamId=%s", url, c.teamID(teamID))
}
payload := string(mustMarshal(request))
req, err := http.NewRequestWithContext(
ctx,
"POST",
url,
strings.NewReader(payload),
)
if err != nil {
return r, err
}

tflog.Trace(ctx, "creating deployment", map[string]interface{}{
"url": url,
"payload": payload,
})
err = c.doRequest(req, &r)
err = c.doRequest(clientRequest{
ctx: ctx,
method: "POST",
url: url,
body: payload,
}, &r)
var apiErr APIError
if errors.As(err, &apiErr) && apiErr.Code == "missing_files" {
var missingFilesError MissingFilesError
Expand Down
16 changes: 6 additions & 10 deletions client/deployment_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"context"
"fmt"
"net/http"

"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand All @@ -20,18 +19,15 @@ func (c *Client) DeleteDeployment(ctx context.Context, deploymentID string, team
if c.teamID(teamID) != "" {
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(teamID))
}
req, err := http.NewRequest(
"DELETE",
url,
nil,
)
if err != nil {
return r, err
}

tflog.Trace(ctx, "deleting deployment", map[string]interface{}{
"url": url,
})
err = c.doRequest(req, &r)
err = c.doRequest(clientRequest{
ctx: ctx,
method: "DELETE",
url: url,
body: "",
}, &r)
return r, err
}
17 changes: 6 additions & 11 deletions client/deployment_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"context"
"fmt"
"net/http"

"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand All @@ -14,20 +13,16 @@ func (c *Client) GetDeployment(ctx context.Context, deploymentID, teamID string)
if c.teamID(teamID) != "" {
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(teamID))
}
req, err := http.NewRequestWithContext(
ctx,
"GET",
url,
nil,
)
if err != nil {
return r, err
}

tflog.Trace(ctx, "getting deployment", map[string]interface{}{
"url": url,
})
err = c.doRequest(req, &r)
err = c.doRequest(clientRequest{
ctx: ctx,
method: "GET",
url: url,
body: "",
}, &r)
r.TeamID = c.teamID(teamID)
return r, err
}
19 changes: 6 additions & 13 deletions client/dns_record_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package client
import (
"context"
"fmt"
"net/http"
"strings"
)

// SRV defines the metata required for creating an SRV type DNS Record.
Expand Down Expand Up @@ -33,20 +31,15 @@ func (c *Client) CreateDNSRecord(ctx context.Context, teamID string, request Cre
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(teamID))
}

req, err := http.NewRequestWithContext(
ctx,
"POST",
url,
strings.NewReader(string(mustMarshal(request))),
)
if err != nil {
return r, err
}

var response struct {
RecordID string `json:"uid"`
}
err = c.doRequest(req, &response)
err = c.doRequest(clientRequest{
ctx: ctx,
method: "POST",
url: url,
body: string(mustMarshal(request)),
}, &response)
if err != nil {
return r, err
}
Expand Down
19 changes: 6 additions & 13 deletions client/dns_record_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package client
import (
"context"
"fmt"
"net/http"
"strings"
)

// DeleteDNSRecord removes a DNS domain from Vercel.
Expand All @@ -14,15 +12,10 @@ func (c *Client) DeleteDNSRecord(ctx context.Context, domain, recordID, teamID s
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(teamID))
}

req, err := http.NewRequestWithContext(
ctx,
"DELETE",
url,
strings.NewReader(""),
)
if err != nil {
return err
}

return c.doRequest(req, nil)
return c.doRequest(clientRequest{
ctx: ctx,
method: "DELETE",
url: url,
body: "",
}, nil)
}
19 changes: 6 additions & 13 deletions client/dns_record_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package client
import (
"context"
"fmt"
"net/http"
"strings"
)

// DNSRecord is the information Vercel surfaces about a DNS record associated with a particular domain.
Expand All @@ -27,17 +25,12 @@ func (c *Client) GetDNSRecord(ctx context.Context, recordID, teamID string) (r D
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(teamID))
}

req, err := http.NewRequestWithContext(
ctx,
"GET",
url,
strings.NewReader(""),
)
if err != nil {
return r, err
}

err = c.doRequest(req, &r)
err = c.doRequest(clientRequest{
ctx: ctx,
method: "GET",
url: url,
body: "",
}, &r)
r.TeamID = c.teamID(teamID)
return r, err
}
19 changes: 6 additions & 13 deletions client/dns_record_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package client
import (
"context"
"fmt"
"net/http"
"strings"
)

// ListDNSRecords is a test helper for listing DNS records that exist for a given domain.
Expand All @@ -17,20 +15,15 @@ func (c *Client) ListDNSRecords(ctx context.Context, domain, teamID string) (r [
url = fmt.Sprintf("%s&teamId=%s", url, c.teamID(teamID))
}

req, err := http.NewRequestWithContext(
ctx,
"GET",
url,
strings.NewReader(""),
)
if err != nil {
return r, err
}

dr := struct {
Records []DNSRecord `json:"records"`
}{}
err = c.doRequest(req, &dr)
err = c.doRequest(clientRequest{
ctx: ctx,
method: "GET",
url: url,
body: "",
}, &dr)
for _, record := range dr.Records {
record.TeamID = c.teamID(teamID)
}
Expand Down
19 changes: 6 additions & 13 deletions client/dns_record_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package client
import (
"context"
"fmt"
"net/http"
"strings"

"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand Down Expand Up @@ -34,21 +32,16 @@ func (c *Client) UpdateDNSRecord(ctx context.Context, teamID, recordID string, r
}

payload := string(mustMarshal(request))
req, err := http.NewRequestWithContext(
ctx,
"PATCH",
url,
strings.NewReader(payload),
)
if err != nil {
return r, err
}

tflog.Trace(ctx, "updating DNS record", map[string]interface{}{
"url": url,
"payload": payload,
})
err = c.doRequest(req, &r)
err = c.doRequest(clientRequest{
ctx: ctx,
method: "PATCH",
url: url,
body: payload,
}, &r)
r.TeamID = c.teamID(teamID)
return r, err
}
Loading