// 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).
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Oci.WaasService;
using Oci.Common;
using Oci.Common.Auth;
namespace Oci.Sdk.DotNet.Example.Waas
{
public class CreateWaasPolicyExample
{
public static async Task Main()
{
// Create a request and dependent object(s).
var createWaasPolicyDetails = new Oci.WaasService.Models.CreateWaasPolicyDetails
{
CompartmentId = "ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value",
DisplayName = "EXAMPLE-displayName-Value",
Domain = "EXAMPLE-domain-Value",
AdditionalDomains = new List<string>
{
"EXAMPLE--Value"
},
Origins = new Dictionary<string, Oci.WaasService.Models.Origin>()
{
{
"EXAMPLE_KEY_QbrtM",
new Oci.WaasService.Models.Origin
{
Uri = "EXAMPLE-uri-Value",
HttpPort = 1620,
HttpsPort = 7999,
CustomHeaders = new List<Oci.WaasService.Models.Header>
{
new Oci.WaasService.Models.Header
{
Name = "EXAMPLE-name-Value",
Value = "EXAMPLE-value-Value"
}
}
}
}
},
OriginGroups = new Dictionary<string, Oci.WaasService.Models.OriginGroup>()
{
{
"EXAMPLE_KEY_pBuOC",
new Oci.WaasService.Models.OriginGroup
{
Origins = new List<Oci.WaasService.Models.OriginGroup_origins>
{
new Oci.WaasService.Models.OriginGroup_origins
{
Origin = "EXAMPLE-origin-Value",
Weight = 8
}
}
}
}
},
PolicyConfig = new Oci.WaasService.Models.PolicyConfig
{
CertificateId = "ocid1.test.oc1..<unique_ID>EXAMPLE-certificateId-Value",
IsHttpsEnabled = false,
IsHttpsForced = false,
TlsProtocols = new List<Oci.WaasService.Models.PolicyConfig.TlsProtocolsEnum>
{
Oci.WaasService.Models.PolicyConfig.TlsProtocolsEnum.TlsV13
},
IsOriginCompressionEnabled = false,
IsBehindCdn = true,
ClientAddressHeader = Oci.WaasService.Models.PolicyConfig.ClientAddressHeaderEnum.XRealIp,
IsCacheControlRespected = true,
IsResponseBufferingEnabled = true,
CipherGroup = Oci.WaasService.Models.PolicyConfig.CipherGroupEnum.Default,
LoadBalancingMethod = new Oci.WaasService.Models.RoundRobinLoadBalancingMethod
{
},
WebsocketPathPrefixes = new List<string>
{
"EXAMPLE--Value"
},
IsSniEnabled = false,
HealthChecks = new Oci.WaasService.Models.HealthCheck
{
IsEnabled = false,
Method = Oci.WaasService.Models.HealthCheck.MethodEnum.Get,
Path = "EXAMPLE-path-Value",
Headers = new Dictionary<string, string>()
{
{
"EXAMPLE_KEY_UCcbB",
"EXAMPLE_VALUE_P2ymGzBxLN0rrXMFpK5L"
}
},
ExpectedResponseCodeGroup = new List<Oci.WaasService.Models.HealthCheck.ExpectedResponseCodeGroupEnum>
{
Oci.WaasService.Models.HealthCheck.ExpectedResponseCodeGroupEnum._2Xx
},
IsResponseTextCheckEnabled = false,
ExpectedResponseText = "EXAMPLE-expectedResponseText-Value",
IntervalInSeconds = 82,
TimeoutInSeconds = 35,
HealthyThreshold = 13,
UnhealthyThreshold = 17
}
},
WafConfig = new Oci.WaasService.Models.WafConfigDetails
{
AccessRules = new List<Oci.WaasService.Models.AccessRule>
{
new Oci.WaasService.Models.AccessRule
{
Name = "EXAMPLE-name-Value",
Criteria = new List<Oci.WaasService.Models.AccessRuleCriteria>
{
new Oci.WaasService.Models.AccessRuleCriteria
{
Condition = Oci.WaasService.Models.AccessRuleCriteria.ConditionEnum.HttpMethodIsNot,
Value = "EXAMPLE-value-Value",
IsCaseSensitive = false
}
},
Action = Oci.WaasService.Models.AccessRule.ActionEnum.Allow,
BlockAction = Oci.WaasService.Models.AccessRule.BlockActionEnum.SetResponseCode,
BlockResponseCode = 541,
BlockErrorPageMessage = "EXAMPLE-blockErrorPageMessage-Value",
BlockErrorPageCode = "EXAMPLE-blockErrorPageCode-Value",
BlockErrorPageDescription = "EXAMPLE-blockErrorPageDescription-Value",
BypassChallenges = new List<Oci.WaasService.Models.AccessRule.BypassChallengesEnum>
{
Oci.WaasService.Models.AccessRule.BypassChallengesEnum.JsChallenge
},
RedirectUrl = "EXAMPLE-redirectUrl-Value",
RedirectResponseCode = Oci.WaasService.Models.AccessRule.RedirectResponseCodeEnum.MovedPermanently,
CaptchaTitle = "EXAMPLE-captchaTitle-Value",
CaptchaHeader = "EXAMPLE-captchaHeader-Value",
CaptchaFooter = "EXAMPLE-captchaFooter-Value",
CaptchaSubmitLabel = "EXAMPLE-captchaSubmitLabel-Value",
ResponseHeaderManipulation = new List<Oci.WaasService.Models.HeaderManipulationAction>
{
new Oci.WaasService.Models.ExtendHttpResponseHeaderAction
{
Header = "EXAMPLE-header-Value",
Value = "EXAMPLE-value-Value"
}
}
}
},
AddressRateLimiting = new Oci.WaasService.Models.AddressRateLimiting
{
IsEnabled = false,
AllowedRatePerAddress = 5104,
MaxDelayedCountPerAddress = 696,
BlockResponseCode = 553
},
Captchas = new List<Oci.WaasService.Models.Captcha>
{
new Oci.WaasService.Models.Captcha
{
Url = "EXAMPLE-url-Value",
SessionExpirationInSeconds = 27111,
Title = "EXAMPLE-title-Value",
HeaderText = "EXAMPLE-headerText-Value",
FooterText = "EXAMPLE-footerText-Value",
FailureMessage = "EXAMPLE-failureMessage-Value",
SubmitLabel = "EXAMPLE-submitLabel-Value"
}
},
DeviceFingerprintChallenge = new Oci.WaasService.Models.DeviceFingerprintChallenge
{
IsEnabled = false,
Action = Oci.WaasService.Models.DeviceFingerprintChallenge.ActionEnum.Block,
FailureThreshold = 778022,
ActionExpirationInSeconds = 58428,
FailureThresholdExpirationInSeconds = 30334,
MaxAddressCount = 1966,
MaxAddressCountExpirationInSeconds = 39032,
ChallengeSettings = new Oci.WaasService.Models.BlockChallengeSettings
{
BlockAction = Oci.WaasService.Models.BlockChallengeSettings.BlockActionEnum.SetResponseCode,
BlockResponseCode = 342,
BlockErrorPageMessage = "EXAMPLE-blockErrorPageMessage-Value",
BlockErrorPageDescription = "EXAMPLE-blockErrorPageDescription-Value",
BlockErrorPageCode = "EXAMPLE-blockErrorPageCode-Value",
CaptchaTitle = "EXAMPLE-captchaTitle-Value",
CaptchaHeader = "EXAMPLE-captchaHeader-Value",
CaptchaFooter = "EXAMPLE-captchaFooter-Value",
CaptchaSubmitLabel = "EXAMPLE-captchaSubmitLabel-Value"
}
},
HumanInteractionChallenge = new Oci.WaasService.Models.HumanInteractionChallenge
{
IsEnabled = true,
Action = Oci.WaasService.Models.HumanInteractionChallenge.ActionEnum.Block,
FailureThreshold = 768541,
ActionExpirationInSeconds = 152944,
FailureThresholdExpirationInSeconds = 49346,
InteractionThreshold = 70,
RecordingPeriodInSeconds = 7507,
SetHttpHeader = new Oci.WaasService.Models.Header
{
Name = "EXAMPLE-name-Value",
Value = "EXAMPLE-value-Value"
},
ChallengeSettings = new Oci.WaasService.Models.BlockChallengeSettings
{
BlockAction = Oci.WaasService.Models.BlockChallengeSettings.BlockActionEnum.ShowErrorPage,
BlockResponseCode = 515,
BlockErrorPageMessage = "EXAMPLE-blockErrorPageMessage-Value",
BlockErrorPageDescription = "EXAMPLE-blockErrorPageDescription-Value",
BlockErrorPageCode = "EXAMPLE-blockErrorPageCode-Value",
CaptchaTitle = "EXAMPLE-captchaTitle-Value",
CaptchaHeader = "EXAMPLE-captchaHeader-Value",
CaptchaFooter = "EXAMPLE-captchaFooter-Value",
CaptchaSubmitLabel = "EXAMPLE-captchaSubmitLabel-Value"
},
IsNatEnabled = true
},
JsChallenge = new Oci.WaasService.Models.JsChallenge
{
IsEnabled = true,
Action = Oci.WaasService.Models.JsChallenge.ActionEnum.Block,
FailureThreshold = 310035,
ActionExpirationInSeconds = 218853,
SetHttpHeader = new Oci.WaasService.Models.Header
{
Name = "EXAMPLE-name-Value",
Value = "EXAMPLE-value-Value"
},
ChallengeSettings = new Oci.WaasService.Models.BlockChallengeSettings
{
BlockAction = Oci.WaasService.Models.BlockChallengeSettings.BlockActionEnum.ShowCaptcha,
BlockResponseCode = 954,
BlockErrorPageMessage = "EXAMPLE-blockErrorPageMessage-Value",
BlockErrorPageDescription = "EXAMPLE-blockErrorPageDescription-Value",
BlockErrorPageCode = "EXAMPLE-blockErrorPageCode-Value",
CaptchaTitle = "EXAMPLE-captchaTitle-Value",
CaptchaHeader = "EXAMPLE-captchaHeader-Value",
CaptchaFooter = "EXAMPLE-captchaFooter-Value",
CaptchaSubmitLabel = "EXAMPLE-captchaSubmitLabel-Value"
},
AreRedirectsChallenged = false,
Criteria = new List<Oci.WaasService.Models.AccessRuleCriteria>
{
new Oci.WaasService.Models.AccessRuleCriteria
{
Condition = Oci.WaasService.Models.AccessRuleCriteria.ConditionEnum.IpIsNot,
Value = "EXAMPLE-value-Value",
IsCaseSensitive = true
}
},
IsNatEnabled = false
},
Origin = "EXAMPLE-origin-Value",
CachingRules = new List<Oci.WaasService.Models.CachingRule>
{
new Oci.WaasService.Models.CachingRule
{
Key = "EXAMPLE-key-Value",
Name = "EXAMPLE-name-Value",
Action = Oci.WaasService.Models.CachingRule.ActionEnum.BypassCache,
CachingDuration = "EXAMPLE-cachingDuration-Value",
IsClientCachingEnabled = true,
ClientCachingDuration = "EXAMPLE-clientCachingDuration-Value",
Criteria = new List<Oci.WaasService.Models.CachingRuleCriteria>
{
new Oci.WaasService.Models.CachingRuleCriteria
{
Condition = Oci.WaasService.Models.CachingRuleCriteria.ConditionEnum.UrlStartsWith,
Value = "EXAMPLE-value-Value"
}
}
}
},
CustomProtectionRules = new List<Oci.WaasService.Models.CustomProtectionRuleSetting>
{
new Oci.WaasService.Models.CustomProtectionRuleSetting
{
Id = "ocid1.test.oc1..<unique_ID>EXAMPLE-id-Value",
Action = Oci.WaasService.Models.CustomProtectionRuleSetting.ActionEnum.Detect,
Exclusions = new List<Oci.WaasService.Models.ProtectionRuleExclusion>
{
new Oci.WaasService.Models.ProtectionRuleExclusion
{
Target = Oci.WaasService.Models.ProtectionRuleExclusion.TargetEnum.RequestCookies,
Exclusions = new List<string>
{
"EXAMPLE--Value"
}
}
}
}
},
OriginGroups = new List<string>
{
"EXAMPLE--Value"
},
ProtectionSettings = new Oci.WaasService.Models.ProtectionSettings
{
BlockAction = Oci.WaasService.Models.ProtectionSettings.BlockActionEnum.SetResponseCode,
BlockResponseCode = 881,
BlockErrorPageMessage = "EXAMPLE-blockErrorPageMessage-Value",
BlockErrorPageCode = "EXAMPLE-blockErrorPageCode-Value",
BlockErrorPageDescription = "EXAMPLE-blockErrorPageDescription-Value",
MaxArgumentCount = 4115,
MaxNameLengthPerArgument = 92380,
MaxTotalNameLengthOfArguments = 326628,
RecommendationsPeriodInDays = 50,
IsResponseInspected = false,
MaxResponseSizeInKiB = 1071,
AllowedHttpMethods = new List<Oci.WaasService.Models.ProtectionSettings.AllowedHttpMethodsEnum>
{
Oci.WaasService.Models.ProtectionSettings.AllowedHttpMethodsEnum.Head
},
MediaTypes = new List<string>
{
"EXAMPLE--Value"
}
},
Whitelists = new List<Oci.WaasService.Models.Whitelist>
{
new Oci.WaasService.Models.Whitelist
{
Name = "EXAMPLE-name-Value",
Addresses = new List<string>
{
"EXAMPLE--Value"
},
AddressLists = new List<string>
{
"EXAMPLE--Value"
}
}
}
},
FreeformTags = new Dictionary<string, string>()
{
{
"EXAMPLE_KEY_Jzb4w",
"EXAMPLE_VALUE_Ml22ywHiRW75SQK8lIZE"
}
},
DefinedTags = new Dictionary<string, Dictionary<string, Object>>()
{
{
"EXAMPLE_KEY_krlFg",
new Dictionary<string, Object>()
{
{
"EXAMPLE_KEY_GaNnO",
"EXAMPLE--Value"
}
}
}
}
};
var createWaasPolicyRequest = new Oci.WaasService.Requests.CreateWaasPolicyRequest
{
CreateWaasPolicyDetails = createWaasPolicyDetails,
OpcRequestId = "YDBIRAMVTNLAODQVFHFF<unique_ID>",
OpcRetryToken = "EXAMPLE-opcRetryToken-Value"
};
// 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.
var provider = new ConfigFileAuthenticationDetailsProvider("DEFAULT");
try
{
// Create a service client and send the request.
using (var client = new WaasClient(provider, new ClientConfiguration()))
{
var response = await client.CreateWaasPolicy(createWaasPolicyRequest);
// Retrieve value from the response.
var versionValue = response.httpResponseMessage.Version;
}
}
catch (Exception e)
{
Console.WriteLine($"CreateWaasPolicy Failed with {e.Message}");
throw e;
}
}
}
}