Skip to content

Commit 0077747

Browse files
authored
Merge pull request #219 from yossig-aquasec/risk_acknowledge
feat: adding support for security acknowledge
2 parents 2b32db8 + ddfefbd commit 0077747

File tree

13 files changed

+1071
-3
lines changed

13 files changed

+1071
-3
lines changed

GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ HOSTNAME := github.com
66
NAMESPACE := aquasec
77
NAME := aquasec
88
BINARY := terraform-provider-${NAME}
9-
VERSION := 0.8.17
9+
VERSION := 0.8.18
1010
OS_ARCH := $(shell go env GOOS)_$(shell go env GOARCH)
1111

1212
default: build

aquasec/data_acknowledge.go

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
package aquasec
2+
3+
import (
4+
"github.com/aquasecurity/terraform-provider-aquasec/client"
5+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
6+
"log"
7+
)
8+
9+
func dataSourceAcknowledges() *schema.Resource {
10+
return &schema.Resource{
11+
Description: "The data source `aquasec_acknowledges` provides a method to query all acknowledges within the Aqua ",
12+
Read: dataAcknowledgesRead,
13+
Schema: map[string]*schema.Schema{
14+
"acknowledges": {
15+
Type: schema.TypeList,
16+
Description: "A list of existing security acknowledges.",
17+
Computed: true,
18+
Elem: &schema.Resource{
19+
Schema: map[string]*schema.Schema{
20+
"issue_type": {
21+
Type: schema.TypeString,
22+
Description: "The type of the security issue (either 'vulnerability', 'sensitive_data' or 'malware')",
23+
Computed: true,
24+
},
25+
"resource_type": {
26+
Type: schema.TypeString,
27+
Description: "The type of the resource where the issue was detected (either 'package', 'file' or 'executable')",
28+
Computed: true,
29+
},
30+
"image_name": {
31+
Type: schema.TypeString,
32+
Description: "Only acknowledge the issue in the context of the specified image (also requires 'registry_name')",
33+
Computed: true,
34+
},
35+
"registry_name": {
36+
Type: schema.TypeString,
37+
Description: "Only acknowledge the issue in the context of the specified repository (also requires 'registry_name').",
38+
Computed: true,
39+
},
40+
"resource_name": {
41+
Type: schema.TypeString,
42+
Description: "When the resource_type is 'package', the name of the package is required.",
43+
Computed: true,
44+
},
45+
"resource_version": {
46+
Type: schema.TypeString,
47+
Description: "When the resource_type is 'package', the version of the package is required",
48+
Computed: true,
49+
},
50+
"resource_format": {
51+
Type: schema.TypeString,
52+
Description: "The format of the resource.",
53+
Computed: true,
54+
},
55+
"resource_cpe": {
56+
Type: schema.TypeString,
57+
Description: "The CPE of the resource as listed in the issue by the Aqua API. This is required for resources of type 'executable'. For packages and files, the next parameters can be specified instead.",
58+
Computed: true,
59+
},
60+
"resource_path": {
61+
Type: schema.TypeString,
62+
Description: "The path of the resource. This is required for resources of type 'file' and 'executable'.",
63+
Computed: true,
64+
},
65+
"resource_hash": {
66+
Type: schema.TypeString,
67+
Description: "When the resource_type is 'file', the hash of the file is required",
68+
Computed: true,
69+
},
70+
"issue_name": {
71+
Type: schema.TypeString,
72+
Description: "The name of the security issue (the CVE or security advisory for vulnerabilities, name of malware or type of sensitive data)",
73+
Computed: true,
74+
},
75+
"comment": {
76+
Type: schema.TypeString,
77+
Description: "A comment describing the reason for the acknowledgment",
78+
Computed: true,
79+
},
80+
"author": {
81+
Type: schema.TypeString,
82+
Description: "The user who acknowledged the issue.",
83+
Computed: true,
84+
},
85+
"date": {
86+
Type: schema.TypeString,
87+
Description: "The date and time of the acknowledgment.",
88+
Computed: true,
89+
},
90+
"fix_version": {
91+
Type: schema.TypeString,
92+
Description: "The version of the package that having a fix for the issue.",
93+
Computed: true,
94+
},
95+
"expiration_days": {
96+
Type: schema.TypeInt,
97+
Description: "Number of days until expiration of the acknowledgement. The value must be integer from 1 to 999, inclusive.",
98+
Computed: true,
99+
},
100+
"expiration_configured_at": {
101+
Type: schema.TypeString,
102+
Description: "The current dat and time when the expiration was set",
103+
Computed: true,
104+
},
105+
"expiration_configured_by": {
106+
Type: schema.TypeString,
107+
Description: "The user who set the expiration of the issue.",
108+
Computed: true,
109+
},
110+
"permission": {
111+
Type: schema.TypeString,
112+
Description: "The permissions of the user who acknowledged the issue.",
113+
Computed: true,
114+
},
115+
"os": {
116+
Type: schema.TypeString,
117+
Description: "When the resource_type is 'package', the operating system is required (e.g., 'ubuntu', 'alpine').",
118+
Computed: true,
119+
},
120+
"os_version": {
121+
Type: schema.TypeString,
122+
Description: "When the resource_type is 'package', the operating system version is required.",
123+
Computed: true,
124+
},
125+
"docker_id": {
126+
Type: schema.TypeString,
127+
Description: "",
128+
Computed: true,
129+
},
130+
},
131+
},
132+
},
133+
},
134+
}
135+
}
136+
137+
func dataAcknowledgesRead(d *schema.ResourceData, m interface{}) error {
138+
log.Println("[DEBUG] inside dataAcknowledges")
139+
c := m.(*client.Client)
140+
result, err := c.AcknowledgeRead()
141+
if err == nil {
142+
acknowledges, id := flattenAcknowledgesData(result)
143+
d.SetId(id)
144+
if err := d.Set("acknowledges", acknowledges); err != nil {
145+
return err
146+
}
147+
} else {
148+
return err
149+
}
150+
151+
return nil
152+
}
153+
154+
func flattenAcknowledgesData(acknowledgesList *client.AcknowledgeList) ([]interface{}, string) {
155+
id := ""
156+
acknowledges := acknowledgesList.Result
157+
if acknowledges != nil {
158+
acks := make([]interface{}, len(acknowledges), len(acknowledges))
159+
160+
for i, acknowledge := range acknowledges {
161+
id = id + acknowledge.IssueName
162+
a := make(map[string]interface{})
163+
164+
a["issue_type"] = acknowledge.IssueType
165+
a["resource_type"] = acknowledge.ResourceType
166+
a["image_name"] = acknowledge.ImageName
167+
a["registry_name"] = acknowledge.RegistryName
168+
a["resource_name"] = acknowledge.ResourceName
169+
a["resource_version"] = acknowledge.ResourceVersion
170+
a["resource_format"] = acknowledge.ResourceFormat
171+
a["resource_cpe"] = acknowledge.ResourceCpe
172+
a["resource_path"] = acknowledge.ResourcePath
173+
a["resource_hash"] = acknowledge.ResourceHash
174+
a["issue_name"] = acknowledge.IssueName
175+
a["comment"] = acknowledge.Comment
176+
a["author"] = acknowledge.Author
177+
a["date"] = acknowledge.Date.String()
178+
a["fix_version"] = acknowledge.FixVersion
179+
a["expiration_days"] = acknowledge.ExpirationDays
180+
a["expiration_configured_at"] = acknowledge.ExpirationConfiguredAt.String()
181+
a["expiration_configured_by"] = acknowledge.ExpirationConfiguredBy
182+
a["permission"] = acknowledge.Permission
183+
a["os"] = acknowledge.Os
184+
a["os_version"] = acknowledge.OsVersion
185+
a["docker_id"] = acknowledge.DockerId
186+
acks[i] = a
187+
}
188+
189+
return acks, id
190+
}
191+
192+
return make([]interface{}, 0), ""
193+
}

aquasec/data_acknowledge_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package aquasec
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
8+
)
9+
10+
func TestDataAcknowledge(t *testing.T) {
11+
t.Parallel()
12+
resource.Test(t, resource.TestCase{
13+
PreCheck: func() { testAccPreCheck(t) },
14+
Providers: testAccProviders,
15+
Steps: []resource.TestStep{
16+
{
17+
Config: testAccCheckAcknowledgeDataSource(),
18+
Check: testAccCheckAcknowledgeDataSourceExists("data.aquasec_acknowledges.acknowledge"),
19+
},
20+
},
21+
})
22+
}
23+
24+
func testAccCheckAcknowledgeDataSource() string {
25+
return `
26+
data "aquasec_acknowledges" "acknowledge" {}
27+
`
28+
}
29+
30+
func testAccCheckAcknowledgeDataSourceExists(n string) resource.TestCheckFunc {
31+
return func(s *terraform.State) error {
32+
rs, ok := s.RootModule().Resources[n]
33+
34+
if !ok {
35+
return NewNotFoundErrorf("%s in state", n)
36+
}
37+
38+
if rs.Primary.ID == "" {
39+
return NewNotFoundErrorf("ID for %s in state", n)
40+
}
41+
42+
return nil
43+
}
44+
}

aquasec/data_aqua_labels_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func testAccCheckAquasecAquaLabelsDataSource(name, description string) string {
3333
}
3434
3535
data "aquasec_aqua_labels" "test_aqua_labels" {
36+
depends_on = [aquasec_aqua_label.new]
3637
}
3738
`, name, description)
3839

aquasec/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func Provider(v string) *schema.Provider {
8585
//"aquasec_sso": resourceSSO(),
8686
"aquasec_role_mapping": resourceRoleMapping(),
8787
"aquasec_aqua_label": resourceAquaLabels(),
88+
"aquasec_acknowledge": resourceAcknowledge(),
8889
//saas
8990
"aquasec_group": resourceGroup(),
9091
"aquasec_user_saas": resourceUserSaas(),
@@ -112,6 +113,7 @@ func Provider(v string) *schema.Provider {
112113
//"aquasec_sso": dataSourceSSO(),
113114
"aquasec_roles_mapping": dataSourceRolesMapping(),
114115
"aquasec_aqua_labels": dataSourceAquaLabels(),
116+
"aquasec_acknowledges": dataSourceAcknowledges(),
115117
//saas:
116118
"aquasec_groups": dataSourceGroups(),
117119
"aquasec_users_saas": dataSourceUsersSaas(),

0 commit comments

Comments
 (0)