Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle webhook secret #250

Merged
merged 3 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions fivetran/resource_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ func resourceWebhookCreateAccount(ctx context.Context, d *schema.ResourceData, m

svcAcc := client.NewWebhookAccountCreate()
svcAcc.Url(d.Get("url").(string))
svcAcc.Secret(d.Get("secret").(string))

if secret, ok := d.GetOk("secret"); ok && secret != "" {
svcAcc.Secret(d.Get("secret").(string))
}

svcAcc.Active(d.Get("active").(bool))

if v, ok := d.GetOk("events"); ok {
Expand All @@ -133,7 +137,11 @@ func resourceWebhookCreateGroup(ctx context.Context, d *schema.ResourceData, m i

svcGroup := client.NewWebhookGroupCreate().GroupId(d.Get("group_id").(string))
svcGroup.Url(d.Get("url").(string))
svcGroup.Secret(d.Get("secret").(string))

if secret, ok := d.GetOk("secret"); ok && secret != "" {
svcGroup.Secret(secret.(string))
}

svcGroup.Active(d.Get("active").(bool))

if v, ok := d.GetOk("events"); ok {
Expand Down Expand Up @@ -177,9 +185,10 @@ func resourceWebhookRead(ctx context.Context, d *schema.ResourceData, m interfac
msi["events"] = resp.Data.Events
msi["active"] = resp.Data.Active

msi["secret"] = resp.Data.Secret
if resp.Data.Secret == "******" && d.Get("secret") != "" {
msi["secret"] = d.Get("secret") // sensitive field
if secret, ok := d.GetOk("secret"); ok && secret != "" {
msi["secret"] = d.Get("secret").(string) // sensitive field
} else {
msi["secret"] = resp.Data.Secret
}

msi["created_at"] = resp.Data.CreatedAt
Expand Down
11 changes: 6 additions & 5 deletions fivetran/resource_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,21 @@ func TestResourceWebhookE2E(t *testing.T) {

type = "account"
url = "https://your-host.your-domain/webhook_1"
secret = "password"
secret = "password_2"
active = "false"
run_tests = "false"
events = ["sync_start","sync_end"]
events = ["sync_start","sync_end", "connection_failure"]
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
testFivetranWebhookResourceUpdate(t, "fivetran_webhook.test_webhook"),
resource.TestCheckResourceAttr("fivetran_webhook.test_webhook", "type", "account"),
resource.TestCheckResourceAttr("fivetran_webhook.test_webhook", "url", "https://your-host.your-domain/webhook_1"),
resource.TestCheckResourceAttr("fivetran_webhook.test_webhook", "secret", "password"),
resource.TestCheckResourceAttr("fivetran_webhook.test_webhook", "secret", "password_2"),
resource.TestCheckResourceAttr("fivetran_webhook.test_webhook", "active", "false"),
resource.TestCheckResourceAttr("fivetran_webhook.test_webhook", "events.0", "sync_end"),
resource.TestCheckResourceAttr("fivetran_webhook.test_webhook", "events.1", "sync_start"),
resource.TestCheckResourceAttr("fivetran_webhook.test_webhook", "events.0", "connection_failure"),
resource.TestCheckResourceAttr("fivetran_webhook.test_webhook", "events.1", "sync_end"),
resource.TestCheckResourceAttr("fivetran_webhook.test_webhook", "events.2", "sync_start"),
),
},
},
Expand Down
24 changes: 13 additions & 11 deletions fivetran/tests/mock/resource_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func setupMockClientWebhookResource(t *testing.T) {
"sync_end"
],
"active": false,
"secret": "password",
"secret": "******",
"created_at": "2022-04-29T10:45:00.000Z",
"created_by": "_airworthy"
}`
Expand All @@ -60,10 +60,11 @@ func setupMockClientWebhookResource(t *testing.T) {
"url": "https://your-host.your-domain/webhook_1",
"events": [
"sync_start",
"sync_end"
"sync_end",
"connection_failure"
],
"active": false,
"secret": "password",
"secret": "******",
"created_at": "2022-04-29T10:45:00.000Z",
"created_by": "_airworthy"
}`
Expand Down Expand Up @@ -139,10 +140,10 @@ func TestResourceWebhookMock(t *testing.T) {
type = "account"
group_id = "_moonbeam"
url = "https://your-host.your-domain/webhook_1"
secret = "password"
secret = "password_2"
active = false
run_tests = false
events = ["sync_start","sync_end"]
events = ["sync_start","sync_end", "connection_failure"]
}`,
Check: resource.ComposeAggregateTestCheckFunc(
func(s *terraform.State) error {
Expand All @@ -152,10 +153,11 @@ func TestResourceWebhookMock(t *testing.T) {
resource.TestCheckResourceAttr("fivetran_webhook.test_webhook", "type", "account"),
resource.TestCheckResourceAttr("fivetran_webhook.test_webhook", "group_id", "_moonbeam"),
resource.TestCheckResourceAttr("fivetran_webhook.test_webhook", "url", "https://your-host.your-domain/webhook_1"),
resource.TestCheckResourceAttr("fivetran_webhook.test_webhook", "secret", "password"),
resource.TestCheckResourceAttr("fivetran_webhook.test_webhook", "secret", "password_2"),
resource.TestCheckResourceAttr("fivetran_webhook.test_webhook", "active", "false"),
resource.TestCheckResourceAttr("fivetran_webhook.test_webhook", "events.0", "sync_end"),
resource.TestCheckResourceAttr("fivetran_webhook.test_webhook", "events.1", "sync_start"),
resource.TestCheckResourceAttr("fivetran_webhook.test_webhook", "events.0", "connection_failure"),
resource.TestCheckResourceAttr("fivetran_webhook.test_webhook", "events.1", "sync_end"),
resource.TestCheckResourceAttr("fivetran_webhook.test_webhook", "events.2", "sync_start"),
),
}

Expand All @@ -167,14 +169,14 @@ func TestResourceWebhookMock(t *testing.T) {
type = "account"
group_id = "_moonbeam"
url = "https://your-host.your-domain/webhook_1"
secret = "password"
secret = "password_2"
active = false
run_tests = true
events = ["sync_start","sync_end"]
events = ["sync_start","sync_end", "connection_failure"]
}`,
Check: resource.ComposeAggregateTestCheckFunc(
func(s *terraform.State) error {
assertEqual(t, webhookTestHandler.Interactions, 2)
assertEqual(t, webhookTestHandler.Interactions, 3)
return nil
},
),
Expand Down
Loading