Skip to content

Commit 4b114fa

Browse files
venc0rJörg Markert
authored andcommitted
feat: add authorization header for webhooks (#69)
Co-authored-by: Jörg Markert <[email protected]> Reviewed-on: https://gitea.com/gitea/terraform-provider-gitea/pulls/69 Reviewed-by: techknowlogick <[email protected]> Co-authored-by: venc0r <[email protected]> Co-committed-by: venc0r <[email protected]>
1 parent fb56ad7 commit 4b114fa

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

docs/resources/repository_webhook.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ This resource allows you to create and manage webhooks for repositories.
2828

2929
### Optional
3030

31+
- `authorization_header` (String) Webhook authorization header
3132
- `secret` (String) Webhook secret
3233

3334
### Read-Only

docs/resources/team_members.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ resource "gitea_team_members" "example_members" {
4343

4444
### Required
4545

46-
- `members` (List of String) The user names of the members of the team.
46+
- `members` (Set of String) The user names of the members of the team.
4747
- `team_id` (Number) The ID of the team.
4848

4949
### Read-Only

gitea/resource_gitea_repository_webhook.go

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
package gitea
22

33
import (
4+
"strconv"
5+
46
"code.gitea.io/sdk/gitea"
57
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
6-
"strconv"
78
)
89

910
const (
10-
repoWebhookUsername string = "username"
11-
repoWebhookName string = "name"
12-
repoWebhookType string = "type"
13-
repoWebhookUrl string = "url"
14-
repoWebhookContentType string = "content_type"
15-
repoWebhookSecret string = "secret"
16-
repoWebhookEvents string = "events"
17-
repoWebhookBranchFilter string = "branch_filter"
18-
repoWebhookActive string = "active"
19-
repoWebhookCreatedAt string = "created_at"
11+
repoWebhookUsername string = "username"
12+
repoWebhookName string = "name"
13+
repoWebhookType string = "type"
14+
repoWebhookUrl string = "url"
15+
repoWebhookContentType string = "content_type"
16+
repoWebhookSecret string = "secret"
17+
repoWebhookAuthorizationHeader string = "authorization_header"
18+
repoWebhookEvents string = "events"
19+
repoWebhookBranchFilter string = "branch_filter"
20+
repoWebhookActive string = "active"
21+
repoWebhookCreatedAt string = "created_at"
2022
)
2123

2224
func resourceRepositoryWebhookRead(d *schema.ResourceData, meta interface{}) (err error) {
@@ -67,11 +69,12 @@ func resourceRepositoryWebhookCreate(d *schema.ResourceData, meta interface{}) (
6769
}
6870

6971
hookOption := gitea.CreateHookOption{
70-
Type: gitea.HookType(d.Get(repoWebhookType).(string)),
71-
Config: config,
72-
Events: events,
73-
BranchFilter: d.Get(repoWebhookBranchFilter).(string),
74-
Active: d.Get(repoWebhookActive).(bool),
72+
Type: gitea.HookType(d.Get(repoWebhookType).(string)),
73+
Config: config,
74+
Events: events,
75+
BranchFilter: d.Get(repoWebhookBranchFilter).(string),
76+
Active: d.Get(repoWebhookActive).(bool),
77+
AuthorizationHeader: d.Get(repoWebhookAuthorizationHeader).(string),
7578
}
7679

7780
hook, _, err := client.CreateRepoHook(user, repo, hookOption)
@@ -112,10 +115,11 @@ func resourceRepositoryWebhookUpdate(d *schema.ResourceData, meta interface{}) (
112115
active := d.Get(repoWebhookActive).(bool)
113116

114117
hookOption := gitea.EditHookOption{
115-
Config: config,
116-
Events: events,
117-
BranchFilter: d.Get(repoWebhookBranchFilter).(string),
118-
Active: &active,
118+
Config: config,
119+
Events: events,
120+
BranchFilter: d.Get(repoWebhookBranchFilter).(string),
121+
Active: &active,
122+
AuthorizationHeader: d.Get(repoWebhookAuthorizationHeader).(string),
119123
}
120124

121125
_, err = client.EditRepoHook(user, repo, id, hookOption)
@@ -170,6 +174,11 @@ func setRepositoryWebhookData(hook *gitea.Hook, d *schema.ResourceData) (err err
170174
d.Set(repoWebhookActive, d.Get(repoWebhookActive).(bool))
171175
d.Set(repoWebhookCreatedAt, hook.Created)
172176

177+
authorizationHeader := d.Get(repoWebhookAuthorizationHeader).(string)
178+
if authorizationHeader != "" {
179+
d.Set(repoWebhookAuthorizationHeader, authorizationHeader)
180+
}
181+
173182
return
174183
}
175184

@@ -212,6 +221,11 @@ func resourceGiteaRepositoryWebhook() *schema.Resource {
212221
Optional: true,
213222
Description: "Webhook secret",
214223
},
224+
"authorization_header": {
225+
Type: schema.TypeString,
226+
Optional: true,
227+
Description: "Webhook authorization header",
228+
},
215229
"events": {
216230
Type: schema.TypeList,
217231
Elem: &schema.Schema{

0 commit comments

Comments
 (0)