// This is an automatically generated code sample.
// To make this code sample work in your Oracle Cloud tenancy,
// please replace the values for any parameters whose current values do not fit
// your use case (such as resource IDs, strings containing ‘EXAMPLE’ or ‘unique_id’, and
// boolean, number, and enum parameters with values not fitting your use case).
package main
import (
"context"
"fmt"
"github.com/oracle/oci-go-sdk/v65/common"
"github.com/oracle/oci-go-sdk/v65/example/helpers"
"github.com/oracle/oci-go-sdk/v65/waas"
)
func ExampleCreateWaasPolicy() {
// Create a default authentication provider that uses the DEFAULT
// profile in the configuration file.
// Refer to <see href="https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File>the public documentation</see> on how to prepare a configuration file.
client, err := waas.NewWaasClientWithConfigurationProvider(common.DefaultConfigProvider())
helpers.FatalIfError(err)
// Create a request and dependent object(s).
req := waas.CreateWaasPolicyRequest{CreateWaasPolicyDetails: waas.CreateWaasPolicyDetails{WafConfig: &waas.WafConfigDetails{OriginGroups: []string{"EXAMPLE--Value"},
ProtectionSettings: &waas.ProtectionSettings{MaxNameLengthPerArgument: common.Int(104181),
MediaTypes: []string{"EXAMPLE--Value"},
BlockErrorPageCode: common.String("EXAMPLE-blockErrorPageCode-Value"),
BlockResponseCode: common.Int(284),
BlockErrorPageDescription: common.String("EXAMPLE-blockErrorPageDescription-Value"),
BlockErrorPageMessage: common.String("EXAMPLE-blockErrorPageMessage-Value"),
IsResponseInspected: common.Bool(true),
MaxArgumentCount: common.Int(1607),
MaxResponseSizeInKiB: common.Int(44),
MaxTotalNameLengthOfArguments: common.Int(294996),
AllowedHttpMethods: []waas.ProtectionSettingsAllowedHttpMethodsEnum{waas.ProtectionSettingsAllowedHttpMethodsPut},
BlockAction: waas.ProtectionSettingsBlockActionShowErrorPage,
RecommendationsPeriodInDays: common.Int(61)},
Whitelists: []waas.Whitelist{waas.Whitelist{AddressLists: []string{"EXAMPLE--Value"},
Addresses: []string{"EXAMPLE--Value"},
Name: common.String("EXAMPLE-name-Value")}},
AddressRateLimiting: &waas.AddressRateLimiting{BlockResponseCode: common.Int(390),
IsEnabled: common.Bool(true),
MaxDelayedCountPerAddress: common.Int(4489),
AllowedRatePerAddress: common.Int(6176)},
CustomProtectionRules: []waas.CustomProtectionRuleSetting{waas.CustomProtectionRuleSetting{Action: waas.CustomProtectionRuleSettingActionDetect,
Exclusions: []waas.ProtectionRuleExclusion{waas.ProtectionRuleExclusion{Exclusions: []string{"EXAMPLE--Value"},
Target: waas.ProtectionRuleExclusionTargetArgsNames}},
Id: common.String("ocid1.test.oc1..<unique_ID>EXAMPLE-id-Value")}},
HumanInteractionChallenge: &waas.HumanInteractionChallenge{FailureThresholdExpirationInSeconds: common.Int(310526),
InteractionThreshold: common.Int(96),
IsEnabled: common.Bool(false),
RecordingPeriodInSeconds: common.Int(11286),
SetHttpHeader: &waas.Header{Name: common.String("EXAMPLE-name-Value"),
Value: common.String("EXAMPLE-value-Value")},
Action: waas.HumanInteractionChallengeActionBlock,
ActionExpirationInSeconds: common.Int(345665),
FailureThreshold: common.Int(43657),
ChallengeSettings: &waas.BlockChallengeSettings{BlockResponseCode: common.Int(682),
CaptchaFooter: common.String("EXAMPLE-captchaFooter-Value"),
BlockAction: waas.BlockChallengeSettingsBlockActionSetResponseCode,
BlockErrorPageDescription: common.String("EXAMPLE-blockErrorPageDescription-Value"),
CaptchaHeader: common.String("EXAMPLE-captchaHeader-Value"),
CaptchaSubmitLabel: common.String("EXAMPLE-captchaSubmitLabel-Value"),
CaptchaTitle: common.String("EXAMPLE-captchaTitle-Value"),
BlockErrorPageCode: common.String("EXAMPLE-blockErrorPageCode-Value"),
BlockErrorPageMessage: common.String("EXAMPLE-blockErrorPageMessage-Value")},
IsNatEnabled: common.Bool(true)},
JsChallenge: &waas.JsChallenge{ActionExpirationInSeconds: common.Int(15101),
FailureThreshold: common.Int(776801),
IsEnabled: common.Bool(false),
IsNatEnabled: common.Bool(false),
SetHttpHeader: &waas.Header{Name: common.String("EXAMPLE-name-Value"),
Value: common.String("EXAMPLE-value-Value")},
Action: waas.JsChallengeActionBlock,
AreRedirectsChallenged: common.Bool(false),
ChallengeSettings: &waas.BlockChallengeSettings{BlockErrorPageDescription: common.String("EXAMPLE-blockErrorPageDescription-Value"),
BlockErrorPageMessage: common.String("EXAMPLE-blockErrorPageMessage-Value"),
BlockResponseCode: common.Int(380),
CaptchaFooter: common.String("EXAMPLE-captchaFooter-Value"),
BlockAction: waas.BlockChallengeSettingsBlockActionSetResponseCode,
CaptchaHeader: common.String("EXAMPLE-captchaHeader-Value"),
CaptchaSubmitLabel: common.String("EXAMPLE-captchaSubmitLabel-Value"),
CaptchaTitle: common.String("EXAMPLE-captchaTitle-Value"),
BlockErrorPageCode: common.String("EXAMPLE-blockErrorPageCode-Value")},
Criteria: []waas.AccessRuleCriteria{waas.AccessRuleCriteria{Condition: waas.AccessRuleCriteriaConditionUrlPartEndsWith,
IsCaseSensitive: common.Bool(false),
Value: common.String("EXAMPLE-value-Value")}}},
Origin: common.String("EXAMPLE-origin-Value"),
AccessRules: []waas.AccessRule{waas.AccessRule{CaptchaTitle: common.String("EXAMPLE-captchaTitle-Value"),
Name: common.String("EXAMPLE-name-Value"),
Action: waas.AccessRuleActionDetect,
BlockErrorPageMessage: common.String("EXAMPLE-blockErrorPageMessage-Value"),
BlockResponseCode: common.Int(145),
CaptchaSubmitLabel: common.String("EXAMPLE-captchaSubmitLabel-Value"),
BlockAction: waas.AccessRuleBlockActionSetResponseCode,
CaptchaHeader: common.String("EXAMPLE-captchaHeader-Value"),
Criteria: []waas.AccessRuleCriteria{waas.AccessRuleCriteria{Value: common.String("EXAMPLE-value-Value"),
Condition: waas.AccessRuleCriteriaConditionIpInList,
IsCaseSensitive: common.Bool(false)}},
BlockErrorPageDescription: common.String("EXAMPLE-blockErrorPageDescription-Value"),
BypassChallenges: []waas.AccessRuleBypassChallengesEnum{waas.AccessRuleBypassChallengesDeviceFingerprintChallenge},
CaptchaFooter: common.String("EXAMPLE-captchaFooter-Value"),
ResponseHeaderManipulation: []waas.HeaderManipulationAction{waas.RemoveHttpResponseHeaderAction{Header: common.String("EXAMPLE-header-Value")}},
BlockErrorPageCode: common.String("EXAMPLE-blockErrorPageCode-Value"),
RedirectResponseCode: waas.AccessRuleRedirectResponseCodeMovedPermanently,
RedirectUrl: common.String("EXAMPLE-redirectUrl-Value")}},
CachingRules: []waas.CachingRule{waas.CachingRule{IsClientCachingEnabled: common.Bool(false),
Key: common.String("EXAMPLE-key-Value"),
Name: common.String("EXAMPLE-name-Value"),
Action: waas.CachingRuleActionBypassCache,
CachingDuration: common.String("EXAMPLE-cachingDuration-Value"),
ClientCachingDuration: common.String("EXAMPLE-clientCachingDuration-Value"),
Criteria: []waas.CachingRuleCriteria{waas.CachingRuleCriteria{Condition: waas.CachingRuleCriteriaConditionPartContains,
Value: common.String("EXAMPLE-value-Value")}}}},
Captchas: []waas.Captcha{waas.Captcha{FailureMessage: common.String("EXAMPLE-failureMessage-Value"),
FooterText: common.String("EXAMPLE-footerText-Value"),
HeaderText: common.String("EXAMPLE-headerText-Value"),
SessionExpirationInSeconds: common.Int(417215),
SubmitLabel: common.String("EXAMPLE-submitLabel-Value"),
Title: common.String("EXAMPLE-title-Value"),
Url: common.String("EXAMPLE-url-Value")}},
DeviceFingerprintChallenge: &waas.DeviceFingerprintChallenge{MaxAddressCount: common.Int(8388),
MaxAddressCountExpirationInSeconds: common.Int(124129),
Action: waas.DeviceFingerprintChallengeActionBlock,
ActionExpirationInSeconds: common.Int(369884),
ChallengeSettings: &waas.BlockChallengeSettings{CaptchaSubmitLabel: common.String("EXAMPLE-captchaSubmitLabel-Value"),
BlockAction: waas.BlockChallengeSettingsBlockActionShowErrorPage,
BlockErrorPageCode: common.String("EXAMPLE-blockErrorPageCode-Value"),
BlockResponseCode: common.Int(458),
CaptchaFooter: common.String("EXAMPLE-captchaFooter-Value"),
BlockErrorPageDescription: common.String("EXAMPLE-blockErrorPageDescription-Value"),
BlockErrorPageMessage: common.String("EXAMPLE-blockErrorPageMessage-Value"),
CaptchaHeader: common.String("EXAMPLE-captchaHeader-Value"),
CaptchaTitle: common.String("EXAMPLE-captchaTitle-Value")},
FailureThreshold: common.Int(480718),
FailureThresholdExpirationInSeconds: common.Int(210268),
IsEnabled: common.Bool(false)}},
DefinedTags: map[string]map[string]interface{}{"EXAMPLE_KEY_dfFVl": map[string]interface{}{"EXAMPLE_KEY_sngZP": "EXAMPLE--Value"}},
Domain: common.String("EXAMPLE-domain-Value"),
Origins: map[string]waas.Origin{"EXAMPLE_KEY_BW0n1": waas.Origin{CustomHeaders: []waas.Header{waas.Header{Name: common.String("EXAMPLE-name-Value"),
Value: common.String("EXAMPLE-value-Value")}},
HttpPort: common.Int(2136),
HttpsPort: common.Int(586),
Uri: common.String("EXAMPLE-uri-Value")}},
FreeformTags: map[string]string{"EXAMPLE_KEY_eWdnJ": "EXAMPLE_VALUE_3Wb6Lwzhv10HRVubnvwN"},
OriginGroups: map[string]waas.OriginGroup{"EXAMPLE_KEY_95TTL": waas.OriginGroup{Origins: []waas.OriginGroupOrigins{waas.OriginGroupOrigins{Origin: common.String("EXAMPLE-origin-Value"),
Weight: common.Int(2594)}}}},
PolicyConfig: &waas.PolicyConfig{IsCacheControlRespected: common.Bool(true),
IsResponseBufferingEnabled: common.Bool(false),
IsSniEnabled: common.Bool(false),
ClientAddressHeader: waas.PolicyConfigClientAddressHeaderTrueClientIp,
IsHttpsEnabled: common.Bool(true),
IsHttpsForced: common.Bool(false),
IsOriginCompressionEnabled: common.Bool(true),
LoadBalancingMethod: waas.RoundRobinLoadBalancingMethod{},
TlsProtocols: []waas.PolicyConfigTlsProtocolsEnum{waas.PolicyConfigTlsProtocolsV1},
WebsocketPathPrefixes: []string{"EXAMPLE--Value"},
CertificateId: common.String("ocid1.test.oc1..<unique_ID>EXAMPLE-certificateId-Value"),
CipherGroup: waas.PolicyConfigCipherGroupDefault,
HealthChecks: &waas.HealthCheck{IsEnabled: common.Bool(false),
IsResponseTextCheckEnabled: common.Bool(true),
TimeoutInSeconds: common.Int(24),
HealthyThreshold: common.Int(11),
IntervalInSeconds: common.Int(61),
Method: waas.HealthCheckMethodPost,
Path: common.String("EXAMPLE-path-Value"),
UnhealthyThreshold: common.Int(6),
ExpectedResponseCodeGroup: []waas.HealthCheckExpectedResponseCodeGroupEnum{waas.HealthCheckExpectedResponseCodeGroup2xx},
ExpectedResponseText: common.String("EXAMPLE-expectedResponseText-Value"),
Headers: map[string]string{"EXAMPLE_KEY_rw3xE": "EXAMPLE_VALUE_4sJf3YPKbX2tfAVuNsS0"}},
IsBehindCdn: common.Bool(false)},
AdditionalDomains: []string{"EXAMPLE--Value"},
CompartmentId: common.String("ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value"),
DisplayName: common.String("EXAMPLE-displayName-Value")},
OpcRequestId: common.String("JC1GOVMXBKQS7R7QEMNG<unique_ID>"),
OpcRetryToken: common.String("EXAMPLE-opcRetryToken-Value")}
// Send the request using the service client
resp, err := client.CreateWaasPolicy(context.Background(), req)
helpers.FatalIfError(err)
// Retrieve value from the response.
fmt.Println(resp)
}