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

Fix permissions issue with uploading deployment files #42

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 1 commit into from
Jun 2, 2022
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
21 changes: 15 additions & 6 deletions client/file_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,35 @@ import (
"github.com/hashicorp/terraform-plugin-log/tflog"
)

type CreateFileRequest struct {
Filename string
SHA string
Content string
TeamID string
}

// CreateFile will upload a file to Vercel so that it can be later used for a Deployment.
func (c *Client) CreateFile(ctx context.Context, filename, sha, content string) error {
func (c *Client) CreateFile(ctx context.Context, request CreateFileRequest) error {
url := fmt.Sprintf("%s/v2/now/files", c.baseURL)
if request.TeamID != "" {
url = fmt.Sprintf("%s?teamId=%s", url, request.TeamID)
}
req, err := http.NewRequestWithContext(
ctx,
"POST",
url,
strings.NewReader(content),
strings.NewReader(request.Content),
)
if err != nil {
return err
}

req.Header.Add("x-vercel-digest", sha)
req.Header.Add("x-vercel-digest", request.SHA)
req.Header.Set("Content-Type", "application/octet-stream")

tflog.Trace(ctx, "uploading file", map[string]interface{}{
"url": url,
"payload": mustMarshal(content),
"sha": sha,
"url": url,
"sha": request.SHA,
})
err = c.doRequest(req, nil)
return err
Expand Down
7 changes: 6 additions & 1 deletion vercel/resource_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,12 @@ func (r resourceDeployment) Create(ctx context.Context, req tfsdk.CreateResource
return
}

err = r.p.client.CreateFile(ctx, f.File, f.Sha, string(content))
err = r.p.client.CreateFile(ctx, client.CreateFileRequest{
Filename: f.File,
SHA: f.Sha,
Content: string(content),
TeamID: plan.TeamID.Value,
})
if err != nil {
resp.Diagnostics.AddError(
"Error uploading deployment file",
Expand Down