Skip to content

Commit

Permalink
set RequestLogging on sigsci.CreateCorpRuleBody when creating a corp …
Browse files Browse the repository at this point in the history
…rule, and set "requestlogging" attribute in resourceCorpRuleRead (#179)

* set RequestLogging on sigsci.CreateCorpRuleBody when creating a corp rule, and set "requestlogging" attribute in resourceCorpRuleRead

* upgrade go-sigsci dependency

* set updateCorpRuleBody.RequestLogging in resourceCorpRuleUpdate

* add TestResourceCorpRequestRule for testing corp request rule creation
  • Loading branch information
shawnps authored Jun 7, 2023
1 parent bd38d33 commit 92e2f63
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/davecgh/go-spew v1.1.1
github.com/hashicorp/terraform-plugin-docs v0.14.1
github.com/hashicorp/terraform-plugin-sdk v1.14.0
github.com/signalsciences/go-sigsci v0.1.15
github.com/signalsciences/go-sigsci v0.1.16
golang.org/x/lint v0.0.0-20190409202823-959b441ac422
honnef.co/go/tools v0.4.2
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/signalsciences/go-sigsci v0.1.15 h1:Z1Wkli5NtN8OsvBBWBgXRS0LpAsmVrl1dgCPqFrKglo=
github.com/signalsciences/go-sigsci v0.1.15/go.mod h1:CXwoXk81ZwFdne6o8cnAYwxvke5kcLg7zE6Bl/e1KUo=
github.com/signalsciences/go-sigsci v0.1.16 h1:4Z6kwgSyo0gPLRLv+/gsaeq+CeGuE/AhENOR2aANnm4=
github.com/signalsciences/go-sigsci v0.1.16/go.mod h1:CXwoXk81ZwFdne6o8cnAYwxvke5kcLg7zE6Bl/e1KUo=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
Expand Down
34 changes: 20 additions & 14 deletions provider/resource_corp_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,14 @@ func resourceCorpRuleCreate(d *schema.ResourceData, m interface{}) error {
sc := pm.Client
corp := pm.Corp
corpRuleBody := sigsci.CreateCorpRuleBody{
Type: d.Get("type").(string),
CorpScope: d.Get("corp_scope").(string),
Enabled: d.Get("enabled").(bool),
GroupOperator: d.Get("group_operator").(string),
Reason: d.Get("reason").(string),
Signal: d.Get("signal").(string),
Expiration: d.Get("expiration").(string),
Type: d.Get("type").(string),
CorpScope: d.Get("corp_scope").(string),
Enabled: d.Get("enabled").(bool),
GroupOperator: d.Get("group_operator").(string),
Reason: d.Get("reason").(string),
Signal: d.Get("signal").(string),
Expiration: d.Get("expiration").(string),
RequestLogging: d.Get("requestlogging").(string),
}

corpRuleBody.SiteNames = expandStringArray(d.Get("site_short_names").(*schema.Set))
Expand All @@ -236,13 +237,14 @@ func resourceCorpRuleUpdate(d *schema.ResourceData, m interface{}) error {
corp := pm.Corp

updateCorpRuleBody := sigsci.CreateCorpRuleBody{
Type: d.Get("type").(string),
CorpScope: d.Get("corp_scope").(string),
Enabled: d.Get("enabled").(bool),
GroupOperator: d.Get("group_operator").(string),
Reason: d.Get("reason").(string),
Signal: d.Get("signal").(string),
Expiration: d.Get("expiration").(string),
Type: d.Get("type").(string),
CorpScope: d.Get("corp_scope").(string),
Enabled: d.Get("enabled").(bool),
GroupOperator: d.Get("group_operator").(string),
Reason: d.Get("reason").(string),
Signal: d.Get("signal").(string),
Expiration: d.Get("expiration").(string),
RequestLogging: d.Get("requestlogging").(string),
}

updateCorpRuleBody.SiteNames = expandStringArray(d.Get("site_short_names").(*schema.Set))
Expand Down Expand Up @@ -295,6 +297,10 @@ func resourceCorpRuleRead(d *schema.ResourceData, m interface{}) error {
if err != nil {
return err
}
err = d.Set("requestlogging", rule.RequestLogging)
if err != nil {
return err
}
err = d.Set("site_short_names", flattenStringArray(rule.SiteNames))
if err != nil {
return err
Expand Down
58 changes: 58 additions & 0 deletions provider/resource_corp_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,61 @@ func testACCCheckCorpRuleDestroy(s *terraform.State) error {
}
return nil
}

func TestResourceCorpRequestRule(t *testing.T) {
t.Parallel()
resourceName := "sigsci_corp_rule.test"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testACCCheckCorpRuleDestroy,
Steps: []resource.TestStep{
{
Config: `
resource "sigsci_corp_rule" "test"{
type= "request"
corp_scope="global"
enabled=true
group_operator="any"
reason="Example corp rule"
requestlogging="none"
expiration= ""
conditions {
type="single"
field="ip"
operator="equals"
value="1.2.3.4"
}
actions {
type="block"
}
}`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "actions.#", "1"),
resource.TestCheckResourceAttr(resourceName, "actions.1990726244.type", "block"),
resource.TestCheckResourceAttr(resourceName, "conditions.#", "1"),
resource.TestCheckResourceAttr(resourceName, "conditions.2534374319.conditions.#", "0"),
resource.TestCheckResourceAttr(resourceName, "conditions.2534374319.field", "ip"),
resource.TestCheckResourceAttr(resourceName, "conditions.2534374319.group_operator", ""),
resource.TestCheckResourceAttr(resourceName, "conditions.2534374319.operator", "equals"),
resource.TestCheckResourceAttr(resourceName, "conditions.2534374319.type", "single"),
resource.TestCheckResourceAttr(resourceName, "conditions.2534374319.value", "1.2.3.4"),
resource.TestCheckResourceAttr(resourceName, "corp_scope", "global"),
resource.TestCheckResourceAttr(resourceName, "enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "expiration", ""),
resource.TestCheckResourceAttr(resourceName, "group_operator", "any"),
resource.TestCheckResourceAttr(resourceName, "reason", "Example corp rule"),
resource.TestCheckResourceAttr(resourceName, "type", "request"),
resource.TestCheckResourceAttr(resourceName, "requestlogging", "none"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateCheck: testAccImportStateCheckFunction(1),
},
},
})
}

0 comments on commit 92e2f63

Please sign in to comment.