Skip to content

Commit

Permalink
Merge pull request #139 from jfrog/GH-7-add-webhook-resource
Browse files Browse the repository at this point in the history
Add webhook resource
  • Loading branch information
alexhung authored Sep 25, 2023
2 parents bc83a78 + 88ee205 commit 1d72cb1
Show file tree
Hide file tree
Showing 7 changed files with 551 additions and 60 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 1.18.0 (September 26, 2023). Tested on Artifactory 7.68.11 and Xray 3.82.11

FEATURES:

* resource/xray_webhook: add a new resource allowing webhook to be managed.

PR: [#139](https://github.com/jfrog/terraform-provider-xray/pull/139)
Issue: [#7](https://github.com/jfrog/terraform-provider-xray/issues/7)

## 1.17.1 (September 15, 2023). Tested on Artifactory 7.68.7 and Xray 3.82.6

IMPROVEMENTS:
Expand All @@ -10,7 +19,7 @@ PR: [#137](https://github.com/jfrog/terraform-provider-xray/pull/137)

FEATURES:

* resource/xray_custom_issue: add a new resource allowing to custom issue event to be managed.
* resource/xray_custom_issue: add a new resource allowing custom issue event to be managed.

PR: [#136](https://github.com/jfrog/terraform-provider-xray/pull/136)
Issue: [#123](https://github.com/jfrog/terraform-provider-xray/issues/123)
Expand Down
35 changes: 35 additions & 0 deletions docs/resources/webhook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "xray_webhook Resource - terraform-provider-xray"
subcategory: ""
description: |-
Provides an Xray webhoook resource. See Xray Webhooks https://jfrog.com/help/r/jfrog-security-documentation/configuring-xray?section=UUID-bb7641b3-e469-e0ef-221d-c0ebf660dde1_id_ConfiguringXray-ConfiguringWebhooks and REST API https://jfrog.com/help/r/jfrog-rest-apis/xray-webhooks for more details.
---

# xray_webhook (Resource)

Provides an Xray webhoook resource. See [Xray Webhooks](https://jfrog.com/help/r/jfrog-security-documentation/configuring-xray?section=UUID-bb7641b3-e469-e0ef-221d-c0ebf660dde1_id_ConfiguringXray-ConfiguringWebhooks) and [REST API](https://jfrog.com/help/r/jfrog-rest-apis/xray-webhooks) for more details.



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) An identifier for the webhook. This is the name that will be used by any Watches that want to invoke the webhook in case of a violation
- `url` (String) The URL that this webhook invokes. For details of the payload provided by Xray to the webhook, please refer to Webhook Payload.

### Optional

- `description` (String) A free text description.
- `headers` (Map of String) Any custom headers that may need to be added to invoke the webhook.. Name/value pairs.
- `password` (String) A password as required by the webhook.
- `use_proxy` (Boolean) Set the webhook to go through the predefined proxy. For more information, see [Managing Proxies](https://jfrog.com/help/r/jfrog-platform-administration-documentation/managing-proxies).
- `user_name` (String) An username as required by the webhook.

### Read-Only

- `id` (String) The ID of this resource.


1 change: 1 addition & 0 deletions pkg/xray/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func Provider() *schema.Provider {
"xray_violations_report": resourceXrayViolationsReport(),
"xray_operational_risks_report": resourceXrayOperationalRisksReport(),
"xray_custom_issue": resourceXrayCustomIssue(),
"xray_webhook": resourceXrayWebhook(),
},
),
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/xray/resource_xray_custom_issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func resourceXrayCustomIssue() *schema.Resource {
return ss
}

var packComponents = func(data *schema.Set, components []Component) []interface{} {
var packComponents = func(components []Component) []interface{} {
var cs []interface{}

for _, component := range components {
Expand Down Expand Up @@ -333,7 +333,7 @@ func resourceXrayCustomIssue() *schema.Resource {
if err := d.Set("source", packSources(customIssue.Sources)); err != nil {
return diag.FromErr(err)
}
if err := d.Set("component", packComponents(d.Get("component").(*schema.Set), customIssue.Components)); err != nil {
if err := d.Set("component", packComponents(customIssue.Components)); err != nil {
return diag.FromErr(err)
}

Expand Down
143 changes: 86 additions & 57 deletions pkg/xray/resource_xray_custom_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,71 +10,71 @@ import (
"github.com/jfrog/terraform-provider-shared/util/sdk"
)

const template = `
resource "xray_custom_issue" "{{ .name }}" {
name = "{{ .name }}"
description = "{{ .description }}"
summary = "{{ .summary }}"
type = "{{ .type }}"
provider_name = "{{ .provider_name }}"
package_type = "{{ .package_type }}"
severity = "{{ .severity }}"
component {
id = "{{ .component_id }}"
vulnerable_versions = ["{{ .component_vulnerable_versions }}"]
vulnerable_ranges {
vulnerable_versions = ["{{ .component_vulnerable_ranges_vulnerable_versions }}"]
func TestAccCustomIssue_full(t *testing.T) {
_, fqrn, resourceName := testutil.MkNames("custom-issue-", "xray_custom_issue")

const template = `
resource "xray_custom_issue" "{{ .name }}" {
name = "{{ .name }}"
description = "{{ .description }}"
summary = "{{ .summary }}"
type = "{{ .type }}"
provider_name = "{{ .provider_name }}"
package_type = "{{ .package_type }}"
severity = "{{ .severity }}"
component {
id = "{{ .component_id }}"
vulnerable_versions = ["{{ .component_vulnerable_versions }}"]
vulnerable_ranges {
vulnerable_versions = ["{{ .component_vulnerable_ranges_vulnerable_versions }}"]
}
}
}
cve {
cve = "{{ .cve }}"
cvss_v2 = "{{ .cve_cvss_v2 }}"
}
cve {
cve = "{{ .cve }}"
cvss_v2 = "{{ .cve_cvss_v2 }}"
}
source {
id = "{{ .source_id }}"
}
}
`

const fullTemplate = `
resource "xray_custom_issue" "{{ .name }}" {
name = "{{ .name }}"
description = "{{ .description }}"
summary = "{{ .summary }}"
type = "{{ .type }}"
provider_name = "{{ .provider_name }}"
package_type = "{{ .package_type }}"
severity = "{{ .severity }}"
component {
id = "{{ .component_id }}"
vulnerable_versions = ["{{ .component_vulnerable_versions }}"]
fixed_versions = ["{{ .component_fixed_versions }}"]
vulnerable_ranges {
vulnerable_versions = ["{{ .component_vulnerable_ranges_vulnerable_versions }}"]
fixed_versions = ["{{ .component_vulnerable_ranges_fixed_versions }}"]
source {
id = "{{ .source_id }}"
}
}
`

cve {
cve = "{{ .cve }}"
cvss_v2 = "{{ .cve_cvss_v2 }}"
cvss_v3 = "{{ .cve_cvss_v3 }}"
}
const fullTemplate = `
resource "xray_custom_issue" "{{ .name }}" {
name = "{{ .name }}"
description = "{{ .description }}"
summary = "{{ .summary }}"
type = "{{ .type }}"
provider_name = "{{ .provider_name }}"
package_type = "{{ .package_type }}"
severity = "{{ .severity }}"
source {
id = "{{ .source_id }}"
name = "{{ .source_name }}"
url = "{{ .source_url }}"
}
}
`
component {
id = "{{ .component_id }}"
vulnerable_versions = ["{{ .component_vulnerable_versions }}"]
fixed_versions = ["{{ .component_fixed_versions }}"]
vulnerable_ranges {
vulnerable_versions = ["{{ .component_vulnerable_ranges_vulnerable_versions }}"]
fixed_versions = ["{{ .component_vulnerable_ranges_fixed_versions }}"]
}
}
func TestAccCustomIssue_full(t *testing.T) {
_, fqrn, resourceName := testutil.MkNames("custom-issue-", "xray_custom_issue")
cve {
cve = "{{ .cve }}"
cvss_v2 = "{{ .cve_cvss_v2 }}"
cvss_v3 = "{{ .cve_cvss_v3 }}"
}
source {
id = "{{ .source_id }}"
name = "{{ .source_name }}"
url = "{{ .source_url }}"
}
}
`

testData := map[string]string{
"name": resourceName,
Expand Down Expand Up @@ -186,6 +186,35 @@ func TestAccCustomIssue_full(t *testing.T) {
}

func TestAccCustomIssue_invalid(t *testing.T) {
const template = `
resource "xray_custom_issue" "{{ .name }}" {
name = "{{ .name }}"
description = "{{ .description }}"
summary = "{{ .summary }}"
type = "{{ .type }}"
provider_name = "{{ .provider_name }}"
package_type = "{{ .package_type }}"
severity = "{{ .severity }}"
component {
id = "{{ .component_id }}"
vulnerable_versions = ["{{ .component_vulnerable_versions }}"]
vulnerable_ranges {
vulnerable_versions = ["{{ .component_vulnerable_ranges_vulnerable_versions }}"]
}
}
cve {
cve = "{{ .cve }}"
cvss_v2 = "{{ .cve_cvss_v2 }}"
}
source {
id = "{{ .source_id }}"
}
}
`

testCases := []struct {
name string
extras map[string]string
Expand Down
Loading

0 comments on commit 1d72cb1

Please sign in to comment.