forked from IBM-Cloud/terraform-provider-ibm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(CIS) - Bot Management & Bot Analytics (IBM-Cloud#4603)
* (feat) CIS - Bot Management * doc changes * doc changes * version revert * doc changes * addressed PR comments * resolved conflicts * corrected variables * added crn and domain --------- Co-authored-by: Arpit Srivastava <arpit-mac@Arpits-MacBook-Pro-6.local>
- Loading branch information
1 parent
56898c0
commit 9edee33
Showing
10 changed files
with
606 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// Copyright IBM Corp. 2017, 2021 All Rights Reserved. | ||
// Licensed under the Mozilla Public License v2.0 | ||
|
||
package cis | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" | ||
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate" | ||
"github.com/IBM/go-sdk-core/v5/core" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
const ( | ||
cisBotManagementFightMode = "fight_mode" | ||
cisBotManagementSessionScore = "session_score" | ||
cisBotManagementEnableJs = "enable_js" | ||
cisBotManagementAuthIdLogging = "auth_id_logging" | ||
cisBotManagementUseLatestModel = "use_latest_model" | ||
) | ||
|
||
func DataSourceIBMCISBotManagement() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceIBMCISBotManagementRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
cisID: { | ||
Type: schema.TypeString, | ||
Description: "CIS instance crn", | ||
Required: true, | ||
ValidateFunc: validate.InvokeDataSourceValidator( | ||
"ibm_cis_bot_managements", | ||
"cis_id"), | ||
}, | ||
cisDomainID: { | ||
Type: schema.TypeString, | ||
Description: "Associated CIS domain", | ||
Required: true, | ||
DiffSuppressFunc: suppressDomainIDDiff, | ||
}, | ||
cisBotManagementFightMode: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Fight Mode", | ||
}, | ||
cisBotManagementSessionScore: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Session Score", | ||
}, | ||
cisBotManagementEnableJs: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Enable JS", | ||
}, | ||
cisBotManagementAuthIdLogging: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Auth ID Logging", | ||
}, | ||
cisBotManagementUseLatestModel: { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Use Latest Model", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func DataSourceIBMCISBotManagementValidator() *validate.ResourceValidator { | ||
|
||
validateSchema := make([]validate.ValidateSchema, 0) | ||
|
||
validateSchema = append(validateSchema, | ||
validate.ValidateSchema{ | ||
Identifier: "cis_id", | ||
ValidateFunctionIdentifier: validate.ValidateCloudData, | ||
Type: validate.TypeString, | ||
CloudDataType: "resource_instance", | ||
CloudDataRange: []string{"service:internet-svcs"}, | ||
Required: true}) | ||
|
||
iBMCISBotManagementValidator := validate.ResourceValidator{ | ||
ResourceName: "ibm_cis_bot_managements", | ||
Schema: validateSchema} | ||
return &iBMCISBotManagementValidator | ||
} | ||
|
||
func dataSourceIBMCISBotManagementRead(d *schema.ResourceData, meta interface{}) error { | ||
cisClient, err := meta.(conns.ClientSession).CisBotManagementSession() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
crn := d.Get(cisID).(string) | ||
zoneName := d.Get(cisDomainID).(string) | ||
cisClient.Crn = core.StringPtr(crn) | ||
cisClient.ZoneIdentifier = core.StringPtr(zoneName) | ||
opt := cisClient.NewGetBotManagementOptions() | ||
|
||
result, resp, err := cisClient.GetBotManagement(opt) | ||
if err != nil { | ||
log.Printf("dataSourceIBMCISBotManagementRead - GetBotManagement Failed %s\n", resp) | ||
return err | ||
} | ||
|
||
res := result.Result | ||
d.Set(cisID, crn) | ||
d.Set(cisDomainID, zoneName) | ||
d.Set(cisBotManagementFightMode, res.FightMode) | ||
d.Set(cisBotManagementSessionScore, res.SessionScore) | ||
d.Set(cisBotManagementEnableJs, res.EnableJs) | ||
d.Set(cisBotManagementAuthIdLogging, res.AuthIdLogging) | ||
d.Set(cisBotManagementUseLatestModel, res.UseLatestModel) | ||
|
||
return nil | ||
} |
37 changes: 37 additions & 0 deletions
37
ibm/service/cis/data_source_ibm_cis_bot_managements_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright IBM Corp. 2017, 2021 All Rights Reserved. | ||
// Licensed under the Mozilla Public License v2.0 | ||
|
||
package cis_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccIBMCisBotManagementDataSource_Basic(t *testing.T) { | ||
name := "data.ibm_cis_bot_managements.test" | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { acc.TestAccPreCheckCis(t) }, | ||
Providers: acc.TestAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCheckCisBotManagementDataSource_basic("test", acc.CisDomainStatic), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(name, "id"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
func testAccCheckCisBotManagementDataSource_basic(id, CisDomainStatic string) string { | ||
return testAccCheckIBMCisDomainDataSourceConfigBasic1() + fmt.Sprintf(` | ||
data "ibm_cis_bot_managements" "%[1]s" { | ||
cis_id = data.ibm_cis.cis.id | ||
domain_id = data.ibm_cis_domain.cis_domain.domain_id | ||
} | ||
`, id, acc.CisDomainStatic) | ||
} |
Oops, something went wrong.