Skip to content

Commit 287375f

Browse files
committed
(feat) add grace days policy to container policy resources
1 parent 576e31c commit 287375f

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

prismacloudcompute/convert/vulnerability_image.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,21 @@ func SchemaToVulnerabilityImageRules(d *schema.ResourceData) ([]policy.Vulnerabi
5252

5353
parsedRule.Disabled = presentRule["disabled"].(bool)
5454
parsedRule.Effect = presentRule["effect"].(string)
55-
parsedRule.GraceDays = presentRule["grace_days"].(int)
55+
56+
if len(presentRule["grace_days_policy"].([]interface{})) > 0 && presentRule["grace_days_policy"].([]interface{})[0] != nil {
57+
presentGraceDaysPolicy := presentRule["grace_days_policy"].([]interface{})[0].(map[string]interface{})
58+
parsedRule.GraceDaysPolicy = policy.VulnerabilityImageGraceDaysPolicy{
59+
Enabled: true,
60+
Low: presentGraceDaysPolicy["low"].(int),
61+
Medium: presentGraceDaysPolicy["medium"].(int),
62+
High: presentGraceDaysPolicy["high"].(int),
63+
Critical: presentGraceDaysPolicy["critical"].(int),
64+
}
65+
parsedRule.GraceDays = 0
66+
} else {
67+
parsedRule.GraceDays = presentRule["grace_days"].(int)
68+
}
69+
5670
parsedRule.Name = presentRule["name"].(string)
5771
parsedRule.Notes = presentRule["notes"].(string)
5872
parsedRule.OnlyFixed = presentRule["only_fixed"].(bool)
@@ -101,6 +115,7 @@ func VulnerabilityImageRulesToSchema(in []policy.VulnerabilityImageRule) []inter
101115
m["disabled"] = val.Disabled
102116
m["effect"] = val.Effect
103117
m["grace_days"] = val.GraceDays
118+
m["grace_days_policy"] = vulnerabilityImageGraceDaysPolicyToSchema(val.GraceDaysPolicy)
104119
m["name"] = val.Name
105120
m["notes"] = val.Notes
106121
m["only_fixed"] = val.OnlyFixed
@@ -163,3 +178,14 @@ func vulnerabilityImageTagRulesToSchema(in []policy.VulnerabilityImageTagRule) [
163178
}
164179
return ans
165180
}
181+
182+
func vulnerabilityImageGraceDaysPolicyToSchema(in policy.VulnerabilityImageGraceDaysPolicy) []interface{} {
183+
ans := make([]interface{}, 0, 1)
184+
m := make(map[string]interface{})
185+
m["low"] = in.Low
186+
m["medium"] = in.Medium
187+
m["high"] = in.High
188+
m["critical"] = in.Critical
189+
ans = append(ans, m)
190+
return ans
191+
}

prismacloudcompute/resource_policies_vulnerability_ci_images.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,32 @@ func resourcePoliciesVulnerabilityCiImage() *schema.Resource {
145145
Optional: true,
146146
Description: "Number of days to suppress the rule's block effect. Measured from date the vulnerability was fixed. If there's no fix, measured from the date the vulnerability was published.",
147147
},
148+
"grace_days_policy": {
149+
Type: schema.TypeList,
150+
MaxItems: 1,
151+
Optional: true,
152+
Description: "Composite alternative to grace_days. Allows to set the effect for different severity level.",
153+
Elem: &schema.Resource{
154+
Schema: map[string]*schema.Schema{
155+
"low": {
156+
Type: schema.TypeInt,
157+
Optional: true,
158+
},
159+
"medium": {
160+
Type: schema.TypeInt,
161+
Optional: true,
162+
},
163+
"high": {
164+
Type: schema.TypeInt,
165+
Optional: true,
166+
},
167+
"critical": {
168+
Type: schema.TypeInt,
169+
Optional: true,
170+
},
171+
},
172+
},
173+
},
148174
"name": {
149175
Type: schema.TypeString,
150176
Optional: true,

prismacloudcompute/resource_policies_vulnerability_images.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,32 @@ func resourcePoliciesVulnerabilityImage() *schema.Resource {
145145
Optional: true,
146146
Description: "Number of days to suppress the rule's block effect. Measured from date the vulnerability was fixed. If there's no fix, measured from the date the vulnerability was published.",
147147
},
148+
"grace_days_policy": {
149+
Type: schema.TypeList,
150+
MaxItems: 1,
151+
Optional: true,
152+
Description: "Composite alternative to grace_days. Allows to set the effect for different severity level.",
153+
Elem: &schema.Resource{
154+
Schema: map[string]*schema.Schema{
155+
"low": {
156+
Type: schema.TypeInt,
157+
Optional: true,
158+
},
159+
"medium": {
160+
Type: schema.TypeInt,
161+
Optional: true,
162+
},
163+
"high": {
164+
Type: schema.TypeInt,
165+
Optional: true,
166+
},
167+
"critical": {
168+
Type: schema.TypeInt,
169+
Optional: true,
170+
},
171+
},
172+
},
173+
},
148174
"name": {
149175
Type: schema.TypeString,
150176
Optional: true,

0 commit comments

Comments
 (0)