From fbc3b39840fac0143dbb1fa8708fa46fd1539f44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Wysoki=C5=84ski?= Date: Sun, 31 Mar 2024 08:12:53 +0200 Subject: [PATCH] feat: secrets - add new events (#26) --- .github/workflows/ci.yml | 8 +++--- .pre-commit-config.yaml | 2 +- docs/data-sources/repository_registry.md | 1 - docs/data-sources/repository_secret.md | 2 +- docs/data-sources/secret.md | 2 +- docs/resources/repository_registry.md | 4 --- docs/resources/repository_secret.md | 2 +- docs/resources/secret.md | 2 +- internal/data_source_repository_registry.go | 4 --- internal/data_source_repository_secret.go | 3 +- internal/data_source_secret.go | 3 +- internal/internal_test.go | 2 +- internal/models.go | 5 ---- internal/resource_repository_registry.go | 8 ------ internal/resource_repository_registry_test.go | 3 -- internal/resource_repository_secret.go | 28 ++++++++++++++++--- internal/resource_repository_secret_test.go | 4 ++- internal/resource_secret.go | 28 ++++++++++++++++--- internal/woodpecker/types.go | 6 ++-- 19 files changed, 69 insertions(+), 48 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d22afbe..899ea21 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,9 +35,9 @@ jobs: run: go test -race -coverprofile=coverage.txt -covermode=atomic ./... env: GITEA_IMAGE: gitea/gitea:1.21 - WOODPECKER_IMAGE: woodpeckerci/woodpecker-server:v2.0 - - name: Forgejo 1.20 & Woodpecker 2.0 + WOODPECKER_IMAGE: woodpeckerci/woodpecker-server:v2.4.1 + - name: Forgejo 1.21 & Woodpecker 2.0 run: go test -race -coverprofile=coverage.txt -covermode=atomic ./... env: - GITEA_IMAGE: codeberg.org/forgejo/forgejo:1.20 - WOODPECKER_IMAGE: woodpeckerci/woodpecker-server:v2.0 + GITEA_IMAGE: codeberg.org/forgejo/forgejo:1.21 + WOODPECKER_IMAGE: woodpeckerci/woodpecker-server:v2.4.1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b672273..9bb1283 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook - rev: v9.5.0 + rev: v9.13.0 hooks: - id: commitlint stages: [commit-msg] diff --git a/docs/data-sources/repository_registry.md b/docs/data-sources/repository_registry.md index 029da17..3e735b4 100644 --- a/docs/data-sources/repository_registry.md +++ b/docs/data-sources/repository_registry.md @@ -33,6 +33,5 @@ data "woodpecker_repository_secret" "test_secret" { ### Read-Only -- `email` (String) email used for authentication - `id` (Number) the id of the registry - `username` (String) username used for authentication diff --git a/docs/data-sources/repository_secret.md b/docs/data-sources/repository_secret.md index aeed754..dce822d 100644 --- a/docs/data-sources/repository_secret.md +++ b/docs/data-sources/repository_secret.md @@ -33,6 +33,6 @@ data "woodpecker_repository_secret" "test_secret" { ### Read-Only -- `events` (Set of String) events for which the secret is available (push, tag, pull_request, deployment, cron, manual) +- `events` (Set of String) events for which the secret is available (push, tag, pull_request, pull_request_closed, deployment, cron, manual, release) - `id` (Number) the secret's id - `images` (Set of String) list of Docker images for which this secret is available diff --git a/docs/data-sources/secret.md b/docs/data-sources/secret.md index e8734b6..6fbc046 100644 --- a/docs/data-sources/secret.md +++ b/docs/data-sources/secret.md @@ -27,6 +27,6 @@ data "woodpecker_secret" "test_secret" { ### Read-Only -- `events` (Set of String) events for which the secret is available (push, tag, pull_request, deployment, cron, manual) +- `events` (Set of String) events for which the secret is available (push, tag, pull_request, pull_request_closed, deployment, cron, manual, release) - `id` (Number) the secret's id - `images` (Set of String) list of Docker images for which this secret is available diff --git a/docs/resources/repository_registry.md b/docs/resources/repository_registry.md index 7ee3aae..cde7b7e 100644 --- a/docs/resources/repository_registry.md +++ b/docs/resources/repository_registry.md @@ -37,10 +37,6 @@ resource "woodpecker_repository_secret" "test" { - `repository_id` (Number) the ID of the repository - `username` (String) username used for authentication -### Optional - -- `email` (String) email used for authentication - ### Read-Only - `id` (Number) the id of the registry diff --git a/docs/resources/repository_secret.md b/docs/resources/repository_secret.md index 031e79e..c982260 100644 --- a/docs/resources/repository_secret.md +++ b/docs/resources/repository_secret.md @@ -32,7 +32,7 @@ resource "woodpecker_repository_secret" "test" { ### Required -- `events` (Set of String) events for which the secret is available (push, tag, pull_request, deployment, cron, manual) +- `events` (Set of String) events for which the secret is available (push, tag, pull_request, pull_request_closed, deployment, cron, manual, release) - `name` (String) the name of the secret - `repository_id` (Number) the ID of the repository - `value` (String, Sensitive) the value of the secret diff --git a/docs/resources/secret.md b/docs/resources/secret.md index 290d7b3..994ea62 100644 --- a/docs/resources/secret.md +++ b/docs/resources/secret.md @@ -26,7 +26,7 @@ resource "woodpecker_secret" "test" { ### Required -- `events` (Set of String) events for which the secret is available (push, tag, pull_request, deployment, cron, manual) +- `events` (Set of String) events for which the secret is available (push, tag, pull_request, pull_request_closed, deployment, cron, manual, release) - `name` (String) the name of the secret - `value` (String, Sensitive) the value of the secret diff --git a/internal/data_source_repository_registry.go b/internal/data_source_repository_registry.go index b9b1a73..f6e8061 100644 --- a/internal/data_source_repository_registry.go +++ b/internal/data_source_repository_registry.go @@ -53,10 +53,6 @@ func (d *repositoryRegistryDataSource) Schema( Computed: true, Description: "username used for authentication", }, - "email": schema.StringAttribute{ - Computed: true, - Description: "email used for authentication", - }, }, } } diff --git a/internal/data_source_repository_secret.go b/internal/data_source_repository_secret.go index ebdefe6..a359b00 100644 --- a/internal/data_source_repository_secret.go +++ b/internal/data_source_repository_secret.go @@ -52,7 +52,8 @@ func (d *repositorySecretDataSource) Schema( "events": schema.SetAttribute{ ElementType: types.StringType, Computed: true, - Description: "events for which the secret is available (push, tag, pull_request, deployment, cron, manual)", + Description: "events for which the secret is available " + + "(push, tag, pull_request, pull_request_closed, deployment, cron, manual, release)", }, "images": schema.SetAttribute{ ElementType: types.StringType, diff --git a/internal/data_source_secret.go b/internal/data_source_secret.go index c841766..5b340b5 100644 --- a/internal/data_source_secret.go +++ b/internal/data_source_secret.go @@ -44,7 +44,8 @@ func (d *secretDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, "events": schema.SetAttribute{ ElementType: types.StringType, Computed: true, - Description: "events for which the secret is available (push, tag, pull_request, deployment, cron, manual)", + Description: "events for which the secret is available " + + "(push, tag, pull_request, pull_request_closed, deployment, cron, manual, release)", }, "images": schema.SetAttribute{ ElementType: types.StringType, diff --git a/internal/internal_test.go b/internal/internal_test.go index 14ff92d..dce13f5 100644 --- a/internal/internal_test.go +++ b/internal/internal_test.go @@ -345,7 +345,7 @@ func (r woodpeckerResource) Close() error { return r.docker.Close() } -const defaultWoodpeckerImage = "woodpeckerci/woodpecker-server:v2.0.0" +const defaultWoodpeckerImage = "woodpeckerci/woodpecker-server:v2.4.1" //nolint:nonamedreturns func getWoodpeckerRepoTag() (repo string, tag string) { diff --git a/internal/models.go b/internal/models.go index f92105e..22c0ea6 100644 --- a/internal/models.go +++ b/internal/models.go @@ -268,14 +268,12 @@ type repositoryRegistryResourceModel struct { Address types.String `tfsdk:"address"` Username types.String `tfsdk:"username"` Password types.String `tfsdk:"password"` - Email types.String `tfsdk:"email"` } func (m *repositoryRegistryResourceModel) setValues(_ context.Context, registry *woodpecker.Registry) diag.Diagnostics { m.ID = types.Int64Value(registry.ID) m.Address = types.StringValue(registry.Address) m.Username = types.StringValue(registry.Username) - m.Email = types.StringValue(registry.Email) return nil } @@ -287,7 +285,6 @@ func (m *repositoryRegistryResourceModel) toWoodpeckerModel( Address: m.Address.ValueString(), Username: m.Username.ValueString(), Password: m.Password.ValueString(), - Email: m.Email.ValueString(), }, nil } @@ -296,7 +293,6 @@ type repositoryRegistryDataSourceModel struct { RepositoryID types.Int64 `tfsdk:"repository_id"` Address types.String `tfsdk:"address"` Username types.String `tfsdk:"username"` - Email types.String `tfsdk:"email"` } func (m *repositoryRegistryDataSourceModel) setValues( @@ -306,6 +302,5 @@ func (m *repositoryRegistryDataSourceModel) setValues( m.ID = types.Int64Value(registry.ID) m.Address = types.StringValue(registry.Address) m.Username = types.StringValue(registry.Username) - m.Email = types.StringValue(registry.Email) return nil } diff --git a/internal/resource_repository_registry.go b/internal/resource_repository_registry.go index 74e5c02..63a4157 100644 --- a/internal/resource_repository_registry.go +++ b/internal/resource_repository_registry.go @@ -76,14 +76,6 @@ func (r *repositoryRegistryResource) Schema( Description: "password used for authentication", Sensitive: true, }, - "email": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "email used for authentication", - PlanModifiers: []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), - }, - }, }, } } diff --git a/internal/resource_repository_registry_test.go b/internal/resource_repository_registry_test.go index c92157e..3f57db6 100644 --- a/internal/resource_repository_registry_test.go +++ b/internal/resource_repository_registry_test.go @@ -60,7 +60,6 @@ resource "woodpecker_repository_registry" "test_registry" { address = "%s" username = "test2" password = "test2" - email = "test@localhost" } `, repo.ID, address), Check: resource.ComposeAggregateTestCheckFunc( @@ -73,7 +72,6 @@ resource "woodpecker_repository_registry" "test_registry" { resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "address", address), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test2"), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test2"), - resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "email", "test@localhost"), ), }, { // update registry @@ -95,7 +93,6 @@ resource "woodpecker_repository_registry" "test_registry" { resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "address", address), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test"), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test"), - resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "email", "test@localhost"), ), }, { // import diff --git a/internal/resource_repository_secret.go b/internal/resource_repository_secret.go index 14cf8bb..0db2f7d 100644 --- a/internal/resource_repository_secret.go +++ b/internal/resource_repository_secret.go @@ -82,10 +82,20 @@ func (r *repositorySecretResource) Schema(_ context.Context, _ resource.SchemaRe "events": schema.SetAttribute{ ElementType: types.StringType, Required: true, - Description: "events for which the secret is available (push, tag, pull_request, deployment, cron, manual)", + Description: "events for which the secret is available " + + "(push, tag, pull_request, pull_request_closed, deployment, cron, manual, release)", Validators: []validator.Set{ setvalidator.ValueStringsAre( - stringvalidator.OneOfCaseInsensitive("push", "tag", "pull_request", "deployment", "cron", "manual"), + stringvalidator.OneOfCaseInsensitive( + "push", + "tag", + "pull_request", + "pull_request_closed", + "deployment", + "cron", + "manual", + "release", + ), ), }, PlanModifiers: []planmodifier.Set{ @@ -300,10 +310,20 @@ func (r *repositorySecretResource) UpgradeState(_ context.Context) map[int64]res "events": schema.SetAttribute{ ElementType: types.StringType, Required: true, - Description: "events for which the secret is available (push, tag, pull_request, deployment, cron, manual)", + Description: "events for which the secret is available " + + "(push, tag, pull_request, pull_request_closed, deployment, cron, manual, release)", Validators: []validator.Set{ setvalidator.ValueStringsAre( - stringvalidator.OneOfCaseInsensitive("push", "tag", "pull_request", "deployment", "cron", "manual"), + stringvalidator.OneOfCaseInsensitive( + "push", + "tag", + "pull_request", + "pull_request_closed", + "deployment", + "cron", + "manual", + "release", + ), ), }, PlanModifiers: []planmodifier.Set{ diff --git a/internal/resource_repository_secret_test.go b/internal/resource_repository_secret_test.go index be73cd7..b8305f6 100644 --- a/internal/resource_repository_secret_test.go +++ b/internal/resource_repository_secret_test.go @@ -62,7 +62,7 @@ resource "woodpecker_repository_secret" "test_secret" { repository_id = %d name = "%s" value = "test123123" - events = ["push", "deployment"] + events = ["push", "deployment", "release", "pull_request_closed"] images = ["testimage"] } `, repo.ID, name), @@ -77,6 +77,8 @@ resource "woodpecker_repository_secret" "test_secret" { resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "value", "test123123"), resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "push"), resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "deployment"), + resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "release"), + resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "pull_request_closed"), resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "images.*", "testimage"), ), }, diff --git a/internal/resource_secret.go b/internal/resource_secret.go index 351b8e9..da9d2b6 100644 --- a/internal/resource_secret.go +++ b/internal/resource_secret.go @@ -68,10 +68,20 @@ func (r *secretResource) Schema(_ context.Context, _ resource.SchemaRequest, res "events": schema.SetAttribute{ ElementType: types.StringType, Required: true, - Description: "events for which the secret is available (push, tag, pull_request, deployment, cron, manual)", + Description: "events for which the secret is available " + + "(push, tag, pull_request, pull_request_closed, deployment, cron, manual, release)", Validators: []validator.Set{ setvalidator.ValueStringsAre( - stringvalidator.OneOfCaseInsensitive("push", "tag", "pull_request", "deployment", "cron", "manual"), + stringvalidator.OneOfCaseInsensitive( + "push", + "tag", + "pull_request", + "pull_request_closed", + "deployment", + "cron", + "manual", + "release", + ), ), }, PlanModifiers: []planmodifier.Set{ @@ -246,10 +256,20 @@ func (r *secretResource) UpgradeState(_ context.Context) map[int64]resource.Stat "events": schema.SetAttribute{ ElementType: types.StringType, Required: true, - Description: "events for which the secret is available (push, tag, pull_request, deployment, cron, manual)", + Description: "events for which the secret is available " + + "(push, tag, pull_request, pull_request_closed, deployment, cron, manual, release)", Validators: []validator.Set{ setvalidator.ValueStringsAre( - stringvalidator.OneOfCaseInsensitive("push", "tag", "pull_request", "deployment", "cron", "manual"), + stringvalidator.OneOfCaseInsensitive( + "push", + "tag", + "pull_request", + "pull_request_closed", + "deployment", + "cron", + "manual", + "release", + ), ), }, PlanModifiers: []planmodifier.Set{ diff --git a/internal/woodpecker/types.go b/internal/woodpecker/types.go index d243d36..0468b8c 100644 --- a/internal/woodpecker/types.go +++ b/internal/woodpecker/types.go @@ -134,8 +134,10 @@ type ( Address string `json:"address"` Username string `json:"username"` Password string `json:"password,omitempty"` - Email string `json:"email"` - Token string `json:"token"` + // Deprecated + Email string `json:"email"` // TODO remove in 3.x + // Deprecated + Token string `json:"token"` // TODO remove in 3.x } // Secret represents a secret variable, such as a password or token.