Skip to content

Commit

Permalink
pingone_risk_predictor: Add the `predictor_bot_detection.include_re…
Browse files Browse the repository at this point in the history
…peated_events_without_sdk` field (#939)

* `pingone_risk_predictor`: Add the `predictor_bot_detection.include_repeated_events_without_sdk` field

* changelog
  • Loading branch information
patrickcping authored Nov 18, 2024
1 parent d5c260b commit 20b22e3
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .changelog/939.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
`resource/pingone_risk_predictor`: Added the `predictor_bot_detection.include_repeated_events_without_sdk` field to choose whether to expand the range of bot activity that PingOne Protect can detect.
```
4 changes: 4 additions & 0 deletions docs/resources/risk_predictor.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,10 @@ Optional:
<a id="nestedatt--predictor_bot_detection"></a>
### Nested Schema for `predictor_bot_detection`

Optional:

- `include_repeated_events_without_sdk` (Boolean) A boolean that specifies whether to expand the range of bot activity that PingOne Protect can detect.


<a id="nestedatt--predictor_composite"></a>
### Nested Schema for `predictor_composite`
Expand Down
45 changes: 39 additions & 6 deletions internal/service/risk/resource_risk_predictor.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ type predictorGenericAllowedDomain struct {
AllowedDomainList types.Set `tfsdk:"allowed_domain_list"`
}

// Bot Detection
type predictorBotDetection struct {
IncludeRepeatedEventsWithoutSDK types.Bool `tfsdk:"include_repeated_events_without_sdk"`
}

// Composite
type predictorComposite struct {
Composition types.Object `tfsdk:"composition"`
Expand Down Expand Up @@ -215,6 +220,11 @@ var (
"allowed_domain_list": types.SetType{ElemType: types.StringType},
}

// Bot Detection
predictorBotDetectionTFObjectTypes = map[string]attr.Type{
"include_repeated_events_without_sdk": types.BoolType,
}

// Composite
predictorCompositeTFObjectTypes = map[string]attr.Type{
"composition": types.ObjectType{
Expand Down Expand Up @@ -701,7 +711,12 @@ func (r *RiskPredictorResource) Schema(ctx context.Context, req resource.SchemaR
MarkdownDescription: predictorBotDetectionDescription.MarkdownDescription,
Optional: true,

Attributes: map[string]schema.Attribute{},
Attributes: map[string]schema.Attribute{
"include_repeated_events_without_sdk": schema.BoolAttribute{
Description: framework.SchemaAttributeDescriptionFromMarkdown("A boolean that specifies whether to expand the range of bot activity that PingOne Protect can detect.").Description,
Optional: true,
},
},

Validators: predictorObjectValidators,

Expand Down Expand Up @@ -1876,7 +1891,7 @@ func (p *riskPredictorResourceModel) expand(ctx context.Context, apiClient *risk
}

if !p.PredictorBotDetection.IsNull() && !p.PredictorBotDetection.IsUnknown() {
riskPredictor.RiskPredictorBotDetection = p.expandPredictorBotDetection(riskPredictorCommonData)
riskPredictor.RiskPredictorBotDetection, d = p.expandPredictorBotDetection(ctx, riskPredictorCommonData)
}

if !p.PredictorComposite.IsNull() && !p.PredictorComposite.IsUnknown() {
Expand Down Expand Up @@ -2005,7 +2020,9 @@ func (p *riskPredictorResourceModel) expandPredictorAnonymousNetwork(ctx context
return &data, diags
}

func (p *riskPredictorResourceModel) expandPredictorBotDetection(riskPredictorCommon *risk.RiskPredictorCommon) *risk.RiskPredictorBotDetection {
func (p *riskPredictorResourceModel) expandPredictorBotDetection(ctx context.Context, riskPredictorCommon *risk.RiskPredictorCommon) (*risk.RiskPredictorBotDetection, diag.Diagnostics) {
var diags diag.Diagnostics

data := risk.RiskPredictorBotDetection{
Name: riskPredictorCommon.Name,
CompactName: riskPredictorCommon.CompactName,
Expand All @@ -2014,7 +2031,21 @@ func (p *riskPredictorResourceModel) expandPredictorBotDetection(riskPredictorCo
Default: riskPredictorCommon.Default,
}

return &data
var predictorPlan predictorBotDetection
d := p.PredictorBotDetection.As(ctx, &predictorPlan, basetypes.ObjectAsOptions{
UnhandledNullAsEmpty: false,
UnhandledUnknownAsEmpty: false,
})
diags.Append(d...)
if diags.HasError() {
return nil, diags
}

if !predictorPlan.IncludeRepeatedEventsWithoutSDK.IsNull() && !predictorPlan.IncludeRepeatedEventsWithoutSDK.IsUnknown() {
data.SetIncludeRepeatedEventsWithoutSdk(predictorPlan.IncludeRepeatedEventsWithoutSDK.ValueBool())
}

return &data, diags
}

func (p *riskPredictorResourceModel) expandPredictorComposite(ctx context.Context, riskPredictorCommon *risk.RiskPredictorCommon) (*risk.RiskPredictorComposite, diag.Diagnostics) {
Expand Down Expand Up @@ -3213,10 +3244,12 @@ func (p *riskPredictorResourceModel) toStateRiskPredictorBotDetection(apiObject
var diags diag.Diagnostics

if apiObject == nil || apiObject.GetId() == "" {
return types.ObjectNull(map[string]attr.Type{}), diags
return types.ObjectNull(predictorBotDetectionTFObjectTypes), diags
}

objValue, d := types.ObjectValue(map[string]attr.Type{}, map[string]attr.Value{})
objValue, d := types.ObjectValue(predictorBotDetectionTFObjectTypes, map[string]attr.Value{
"include_repeated_events_without_sdk": framework.BoolOkToTF(apiObject.GetIncludeRepeatedEventsWithoutSdkOk()),
})
diags.Append(d...)

return objValue, diags
Expand Down
14 changes: 9 additions & 5 deletions internal/service/risk/resource_risk_predictor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,14 +567,14 @@ func TestAccRiskPredictor_Bot_Detection(t *testing.T) {
resource.TestCheckResourceAttr(resourceFullName, "type", "BOT"),
resource.TestCheckResourceAttr(resourceFullName, "deletable", "true"),
resource.TestCheckResourceAttr(resourceFullName, "default.result.level", "MEDIUM"),
resource.TestCheckResourceAttr(resourceFullName, "predictor_bot_detection.#", "0"),
resource.TestCheckResourceAttr(resourceFullName, "predictor_bot_detection.include_repeated_events_without_sdk", "true"),
)

minimalCheck := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceFullName, "type", "BOT"),
resource.TestCheckResourceAttr(resourceFullName, "deletable", "true"),
resource.TestCheckNoResourceAttr(resourceFullName, "default.result.level"),
resource.TestCheckResourceAttr(resourceFullName, "predictor_bot_detection.#", "0"),
resource.TestCheckNoResourceAttr(resourceFullName, "predictor_bot_detection.include_repeated_events_without_sdk"),
)

resource.Test(t, resource.TestCase{
Expand Down Expand Up @@ -652,7 +652,7 @@ func TestAccRiskPredictor_Bot_Detection_OverwriteUndeletable(t *testing.T) {
resource.TestCheckResourceAttr(resourceFullName, "type", "BOT"),
resource.TestCheckResourceAttr(resourceFullName, "deletable", "false"),
resource.TestCheckResourceAttr(resourceFullName, "default.result.level", "MEDIUM"),
resource.TestCheckResourceAttr(resourceFullName, "predictor_bot_detection.#", "0"),
resource.TestCheckResourceAttr(resourceFullName, "predictor_bot_detection.include_repeated_events_without_sdk", "true"),
)

resource.Test(t, resource.TestCase{
Expand Down Expand Up @@ -2494,7 +2494,9 @@ resource "pingone_risk_predictor" "%[2]s" {
}
}
predictor_bot_detection = {}
predictor_bot_detection = {
include_repeated_events_without_sdk = true
}
}`, acctest.GenericSandboxEnvironment(), resourceName, name)
}
Expand Down Expand Up @@ -2529,7 +2531,9 @@ resource "pingone_risk_predictor" "%[2]s" {
}
}
predictor_bot_detection = {}
predictor_bot_detection = {
include_repeated_events_without_sdk = true
}
}`, acctest.GenericSandboxEnvironment(), resourceName, name, compactName)
}
Expand Down

0 comments on commit 20b22e3

Please sign in to comment.