feat: add authorization header for webhooks (#69)
Co-authored-by: Jörg Markert <venc0r@live.com> Reviewed-on: https://gitea.com/gitea/terraform-provider-gitea/pulls/69 Reviewed-by: techknowlogick <techknowlogick@noreply.gitea.com> Co-authored-by: venc0r <venc0r@noreply.gitea.com> Co-committed-by: venc0r <venc0r@noreply.gitea.com>
This commit is contained in:
parent
fb56ad7c76
commit
4b114faecf
@ -28,6 +28,7 @@ This resource allows you to create and manage webhooks for repositories.
|
|||||||
|
|
||||||
### Optional
|
### Optional
|
||||||
|
|
||||||
|
- `authorization_header` (String) Webhook authorization header
|
||||||
- `secret` (String) Webhook secret
|
- `secret` (String) Webhook secret
|
||||||
|
|
||||||
### Read-Only
|
### Read-Only
|
||||||
|
@ -43,7 +43,7 @@ resource "gitea_team_members" "example_members" {
|
|||||||
|
|
||||||
### Required
|
### Required
|
||||||
|
|
||||||
- `members` (List of String) The user names of the members of the team.
|
- `members` (Set of String) The user names of the members of the team.
|
||||||
- `team_id` (Number) The ID of the team.
|
- `team_id` (Number) The ID of the team.
|
||||||
|
|
||||||
### Read-Only
|
### Read-Only
|
||||||
|
@ -1,22 +1,24 @@
|
|||||||
package gitea
|
package gitea
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"code.gitea.io/sdk/gitea"
|
"code.gitea.io/sdk/gitea"
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
repoWebhookUsername string = "username"
|
repoWebhookUsername string = "username"
|
||||||
repoWebhookName string = "name"
|
repoWebhookName string = "name"
|
||||||
repoWebhookType string = "type"
|
repoWebhookType string = "type"
|
||||||
repoWebhookUrl string = "url"
|
repoWebhookUrl string = "url"
|
||||||
repoWebhookContentType string = "content_type"
|
repoWebhookContentType string = "content_type"
|
||||||
repoWebhookSecret string = "secret"
|
repoWebhookSecret string = "secret"
|
||||||
repoWebhookEvents string = "events"
|
repoWebhookAuthorizationHeader string = "authorization_header"
|
||||||
repoWebhookBranchFilter string = "branch_filter"
|
repoWebhookEvents string = "events"
|
||||||
repoWebhookActive string = "active"
|
repoWebhookBranchFilter string = "branch_filter"
|
||||||
repoWebhookCreatedAt string = "created_at"
|
repoWebhookActive string = "active"
|
||||||
|
repoWebhookCreatedAt string = "created_at"
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceRepositoryWebhookRead(d *schema.ResourceData, meta interface{}) (err error) {
|
func resourceRepositoryWebhookRead(d *schema.ResourceData, meta interface{}) (err error) {
|
||||||
@ -67,11 +69,12 @@ func resourceRepositoryWebhookCreate(d *schema.ResourceData, meta interface{}) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
hookOption := gitea.CreateHookOption{
|
hookOption := gitea.CreateHookOption{
|
||||||
Type: gitea.HookType(d.Get(repoWebhookType).(string)),
|
Type: gitea.HookType(d.Get(repoWebhookType).(string)),
|
||||||
Config: config,
|
Config: config,
|
||||||
Events: events,
|
Events: events,
|
||||||
BranchFilter: d.Get(repoWebhookBranchFilter).(string),
|
BranchFilter: d.Get(repoWebhookBranchFilter).(string),
|
||||||
Active: d.Get(repoWebhookActive).(bool),
|
Active: d.Get(repoWebhookActive).(bool),
|
||||||
|
AuthorizationHeader: d.Get(repoWebhookAuthorizationHeader).(string),
|
||||||
}
|
}
|
||||||
|
|
||||||
hook, _, err := client.CreateRepoHook(user, repo, hookOption)
|
hook, _, err := client.CreateRepoHook(user, repo, hookOption)
|
||||||
@ -112,10 +115,11 @@ func resourceRepositoryWebhookUpdate(d *schema.ResourceData, meta interface{}) (
|
|||||||
active := d.Get(repoWebhookActive).(bool)
|
active := d.Get(repoWebhookActive).(bool)
|
||||||
|
|
||||||
hookOption := gitea.EditHookOption{
|
hookOption := gitea.EditHookOption{
|
||||||
Config: config,
|
Config: config,
|
||||||
Events: events,
|
Events: events,
|
||||||
BranchFilter: d.Get(repoWebhookBranchFilter).(string),
|
BranchFilter: d.Get(repoWebhookBranchFilter).(string),
|
||||||
Active: &active,
|
Active: &active,
|
||||||
|
AuthorizationHeader: d.Get(repoWebhookAuthorizationHeader).(string),
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = client.EditRepoHook(user, repo, id, hookOption)
|
_, err = client.EditRepoHook(user, repo, id, hookOption)
|
||||||
@ -170,6 +174,11 @@ func setRepositoryWebhookData(hook *gitea.Hook, d *schema.ResourceData) (err err
|
|||||||
d.Set(repoWebhookActive, d.Get(repoWebhookActive).(bool))
|
d.Set(repoWebhookActive, d.Get(repoWebhookActive).(bool))
|
||||||
d.Set(repoWebhookCreatedAt, hook.Created)
|
d.Set(repoWebhookCreatedAt, hook.Created)
|
||||||
|
|
||||||
|
authorizationHeader := d.Get(repoWebhookAuthorizationHeader).(string)
|
||||||
|
if authorizationHeader != "" {
|
||||||
|
d.Set(repoWebhookAuthorizationHeader, authorizationHeader)
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,6 +221,11 @@ func resourceGiteaRepositoryWebhook() *schema.Resource {
|
|||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "Webhook secret",
|
Description: "Webhook secret",
|
||||||
},
|
},
|
||||||
|
"authorization_header": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
Description: "Webhook authorization header",
|
||||||
|
},
|
||||||
"events": {
|
"events": {
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Elem: &schema.Schema{
|
Elem: &schema.Schema{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user