Skip to content

Commit

Permalink
Merge pull request #79 from kchygoe/fix_project_api
Browse files Browse the repository at this point in the history
Fix project api cve_allowlist
  • Loading branch information
wrighbr authored Feb 12, 2021
2 parents bfb0ce8 + 4592734 commit 90a9268
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
26 changes: 13 additions & 13 deletions client/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,28 @@ func ProjectBody(d *schema.ResourceData) models.ProjectsBodyPost {
body.Metadata.PreventVul = "false"
}

cveWhiteList := d.Get("cve_whitelist").([]interface{})
log.Printf("[DEBUG] %v ", cveWhiteList)
if len(cveWhiteList) > 0 {
log.Printf("[DEBUG] %v ", expandCveWhiteList(cveWhiteList))
body.CveWhitelist.Items = expandCveWhiteList(cveWhiteList)
body.Metadata.ReuseSysCveWhitelist = "false"
cveAllowList := d.Get("cve_allowlist").([]interface{})
log.Printf("[DEBUG] %v ", cveAllowList)
if len(cveAllowList) > 0 {
log.Printf("[DEBUG] %v ", expandCveAllowList(cveAllowList))
body.CveAllowlist.Items = expandCveAllowList(cveAllowList)
body.Metadata.ReuseSysCveAllowlist = "false"
} else {
body.Metadata.ReuseSysCveWhitelist = "true"
body.Metadata.ReuseSysCveAllowlist = "true"
}

return body
}

func expandCveWhiteList(cveWhitelist []interface{}) models.CveWhitelistItems {
whitelist := models.CveWhitelistItems{}
func expandCveAllowList(cveAllowlist []interface{}) models.CveAllowlistItems {
allowlist := models.CveAllowlistItems{}

for _, data := range cveWhitelist {
item := models.CveWhitelistItem{
for _, data := range cveAllowlist {
item := models.CveAllowlistItem{
CveID: data.(string),
}
whitelist = append(whitelist, item)
allowlist = append(allowlist, item)
}

return whitelist
return allowlist
}
18 changes: 9 additions & 9 deletions models/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ type ProjectsBodyPost struct {
CountLimit int `json:"count_limit,omitempty"`
ProjectName string `json:"project_name,omitempty"`
RegistryID int `json:"registry_id,omitempty"`
CveWhitelist struct {
Items CveWhitelistItems `json:"items,omitempty"`
CveAllowlist struct {
Items CveAllowlistItems `json:"items,omitempty"`
// Items []struct {
// CveID string `json:"cve_id,omitempty"`
// } `json:"items,omitempty"`
ProjectID int `json:"project_id,omitempty"`
ID int `json:"id,omitempty"`
ExpiresAt int `json:"expires_at,omitempty"`
} `json:"cve_whitelist,omitempty"`
} `json:"cve_allowlist,omitempty"`
StorageLimit int `json:"storage_limit,omitempty"`
Metadata struct {
EnableContentTrust string `json:"enable_content_trust,omitempty"`
AutoScan string `json:"auto_scan,omitempty"`
Severity string `json:"severity,omitempty"`
ReuseSysCveWhitelist string `json:"reuse_sys_cve_whitelist,omitempty"`
ReuseSysCveAllowlist string `json:"reuse_sys_cve_allowlist,omitempty"`
Public string `json:"public,omitempty"`
PreventVul string `json:"prevent_vul,omitempty"`
} `json:"metadata,omitempty"`
Expand All @@ -39,27 +39,27 @@ type ProjectsBodyResponses struct {
CurrentUserRoleID int `json:"current_user_role_id"`
CurrentUserRoleIds []int `json:"current_user_role_ids"`
ChartCount int `json:"chart_count"`
CveWhitelist struct {
CveAllowlist struct {
Items []struct {
CveID string `json:"cve_id"`
} `json:"items"`
ProjectID int `json:"project_id"`
ID int `json:"id"`
ExpiresAt int `json:"expires_at"`
} `json:"cve_whitelist"`
} `json:"cve_allowlist"`
Metadata struct {
EnableContentTrust string `json:"enable_content_trust"`
AutoScan string `json:"auto_scan"`
Severity string `json:"severity"`
ReuseSysCveWhitelist string `json:"reuse_sys_cve_whitelist"`
ReuseSysCveAllowlist string `json:"reuse_sys_cve_allowlist"`
Public string `json:"public"`
PreventVul string `json:"prevent_vul"`
} `json:"metadata"`
}

type CveWhitelistItems []struct {
type CveAllowlistItems []struct {
CveID string `json:"cve_id,omitempty"`
}
type CveWhitelistItem struct {
type CveAllowlistItem struct {
CveID string `json:"cve_id,omitempty"`
}
2 changes: 1 addition & 1 deletion provider/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func resourceProject() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"cve_whitelist": {
"cve_allowlist": {
Type: schema.TypeList,
Elem: &schema.Schema{
Type: schema.TypeString,
Expand Down

0 comments on commit 90a9268

Please sign in to comment.