// 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{AccessRules: []waas.AccessRule{waas.AccessRule{CaptchaHeader: common.String("EXAMPLE-captchaHeader-Value"),
		BlockErrorPageMessage:     common.String("EXAMPLE-blockErrorPageMessage-Value"),
		Action:                    waas.AccessRuleActionShowCaptcha,
		BlockErrorPageDescription: common.String("EXAMPLE-blockErrorPageDescription-Value"),
		BlockResponseCode:         common.Int(954),
		CaptchaFooter:             common.String("EXAMPLE-captchaFooter-Value"),
		Criteria: []waas.AccessRuleCriteria{waas.AccessRuleCriteria{IsCaseSensitive: common.Bool(false),
			Value:     common.String("EXAMPLE-value-Value"),
			Condition: waas.AccessRuleCriteriaConditionUrlStartsWith}},
		RedirectResponseCode:       waas.AccessRuleRedirectResponseCodeFound,
		BlockAction:                waas.AccessRuleBlockActionSetResponseCode,
		BlockErrorPageCode:         common.String("EXAMPLE-blockErrorPageCode-Value"),
		CaptchaSubmitLabel:         common.String("EXAMPLE-captchaSubmitLabel-Value"),
		CaptchaTitle:               common.String("EXAMPLE-captchaTitle-Value"),
		Name:                       common.String("EXAMPLE-name-Value"),
		RedirectUrl:                common.String("EXAMPLE-redirectUrl-Value"),
		ResponseHeaderManipulation: []waas.HeaderManipulationAction{waas.RemoveHttpResponseHeaderAction{Header: common.String("EXAMPLE-header-Value")}},
		BypassChallenges:           []waas.AccessRuleBypassChallengesEnum{waas.AccessRuleBypassChallengesHumanInteractionChallenge}}},
		AddressRateLimiting: &waas.AddressRateLimiting{MaxDelayedCountPerAddress: common.Int(4348),
			AllowedRatePerAddress: common.Int(1626),
			BlockResponseCode:     common.Int(835),
			IsEnabled:             common.Bool(false)},
		Captchas: []waas.Captcha{waas.Captcha{SubmitLabel: common.String("EXAMPLE-submitLabel-Value"),
			Title:                      common.String("EXAMPLE-title-Value"),
			Url:                        common.String("EXAMPLE-url-Value"),
			FailureMessage:             common.String("EXAMPLE-failureMessage-Value"),
			FooterText:                 common.String("EXAMPLE-footerText-Value"),
			HeaderText:                 common.String("EXAMPLE-headerText-Value"),
			SessionExpirationInSeconds: common.Int(172966)}},
		Origin: common.String("EXAMPLE-origin-Value"),
		CachingRules: []waas.CachingRule{waas.CachingRule{ClientCachingDuration: common.String("EXAMPLE-clientCachingDuration-Value"),
			Criteria: []waas.CachingRuleCriteria{waas.CachingRuleCriteria{Condition: waas.CachingRuleCriteriaConditionPartContains,
				Value: common.String("EXAMPLE-value-Value")}},
			IsClientCachingEnabled: common.Bool(true),
			Key:                    common.String("EXAMPLE-key-Value"),
			Name:                   common.String("EXAMPLE-name-Value"),
			Action:                 waas.CachingRuleActionCache,
			CachingDuration:        common.String("EXAMPLE-cachingDuration-Value")}},
		CustomProtectionRules: []waas.CustomProtectionRuleSetting{waas.CustomProtectionRuleSetting{Action: waas.CustomProtectionRuleSettingActionDetect,
			Exclusions: []waas.ProtectionRuleExclusion{waas.ProtectionRuleExclusion{Exclusions: []string{"EXAMPLE--Value"},
				Target: waas.ProtectionRuleExclusionTargetRequestCookieNames}},
			Id: common.String("ocid1.test.oc1..<unique_ID>EXAMPLE-id-Value")}},
		DeviceFingerprintChallenge: &waas.DeviceFingerprintChallenge{IsEnabled: common.Bool(false),
			MaxAddressCount:                    common.Int(5196),
			MaxAddressCountExpirationInSeconds: common.Int(355329),
			Action:                             waas.DeviceFingerprintChallengeActionDetect,
			ActionExpirationInSeconds:          common.Int(44403),
			ChallengeSettings: &waas.BlockChallengeSettings{BlockErrorPageCode: common.String("EXAMPLE-blockErrorPageCode-Value"),
				BlockErrorPageDescription: common.String("EXAMPLE-blockErrorPageDescription-Value"),
				BlockErrorPageMessage:     common.String("EXAMPLE-blockErrorPageMessage-Value"),
				BlockResponseCode:         common.Int(614),
				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")},
			FailureThreshold:                    common.Int(84403),
			FailureThresholdExpirationInSeconds: common.Int(99753)},
		HumanInteractionChallenge: &waas.HumanInteractionChallenge{ChallengeSettings: &waas.BlockChallengeSettings{CaptchaSubmitLabel: common.String("EXAMPLE-captchaSubmitLabel-Value"),
			CaptchaTitle:              common.String("EXAMPLE-captchaTitle-Value"),
			BlockErrorPageDescription: common.String("EXAMPLE-blockErrorPageDescription-Value"),
			CaptchaHeader:             common.String("EXAMPLE-captchaHeader-Value"),
			BlockAction:               waas.BlockChallengeSettingsBlockActionSetResponseCode,
			BlockErrorPageCode:        common.String("EXAMPLE-blockErrorPageCode-Value"),
			BlockErrorPageMessage:     common.String("EXAMPLE-blockErrorPageMessage-Value"),
			BlockResponseCode:         common.Int(202),
			CaptchaFooter:             common.String("EXAMPLE-captchaFooter-Value")},
			FailureThresholdExpirationInSeconds: common.Int(311255),
			InteractionThreshold:                common.Int(32),
			IsEnabled:                           common.Bool(false),
			RecordingPeriodInSeconds:            common.Int(8772),
			Action:                              waas.HumanInteractionChallengeActionDetect,
			ActionExpirationInSeconds:           common.Int(191175),
			FailureThreshold:                    common.Int(204208),
			IsNatEnabled:                        common.Bool(false),
			SetHttpHeader: &waas.Header{Value: common.String("EXAMPLE-value-Value"),
				Name: common.String("EXAMPLE-name-Value")}},
		JsChallenge: &waas.JsChallenge{Action: waas.JsChallengeActionBlock,
			AreRedirectsChallenged: common.Bool(false),
			Criteria: []waas.AccessRuleCriteria{waas.AccessRuleCriteria{Condition: waas.AccessRuleCriteriaConditionCountryIsNot,
				IsCaseSensitive: common.Bool(true),
				Value:           common.String("EXAMPLE-value-Value")}},
			FailureThreshold:          common.Int(792993),
			IsEnabled:                 common.Bool(true),
			ActionExpirationInSeconds: common.Int(230947),
			ChallengeSettings: &waas.BlockChallengeSettings{BlockErrorPageMessage: common.String("EXAMPLE-blockErrorPageMessage-Value"),
				CaptchaFooter:             common.String("EXAMPLE-captchaFooter-Value"),
				CaptchaHeader:             common.String("EXAMPLE-captchaHeader-Value"),
				CaptchaSubmitLabel:        common.String("EXAMPLE-captchaSubmitLabel-Value"),
				BlockErrorPageCode:        common.String("EXAMPLE-blockErrorPageCode-Value"),
				BlockErrorPageDescription: common.String("EXAMPLE-blockErrorPageDescription-Value"),
				BlockResponseCode:         common.Int(477),
				CaptchaTitle:              common.String("EXAMPLE-captchaTitle-Value"),
				BlockAction:               waas.BlockChallengeSettingsBlockActionShowErrorPage},
			IsNatEnabled: common.Bool(false),
			SetHttpHeader: &waas.Header{Name: common.String("EXAMPLE-name-Value"),
				Value: common.String("EXAMPLE-value-Value")}},
		OriginGroups: []string{"EXAMPLE--Value"},
		ProtectionSettings: &waas.ProtectionSettings{BlockAction: waas.ProtectionSettingsBlockActionSetResponseCode,
			BlockErrorPageCode:            common.String("EXAMPLE-blockErrorPageCode-Value"),
			BlockErrorPageDescription:     common.String("EXAMPLE-blockErrorPageDescription-Value"),
			BlockErrorPageMessage:         common.String("EXAMPLE-blockErrorPageMessage-Value"),
			MaxArgumentCount:              common.Int(3169),
			AllowedHttpMethods:            []waas.ProtectionSettingsAllowedHttpMethodsEnum{waas.ProtectionSettingsAllowedHttpMethodsConnect},
			BlockResponseCode:             common.Int(783),
			IsResponseInspected:           common.Bool(true),
			MaxNameLengthPerArgument:      common.Int(49966),
			MaxResponseSizeInKiB:          common.Int(277),
			MaxTotalNameLengthOfArguments: common.Int(261620),
			MediaTypes:                    []string{"EXAMPLE--Value"},
			RecommendationsPeriodInDays:   common.Int(30)},
		Whitelists: []waas.Whitelist{waas.Whitelist{AddressLists: []string{"EXAMPLE--Value"},
			Addresses: []string{"EXAMPLE--Value"},
			Name:      common.String("EXAMPLE-name-Value")}}},
		CompartmentId: common.String("ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value"),
		Domain:        common.String("EXAMPLE-domain-Value"),
		FreeformTags:  map[string]string{"EXAMPLE_KEY_xVsnd": "EXAMPLE_VALUE_V1BrMnaro9NppYnpUTjg"},
		OriginGroups: map[string]waas.OriginGroup{"EXAMPLE_KEY_0bKlY": waas.OriginGroup{Origins: []waas.OriginGroupOrigins{waas.OriginGroupOrigins{Weight: common.Int(9177),
			Origin: common.String("EXAMPLE-origin-Value")}}}},
		Origins: map[string]waas.Origin{"EXAMPLE_KEY_6TYXX": waas.Origin{CustomHeaders: []waas.Header{waas.Header{Name: common.String("EXAMPLE-name-Value"),
			Value: common.String("EXAMPLE-value-Value")}},
			HttpPort:  common.Int(39065),
			HttpsPort: common.Int(59968),
			Uri:       common.String("EXAMPLE-uri-Value")}},
		AdditionalDomains: []string{"EXAMPLE--Value"},
		DefinedTags:       map[string]map[string]interface{}{"EXAMPLE_KEY_xGxoY": map[string]interface{}{"EXAMPLE_KEY_kIHbc": "EXAMPLE--Value"}},
		DisplayName:       common.String("EXAMPLE-displayName-Value"),
		PolicyConfig: &waas.PolicyConfig{ClientAddressHeader: waas.PolicyConfigClientAddressHeaderClientIp,
			IsOriginCompressionEnabled: common.Bool(true),
			IsResponseBufferingEnabled: common.Bool(false),
			IsSniEnabled:               common.Bool(false),
			LoadBalancingMethod:        waas.RoundRobinLoadBalancingMethod{},
			TlsProtocols:               []waas.PolicyConfigTlsProtocolsEnum{waas.PolicyConfigTlsProtocolsV12},
			WebsocketPathPrefixes:      []string{"EXAMPLE--Value"},
			CertificateId:              common.String("ocid1.test.oc1..<unique_ID>EXAMPLE-certificateId-Value"),
			CipherGroup:                waas.PolicyConfigCipherGroupDefault,
			HealthChecks: &waas.HealthCheck{UnhealthyThreshold: common.Int(11),
				IsEnabled:                  common.Bool(true),
				IsResponseTextCheckEnabled: common.Bool(false),
				TimeoutInSeconds:           common.Int(104),
				ExpectedResponseCodeGroup:  []waas.HealthCheckExpectedResponseCodeGroupEnum{waas.HealthCheckExpectedResponseCodeGroup2xx},
				ExpectedResponseText:       common.String("EXAMPLE-expectedResponseText-Value"),
				Headers:                    map[string]string{"EXAMPLE_KEY_7eEkc": "EXAMPLE_VALUE_wWGkoNk7GvGhQ2BybDwT"},
				HealthyThreshold:           common.Int(19),
				IntervalInSeconds:          common.Int(83),
				Method:                     waas.HealthCheckMethodGet,
				Path:                       common.String("EXAMPLE-path-Value")},
			IsBehindCdn:             common.Bool(true),
			IsCacheControlRespected: common.Bool(false),
			IsHttpsEnabled:          common.Bool(false),
			IsHttpsForced:           common.Bool(true)}},
		OpcRequestId:  common.String("JVMJLSCEHHUDJHKB3NBQ<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)
}