Skip to content

Commit 40faef1

Browse files
committed
webhook source resource: add url attr
1 parent 157684c commit 40faef1

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

docs/resources/source_webhook.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ resource "materialize_source_webhook" "example_webhook" {
7575
- `id` (String) The ID of this resource.
7676
- `qualified_sql_name` (String) The fully qualified name of the source.
7777
- `size` (String) The size of the cluster maintaining this source.
78+
- `url` (String) The webhook URL that can be used to send data to this source.
7879

7980
<a id="nestedblock--check_options"></a>
8081
### Nested Schema for `check_options`

pkg/materialize/source.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ type SourceParams struct {
124124
ClusterName sql.NullString `db:"cluster_name"`
125125
Comment sql.NullString `db:"comment"`
126126
OwnerName sql.NullString `db:"owner_name"`
127+
WebhookUrl sql.NullString `db:"webhook_url"`
127128
Privileges pq.StringArray `db:"privileges"`
128129
}
129130

@@ -142,6 +143,7 @@ var sourceQuery = NewBaseQuery(`
142143
mz_clusters.name as cluster_name,
143144
comments.comment AS comment,
144145
mz_roles.name AS owner_name,
146+
mz_webhook_sources.url AS webhook_url,
145147
mz_sources.privileges
146148
FROM mz_sources
147149
JOIN mz_schemas
@@ -163,7 +165,9 @@ var sourceQuery = NewBaseQuery(`
163165
FROM mz_internal.mz_comments
164166
WHERE object_type = 'source'
165167
) comments
166-
ON mz_sources.id = comments.id`)
168+
ON mz_sources.id = comments.id
169+
LEFT JOIN mz_internal.mz_webhook_sources
170+
ON mz_sources.id = mz_webhook_sources.id`)
167171

168172
func SourceId(conn *sqlx.DB, obj MaterializeObject) (string, error) {
169173
p := map[string]string{

pkg/provider/acceptance_source_webhook_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func TestAccSourceWebhook_basic(t *testing.T) {
4242
resource.TestCheckResourceAttr("materialize_source_webhook.test", "check_options.1.field.0.headers", "true"),
4343
resource.TestCheckResourceAttr("materialize_source_webhook.test", "check_options.2.field.0.secret.0.name", secretName),
4444
resource.TestCheckResourceAttr("materialize_source_webhook.test", "check_expression", "headers->'authorization' = BASIC_HOOK_AUTH"),
45+
resource.TestCheckResourceAttrSet("materialize_source_webhook.test", "url"),
4546
),
4647
},
4748
{
@@ -76,6 +77,7 @@ func TestAccSourceWebhookSegment_basic(t *testing.T) {
7677
resource.TestCheckResourceAttr("materialize_source_webhook.test", "check_options.2.alias", "secret"),
7778
resource.TestCheckResourceAttr("materialize_source_webhook.test", "check_options.2.bytes", "true"),
7879
resource.TestCheckResourceAttr("materialize_source_webhook.test", "check_expression", "decode(headers->'x-signature', 'hex') = hmac(body, secret, 'sha1')"),
80+
resource.TestCheckResourceAttrSet("materialize_source_webhook.test", "url"),
7981
),
8082
},
8183
{
@@ -107,6 +109,7 @@ func TestAccSourceWebhookRudderstack_basic(t *testing.T) {
107109
resource.TestCheckResourceAttr("materialize_source_webhook.test", "check_options.1.field.0.headers", "true"),
108110
resource.TestCheckResourceAttr("materialize_source_webhook.test", "check_options.2.field.0.secret.0.name", "rudderstack_basic_auth"),
109111
resource.TestCheckResourceAttr("materialize_source_webhook.test", "check_expression", "headers->'authorization' = rudderstack_basic_auth"),
112+
resource.TestCheckResourceAttrSet("materialize_source_webhook.test", "url"),
110113
),
111114
},
112115
{
@@ -137,6 +140,7 @@ func TestAccSourceWebhook_update(t *testing.T) {
137140
resource.TestCheckResourceAttr("materialize_source_webhook.test", "name", sourceName),
138141
resource.TestCheckResourceAttr("materialize_source_webhook.test", "ownership_role", "mz_system"),
139142
resource.TestCheckResourceAttr("materialize_source_webhook.test", "comment", "Comment"),
143+
resource.TestCheckResourceAttrSet("materialize_source_webhook.test", "url"),
140144
),
141145
},
142146
{
@@ -146,6 +150,7 @@ func TestAccSourceWebhook_update(t *testing.T) {
146150
resource.TestCheckResourceAttr("materialize_source_webhook.test", "name", newSourceName),
147151
resource.TestCheckResourceAttr("materialize_source_webhook.test", "ownership_role", roleName),
148152
resource.TestCheckResourceAttr("materialize_source_webhook.test", "comment", "New Comment"),
153+
resource.TestCheckResourceAttrSet("materialize_source_webhook.test", "url"),
149154
),
150155
},
151156
},

pkg/resources/resource_source.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ func sourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) d
6161
return diag.FromErr(err)
6262
}
6363

64+
// Set the webhook URL if this is a webhook source
65+
if err := d.Set("url", s.WebhookUrl.String); err != nil {
66+
return diag.FromErr(err)
67+
}
68+
6469
if v, ok := d.GetOk("envelope"); ok {
6570
envelope := v.([]interface{})[0].(map[string]interface{})
6671
if upsertOptions, ok := envelope["upsert_options"].([]interface{}); ok && len(upsertOptions) > 0 {

pkg/resources/resource_source_webhook.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ var sourceWebhookSchema = map[string]*schema.Schema{
2828
Type: schema.TypeString,
2929
Computed: true,
3030
},
31+
"url": {
32+
Description: "The webhook URL that can be used to send data to this source.",
33+
Type: schema.TypeString,
34+
Computed: true,
35+
},
3136
"body_format": {
3237
Description: "The body format of the webhook.",
3338
Type: schema.TypeString,

pkg/testhelpers/mock_scans.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ func MockSourceScan(mock sqlmock.Sqlmock, predicate string) {
546546
mz_clusters.name as cluster_name,
547547
comments.comment AS comment,
548548
mz_roles.name AS owner_name,
549+
mz_webhook_sources.url AS webhook_url,
549550
mz_sources.privileges
550551
FROM mz_sources
551552
JOIN mz_schemas
@@ -567,11 +568,13 @@ func MockSourceScan(mock sqlmock.Sqlmock, predicate string) {
567568
FROM mz_internal.mz_comments
568569
WHERE object_type = 'source'
569570
\) comments
570-
ON mz_sources.id = comments.id`
571+
ON mz_sources.id = comments.id
572+
LEFT JOIN mz_internal.mz_webhook_sources
573+
ON mz_sources.id = mz_webhook_sources.id`
571574

572575
q := mockQueryBuilder(b, predicate, "")
573-
ir := mock.NewRows([]string{"id", "name", "schema_name", "database_name", "source_type", "size", "envelope_type", "connection_name", "connection_schema_name", "connection_database_name", "cluster_name", "comment", "owner_name", "privileges"}).
574-
AddRow("u1", "source", "schema", "database", "kafka", "small", "BYTES", "conn", "public", "materialize", "cluster", nil, "joe", defaultPrivilege)
576+
ir := mock.NewRows([]string{"id", "name", "schema_name", "database_name", "source_type", "size", "envelope_type", "connection_name", "connection_schema_name", "connection_database_name", "cluster_name", "comment", "owner_name", "webhook_url", "privileges"}).
577+
AddRow("u1", "source", "schema", "database", "kafka", "small", "BYTES", "conn", "public", "materialize", "cluster", nil, "joe", "https://webhook.url/example", defaultPrivilege)
575578
mock.ExpectQuery(q).WillReturnRows(ir)
576579
}
577580

0 commit comments

Comments
 (0)