Skip to content

Commit

Permalink
Save in state also webhookKey + url (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvirsegev authored Aug 15, 2023
1 parent efeb535 commit 6894be4
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/cli/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ type (
Enabled *bool `json:"enabled,omitempty"`
Security *Security `json:"security,omitempty"`
Mappings []Mappings `json:"mappings,omitempty"`
WebhookKey string `json:"webhookKey,omitempty"`
Url string `json:"url,omitempty"`
}

Security struct {
Expand Down
2 changes: 2 additions & 0 deletions port/webhook/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type WebhookModel struct {
Title types.String `tfsdk:"title"`
Description types.String `tfsdk:"description"`
Enabled types.Bool `tfsdk:"enabled"`
WebhookKey types.String `tfsdk:"webhook_key"`
Url types.String `tfsdk:"url"`
Security *SecurityModel `tfsdk:"security"`
Mappings []MappingsModel `tfsdk:"mappings"`
CreatedAt types.String `tfsdk:"created_at"`
Expand Down
2 changes: 2 additions & 0 deletions port/webhook/refreshWebhookState.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ func refreshWebhookState(ctx context.Context, state *WebhookModel, w *cli.Webhoo
state.CreatedBy = types.StringValue(w.CreatedBy)
state.UpdatedAt = types.StringValue(w.UpdatedAt.String())
state.UpdatedBy = types.StringValue(w.UpdatedBy)
state.Url = types.StringValue(w.Url)
state.WebhookKey = types.StringValue(w.WebhookKey)
state.Icon = flex.GoStringToFramework(w.Icon)
state.Title = flex.GoStringToFramework(w.Title)
state.Description = flex.GoStringToFramework(w.Description)
Expand Down
2 changes: 2 additions & 0 deletions port/webhook/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ func writeWebhookComputedFieldsToState(state *WebhookModel, wp *cli.Webhook) {
state.CreatedBy = types.StringValue(wp.CreatedBy)
state.UpdatedAt = types.StringValue(wp.UpdatedAt.String())
state.UpdatedBy = types.StringValue(wp.UpdatedBy)
state.Url = types.StringValue(wp.Url)
state.WebhookKey = types.StringValue(wp.WebhookKey)
}

func (r *WebhookResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
Expand Down
42 changes: 42 additions & 0 deletions port/webhook/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ func TestAccPortWebhookBasic(t *testing.T) {
resource.TestCheckResourceAttr("port_webhook.create_pr", "title", "Test"),
resource.TestCheckResourceAttr("port_webhook.create_pr", "icon", "Terraform"),
resource.TestCheckResourceAttr("port_webhook.create_pr", "enabled", "true"),
resource.TestCheckResourceAttrWith("port_webhook.create_pr", "url",
func(value string) error {
if value == "" {
return fmt.Errorf("value is empty")
}
return nil
}),
resource.TestCheckResourceAttrWith("port_webhook.create_pr", "webhook_key",
func(value string) error {
if value == "" {
return fmt.Errorf("value is empty")
}
return nil
}),
),
},
},
Expand Down Expand Up @@ -111,6 +125,20 @@ func TestAccPortWebhook(t *testing.T) {
resource.TestCheckResourceAttr("port_webhook.create_pr", "title", "Test"),
resource.TestCheckResourceAttr("port_webhook.create_pr", "icon", "Terraform"),
resource.TestCheckResourceAttr("port_webhook.create_pr", "enabled", "true"),
resource.TestCheckResourceAttrWith("port_webhook.create_pr", "url",
func(value string) error {
if value == "" {
return fmt.Errorf("value is empty")
}
return nil
}),
resource.TestCheckResourceAttrWith("port_webhook.create_pr", "webhook_key",
func(value string) error {
if value == "" {
return fmt.Errorf("value is empty")
}
return nil
}),
resource.TestCheckResourceAttr("port_webhook.create_pr", "security.signature_header_name", "X-Hub-Signature-256"),
resource.TestCheckResourceAttr("port_webhook.create_pr", "security.signature_algorithm", "sha256"),
resource.TestCheckResourceAttr("port_webhook.create_pr", "security.signature_prefix", "sha256="),
Expand Down Expand Up @@ -181,6 +209,20 @@ func TestAccPortWebhookImport(t *testing.T) {
resource.TestCheckResourceAttr("port_webhook.create_pr", "title", "Test"),
resource.TestCheckResourceAttr("port_webhook.create_pr", "icon", "Terraform"),
resource.TestCheckResourceAttr("port_webhook.create_pr", "enabled", "true"),
resource.TestCheckResourceAttrWith("port_webhook.create_pr", "url",
func(value string) error {
if value == "" {
return fmt.Errorf("value is empty")
}
return nil
}),
resource.TestCheckResourceAttrWith("port_webhook.create_pr", "webhook_key",
func(value string) error {
if value == "" {
return fmt.Errorf("value is empty")
}
return nil
}),
resource.TestCheckResourceAttr("port_webhook.create_pr", "security.signature_header_name", "X-Hub-Signature-256"),
resource.TestCheckResourceAttr("port_webhook.create_pr", "security.signature_algorithm", "sha256"),
resource.TestCheckResourceAttr("port_webhook.create_pr", "security.signature_prefix", "sha256="),
Expand Down
8 changes: 8 additions & 0 deletions port/webhook/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ func WebhookSchema() map[string]schema.Attribute {
Computed: true,
Default: booldefault.StaticBool(false),
},
"url": schema.StringAttribute{
MarkdownDescription: "The url of the webhook",
Computed: true,
},
"webhook_key": schema.StringAttribute{
MarkdownDescription: "The webhook key of the webhook",
Computed: true,
},
"security": schema.SingleNestedAttribute{
MarkdownDescription: "The security of the webhook",
Optional: true,
Expand Down

0 comments on commit 6894be4

Please sign in to comment.