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

Move to using fewer files across the codebase #169

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
Apr 19, 2024
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
102 changes: 102 additions & 0 deletions client/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package client

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-log/tflog"
)

// CreateAliasRequest defines the request the Vercel API expects in order to create an alias.
type CreateAliasRequest struct {
Alias string `json:"alias"`
}

// The create Alias endpoint does not return the full AliasResponse, only the UID and Alias.
type createAliasResponse struct {
UID string `json:"uid"`
Alias string `json:"alias"`
TeamID string `json:"-"`
}

// CreateAlias creates an alias within Vercel.
func (c *Client) CreateAlias(ctx context.Context, request CreateAliasRequest, deploymentID string, teamID string) (r AliasResponse, err error) {
url := fmt.Sprintf("%s/v2/deployments/%s/aliases", c.baseURL, deploymentID)
if c.teamID(teamID) != "" {
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(teamID))
}
payload := string(mustMarshal(request))

tflog.Info(ctx, "creating alias", map[string]interface{}{
"url": url,
"payload": payload,
})
var aliasResponse createAliasResponse
err = c.doRequest(clientRequest{
ctx: ctx,
method: "POST",
url: url,
body: payload,
}, &aliasResponse)
if err != nil {
return r, err
}

return AliasResponse{
UID: aliasResponse.UID,
Alias: aliasResponse.Alias,
DeploymentID: deploymentID,
TeamID: c.teamID(teamID),
}, nil
}

// DeleteAliasResponse defines the response the Vercel API returns when an alias is deleted.
type DeleteAliasResponse struct {
Status string `json:"status"`
}

// DeleteAlias deletes an alias within Vercel.
func (c *Client) DeleteAlias(ctx context.Context, aliasUID string, teamID string) (r DeleteAliasResponse, err error) {
url := fmt.Sprintf("%s/v2/aliases/%s", c.baseURL, aliasUID)
if c.teamID(teamID) != "" {
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(teamID))
}

tflog.Info(ctx, "deleting alias", map[string]interface{}{
"url": url,
})
err = c.doRequest(clientRequest{
ctx: ctx,
method: "DELETE",
url: url,
body: "",
}, &r)
return r, err
}

// AliasResponse defines the response the Vercel API returns for an alias.
type AliasResponse struct {
UID string `json:"uid"`
Alias string `json:"alias"`
DeploymentID string `json:"deploymentId"`
TeamID string `json:"-"`
}

// GetAlias retrieves information about an existing alias from vercel.
func (c *Client) GetAlias(ctx context.Context, alias, teamID string) (r AliasResponse, err error) {
url := fmt.Sprintf("%s/v4/aliases/%s", c.baseURL, alias)
if c.teamID(teamID) != "" {
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(teamID))
}
tflog.Info(ctx, "getting alias", map[string]interface{}{
"url": url,
})
err = c.doRequest(clientRequest{
ctx: ctx,
method: "GET",
url: url,
body: "",
}, &r)
r.TeamID = c.teamID(teamID)
return r, err
}
51 changes: 0 additions & 51 deletions client/alias_create.go

This file was deleted.

32 changes: 0 additions & 32 deletions client/alias_delete.go

This file was deleted.

35 changes: 0 additions & 35 deletions client/alias_get.go

This file was deleted.

45 changes: 45 additions & 0 deletions client/deployment_create.go → client/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,48 @@ func (c *Client) CreateDeployment(ctx context.Context, request CreateDeploymentR

return r, nil
}

// DeleteDeploymentResponse defines the response the Vercel API returns when a deployment is deleted.
type DeleteDeploymentResponse struct {
State string `json:"state"`
UID string `json:"uid"`
}

// DeleteDeployment deletes a deployment within Vercel.
func (c *Client) DeleteDeployment(ctx context.Context, deploymentID string, teamID string) (r DeleteDeploymentResponse, err error) {
url := fmt.Sprintf("%s/v13/deployments/%s", c.baseURL, deploymentID)
if c.teamID(teamID) != "" {
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(teamID))
}

tflog.Info(ctx, "deleting deployment", map[string]interface{}{
"url": url,
})
err = c.doRequest(clientRequest{
ctx: ctx,
method: "DELETE",
url: url,
body: "",
}, &r)
return r, err
}

// GetDeployment retrieves information from Vercel about an existing Deployment.
func (c *Client) GetDeployment(ctx context.Context, deploymentID, teamID string) (r DeploymentResponse, err error) {
url := fmt.Sprintf("%s/v13/deployments/%s", c.baseURL, deploymentID)
if c.teamID(teamID) != "" {
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(teamID))
}

tflog.Info(ctx, "getting deployment", map[string]interface{}{
"url": url,
})
err = c.doRequest(clientRequest{
ctx: ctx,
method: "GET",
url: url,
body: "",
}, &r)
r.TeamID = c.teamID(teamID)
return r, err
}
33 changes: 0 additions & 33 deletions client/deployment_delete.go

This file was deleted.

28 changes: 0 additions & 28 deletions client/deployment_get.go

This file was deleted.

Loading