Skip to content

Commit

Permalink
Merge pull request #248 from dbt-labs/release-0.2.24
Browse files Browse the repository at this point in the history
  • Loading branch information
b-per authored Apr 15, 2024
2 parents 29f2e93 + 14ca90b commit c128bd5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

All notable changes to this project will be documented in this file.

## [Unreleased](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.2.23...HEAD)
## [Unreleased](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.2.24...HEAD)

## [0.2.24](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.2.23...v0.2.24)

## Fixes

- [#247](https://github.com/dbt-labs/terraform-provider-dbtcloud/issues/247) Segfault when the env var for the token is empty
- [Internal] Issue with `job_ids` required to be set going forward, even if it is empty

## [0.2.23](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.2.22...v0.2.23)

Expand Down
7 changes: 6 additions & 1 deletion pkg/dbt_cloud/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,19 @@ type APIError struct {

// NewClient -
func NewClient(account_id *int, token *string, host_url *string) (*Client, error) {

if (token == nil) || (*token == "") {
return nil, fmt.Errorf("token is set but it is empty")
}

c := Client{
HTTPClient: &http.Client{Timeout: 30 * time.Second},
HostURL: *host_url,
Token: *token,
AccountID: *account_id,
}

if (account_id != nil) && (token != nil) {
if account_id != nil {
url := fmt.Sprintf("%s/v2/accounts/", *host_url)

// authenticate
Expand Down
47 changes: 41 additions & 6 deletions pkg/dbt_cloud/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type WebhookRead struct {
Description string `json:"description,omitempty"`
ClientUrl string `json:"client_url"`
EventTypes []string `json:"event_types,omitempty"`
JobIds []string `json:"job_ids,omitempty"`
JobIds []string `json:"job_ids"`
Active bool `json:"active,omitempty"`
HmacSecret *string `json:"hmac_secret,omitempty"`
HttpStatusCode *string `json:"http_status_code,omitempty"`
Expand All @@ -32,12 +32,21 @@ type WebhookWrite struct {
Description string `json:"description,omitempty"`
ClientUrl string `json:"client_url"`
EventTypes []string `json:"event_types,omitempty"`
JobIds []int `json:"job_ids,omitempty"`
JobIds []int `json:"job_ids"`
Active bool `json:"active,omitempty"`
}

func (c *Client) GetWebhook(webhookID string) (*WebhookRead, error) {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/v3/accounts/%s/webhooks/subscription/%s", c.HostURL, strconv.Itoa(c.AccountID), webhookID), nil)
req, err := http.NewRequest(
"GET",
fmt.Sprintf(
"%s/v3/accounts/%s/webhooks/subscription/%s",
c.HostURL,
strconv.Itoa(c.AccountID),
webhookID,
),
nil,
)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -81,7 +90,15 @@ func (c *Client) CreateWebhook(
return nil, err
}

req, err := http.NewRequest("POST", fmt.Sprintf("%s/v3/accounts/%s/webhooks/subscriptions", c.HostURL, strconv.Itoa(c.AccountID)), strings.NewReader(string(newWebhookData)))
req, err := http.NewRequest(
"POST",
fmt.Sprintf(
"%s/v3/accounts/%s/webhooks/subscriptions",
c.HostURL,
strconv.Itoa(c.AccountID),
),
strings.NewReader(string(newWebhookData)),
)
if err != nil {
return nil, err
}
Expand All @@ -106,7 +123,16 @@ func (c *Client) UpdateWebhook(webhookId string, webhook WebhookWrite) (*Webhook
return nil, err
}

req, err := http.NewRequest("PUT", fmt.Sprintf("%s/v3/accounts/%s/webhooks/subscription/%s", c.HostURL, strconv.Itoa(c.AccountID), webhookId), strings.NewReader(string(webhookData)))
req, err := http.NewRequest(
"PUT",
fmt.Sprintf(
"%s/v3/accounts/%s/webhooks/subscription/%s",
c.HostURL,
strconv.Itoa(c.AccountID),
webhookId,
),
strings.NewReader(string(webhookData)),
)
if err != nil {
return nil, err
}
Expand All @@ -126,7 +152,16 @@ func (c *Client) UpdateWebhook(webhookId string, webhook WebhookWrite) (*Webhook
}

func (c *Client) DeleteWebhook(webhookId string) (string, error) {
req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/v3/accounts/%s/webhooks/subscription/%s", c.HostURL, strconv.Itoa(c.AccountID), webhookId), nil)
req, err := http.NewRequest(
"DELETE",
fmt.Sprintf(
"%s/v3/accounts/%s/webhooks/subscription/%s",
c.HostURL,
strconv.Itoa(c.AccountID),
webhookId,
),
nil,
)
if err != nil {
return "", err
}
Expand Down

0 comments on commit c128bd5

Please sign in to comment.