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

Set User Agent & a bunch of small fixes #178

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
May 1, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
terraform-provider-vercel
.task/
Dist/
dist/
.DS_Store
6 changes: 1 addition & 5 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Visit https://goreleaser.com for documentation on how to customize this
# behavior.
before:
hooks:
# this is just an example and not a requirement for provider building/publishing
- go mod tidy
builds:
- env:
# goreleaser does not work with CGO, it could also complicate
Expand All @@ -14,7 +10,7 @@ builds:
flags:
- -trimpath
ldflags:
- "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}"
- "-s -w -X github.com/vercel/terraform-provider-vercel/client.version={{.Version}}"
goos:
- freebsd
- windows
Expand Down
30 changes: 19 additions & 11 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ version: "3"
tasks:
build:
desc: "Build the provider binary"
deps:
- install-goreleaser
cmds:
- go build -o terraform-provider-vercel
- goreleaser build --single-target --skip=validate --clean --snapshot
sources:
- "**/*.go"
- go.mod
Expand All @@ -27,6 +29,13 @@ tasks:
status:
- which tfplugindocs

install-goreleaser:
desc: "Install goreleaser"
cmds:
- go install github.com/goreleaser/goreleaser@latest
status:
- which goreleaser

docs:
desc: "Update the docs generated from description fields"
deps:
Expand All @@ -50,22 +59,21 @@ tasks:
status:
- which staticcheck

# Temporarily disable tfproviderlint as it doesn't support go 1.18+ syntax
# install-providerlint:
# desc: "Install tfproviderlint tool"
# cmds:
# - go install github.com/bflad/tfproviderlint/cmd/tfproviderlint@latest
# status:
# - which tfproviderlint
install-providerlint:
desc: "Install tfproviderlint tool"
cmds:
- go install github.com/bflad/tfproviderlint/cmd/tfproviderlint@latest
status:
- which tfproviderlint

lint:
desc: "Run linters against the provider"
deps:
- install-staticcheck
# - install-providerlint
- install-providerlint
cmds:
- staticcheck -tags it ./...
# - tfproviderlint -R018=false -R009=false ./...
- tfproviderlint -R018=false -R009=false ./...
- cmd: |
export BADFMT=$(gofmt -s -l .)
test -z "$BADFMT" || (echo -e "invalid gofmt: $BADFMT"; exit 1)
Expand All @@ -79,7 +87,7 @@ tasks:
cat << EOF > ~/.terraformrc
provider_installation {
dev_overrides {
"vercel/vercel" = "$(pwd)"
"vercel/vercel" = "$(pwd)/dist/terraform-provider-vercel_{{ OS }}_{{ ARCH }}"
}
direct {}
}
Expand Down
9 changes: 2 additions & 7 deletions client/project_protection_bypass_for_automation_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package client

import (
"context"
"encoding/json"
"fmt"
"time"

Expand All @@ -26,18 +25,14 @@ func getUpdateBypassProtectionRequestBody(newValue bool, secret string) string {
return "{}"
}

bytes, err := json.Marshal(struct {
return string(mustMarshal(struct {
Revoke revokeBypassProtectionRequest `json:"revoke"`
}{
Revoke: revokeBypassProtectionRequest{
Regenerate: false,
Secret: secret,
},
})
if err != nil {
panic(err)
}
return string(bytes)
}))
}

func (c *Client) UpdateProtectionBypassForAutomation(ctx context.Context, request UpdateProtectionBypassForAutomationRequest) (s string, err error) {
Expand Down
8 changes: 8 additions & 0 deletions client/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import (
"github.com/hashicorp/terraform-plugin-log/tflog"
)

/*
* version is the tagged version of this repository. It is overriden at build time by ldflags.
* please see the .goreleaser.yml file for more information.
*/
var version = "dev"

// APIError is an error type that exposes additional information about why an API request failed.
type APIError struct {
Code string `json:"code"`
Expand Down Expand Up @@ -46,6 +52,7 @@ func (cr *clientRequest) toHTTPRequest() (*http.Request, error) {
if err != nil {
return nil, err
}
r.Header.Set("User-Agent", fmt.Sprintf("terraform-provider-vercel/%s", version))
if cr.body != "" {
r.Header.Set("Content-Type", "application/json")
}
Expand All @@ -55,6 +62,7 @@ func (cr *clientRequest) toHTTPRequest() (*http.Request, error) {
// doRequest is a helper function for consistently requesting data from vercel.
// This manages:
// - Setting the default Content-Type for requests with a body
// - Setting the User-Agent
// - Authorization via the Bearer token
// - Converting error responses into an inspectable type
// - Unmarshaling responses
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ provider "vercel" {
### Optional

- `api_token` (String, Sensitive) The Vercel API Token to use. This can also be specified with the `VERCEL_API_TOKEN` shell environment variable. Tokens can be created from your [Vercel settings](https://vercel.com/account/tokens).
- `team` (String) The default Vercel Team to use when creating resources. This can be provided as either a team slug, or team ID. The slug and ID are both available from the Team Settings page in the Vercel dashboard.
- `team` (String) The default Vercel Team to use when creating resources or reading data sources. This can be provided as either a team slug, or team ID. The slug and ID are both available from the Team Settings page in the Vercel dashboard.
2 changes: 1 addition & 1 deletion vercel/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Use the navigation to the left to read about the available resources.
},
"team": schema.StringAttribute{
Optional: true,
Description: "The default Vercel Team to use when creating resources. This can be provided as either a team slug, or team ID. The slug and ID are both available from the Team Settings page in the Vercel dashboard.",
Description: "The default Vercel Team to use when creating resources or reading data sources. This can be provided as either a team slug, or team ID. The slug and ID are both available from the Team Settings page in the Vercel dashboard.",
},
},
}
Expand Down