Create a WAF Policy
https://api.datadoghq.com/api/v2/remote_config/products/asm/waf/policieshttps://api.us3.datadoghq.com/api/v2/remote_config/products/asm/waf/policieshttps://api.us5.datadoghq.com/api/v2/remote_config/products/asm/waf/policieshttps://api.datadoghq.eu/api/v2/remote_config/products/asm/waf/policieshttps://api.ap1.datadoghq.com/api/v2/remote_config/products/asm/waf/policieshttps://api.ap2.datadoghq.com/api/v2/remote_config/products/asm/waf/policieshttps://api.uk1.datadoghq.com/api/v2/remote_config/products/asm/waf/policieshttps://api.ddog-gov.com/api/v2/remote_config/products/asm/waf/policieshttps://api.us2.ddog-gov.com/api/v2/remote_config/products/asm/waf/policiesPrésentation
Create a new WAF policy.
Requête
Body Data (required)
The new WAF policy.
data [required]Object for a single WAF policy.
attributes [required]Create a new WAF policy.
basedOn [required]When creating a new policy, clone the policy indicated by this identifier.
description [required]Description of the WAF policy.
isDefaultMake this policy the default policy. The default policy is applied to every service not specifically assigned to another policy.
name [required]The name of the WAF policy.
protectionPresetsPresets enabled on this policy.
rulesRule overrides applied by the policy.
blocking [required]When blocking is enabled, the rule will block the traffic matched by this rule.
enabled [required]When false, this rule will not match any traffic.
extended_data_collectionWhen true, collects additional data from the WAF for this rule.
id [required]Override the parameters for this WAF rule identifier.
rulesetsDEPRECATED Deprecated: Ruleset overrides. Use protectionPresets instead.
blocking [required]When blocking is enabled, the ruleset will block the traffic it matches.
enabled [required]When false, this ruleset will not match any traffic.
id [required]The identifier of the ruleset to override.
scopeThe scope of the WAF policy.
env [required]The environment scope for the WAF policy.
service [required]The service scope for the WAF policy.
versionVersion of the WAF ruleset maintained by Datadog used by this policy. 0 is the default value.
0type [required]The type of the resource. The value should always be policy.
policypolicy{
"data": {
"attributes": {
"basedOn": "recommended",
"description": "Policy applied to internal web applications.",
"isDefault": false,
"name": "Internal Network Policy",
"protectionPresets": [
"attack-tools"
],
"rules": [
{
"blocking": false,
"enabled": true,
"id": "rasp-001-002"
}
],
"scope": [
{
"env": "prod",
"service": "billing-service"
}
],
"version": 0
},
"type": "policy"
}
}Réponse
Created
Response object that includes a single WAF policy.
dataObject for a single WAF policy.
attributesA WAF policy.
description [required]Description of the WAF policy.
isDefaultMake this policy the default policy. The default policy is applied to every service not specifically assigned to another policy.
name [required]The name of the WAF policy.
protectionPresetsPresets enabled on this policy.
rulesRule overrides applied by the policy.
blocking [required]When blocking is enabled, the rule will block the traffic matched by this rule.
enabled [required]When false, this rule will not match any traffic.
extended_data_collectionWhen true, collects additional data from the WAF for this rule.
id [required]Override the parameters for this WAF rule identifier.
rulesetsDEPRECATED Deprecated: Ruleset overrides. Use protectionPresets instead.
blocking [required]When blocking is enabled, the ruleset will block the traffic it matches.
enabled [required]When false, this ruleset will not match any traffic.
id [required]The identifier of the ruleset to override.
scopeThe scope of the WAF policy.
env [required]The environment scope for the WAF policy.
service [required]The service scope for the WAF policy.
versionVersion of the WAF ruleset maintained by Datadog used by this policy. 0 is the default value.
0idThe ID of the policy.
metaMetadata associated with the WAF policy.
added_atThe date and time the WAF policy was created.
added_byThe handle of the user who created the WAF policy.
added_by_nameThe name of the user who created the WAF policy.
modified_atThe date and time the WAF policy was last updated.
modified_byThe handle of the user who last updated the WAF policy.
modified_by_nameThe name of the user who last updated the WAF policy.
typeThe type of the resource. The value should always be policy.
policypolicy{
"data": {
"attributes": {
"description": "Policy applied to internal web applications.",
"isDefault": false,
"name": "Internal Network Policy",
"protectionPresets": [
"attack-tools"
],
"rules": [
{
"blocking": false,
"enabled": true,
"extended_data_collection": false,
"id": "rasp-001-002"
}
],
"rulesets": [
{
"blocking": false,
"enabled": true,
"id": "attack_tool"
}
],
"scope": [
{
"env": "prod",
"service": "billing-service"
}
],
"version": 0
},
"id": "2857c47d-1e3a-4300-8b2f-dc24089c084b",
"meta": {
"added_at": "2021-01-01T00:00:00Z",
"added_by": "john.doe@datadoghq.com",
"added_by_name": "John Doe",
"modified_at": "2021-01-01T00:00:00Z",
"modified_by": "john.doe@datadoghq.com",
"modified_by_name": "John Doe"
},
"type": "policy"
}
}Bad Request
API error response.
errors [required]A list of errors.
{
"errors": [
"Bad Request"
]
}Not Authorized
API error response.
errors [required]A list of errors.
{
"errors": [
"Bad Request"
]
}Concurrent Modification
API error response.
errors [required]A list of errors.
{
"errors": [
"Bad Request"
]
}Too many requests
API error response.
errors [required]A list of errors.
{
"errors": [
"Bad Request"
]
}Exemple de code
# Set your Datadog site and credentials
export DD_SITE="datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/remote_config/products/asm/waf/policies" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"basedOn": "recommended",
"description": "Policy applied to internal web applications.",
"isDefault": false,
"name": "Internal Network Policy",
"protectionPresets": [
"attack-tools"
],
"rules": [
{
"blocking": false,
"enabled": true,
"id": "rasp-001-002"
}
],
"scope": [
{
"env": "prod",
"service": "billing-service"
}
],
"version": 0
},
"type": "policy"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="us3.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/remote_config/products/asm/waf/policies" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"basedOn": "recommended",
"description": "Policy applied to internal web applications.",
"isDefault": false,
"name": "Internal Network Policy",
"protectionPresets": [
"attack-tools"
],
"rules": [
{
"blocking": false,
"enabled": true,
"id": "rasp-001-002"
}
],
"scope": [
{
"env": "prod",
"service": "billing-service"
}
],
"version": 0
},
"type": "policy"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="us5.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/remote_config/products/asm/waf/policies" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"basedOn": "recommended",
"description": "Policy applied to internal web applications.",
"isDefault": false,
"name": "Internal Network Policy",
"protectionPresets": [
"attack-tools"
],
"rules": [
{
"blocking": false,
"enabled": true,
"id": "rasp-001-002"
}
],
"scope": [
{
"env": "prod",
"service": "billing-service"
}
],
"version": 0
},
"type": "policy"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="datadoghq.eu"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/remote_config/products/asm/waf/policies" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"basedOn": "recommended",
"description": "Policy applied to internal web applications.",
"isDefault": false,
"name": "Internal Network Policy",
"protectionPresets": [
"attack-tools"
],
"rules": [
{
"blocking": false,
"enabled": true,
"id": "rasp-001-002"
}
],
"scope": [
{
"env": "prod",
"service": "billing-service"
}
],
"version": 0
},
"type": "policy"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="ap1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/remote_config/products/asm/waf/policies" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"basedOn": "recommended",
"description": "Policy applied to internal web applications.",
"isDefault": false,
"name": "Internal Network Policy",
"protectionPresets": [
"attack-tools"
],
"rules": [
{
"blocking": false,
"enabled": true,
"id": "rasp-001-002"
}
],
"scope": [
{
"env": "prod",
"service": "billing-service"
}
],
"version": 0
},
"type": "policy"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="ap2.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/remote_config/products/asm/waf/policies" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"basedOn": "recommended",
"description": "Policy applied to internal web applications.",
"isDefault": false,
"name": "Internal Network Policy",
"protectionPresets": [
"attack-tools"
],
"rules": [
{
"blocking": false,
"enabled": true,
"id": "rasp-001-002"
}
],
"scope": [
{
"env": "prod",
"service": "billing-service"
}
],
"version": 0
},
"type": "policy"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="uk1.datadoghq.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/remote_config/products/asm/waf/policies" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"basedOn": "recommended",
"description": "Policy applied to internal web applications.",
"isDefault": false,
"name": "Internal Network Policy",
"protectionPresets": [
"attack-tools"
],
"rules": [
{
"blocking": false,
"enabled": true,
"id": "rasp-001-002"
}
],
"scope": [
{
"env": "prod",
"service": "billing-service"
}
],
"version": 0
},
"type": "policy"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/remote_config/products/asm/waf/policies" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"basedOn": "recommended",
"description": "Policy applied to internal web applications.",
"isDefault": false,
"name": "Internal Network Policy",
"protectionPresets": [
"attack-tools"
],
"rules": [
{
"blocking": false,
"enabled": true,
"id": "rasp-001-002"
}
],
"scope": [
{
"env": "prod",
"service": "billing-service"
}
],
"version": 0
},
"type": "policy"
}
}
EOF# Set your Datadog site and credentials
export DD_SITE="us2.ddog-gov.com"
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
curl -X POST "https://api.${DD_SITE}/api/v2/remote_config/products/asm/waf/policies" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"basedOn": "recommended",
"description": "Policy applied to internal web applications.",
"isDefault": false,
"name": "Internal Network Policy",
"protectionPresets": [
"attack-tools"
],
"rules": [
{
"blocking": false,
"enabled": true,
"id": "rasp-001-002"
}
],
"scope": [
{
"env": "prod",
"service": "billing-service"
}
],
"version": 0
},
"type": "policy"
}
}
EOF// Create a WAF Policy returns "Created" response
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
)
func main() {
body := datadogV2.ApplicationSecurityPolicyCreateRequest{
Data: datadogV2.ApplicationSecurityPolicyCreateData{
Attributes: datadogV2.ApplicationSecurityPolicyCreateAttributes{
BasedOn: "recommended",
Description: "Policy applied to internal web applications.",
IsDefault: datadog.PtrBool(false),
Name: "Internal Network Policy",
ProtectionPresets: []string{
"attack-tools",
},
Rules: []datadogV2.ApplicationSecurityPolicyRuleOverride{
{
Blocking: false,
Enabled: true,
Id: "rasp-001-002",
},
},
Scope: []datadogV2.ApplicationSecurityPolicyScope{
{
Env: "prod",
Service: "billing-service",
},
},
Version: datadog.PtrInt64(0),
},
Type: datadogV2.APPLICATIONSECURITYPOLICYTYPE_POLICY,
},
}
ctx := datadog.NewDefaultContext(context.Background())
ctx = context.WithValue(ctx, datadog.ContextAccessToken, os.Getenv("DD_BEARER_TOKEN"))
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV2.NewApplicationSecurityApi(apiClient)
resp, r, err := api.CreateApplicationSecurityWafPolicy(ctx, body)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `ApplicationSecurityApi.CreateApplicationSecurityWafPolicy`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `ApplicationSecurityApi.CreateApplicationSecurityWafPolicy`:\n%s\n", responseContent)
}
Instructions
First install the library and its dependencies and then save the example to main.go and run following commands:
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"// Create a WAF Policy returns "Created" response
import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.ApplicationSecurityApi;
import com.datadog.api.client.v2.model.ApplicationSecurityPolicyCreateAttributes;
import com.datadog.api.client.v2.model.ApplicationSecurityPolicyCreateData;
import com.datadog.api.client.v2.model.ApplicationSecurityPolicyCreateRequest;
import com.datadog.api.client.v2.model.ApplicationSecurityPolicyResponse;
import com.datadog.api.client.v2.model.ApplicationSecurityPolicyRuleOverride;
import com.datadog.api.client.v2.model.ApplicationSecurityPolicyScope;
import com.datadog.api.client.v2.model.ApplicationSecurityPolicyType;
import java.util.Collections;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
defaultClient.setAccessToken(System.getenv("DD_BEARER_TOKEN"));
ApplicationSecurityApi apiInstance = new ApplicationSecurityApi(defaultClient);
ApplicationSecurityPolicyCreateRequest body =
new ApplicationSecurityPolicyCreateRequest()
.data(
new ApplicationSecurityPolicyCreateData()
.attributes(
new ApplicationSecurityPolicyCreateAttributes()
.basedOn("recommended")
.description("Policy applied to internal web applications.")
.isDefault(false)
.name("Internal Network Policy")
.protectionPresets(Collections.singletonList("attack-tools"))
.rules(
Collections.singletonList(
new ApplicationSecurityPolicyRuleOverride()
.blocking(false)
.enabled(true)
.id("rasp-001-002")))
.scope(
Collections.singletonList(
new ApplicationSecurityPolicyScope()
.env("prod")
.service("billing-service")))
.version(0L))
.type(ApplicationSecurityPolicyType.POLICY));
try {
ApplicationSecurityPolicyResponse result =
apiInstance.createApplicationSecurityWafPolicy(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println(
"Exception when calling ApplicationSecurityApi#createApplicationSecurityWafPolicy");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
Instructions
First install the library and its dependencies and then save the example to Example.java and run following commands:
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java""""
Create a WAF Policy returns "Created" response
"""
from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.application_security_api import ApplicationSecurityApi
from datadog_api_client.v2.model.application_security_policy_create_attributes import (
ApplicationSecurityPolicyCreateAttributes,
)
from datadog_api_client.v2.model.application_security_policy_create_data import ApplicationSecurityPolicyCreateData
from datadog_api_client.v2.model.application_security_policy_create_request import (
ApplicationSecurityPolicyCreateRequest,
)
from datadog_api_client.v2.model.application_security_policy_rule_override import ApplicationSecurityPolicyRuleOverride
from datadog_api_client.v2.model.application_security_policy_scope import ApplicationSecurityPolicyScope
from datadog_api_client.v2.model.application_security_policy_type import ApplicationSecurityPolicyType
body = ApplicationSecurityPolicyCreateRequest(
data=ApplicationSecurityPolicyCreateData(
attributes=ApplicationSecurityPolicyCreateAttributes(
based_on="recommended",
description="Policy applied to internal web applications.",
is_default=False,
name="Internal Network Policy",
protection_presets=[
"attack-tools",
],
rules=[
ApplicationSecurityPolicyRuleOverride(
blocking=False,
enabled=True,
id="rasp-001-002",
),
],
scope=[
ApplicationSecurityPolicyScope(
env="prod",
service="billing-service",
),
],
version=0,
),
type=ApplicationSecurityPolicyType.POLICY,
),
)
configuration = Configuration()
configuration.access_token = environ["DD_BEARER_TOKEN"]
with ApiClient(configuration) as api_client:
api_instance = ApplicationSecurityApi(api_client)
response = api_instance.create_application_security_waf_policy(body=body)
print(response)
Instructions
First install the library and its dependencies and then save the example to example.py and run following commands:
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"# Create a WAF Policy returns "Created" response
require "datadog_api_client"
DatadogAPIClient.configure do |config|
config.access_token = ENV["DD_BEARER_TOKEN"]
end
api_instance = DatadogAPIClient::V2::ApplicationSecurityAPI.new
body = DatadogAPIClient::V2::ApplicationSecurityPolicyCreateRequest.new({
data: DatadogAPIClient::V2::ApplicationSecurityPolicyCreateData.new({
attributes: DatadogAPIClient::V2::ApplicationSecurityPolicyCreateAttributes.new({
based_on: "recommended",
description: "Policy applied to internal web applications.",
is_default: false,
name: "Internal Network Policy",
protection_presets: [
"attack-tools",
],
rules: [
DatadogAPIClient::V2::ApplicationSecurityPolicyRuleOverride.new({
blocking: false,
enabled: true,
id: "rasp-001-002",
}),
],
scope: [
DatadogAPIClient::V2::ApplicationSecurityPolicyScope.new({
env: "prod",
service: "billing-service",
}),
],
version: 0,
}),
type: DatadogAPIClient::V2::ApplicationSecurityPolicyType::POLICY,
}),
})
p api_instance.create_application_security_waf_policy(body)
Instructions
First install the library and its dependencies and then save the example to example.rb and run following commands:
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"// Create a WAF Policy returns "Created" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_application_security::ApplicationSecurityAPI;
use datadog_api_client::datadogV2::model::ApplicationSecurityPolicyCreateAttributes;
use datadog_api_client::datadogV2::model::ApplicationSecurityPolicyCreateData;
use datadog_api_client::datadogV2::model::ApplicationSecurityPolicyCreateRequest;
use datadog_api_client::datadogV2::model::ApplicationSecurityPolicyRuleOverride;
use datadog_api_client::datadogV2::model::ApplicationSecurityPolicyScope;
use datadog_api_client::datadogV2::model::ApplicationSecurityPolicyType;
#[tokio::main]
async fn main() {
let body =
ApplicationSecurityPolicyCreateRequest::new(ApplicationSecurityPolicyCreateData::new(
ApplicationSecurityPolicyCreateAttributes::new(
"recommended".to_string(),
"Policy applied to internal web applications.".to_string(),
"Internal Network Policy".to_string(),
)
.is_default(false)
.protection_presets(vec!["attack-tools".to_string()])
.rules(vec![ApplicationSecurityPolicyRuleOverride::new(
false,
true,
"rasp-001-002".to_string(),
)])
.scope(vec![ApplicationSecurityPolicyScope::new(
"prod".to_string(),
"billing-service".to_string(),
)])
.version(0),
ApplicationSecurityPolicyType::POLICY,
));
let configuration = datadog::Configuration::new();
let api = ApplicationSecurityAPI::with_config(configuration);
let resp = api.create_application_security_waf_policy(body).await;
if let Ok(value) = resp {
println!("{:#?}", value);
} else {
println!("{:#?}", resp.unwrap_err());
}
}
Instructions
First install the library and its dependencies and then save the example to src/main.rs and run following commands:
DD_SITE="datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="us3.datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="us5.datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="datadoghq.eu" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="ap1.datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="ap2.datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="uk1.datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="ddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo runDD_SITE="us2.ddog-gov.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo run/**
* Create a WAF Policy returns "Created" response
*/
import { client, v2 } from "@datadog/datadog-api-client";
const configuration = client.createConfiguration({
authMethods: {
AuthZ: {
accessToken: process.env.DD_BEARER_TOKEN as string,
},
},
});
const apiInstance = new v2.ApplicationSecurityApi(configuration);
const params: v2.ApplicationSecurityApiCreateApplicationSecurityWafPolicyRequest =
{
body: {
data: {
attributes: {
basedOn: "recommended",
description: "Policy applied to internal web applications.",
isDefault: false,
name: "Internal Network Policy",
protectionPresets: ["attack-tools"],
rules: [
{
blocking: false,
enabled: true,
id: "rasp-001-002",
},
],
scope: [
{
env: "prod",
service: "billing-service",
},
],
version: 0,
},
type: "policy",
},
},
};
apiInstance
.createApplicationSecurityWafPolicy(params)
.then((data: v2.ApplicationSecurityPolicyResponse) => {
console.log(
"API called successfully. Returned data: " + JSON.stringify(data)
);
})
.catch((error: any) => console.error(error));
Instructions
First install the library and its dependencies and then save the example to example.ts and run following commands:
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="us3.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="us5.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="datadoghq.eu" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="ap1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="ap2.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="uk1.datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"DD_SITE="us2.ddog-gov.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"