커스텀 규칙 수정 버전 생성
https://api.datadoghq.com/api/v2/static-analysis/custom/rulesets/{ruleset_name}/rules/{rule_name}/revisionshttps://api.us3.datadoghq.com/api/v2/static-analysis/custom/rulesets/{ruleset_name}/rules/{rule_name}/revisionshttps://api.us5.datadoghq.com/api/v2/static-analysis/custom/rulesets/{ruleset_name}/rules/{rule_name}/revisionshttps://api.datadoghq.eu/api/v2/static-analysis/custom/rulesets/{ruleset_name}/rules/{rule_name}/revisionshttps://api.ap1.datadoghq.com/api/v2/static-analysis/custom/rulesets/{ruleset_name}/rules/{rule_name}/revisionshttps://api.ap2.datadoghq.com/api/v2/static-analysis/custom/rulesets/{ruleset_name}/rules/{rule_name}/revisionshttps://api.uk1.datadoghq.com/api/v2/static-analysis/custom/rulesets/{ruleset_name}/rules/{rule_name}/revisionshttps://api.ddog-gov.com/api/v2/static-analysis/custom/rulesets/{ruleset_name}/rules/{rule_name}/revisionshttps://api.us2.ddog-gov.com/api/v2/static-analysis/custom/rulesets/{ruleset_name}/rules/{rule_name}/revisions개요
커스텀 규칙에 대한 새 수정 버전을 생성합니다.
인수
경로 파라미터
ruleset_name [required]The ruleset name
rule_name [required]The rule name
요청
Body Data (required)
_authentication_token새 커스텀 규칙 수정 버전을 생성하기 위한 요청 본문입니다.
dataData object for a custom rule revision create request.
attributesInput attributes for creating or updating a custom rule revision.
arguments [required]Rule arguments
description [required]Base64-encoded argument description
name [required]Base64-encoded argument name
category [required]Rule category
SECURITY, BEST_PRACTICES, CODE_STYLE, ERROR_PRONE, PERFORMANCEcode [required]Rule code
creation_message [required]Revision creation message
cveAssociated CVE
cweAssociated CWE
description [required]Full description
documentation_urlDocumentation URL
is_published [required]Whether the revision is published
is_testing [required]Whether this is a testing revision
language [required]Programming language
PYTHON, JAVASCRIPT, TYPESCRIPT, JAVA, GO, YAML, RUBY, CSHARP, PHP, KOTLINShow 13 more
SWIFT, DART, DOCKERFILE, ELIXIR, JSON, RUST, TERRAFORM, STARLARK, BASH, MARKDOWN, APEX, R, SQLseverity [required]Rule severity
ERROR, WARNING, NOTICE, NONEshort_description [required]Short description
should_use_ai_fix [required]Whether to use AI for fixes
tags [required]Rule tags
tests [required]Rule tests
annotation_count [required]Expected violation count
code [required]Test code
filename [required]Test filename
tree_sitter_query [required]Tree-sitter query
idRevision identifier
typeResource type
custom_rule_revision{
"_authentication_token": "string",
"data": {
"attributes": {
"arguments": [
{
"description": "YXJndW1lbnQgZGVzY3JpcHRpb24=",
"name": "YXJndW1lbnRfbmFtZQ=="
}
],
"category": "SECURITY",
"code": "Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==",
"creation_message": "Initial revision",
"cve": "CVE-2024-1234",
"cwe": "CWE-79",
"description": "bG9uZyBkZXNjcmlwdGlvbg==",
"documentation_url": "https://docs.example.com/rules/my-rule",
"is_published": false,
"is_testing": false,
"language": "PYTHON",
"severity": "ERROR",
"short_description": "c2hvcnQgZGVzY3JpcHRpb24=",
"should_use_ai_fix": false,
"tags": [
"security",
"custom"
],
"tests": [
{
"annotation_count": 1,
"code": "Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==",
"filename": "test.yaml"
}
],
"tree_sitter_query": "Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ=="
},
"id": "string",
"type": "custom_rule_revision"
}
}응답
Successfully created
Bad request
API error response.
errors [required]A list of errors.
detailA human-readable explanation specific to this occurrence of the error.
metaNon-standard meta-information about the error
sourceReferences to the source of the error.
headerA string indicating the name of a single request header which caused the error.
parameterA string indicating which URI query parameter caused the error.
pointerA JSON pointer to the value in the request document that caused the error.
statusStatus code of the response.
titleShort human-readable summary of the error.
{
"errors": [
{
"detail": "Missing required attribute in body",
"meta": {},
"source": {
"header": "Authorization",
"parameter": "limit",
"pointer": "/data/attributes/title"
},
"status": "400",
"title": "Bad Request"
}
]
}Unauthorized - custom rules not enabled
API error response.
errors [required]A list of errors.
detailA human-readable explanation specific to this occurrence of the error.
metaNon-standard meta-information about the error
sourceReferences to the source of the error.
headerA string indicating the name of a single request header which caused the error.
parameterA string indicating which URI query parameter caused the error.
pointerA JSON pointer to the value in the request document that caused the error.
statusStatus code of the response.
titleShort human-readable summary of the error.
{
"errors": [
{
"detail": "Missing required attribute in body",
"meta": {},
"source": {
"header": "Authorization",
"parameter": "limit",
"pointer": "/data/attributes/title"
},
"status": "400",
"title": "Bad Request"
}
]
}Rule not found
API error response.
errors [required]A list of errors.
detailA human-readable explanation specific to this occurrence of the error.
metaNon-standard meta-information about the error
sourceReferences to the source of the error.
headerA string indicating the name of a single request header which caused the error.
parameterA string indicating which URI query parameter caused the error.
pointerA JSON pointer to the value in the request document that caused the error.
statusStatus code of the response.
titleShort human-readable summary of the error.
{
"errors": [
{
"detail": "Missing required attribute in body",
"meta": {},
"source": {
"header": "Authorization",
"parameter": "limit",
"pointer": "/data/attributes/title"
},
"status": "400",
"title": "Bad Request"
}
]
}Too many requests
API error response.
errors [required]A list of errors.
{
"errors": [
"Bad Request"
]
}코드 예시
# Path parameters
export ruleset_name="CHANGE_ME"
export rule_name="CHANGE_ME"
# 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 PUT "https://api.${DD_SITE}/api/v2/static-analysis/custom/rulesets/${ruleset_name}/rules/${rule_name}/revisions" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"arguments": [
{
"description": "Maximum call depth to analyze",
"name": "max_depth"
}
],
"category": "SECURITY",
"code": "def rule(node): return node.type == 'call'",
"creation_message": "Initial revision",
"cve": "CVE-2024-1234",
"cwe": "CWE-79",
"description": "Detects insecure coding patterns that may lead to vulnerabilities",
"documentation_url": "https://docs.example.com/rules/my-rule",
"is_published": false,
"is_testing": false,
"language": "PYTHON",
"severity": "ERROR",
"short_description": "Rule to detect insecure patterns",
"should_use_ai_fix": false,
"tags": [
"security",
"custom"
],
"tests": [
{
"annotation_count": 1,
"code": "result = insecure_function()",
"filename": "test.yaml"
}
],
"tree_sitter_query": "(call_expression) @call"
},
"type": "custom_rule_revision"
}
}
EOF# Path parameters
export ruleset_name="CHANGE_ME"
export rule_name="CHANGE_ME"
# 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 PUT "https://api.${DD_SITE}/api/v2/static-analysis/custom/rulesets/${ruleset_name}/rules/${rule_name}/revisions" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"arguments": [
{
"description": "Maximum call depth to analyze",
"name": "max_depth"
}
],
"category": "SECURITY",
"code": "def rule(node): return node.type == 'call'",
"creation_message": "Initial revision",
"cve": "CVE-2024-1234",
"cwe": "CWE-79",
"description": "Detects insecure coding patterns that may lead to vulnerabilities",
"documentation_url": "https://docs.example.com/rules/my-rule",
"is_published": false,
"is_testing": false,
"language": "PYTHON",
"severity": "ERROR",
"short_description": "Rule to detect insecure patterns",
"should_use_ai_fix": false,
"tags": [
"security",
"custom"
],
"tests": [
{
"annotation_count": 1,
"code": "result = insecure_function()",
"filename": "test.yaml"
}
],
"tree_sitter_query": "(call_expression) @call"
},
"type": "custom_rule_revision"
}
}
EOF# Path parameters
export ruleset_name="CHANGE_ME"
export rule_name="CHANGE_ME"
# 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 PUT "https://api.${DD_SITE}/api/v2/static-analysis/custom/rulesets/${ruleset_name}/rules/${rule_name}/revisions" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"arguments": [
{
"description": "Maximum call depth to analyze",
"name": "max_depth"
}
],
"category": "SECURITY",
"code": "def rule(node): return node.type == 'call'",
"creation_message": "Initial revision",
"cve": "CVE-2024-1234",
"cwe": "CWE-79",
"description": "Detects insecure coding patterns that may lead to vulnerabilities",
"documentation_url": "https://docs.example.com/rules/my-rule",
"is_published": false,
"is_testing": false,
"language": "PYTHON",
"severity": "ERROR",
"short_description": "Rule to detect insecure patterns",
"should_use_ai_fix": false,
"tags": [
"security",
"custom"
],
"tests": [
{
"annotation_count": 1,
"code": "result = insecure_function()",
"filename": "test.yaml"
}
],
"tree_sitter_query": "(call_expression) @call"
},
"type": "custom_rule_revision"
}
}
EOF# Path parameters
export ruleset_name="CHANGE_ME"
export rule_name="CHANGE_ME"
# 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 PUT "https://api.${DD_SITE}/api/v2/static-analysis/custom/rulesets/${ruleset_name}/rules/${rule_name}/revisions" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"arguments": [
{
"description": "Maximum call depth to analyze",
"name": "max_depth"
}
],
"category": "SECURITY",
"code": "def rule(node): return node.type == 'call'",
"creation_message": "Initial revision",
"cve": "CVE-2024-1234",
"cwe": "CWE-79",
"description": "Detects insecure coding patterns that may lead to vulnerabilities",
"documentation_url": "https://docs.example.com/rules/my-rule",
"is_published": false,
"is_testing": false,
"language": "PYTHON",
"severity": "ERROR",
"short_description": "Rule to detect insecure patterns",
"should_use_ai_fix": false,
"tags": [
"security",
"custom"
],
"tests": [
{
"annotation_count": 1,
"code": "result = insecure_function()",
"filename": "test.yaml"
}
],
"tree_sitter_query": "(call_expression) @call"
},
"type": "custom_rule_revision"
}
}
EOF# Path parameters
export ruleset_name="CHANGE_ME"
export rule_name="CHANGE_ME"
# 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 PUT "https://api.${DD_SITE}/api/v2/static-analysis/custom/rulesets/${ruleset_name}/rules/${rule_name}/revisions" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"arguments": [
{
"description": "Maximum call depth to analyze",
"name": "max_depth"
}
],
"category": "SECURITY",
"code": "def rule(node): return node.type == 'call'",
"creation_message": "Initial revision",
"cve": "CVE-2024-1234",
"cwe": "CWE-79",
"description": "Detects insecure coding patterns that may lead to vulnerabilities",
"documentation_url": "https://docs.example.com/rules/my-rule",
"is_published": false,
"is_testing": false,
"language": "PYTHON",
"severity": "ERROR",
"short_description": "Rule to detect insecure patterns",
"should_use_ai_fix": false,
"tags": [
"security",
"custom"
],
"tests": [
{
"annotation_count": 1,
"code": "result = insecure_function()",
"filename": "test.yaml"
}
],
"tree_sitter_query": "(call_expression) @call"
},
"type": "custom_rule_revision"
}
}
EOF# Path parameters
export ruleset_name="CHANGE_ME"
export rule_name="CHANGE_ME"
# 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 PUT "https://api.${DD_SITE}/api/v2/static-analysis/custom/rulesets/${ruleset_name}/rules/${rule_name}/revisions" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"arguments": [
{
"description": "Maximum call depth to analyze",
"name": "max_depth"
}
],
"category": "SECURITY",
"code": "def rule(node): return node.type == 'call'",
"creation_message": "Initial revision",
"cve": "CVE-2024-1234",
"cwe": "CWE-79",
"description": "Detects insecure coding patterns that may lead to vulnerabilities",
"documentation_url": "https://docs.example.com/rules/my-rule",
"is_published": false,
"is_testing": false,
"language": "PYTHON",
"severity": "ERROR",
"short_description": "Rule to detect insecure patterns",
"should_use_ai_fix": false,
"tags": [
"security",
"custom"
],
"tests": [
{
"annotation_count": 1,
"code": "result = insecure_function()",
"filename": "test.yaml"
}
],
"tree_sitter_query": "(call_expression) @call"
},
"type": "custom_rule_revision"
}
}
EOF# Path parameters
export ruleset_name="CHANGE_ME"
export rule_name="CHANGE_ME"
# 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 PUT "https://api.${DD_SITE}/api/v2/static-analysis/custom/rulesets/${ruleset_name}/rules/${rule_name}/revisions" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"arguments": [
{
"description": "Maximum call depth to analyze",
"name": "max_depth"
}
],
"category": "SECURITY",
"code": "def rule(node): return node.type == 'call'",
"creation_message": "Initial revision",
"cve": "CVE-2024-1234",
"cwe": "CWE-79",
"description": "Detects insecure coding patterns that may lead to vulnerabilities",
"documentation_url": "https://docs.example.com/rules/my-rule",
"is_published": false,
"is_testing": false,
"language": "PYTHON",
"severity": "ERROR",
"short_description": "Rule to detect insecure patterns",
"should_use_ai_fix": false,
"tags": [
"security",
"custom"
],
"tests": [
{
"annotation_count": 1,
"code": "result = insecure_function()",
"filename": "test.yaml"
}
],
"tree_sitter_query": "(call_expression) @call"
},
"type": "custom_rule_revision"
}
}
EOF# Path parameters
export ruleset_name="CHANGE_ME"
export rule_name="CHANGE_ME"
# 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 PUT "https://api.${DD_SITE}/api/v2/static-analysis/custom/rulesets/${ruleset_name}/rules/${rule_name}/revisions" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"arguments": [
{
"description": "Maximum call depth to analyze",
"name": "max_depth"
}
],
"category": "SECURITY",
"code": "def rule(node): return node.type == 'call'",
"creation_message": "Initial revision",
"cve": "CVE-2024-1234",
"cwe": "CWE-79",
"description": "Detects insecure coding patterns that may lead to vulnerabilities",
"documentation_url": "https://docs.example.com/rules/my-rule",
"is_published": false,
"is_testing": false,
"language": "PYTHON",
"severity": "ERROR",
"short_description": "Rule to detect insecure patterns",
"should_use_ai_fix": false,
"tags": [
"security",
"custom"
],
"tests": [
{
"annotation_count": 1,
"code": "result = insecure_function()",
"filename": "test.yaml"
}
],
"tree_sitter_query": "(call_expression) @call"
},
"type": "custom_rule_revision"
}
}
EOF# Path parameters
export ruleset_name="CHANGE_ME"
export rule_name="CHANGE_ME"
# 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 PUT "https://api.${DD_SITE}/api/v2/static-analysis/custom/rulesets/${ruleset_name}/rules/${rule_name}/revisions" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"arguments": [
{
"description": "Maximum call depth to analyze",
"name": "max_depth"
}
],
"category": "SECURITY",
"code": "def rule(node): return node.type == 'call'",
"creation_message": "Initial revision",
"cve": "CVE-2024-1234",
"cwe": "CWE-79",
"description": "Detects insecure coding patterns that may lead to vulnerabilities",
"documentation_url": "https://docs.example.com/rules/my-rule",
"is_published": false,
"is_testing": false,
"language": "PYTHON",
"severity": "ERROR",
"short_description": "Rule to detect insecure patterns",
"should_use_ai_fix": false,
"tags": [
"security",
"custom"
],
"tests": [
{
"annotation_count": 1,
"code": "result = insecure_function()",
"filename": "test.yaml"
}
],
"tree_sitter_query": "(call_expression) @call"
},
"type": "custom_rule_revision"
}
}
EOF// Create Custom Rule Revision returns "Successfully created" response
package main
import (
"context"
"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.CustomRuleRevisionRequest{
Data: &datadogV2.CustomRuleRevisionRequestData{
Attributes: &datadogV2.CustomRuleRevisionInputAttributes{
Arguments: *datadog.NewNullableList(&[]datadogV2.Argument{
{
Description: "YXJndW1lbnQgZGVzY3JpcHRpb24=",
Name: "YXJndW1lbnRfbmFtZQ==",
},
}),
Category: datadogV2.CUSTOMRULEREVISIONATTRIBUTESCATEGORY_SECURITY,
Code: "Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==",
CreationMessage: "Initial revision",
Cve: *datadog.NewNullableString(datadog.PtrString("CVE-2024-1234")),
Cwe: *datadog.NewNullableString(datadog.PtrString("CWE-79")),
Description: "bG9uZyBkZXNjcmlwdGlvbg==",
DocumentationUrl: *datadog.NewNullableString(datadog.PtrString("https://docs.example.com/rules/my-rule")),
IsPublished: false,
IsTesting: false,
Language: datadogV2.LANGUAGE_PYTHON,
Severity: datadogV2.CUSTOMRULEREVISIONATTRIBUTESSEVERITY_ERROR,
ShortDescription: "c2hvcnQgZGVzY3JpcHRpb24=",
ShouldUseAiFix: false,
Tags: *datadog.NewNullableList(&[]string{
"security",
"custom",
}),
Tests: *datadog.NewNullableList(&[]datadogV2.CustomRuleRevisionTest{
{
AnnotationCount: 1,
Code: "Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==",
Filename: "test.yaml",
},
}),
TreeSitterQuery: "Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==",
},
Type: datadogV2.CUSTOMRULEREVISIONDATATYPE_CUSTOM_RULE_REVISION.Ptr(),
},
}
ctx := datadog.NewDefaultContext(context.Background())
ctx = context.WithValue(ctx, datadog.ContextAccessToken, os.Getenv("DD_BEARER_TOKEN"))
configuration := datadog.NewConfiguration()
configuration.SetUnstableOperationEnabled("v2.CreateCustomRuleRevision", true)
apiClient := datadog.NewAPIClient(configuration)
api := datadogV2.NewStaticAnalysisApi(apiClient)
r, err := api.CreateCustomRuleRevision(ctx, "ruleset_name", "rule_name", body)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `StaticAnalysisApi.CreateCustomRuleRevision`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
}
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 Custom Rule Revision returns "Successfully created" response
import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.StaticAnalysisApi;
import com.datadog.api.client.v2.model.Argument;
import com.datadog.api.client.v2.model.CustomRuleRevisionAttributesCategory;
import com.datadog.api.client.v2.model.CustomRuleRevisionAttributesSeverity;
import com.datadog.api.client.v2.model.CustomRuleRevisionDataType;
import com.datadog.api.client.v2.model.CustomRuleRevisionInputAttributes;
import com.datadog.api.client.v2.model.CustomRuleRevisionRequest;
import com.datadog.api.client.v2.model.CustomRuleRevisionRequestData;
import com.datadog.api.client.v2.model.CustomRuleRevisionTest;
import com.datadog.api.client.v2.model.Language;
import java.util.Arrays;
import java.util.Collections;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
defaultClient.setAccessToken(System.getenv("DD_BEARER_TOKEN"));
defaultClient.setUnstableOperationEnabled("v2.createCustomRuleRevision", true);
StaticAnalysisApi apiInstance = new StaticAnalysisApi(defaultClient);
CustomRuleRevisionRequest body =
new CustomRuleRevisionRequest()
.data(
new CustomRuleRevisionRequestData()
.attributes(
new CustomRuleRevisionInputAttributes()
.arguments(
Collections.singletonList(
new Argument()
.description("YXJndW1lbnQgZGVzY3JpcHRpb24=")
.name("YXJndW1lbnRfbmFtZQ==")))
.category(CustomRuleRevisionAttributesCategory.SECURITY)
.code("Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==")
.creationMessage("Initial revision")
.cve("CVE-2024-1234")
.cwe("CWE-79")
.description("bG9uZyBkZXNjcmlwdGlvbg==")
.documentationUrl("https://docs.example.com/rules/my-rule")
.isPublished(false)
.isTesting(false)
.language(Language.PYTHON)
.severity(CustomRuleRevisionAttributesSeverity.ERROR)
.shortDescription("c2hvcnQgZGVzY3JpcHRpb24=")
.shouldUseAiFix(false)
.tags(Arrays.asList("security", "custom"))
.tests(
Collections.singletonList(
new CustomRuleRevisionTest()
.annotationCount(1L)
.code("Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==")
.filename("test.yaml")))
.treeSitterQuery("Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ=="))
.type(CustomRuleRevisionDataType.CUSTOM_RULE_REVISION));
try {
apiInstance.createCustomRuleRevision("ruleset_name", "rule_name", body);
} catch (ApiException e) {
System.err.println("Exception when calling StaticAnalysisApi#createCustomRuleRevision");
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 Custom Rule Revision returns "Successfully created" response
"""
from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.static_analysis_api import StaticAnalysisApi
from datadog_api_client.v2.model.argument import Argument
from datadog_api_client.v2.model.custom_rule_revision_attributes_category import CustomRuleRevisionAttributesCategory
from datadog_api_client.v2.model.custom_rule_revision_attributes_severity import CustomRuleRevisionAttributesSeverity
from datadog_api_client.v2.model.custom_rule_revision_data_type import CustomRuleRevisionDataType
from datadog_api_client.v2.model.custom_rule_revision_input_attributes import CustomRuleRevisionInputAttributes
from datadog_api_client.v2.model.custom_rule_revision_request import CustomRuleRevisionRequest
from datadog_api_client.v2.model.custom_rule_revision_request_data import CustomRuleRevisionRequestData
from datadog_api_client.v2.model.custom_rule_revision_test import CustomRuleRevisionTest
from datadog_api_client.v2.model.language import Language
body = CustomRuleRevisionRequest(
data=CustomRuleRevisionRequestData(
attributes=CustomRuleRevisionInputAttributes(
arguments=[
Argument(
description="YXJndW1lbnQgZGVzY3JpcHRpb24=",
name="YXJndW1lbnRfbmFtZQ==",
),
],
category=CustomRuleRevisionAttributesCategory.SECURITY,
code="Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==",
creation_message="Initial revision",
cve="CVE-2024-1234",
cwe="CWE-79",
description="bG9uZyBkZXNjcmlwdGlvbg==",
documentation_url="https://docs.example.com/rules/my-rule",
is_published=False,
is_testing=False,
language=Language.PYTHON,
severity=CustomRuleRevisionAttributesSeverity.ERROR,
short_description="c2hvcnQgZGVzY3JpcHRpb24=",
should_use_ai_fix=False,
tags=[
"security",
"custom",
],
tests=[
CustomRuleRevisionTest(
annotation_count=1,
code="Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==",
filename="test.yaml",
),
],
tree_sitter_query="Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==",
),
type=CustomRuleRevisionDataType.CUSTOM_RULE_REVISION,
),
)
configuration = Configuration()
configuration.access_token = environ["DD_BEARER_TOKEN"]
configuration.unstable_operations["create_custom_rule_revision"] = True
with ApiClient(configuration) as api_client:
api_instance = StaticAnalysisApi(api_client)
api_instance.create_custom_rule_revision(ruleset_name="ruleset_name", rule_name="rule_name", body=body)
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 Custom Rule Revision returns "Successfully created" response
require "datadog_api_client"
DatadogAPIClient.configure do |config|
config.access_token = ENV["DD_BEARER_TOKEN"]
config.unstable_operations["v2.create_custom_rule_revision".to_sym] = true
end
api_instance = DatadogAPIClient::V2::StaticAnalysisAPI.new
body = DatadogAPIClient::V2::CustomRuleRevisionRequest.new({
data: DatadogAPIClient::V2::CustomRuleRevisionRequestData.new({
attributes: DatadogAPIClient::V2::CustomRuleRevisionInputAttributes.new({
arguments: [
DatadogAPIClient::V2::Argument.new({
description: "YXJndW1lbnQgZGVzY3JpcHRpb24=",
name: "YXJndW1lbnRfbmFtZQ==",
}),
],
category: DatadogAPIClient::V2::CustomRuleRevisionAttributesCategory::SECURITY,
code: "Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==",
creation_message: "Initial revision",
cve: "CVE-2024-1234",
cwe: "CWE-79",
description: "bG9uZyBkZXNjcmlwdGlvbg==",
documentation_url: "https://docs.example.com/rules/my-rule",
is_published: false,
is_testing: false,
language: DatadogAPIClient::V2::Language::PYTHON,
severity: DatadogAPIClient::V2::CustomRuleRevisionAttributesSeverity::ERROR,
short_description: "c2hvcnQgZGVzY3JpcHRpb24=",
should_use_ai_fix: false,
tags: [
"security",
"custom",
],
tests: [
DatadogAPIClient::V2::CustomRuleRevisionTest.new({
annotation_count: 1,
code: "Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==",
filename: "test.yaml",
}),
],
tree_sitter_query: "Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==",
}),
type: DatadogAPIClient::V2::CustomRuleRevisionDataType::CUSTOM_RULE_REVISION,
}),
})
p api_instance.create_custom_rule_revision("ruleset_name", "rule_name", 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 Custom Rule Revision returns "Successfully created" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_static_analysis::StaticAnalysisAPI;
use datadog_api_client::datadogV2::model::Argument;
use datadog_api_client::datadogV2::model::CustomRuleRevisionAttributesCategory;
use datadog_api_client::datadogV2::model::CustomRuleRevisionAttributesSeverity;
use datadog_api_client::datadogV2::model::CustomRuleRevisionDataType;
use datadog_api_client::datadogV2::model::CustomRuleRevisionInputAttributes;
use datadog_api_client::datadogV2::model::CustomRuleRevisionRequest;
use datadog_api_client::datadogV2::model::CustomRuleRevisionRequestData;
use datadog_api_client::datadogV2::model::CustomRuleRevisionTest;
use datadog_api_client::datadogV2::model::Language;
#[tokio::main]
async fn main() {
let body = CustomRuleRevisionRequest::new().data(
CustomRuleRevisionRequestData::new()
.attributes(
CustomRuleRevisionInputAttributes::new(
Some(vec![Argument::new(
"YXJndW1lbnQgZGVzY3JpcHRpb24=".to_string(),
"YXJndW1lbnRfbmFtZQ==".to_string(),
)]),
CustomRuleRevisionAttributesCategory::SECURITY,
"Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==".to_string(),
"Initial revision".to_string(),
"bG9uZyBkZXNjcmlwdGlvbg==".to_string(),
false,
false,
Language::PYTHON,
CustomRuleRevisionAttributesSeverity::ERROR,
"c2hvcnQgZGVzY3JpcHRpb24=".to_string(),
false,
Some(vec!["security".to_string(), "custom".to_string()]),
Some(vec![CustomRuleRevisionTest::new(
1,
"Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==".to_string(),
"test.yaml".to_string(),
)]),
"Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==".to_string(),
)
.cve(Some("CVE-2024-1234".to_string()))
.cwe(Some("CWE-79".to_string()))
.documentation_url(Some("https://docs.example.com/rules/my-rule".to_string())),
)
.type_(CustomRuleRevisionDataType::CUSTOM_RULE_REVISION),
);
let mut configuration = datadog::Configuration::new();
configuration.set_unstable_operation_enabled("v2.create_custom_rule_revision", true);
let api = StaticAnalysisAPI::with_config(configuration);
let resp = api
.create_custom_rule_revision("ruleset_name".to_string(), "rule_name".to_string(), 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 Custom Rule Revision returns "Successfully created" response
*/
import { client, v2 } from "@datadog/datadog-api-client";
const configuration = client.createConfiguration({
authMethods: {
AuthZ: {
accessToken: process.env.DD_BEARER_TOKEN as string,
},
},
});
configuration.unstableOperations["v2.createCustomRuleRevision"] = true;
const apiInstance = new v2.StaticAnalysisApi(configuration);
const params: v2.StaticAnalysisApiCreateCustomRuleRevisionRequest = {
body: {
data: {
attributes: {
arguments: [
{
description: "YXJndW1lbnQgZGVzY3JpcHRpb24=",
name: "YXJndW1lbnRfbmFtZQ==",
},
],
category: "SECURITY",
code: "Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==",
creationMessage: "Initial revision",
cve: "CVE-2024-1234",
cwe: "CWE-79",
description: "bG9uZyBkZXNjcmlwdGlvbg==",
documentationUrl: "https://docs.example.com/rules/my-rule",
isPublished: false,
isTesting: false,
language: "PYTHON",
severity: "ERROR",
shortDescription: "c2hvcnQgZGVzY3JpcHRpb24=",
shouldUseAiFix: false,
tags: ["security", "custom"],
tests: [
{
annotationCount: 1,
code: "Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==",
filename: "test.yaml",
},
],
treeSitterQuery: "Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==",
},
type: "custom_rule_revision",
},
},
rulesetName: "ruleset_name",
ruleName: "rule_name",
};
apiInstance
.createCustomRuleRevision(params)
.then((data: any) => {
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"