Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
enforcement rule
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesWoolfenden committed Jul 29, 2022
1 parent 2776276 commit 64d0475
Show file tree
Hide file tree
Showing 28 changed files with 508 additions and 338 deletions.
4 changes: 3 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# Visit https://goreleaser.com for documentation on how to customize this
# behavior.
# behaviour.
before:
hooks:
# this is just an example and not a requirement for
Expand Down Expand Up @@ -30,6 +30,8 @@ builds:
ignore:
- goos: darwin
goarch: '386'
- goos: windows
goarch: 'arm64'
binary: '{{ .ProjectName }}_v{{ .Version }}'
archives:
- format: zip # yamllint indentation
Expand Down
38 changes: 19 additions & 19 deletions bridgecrew/data_source_code_reviews.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,20 @@ func dataSourceCodeReviews() *schema.Resource {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"supplychain": {
"supply_chain": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"softfailthreshold": {
"soft_fail_threshold": {
Type: schema.TypeString,
Computed: true,
},
"hardfailthreshold": {
"hard_fail_threshold": {
Type: schema.TypeString,
Computed: true,
},
"commentsbotthreshold": {
"comments_bot_threshold": {
Type: schema.TypeString,
Computed: true,
},
Expand All @@ -148,15 +148,15 @@ func dataSourceCodeReviews() *schema.Resource {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"softfailthreshold": {
"soft_fail_threshold": {
Type: schema.TypeString,
Computed: true,
},
"hardfailthreshold": {
"hard_fail_threshold": {
Type: schema.TypeString,
Computed: true,
},
"commentsbotthreshold": {
"comments_bot_threshold": {
Type: schema.TypeString,
Computed: true,
},
Expand All @@ -168,15 +168,15 @@ func dataSourceCodeReviews() *schema.Resource {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"softfailthreshold": {
"soft_fail_threshold": {
Type: schema.TypeString,
Computed: true,
},
"hardfailthreshold": {
"hard_fail_threshold": {
Type: schema.TypeString,
Computed: true,
},
"commentsbotthreshold": {
"comments_bot_threshold": {
Type: schema.TypeString,
Computed: true,
},
Expand All @@ -188,35 +188,35 @@ func dataSourceCodeReviews() *schema.Resource {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"softfailthreshold": {
"soft_fail_threshold": {
Type: schema.TypeString,
Computed: true,
},
"hardfailthreshold": {
"hard_fail_threshold": {
Type: schema.TypeString,
Computed: true,
},
"commentsbotthreshold": {
"comments_bot_threshold": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"opensource": {
"open_source": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"softfailthreshold": {
"soft_fail_threshold": {
Type: schema.TypeString,
Computed: true,
},
"hardfailthreshold": {
"hard_fail_threshold": {
Type: schema.TypeString,
Computed: true,
},
"commentsbotthreshold": {
"comments_bot_threshold": {
Type: schema.TypeString,
Computed: true,
},
Expand Down Expand Up @@ -319,11 +319,11 @@ func flattenCodeReviews(codereviews map[string]interface{}, d *schema.ResourceDa
images := setcategories(mycode, "IMAGES")
opensource := setcategories(mycode, "OPEN_SOURCE")

mycat["supplychain"] = supplies
mycat["supply_chain"] = supplies
mycat["secrets"] = secrets
mycat["iac"] = iac
mycat["images"] = images
mycat["opensource"] = opensource
mycat["open_source"] = opensource

enforcement = append(enforcement, mycat)
mypr["enforcement_rule"] = enforcement
Expand Down
8 changes: 4 additions & 4 deletions bridgecrew/data_source_enforcement_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ func dataSourceEnforcementAccounts() *schema.Resource {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"accountid": {
"account_id": {
Type: schema.TypeString,
Computed: true,
},
"accountname": {
"account_name": {
Type: schema.TypeString,
Computed: true,
},
Expand Down Expand Up @@ -90,8 +90,8 @@ func flattenEnforcementAccounts(Enforcement []map[string]interface{}, d *schema.
if Enforcement != nil {
for _, account := range Enforcement {
myaccount := make(map[string]interface{})
myaccount["accountid"] = account["accountId"]
myaccount["accountname"] = account["accountName"]
myaccount["account_id"] = account["accountId"]
myaccount["account_name"] = account["accountName"]
myaccount["source"] = account["source"]
accounts = append(accounts, myaccount)
}
Expand Down
58 changes: 21 additions & 37 deletions bridgecrew/data_source_enforcement_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func dataSourceEnforcementRule() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceEnforcementRuleRead,
Schema: map[string]*schema.Schema{
"accountid": {
"account_id": {
Type: schema.TypeString,
Required: true,
Description: "Account ID",
Expand All @@ -26,20 +26,20 @@ func dataSourceEnforcementRule() *schema.Resource {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"supplychain": {
"supply_chain": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"softfailthreshold": {
"soft_fail_threshold": {
Type: schema.TypeString,
Computed: true,
},
"hardfailthreshold": {
"hard_fail_threshold": {
Type: schema.TypeString,
Computed: true,
},
"commentsbotthreshold": {
"comments_bot_threshold": {
Type: schema.TypeString,
Computed: true,
},
Expand All @@ -51,15 +51,15 @@ func dataSourceEnforcementRule() *schema.Resource {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"softfailthreshold": {
"soft_fail_threshold": {
Type: schema.TypeString,
Computed: true,
},
"hardfailthreshold": {
"hard_fail_threshold": {
Type: schema.TypeString,
Computed: true,
},
"commentsbotthreshold": {
"comments_bot_threshold": {
Type: schema.TypeString,
Computed: true,
},
Expand All @@ -71,15 +71,15 @@ func dataSourceEnforcementRule() *schema.Resource {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"softfailthreshold": {
"soft_fail_threshold": {
Type: schema.TypeString,
Computed: true,
},
"hardfailthreshold": {
"hard_fail_threshold": {
Type: schema.TypeString,
Computed: true,
},
"commentsbotthreshold": {
"comments_bot_threshold": {
Type: schema.TypeString,
Computed: true,
},
Expand All @@ -91,35 +91,35 @@ func dataSourceEnforcementRule() *schema.Resource {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"softfailthreshold": {
"soft_fail_threshold": {
Type: schema.TypeString,
Computed: true,
},
"hardfailthreshold": {
"hard_fail_threshold": {
Type: schema.TypeString,
Computed: true,
},
"commentsbotthreshold": {
"comments_bot_threshold": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"opensource": {
"open_source": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"softfailthreshold": {
"soft_fail_threshold": {
Type: schema.TypeString,
Computed: true,
},
"hardfailthreshold": {
"hard_fail_threshold": {
Type: schema.TypeString,
Computed: true,
},
"commentsbotthreshold": {
"comments_bot_threshold": {
Type: schema.TypeString,
Computed: true,
},
Expand All @@ -136,7 +136,7 @@ func dataSourceEnforcementRule() *schema.Resource {
//goland:noinspection GoUnusedParameter,GoLinter,GoLinter
func dataSourceEnforcementRuleRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {

id := d.Get("accountid").(string)
id := d.Get("account_id").(string)
request := "%s/enforcement-rules/account/" + id
params := RequestParams{request, "v1", "GET"}

Expand Down Expand Up @@ -182,27 +182,11 @@ func dataSourceEnforcementRuleRead(ctx context.Context, d *schema.ResourceData,
func flattenEnforcementRule(enforcement map[string]interface{}, d *schema.ResourceData) diag.Diagnostics {
accountid := enforcement["accountId"]

if err := d.Set("accountid", accountid.(string)); err != nil {
if err := d.Set("account_id", accountid.(string)); err != nil {
return diag.FromErr(err)
}

codecategories := make([]interface{}, 0)
mycat := make(map[string]interface{})
mycode := enforcement["codeCategories"].(map[string]interface{})

supplies := setcategories(mycode, "SUPPLY_CHAIN")
secrets := setcategories(mycode, "SECRETS")
iac := setcategories(mycode, "IAC")
images := setcategories(mycode, "IMAGES")
opensource := setcategories(mycode, "OPEN_SOURCE")

mycat["supplychain"] = supplies
mycat["secrets"] = secrets
mycat["iac"] = iac
mycat["images"] = images
mycat["opensource"] = opensource

codecategories = append(codecategories, mycat)
codecategories := SetCodeCategories(enforcement)

if err := d.Set("codecategories", codecategories); err != nil {
return diag.FromErr(err)
Expand Down
Loading

0 comments on commit 64d0475

Please sign in to comment.