diff --git a/.github/workflows/ *Minibuf-1* b/.github/workflows/ *Minibuf-1* new file mode 100644 index 0000000..57209d3 --- /dev/null +++ b/.github/workflows/ *Minibuf-1* @@ -0,0 +1,47 @@ +File /home/nick/src/terraform-provider-docker/.github/workflows/ci.yaml is read-only on disk. Make buffer read-only, too? (y or n) name: CI + +on: + pull_request: + branches: + - 'main' + push: + branches: + - 'main' + +permissions: + id-token: write + contents: write + security-events: write + actions: read + +jobs: + # go-test: + # name: Go lint and test + # uses: docker/actions/.github/workflows/lint-test-go.yaml@lint-test-go/v1 + # with: + # dir: . + # secrets: inherit + + version: + name: Bump Version + runs-on: ubuntu-latest + outputs: + next_version_number: ${{ steps.version.outputs.next_version_number }} + steps: + - uses: actions/checkout@v4 + - id: version + uses: docker/actions/bump-version@bump-version/v1 + with: + name: nicksantos-hello + include_tag: ${{ github.event_name == 'push' && 'true' || '' }} + + release: + name: Release ${{ github.event_name == 'pull_request' && '(Dry Run)' || '' }} + uses: ./.github/workflows/release.yaml + needs: + - version + with: + service: nicksantos-hello + version: ${{ needs.version.outputs.next_version_number }} + dry_run: ${{ github.event_name == 'pull_request' && 'true' || '' }} + secrets: inherit diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..10a9585 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,19 @@ +name: CI + +on: + pull_request: + branches: + - 'main' + push: + branches: + - 'main' + +jobs: + build: + name: Build and Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + - run: | + go vet ./... diff --git a/internal/pkg/hubclient/client.go b/internal/pkg/hubclient/client.go index 48f78f0..3d7c394 100644 --- a/internal/pkg/hubclient/client.go +++ b/internal/pkg/hubclient/client.go @@ -25,19 +25,33 @@ type Client struct { BaseURL string auth Auth HTTPClient *http.Client + userAgent string +} + +type Config struct { + Host string + Username string + Password string + UserAgentVersion string } // Create the API client, providing the authentication. -func NewClient(host string, username string, password string) *Client { +func NewClient(config Config) *Client { + version := config.UserAgentVersion + if version == "" { + version = "dev" + } + return &Client{ - BaseURL: host, + BaseURL: config.Host, auth: Auth{ - Username: username, - Password: password, + Username: config.Username, + Password: config.Password, }, HTTPClient: &http.Client{ Timeout: time.Minute, }, + userAgent: fmt.Sprintf("terraform-provider-docker/%s", version), } } @@ -80,8 +94,7 @@ func (c *Client) sendRequest(ctx context.Context, method string, url string, bod } req.Header.Set("Content-Type", "application/json; charset=utf-8") req.Header.Set("Accept", "application/json; charset=utf-8") - // TODO: put correct client version, or omit completely - req.Header.Set("User-Agent", "terraform-provider-dockerhub/v0.1.0") + req.Header.Set("User-Agent", c.userAgent) req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token.Token)) req = req.WithContext(ctx) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 9d82fd3..da4efaa 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -166,7 +166,12 @@ func (p *DockerHubProvider) Configure(ctx context.Context, req provider.Configur tflog.Debug(ctx, "Creating Docker Hub client") - client := hubclient.NewClient(host, username, password) + client := hubclient.NewClient(hubclient.Config{ + Host: host, + Username: username, + Password: password, + UserAgentVersion: p.version, + }) resp.DataSourceData = client resp.ResourceData = client }