|
1 | 1 | package gitea |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "strconv" |
| 5 | + |
4 | 6 | "code.gitea.io/sdk/gitea" |
5 | 7 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
6 | | - "strconv" |
7 | 8 | ) |
8 | 9 |
|
9 | 10 | 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" |
20 | 22 | ) |
21 | 23 |
|
22 | 24 | func resourceRepositoryWebhookRead(d *schema.ResourceData, meta interface{}) (err error) { |
@@ -67,11 +69,12 @@ func resourceRepositoryWebhookCreate(d *schema.ResourceData, meta interface{}) ( |
67 | 69 | } |
68 | 70 |
|
69 | 71 | 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), |
75 | 78 | } |
76 | 79 |
|
77 | 80 | hook, _, err := client.CreateRepoHook(user, repo, hookOption) |
@@ -112,10 +115,11 @@ func resourceRepositoryWebhookUpdate(d *schema.ResourceData, meta interface{}) ( |
112 | 115 | active := d.Get(repoWebhookActive).(bool) |
113 | 116 |
|
114 | 117 | 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), |
119 | 123 | } |
120 | 124 |
|
121 | 125 | _, err = client.EditRepoHook(user, repo, id, hookOption) |
@@ -170,6 +174,11 @@ func setRepositoryWebhookData(hook *gitea.Hook, d *schema.ResourceData) (err err |
170 | 174 | d.Set(repoWebhookActive, d.Get(repoWebhookActive).(bool)) |
171 | 175 | d.Set(repoWebhookCreatedAt, hook.Created) |
172 | 176 |
|
| 177 | + authorizationHeader := d.Get(repoWebhookAuthorizationHeader).(string) |
| 178 | + if authorizationHeader != "" { |
| 179 | + d.Set(repoWebhookAuthorizationHeader, authorizationHeader) |
| 180 | + } |
| 181 | + |
173 | 182 | return |
174 | 183 | } |
175 | 184 |
|
@@ -212,6 +221,11 @@ func resourceGiteaRepositoryWebhook() *schema.Resource { |
212 | 221 | Optional: true, |
213 | 222 | Description: "Webhook secret", |
214 | 223 | }, |
| 224 | + "authorization_header": { |
| 225 | + Type: schema.TypeString, |
| 226 | + Optional: true, |
| 227 | + Description: "Webhook authorization header", |
| 228 | + }, |
215 | 229 | "events": { |
216 | 230 | Type: schema.TypeList, |
217 | 231 | Elem: &schema.Schema{ |
|
0 commit comments