Skip to content

Commit

Permalink
feat: secrets - add new events (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kichiyaki authored Mar 31, 2024
1 parent b728dee commit fbc3b39
Show file tree
Hide file tree
Showing 19 changed files with 69 additions and 48 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
1 change: 0 additions & 1 deletion docs/data-sources/repository_registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion docs/data-sources/repository_secret.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion docs/data-sources/secret.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 0 additions & 4 deletions docs/resources/repository_registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/repository_secret.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/secret.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 0 additions & 4 deletions internal/data_source_repository_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/data_source_repository_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion internal/data_source_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion internal/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 0 additions & 5 deletions internal/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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(
Expand All @@ -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
}
8 changes: 0 additions & 8 deletions internal/resource_repository_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
},
},
}
}
Expand Down
3 changes: 0 additions & 3 deletions internal/resource_repository_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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
Expand Down
28 changes: 24 additions & 4 deletions internal/resource_repository_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
4 changes: 3 additions & 1 deletion internal/resource_repository_secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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"),
),
},
Expand Down
28 changes: 24 additions & 4 deletions internal/resource_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
6 changes: 4 additions & 2 deletions internal/woodpecker/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit fbc3b39

Please sign in to comment.