Update Custom Ruleset
https://api.datadoghq.com/api/v2/static-analysis/custom/rulesets/{ruleset_name}https://api.us3.datadoghq.com/api/v2/static-analysis/custom/rulesets/{ruleset_name}https://api.us5.datadoghq.com/api/v2/static-analysis/custom/rulesets/{ruleset_name}https://api.datadoghq.eu/api/v2/static-analysis/custom/rulesets/{ruleset_name}https://api.ap1.datadoghq.com/api/v2/static-analysis/custom/rulesets/{ruleset_name}https://api.ap2.datadoghq.com/api/v2/static-analysis/custom/rulesets/{ruleset_name}https://api.uk1.datadoghq.com/api/v2/static-analysis/custom/rulesets/{ruleset_name}https://api.ddog-gov.com/api/v2/static-analysis/custom/rulesets/{ruleset_name}https://api.us2.ddog-gov.com/api/v2/static-analysis/custom/rulesets/{ruleset_name}Overview
Update an existing custom ruleset
Arguments
Path Parameters
ruleset_name [required]The ruleset name
Request
Body Data (required)
dataData object for a custom ruleset create or update request. The resource id is
required and must equal both attributes.name and, on update, the ruleset_name
path parameter; a request that omits it or supplies a different value is rejected
with a 412 response.
attributes [required]Attributes for creating or updating a custom ruleset. name is required and must
equal the resource id; the server rejects a mismatch with a 412 response.
descriptionBase64-encoded full description
name [required]Ruleset name, which must be the same as the resource identifier.
rulesRules in the ruleset
id [required]Rule identifier, which is the same as the rule name.
last_revisionMost recent revision
argumentsRule arguments
description [required]Base64-encoded argument description
name [required]Base64-encoded argument name
categoryRule category
SECURITY, BEST_PRACTICES, CODE_STYLE, ERROR_PRONE, PERFORMANCEcodeRule code
creation_messageRevision creation message
cveAssociated CVE
cweAssociated CWE
descriptionBase64-encoded full description
documentation_urlDocumentation URL
is_publishedWhether the revision should be published
is_testingWhether this is a testing revision
languageProgramming 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, SQLseverityRule severity
ERROR, WARNING, NOTICE, NONEshort_descriptionBase64-encoded short description
should_use_ai_fixWhether to use AI for fixes
tagsRule tags
testsRule tests
annotation_count [required]Expected violation count
code [required]Test code
filename [required]Test filename
tree_sitter_queryTree-sitter query
name [required]Rule name
revisionsRevision history of the rule.
argumentsRule arguments
description [required]Base64-encoded argument description
name [required]Base64-encoded argument name
categoryRule category
SECURITY, BEST_PRACTICES, CODE_STYLE, ERROR_PRONE, PERFORMANCEcodeRule code
creation_messageRevision creation message
cveAssociated CVE
cweAssociated CWE
descriptionBase64-encoded full description
documentation_urlDocumentation URL
is_publishedWhether the revision should be published
is_testingWhether this is a testing revision
languageProgramming 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, SQLseverityRule severity
ERROR, WARNING, NOTICE, NONEshort_descriptionBase64-encoded short description
should_use_ai_fixWhether to use AI for fixes
tagsRule tags
testsRule tests
annotation_count [required]Expected violation count
code [required]Test code
filename [required]Test filename
tree_sitter_queryTree-sitter query
short_descriptionBase64-encoded short description
id [required]Ruleset identifier, which is the same as the ruleset name.
type [required]Resource type
custom_ruleset{
"data": {
"attributes": {
"description": "bG9uZyBkZXNjcmlwdGlvbg==",
"name": "my-ruleset",
"rules": [
{
"id": "my-rule",
"last_revision": {
"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=="
},
"name": "my-rule",
"revisions": [
{
"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=="
}
]
}
],
"short_description": "c2hvcnQgZGVzY3JpcHRpb24="
},
"id": "my-ruleset",
"type": "custom_ruleset"
}
}Response
Successfully updated
Response containing a single custom ruleset.
data [required]A custom static analysis ruleset containing a set of user-defined rules.
attributes [required]Attributes of a custom ruleset, including its name, description, and rules.
created_at [required]Creation timestamp
created_by [required]Creator identifier
description [required]Base64-encoded full description
name [required]Ruleset name
rules [required]Rules in the ruleset
created_at [required]Creation timestamp
created_by [required]Creator identifier
id [required]Rule identifier, which is the same as the rule name.
last_revision [required]Most recent revision of the rule, or null when the rule has no revisions.
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, PERFORMANCEchecksum [required]Code checksum
code [required]Rule code
created_at [required]Creation timestamp
created_by [required]Creator identifier
creation_message [required]Revision creation message
cveAssociated CVE. Omitted when the revision has no associated CVE.
cweAssociated CWE. Omitted when the revision has no associated CWE.
description [required]Full description
documentation_urlDocumentation URL. Omitted when the revision has no documentation URL.
id [required]Revision identifier
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
version_id [required]Monotonically increasing version number of the revision.
name [required]Rule name
revisions [required]Revision history of the rule.
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, PERFORMANCEchecksum [required]Code checksum
code [required]Rule code
created_at [required]Creation timestamp
created_by [required]Creator identifier
creation_message [required]Revision creation message
cveAssociated CVE. Omitted when the revision has no associated CVE.
cweAssociated CWE. Omitted when the revision has no associated CWE.
description [required]Full description
documentation_urlDocumentation URL. Omitted when the revision has no documentation URL.
id [required]Revision identifier
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
version_id [required]Monotonically increasing version number of the revision.
short_description [required]Base64-encoded short description
id [required]Ruleset identifier
type [required]Resource type
custom_ruleset{
"data": {
"attributes": {
"created_at": "2026-01-09T13:00:57.473141Z",
"created_by": "foobarbaz",
"description": "bG9uZyBkZXNjcmlwdGlvbg==",
"name": "my-ruleset",
"rules": [
{
"created_at": "2026-01-09T13:00:57.473141Z",
"created_by": "foobarbaz",
"id": "my-rule",
"last_revision": {
"arguments": [
{
"description": "YXJndW1lbnQgZGVzY3JpcHRpb24=",
"name": "YXJndW1lbnRfbmFtZQ=="
}
],
"category": "SECURITY",
"checksum": "8a66c4e4e631099ad71be3c1ea3ea8fc2d57193e56db2c296e2dd8a508b26b99",
"code": "Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==",
"created_at": "2026-01-09T13:00:57.473141Z",
"created_by": "foobarbaz",
"creation_message": "Initial revision",
"cve": "CVE-2024-1234",
"cwe": "CWE-79",
"description": "bG9uZyBkZXNjcmlwdGlvbg==",
"documentation_url": "https://docs.example.com/rules/my-rule",
"id": "revision-123",
"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==",
"version_id": 1
},
"name": "my-rule",
"revisions": [
{
"arguments": [
{
"description": "YXJndW1lbnQgZGVzY3JpcHRpb24=",
"name": "YXJndW1lbnRfbmFtZQ=="
}
],
"category": "SECURITY",
"checksum": "8a66c4e4e631099ad71be3c1ea3ea8fc2d57193e56db2c296e2dd8a508b26b99",
"code": "Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==",
"created_at": "2026-01-09T13:00:57.473141Z",
"created_by": "foobarbaz",
"creation_message": "Initial revision",
"cve": "CVE-2024-1234",
"cwe": "CWE-79",
"description": "bG9uZyBkZXNjcmlwdGlvbg==",
"documentation_url": "https://docs.example.com/rules/my-rule",
"id": "revision-123",
"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==",
"version_id": 1
}
]
}
],
"short_description": "c2hvcnQgZGVzY3JpcHRpb24="
},
"id": "my-ruleset",
"type": "custom_ruleset"
}
}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"
}
]
}Precondition failed - validation error or ruleset 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"
]
}Code Example
# Path parameters
export ruleset_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 PATCH "https://api.${DD_SITE}/api/v2/static-analysis/custom/rulesets/${ruleset_name}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"name": "my-ruleset",
"rules": [
{
"id": "my-rule",
"last_revision": {
"creation_message": "Initial revision"
},
"name": "my-rule"
}
]
},
"id": "my-ruleset",
"type": "custom_ruleset"
}
}
EOF# Path parameters
export ruleset_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 PATCH "https://api.${DD_SITE}/api/v2/static-analysis/custom/rulesets/${ruleset_name}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"name": "my-ruleset",
"rules": [
{
"id": "my-rule",
"last_revision": {
"creation_message": "Initial revision"
},
"name": "my-rule"
}
]
},
"id": "my-ruleset",
"type": "custom_ruleset"
}
}
EOF# Path parameters
export ruleset_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 PATCH "https://api.${DD_SITE}/api/v2/static-analysis/custom/rulesets/${ruleset_name}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"name": "my-ruleset",
"rules": [
{
"id": "my-rule",
"last_revision": {
"creation_message": "Initial revision"
},
"name": "my-rule"
}
]
},
"id": "my-ruleset",
"type": "custom_ruleset"
}
}
EOF# Path parameters
export ruleset_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 PATCH "https://api.${DD_SITE}/api/v2/static-analysis/custom/rulesets/${ruleset_name}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"name": "my-ruleset",
"rules": [
{
"id": "my-rule",
"last_revision": {
"creation_message": "Initial revision"
},
"name": "my-rule"
}
]
},
"id": "my-ruleset",
"type": "custom_ruleset"
}
}
EOF# Path parameters
export ruleset_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 PATCH "https://api.${DD_SITE}/api/v2/static-analysis/custom/rulesets/${ruleset_name}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"name": "my-ruleset",
"rules": [
{
"id": "my-rule",
"last_revision": {
"creation_message": "Initial revision"
},
"name": "my-rule"
}
]
},
"id": "my-ruleset",
"type": "custom_ruleset"
}
}
EOF# Path parameters
export ruleset_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 PATCH "https://api.${DD_SITE}/api/v2/static-analysis/custom/rulesets/${ruleset_name}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"name": "my-ruleset",
"rules": [
{
"id": "my-rule",
"last_revision": {
"creation_message": "Initial revision"
},
"name": "my-rule"
}
]
},
"id": "my-ruleset",
"type": "custom_ruleset"
}
}
EOF# Path parameters
export ruleset_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 PATCH "https://api.${DD_SITE}/api/v2/static-analysis/custom/rulesets/${ruleset_name}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"name": "my-ruleset",
"rules": [
{
"id": "my-rule",
"last_revision": {
"creation_message": "Initial revision"
},
"name": "my-rule"
}
]
},
"id": "my-ruleset",
"type": "custom_ruleset"
}
}
EOF# Path parameters
export ruleset_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 PATCH "https://api.${DD_SITE}/api/v2/static-analysis/custom/rulesets/${ruleset_name}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"name": "my-ruleset",
"rules": [
{
"id": "my-rule",
"last_revision": {
"creation_message": "Initial revision"
},
"name": "my-rule"
}
]
},
"id": "my-ruleset",
"type": "custom_ruleset"
}
}
EOF# Path parameters
export ruleset_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 PATCH "https://api.${DD_SITE}/api/v2/static-analysis/custom/rulesets/${ruleset_name}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
"data": {
"attributes": {
"name": "my-ruleset",
"rules": [
{
"id": "my-rule",
"last_revision": {
"creation_message": "Initial revision"
},
"name": "my-rule"
}
]
},
"id": "my-ruleset",
"type": "custom_ruleset"
}
}
EOF// Update Custom Ruleset returns "Successfully updated" 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.CustomRulesetRequest{
Data: &datadogV2.CustomRulesetRequestData{
Attributes: datadogV2.CustomRulesetRequestDataAttributes{
Description: datadog.PtrString("bG9uZyBkZXNjcmlwdGlvbg=="),
Name: "my-ruleset",
Rules: []datadogV2.CustomRule{
{
Id: "my-rule",
LastRevision: &datadogV2.CustomRuleRevisionInput{
Arguments: []datadogV2.Argument{
{
Description: "YXJndW1lbnQgZGVzY3JpcHRpb24=",
Name: "YXJndW1lbnRfbmFtZQ==",
},
},
Category: datadogV2.CUSTOMRULEREVISIONATTRIBUTESCATEGORY_SECURITY.Ptr(),
Code: datadog.PtrString("Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ=="),
CreationMessage: datadog.PtrString("Initial revision"),
Cve: *datadog.NewNullableString(datadog.PtrString("CVE-2024-1234")),
Cwe: *datadog.NewNullableString(datadog.PtrString("CWE-79")),
Description: datadog.PtrString("bG9uZyBkZXNjcmlwdGlvbg=="),
DocumentationUrl: *datadog.NewNullableString(datadog.PtrString("https://docs.example.com/rules/my-rule")),
IsPublished: datadog.PtrBool(false),
IsTesting: datadog.PtrBool(false),
Language: datadogV2.LANGUAGE_PYTHON.Ptr(),
Severity: datadogV2.CUSTOMRULEREVISIONATTRIBUTESSEVERITY_ERROR.Ptr(),
ShortDescription: datadog.PtrString("c2hvcnQgZGVzY3JpcHRpb24="),
ShouldUseAiFix: datadog.PtrBool(false),
Tags: *datadog.NewNullableList(&[]string{
"security",
"custom",
}),
Tests: []datadogV2.CustomRuleRevisionTest{
{
AnnotationCount: 1,
Code: "Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==",
Filename: "test.yaml",
},
},
TreeSitterQuery: datadog.PtrString("Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ=="),
},
Name: "my-rule",
Revisions: []datadogV2.CustomRuleRevisionInput{
{
Arguments: []datadogV2.Argument{
{
Description: "YXJndW1lbnQgZGVzY3JpcHRpb24=",
Name: "YXJndW1lbnRfbmFtZQ==",
},
},
Category: datadogV2.CUSTOMRULEREVISIONATTRIBUTESCATEGORY_SECURITY.Ptr(),
Code: datadog.PtrString("Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ=="),
CreationMessage: datadog.PtrString("Initial revision"),
Cve: *datadog.NewNullableString(datadog.PtrString("CVE-2024-1234")),
Cwe: *datadog.NewNullableString(datadog.PtrString("CWE-79")),
Description: datadog.PtrString("bG9uZyBkZXNjcmlwdGlvbg=="),
DocumentationUrl: *datadog.NewNullableString(datadog.PtrString("https://docs.example.com/rules/my-rule")),
IsPublished: datadog.PtrBool(false),
IsTesting: datadog.PtrBool(false),
Language: datadogV2.LANGUAGE_PYTHON.Ptr(),
Severity: datadogV2.CUSTOMRULEREVISIONATTRIBUTESSEVERITY_ERROR.Ptr(),
ShortDescription: datadog.PtrString("c2hvcnQgZGVzY3JpcHRpb24="),
ShouldUseAiFix: datadog.PtrBool(false),
Tags: *datadog.NewNullableList(&[]string{
"security",
"custom",
}),
Tests: []datadogV2.CustomRuleRevisionTest{
{
AnnotationCount: 1,
Code: "Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==",
Filename: "test.yaml",
},
},
TreeSitterQuery: datadog.PtrString("Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ=="),
},
},
},
},
ShortDescription: datadog.PtrString("c2hvcnQgZGVzY3JpcHRpb24="),
},
Id: "my-ruleset",
Type: datadogV2.CUSTOMRULESETDATATYPE_CUSTOM_RULESET,
},
}
ctx := datadog.NewDefaultContext(context.Background())
ctx = context.WithValue(ctx, datadog.ContextAccessToken, os.Getenv("DD_BEARER_TOKEN"))
configuration := datadog.NewConfiguration()
configuration.SetUnstableOperationEnabled("v2.UpdateCustomRuleset", true)
apiClient := datadog.NewAPIClient(configuration)
api := datadogV2.NewStaticAnalysisApi(apiClient)
resp, r, err := api.UpdateCustomRuleset(ctx, "ruleset_name", body)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `StaticAnalysisApi.UpdateCustomRuleset`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `StaticAnalysisApi.UpdateCustomRuleset`:\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"// Update Custom Ruleset returns "Successfully updated" 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.CustomRule;
import com.datadog.api.client.v2.model.CustomRuleRevisionAttributesCategory;
import com.datadog.api.client.v2.model.CustomRuleRevisionAttributesSeverity;
import com.datadog.api.client.v2.model.CustomRuleRevisionInput;
import com.datadog.api.client.v2.model.CustomRuleRevisionTest;
import com.datadog.api.client.v2.model.CustomRulesetDataType;
import com.datadog.api.client.v2.model.CustomRulesetRequest;
import com.datadog.api.client.v2.model.CustomRulesetRequestData;
import com.datadog.api.client.v2.model.CustomRulesetRequestDataAttributes;
import com.datadog.api.client.v2.model.CustomRulesetResponse;
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.updateCustomRuleset", true);
StaticAnalysisApi apiInstance = new StaticAnalysisApi(defaultClient);
CustomRulesetRequest body =
new CustomRulesetRequest()
.data(
new CustomRulesetRequestData()
.attributes(
new CustomRulesetRequestDataAttributes()
.description("bG9uZyBkZXNjcmlwdGlvbg==")
.name("my-ruleset")
.rules(
Collections.singletonList(
new CustomRule()
.id("my-rule")
.lastRevision(
new CustomRuleRevisionInput()
.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=="))
.name("my-rule")
.revisions(
Collections.singletonList(
new CustomRuleRevisionInput()
.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==")))))
.shortDescription("c2hvcnQgZGVzY3JpcHRpb24="))
.id("my-ruleset")
.type(CustomRulesetDataType.CUSTOM_RULESET));
try {
CustomRulesetResponse result = apiInstance.updateCustomRuleset("ruleset_name", body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling StaticAnalysisApi#updateCustomRuleset");
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""""
Update Custom Ruleset returns "Successfully updated" 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 import CustomRule
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_input import CustomRuleRevisionInput
from datadog_api_client.v2.model.custom_rule_revision_test import CustomRuleRevisionTest
from datadog_api_client.v2.model.custom_ruleset_data_type import CustomRulesetDataType
from datadog_api_client.v2.model.custom_ruleset_request import CustomRulesetRequest
from datadog_api_client.v2.model.custom_ruleset_request_data import CustomRulesetRequestData
from datadog_api_client.v2.model.custom_ruleset_request_data_attributes import CustomRulesetRequestDataAttributes
from datadog_api_client.v2.model.language import Language
body = CustomRulesetRequest(
data=CustomRulesetRequestData(
attributes=CustomRulesetRequestDataAttributes(
description="bG9uZyBkZXNjcmlwdGlvbg==",
name="my-ruleset",
rules=[
CustomRule(
id="my-rule",
last_revision=CustomRuleRevisionInput(
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==",
),
name="my-rule",
revisions=[
CustomRuleRevisionInput(
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==",
),
],
),
],
short_description="c2hvcnQgZGVzY3JpcHRpb24=",
),
id="my-ruleset",
type=CustomRulesetDataType.CUSTOM_RULESET,
),
)
configuration = Configuration()
configuration.access_token = environ["DD_BEARER_TOKEN"]
configuration.unstable_operations["update_custom_ruleset"] = True
with ApiClient(configuration) as api_client:
api_instance = StaticAnalysisApi(api_client)
response = api_instance.update_custom_ruleset(ruleset_name="ruleset_name", 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"# Update Custom Ruleset returns "Successfully updated" response
require "datadog_api_client"
DatadogAPIClient.configure do |config|
config.access_token = ENV["DD_BEARER_TOKEN"]
config.unstable_operations["v2.update_custom_ruleset".to_sym] = true
end
api_instance = DatadogAPIClient::V2::StaticAnalysisAPI.new
body = DatadogAPIClient::V2::CustomRulesetRequest.new({
data: DatadogAPIClient::V2::CustomRulesetRequestData.new({
attributes: DatadogAPIClient::V2::CustomRulesetRequestDataAttributes.new({
description: "bG9uZyBkZXNjcmlwdGlvbg==",
name: "my-ruleset",
rules: [
DatadogAPIClient::V2::CustomRule.new({
id: "my-rule",
last_revision: DatadogAPIClient::V2::CustomRuleRevisionInput.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==",
}),
name: "my-rule",
revisions: [
DatadogAPIClient::V2::CustomRuleRevisionInput.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==",
}),
],
}),
],
short_description: "c2hvcnQgZGVzY3JpcHRpb24=",
}),
id: "my-ruleset",
type: DatadogAPIClient::V2::CustomRulesetDataType::CUSTOM_RULESET,
}),
})
p api_instance.update_custom_ruleset("ruleset_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"// Update Custom Ruleset returns "Successfully updated" 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::CustomRule;
use datadog_api_client::datadogV2::model::CustomRuleRevisionAttributesCategory;
use datadog_api_client::datadogV2::model::CustomRuleRevisionAttributesSeverity;
use datadog_api_client::datadogV2::model::CustomRuleRevisionInput;
use datadog_api_client::datadogV2::model::CustomRuleRevisionTest;
use datadog_api_client::datadogV2::model::CustomRulesetDataType;
use datadog_api_client::datadogV2::model::CustomRulesetRequest;
use datadog_api_client::datadogV2::model::CustomRulesetRequestData;
use datadog_api_client::datadogV2::model::CustomRulesetRequestDataAttributes;
use datadog_api_client::datadogV2::model::Language;
#[tokio::main]
async fn main() {
let body = CustomRulesetRequest::new().data(CustomRulesetRequestData::new(
CustomRulesetRequestDataAttributes::new("my-ruleset".to_string())
.description("bG9uZyBkZXNjcmlwdGlvbg==".to_string())
.rules(Some(vec![CustomRule::new(
"my-rule".to_string(),
"my-rule".to_string(),
)
.last_revision(
CustomRuleRevisionInput::new()
.arguments(Some(vec![Argument::new(
"YXJndW1lbnQgZGVzY3JpcHRpb24=".to_string(),
"YXJndW1lbnRfbmFtZQ==".to_string(),
)]))
.category(CustomRuleRevisionAttributesCategory::SECURITY)
.code("Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==".to_string())
.creation_message("Initial revision".to_string())
.cve(Some("CVE-2024-1234".to_string()))
.cwe(Some("CWE-79".to_string()))
.description("bG9uZyBkZXNjcmlwdGlvbg==".to_string())
.documentation_url(Some("https://docs.example.com/rules/my-rule".to_string()))
.is_published(false)
.is_testing(false)
.language(Language::PYTHON)
.severity(CustomRuleRevisionAttributesSeverity::ERROR)
.short_description("c2hvcnQgZGVzY3JpcHRpb24=".to_string())
.should_use_ai_fix(false)
.tags(Some(vec!["security".to_string(), "custom".to_string()]))
.tests(Some(vec![CustomRuleRevisionTest::new(
1,
"Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==".to_string(),
"test.yaml".to_string(),
)]))
.tree_sitter_query(
"Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==".to_string(),
),
)
.revisions(Some(vec![CustomRuleRevisionInput::new()
.arguments(Some(vec![Argument::new(
"YXJndW1lbnQgZGVzY3JpcHRpb24=".to_string(),
"YXJndW1lbnRfbmFtZQ==".to_string(),
)]))
.category(CustomRuleRevisionAttributesCategory::SECURITY)
.code("Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==".to_string())
.creation_message("Initial revision".to_string())
.cve(Some("CVE-2024-1234".to_string()))
.cwe(Some("CWE-79".to_string()))
.description("bG9uZyBkZXNjcmlwdGlvbg==".to_string())
.documentation_url(Some("https://docs.example.com/rules/my-rule".to_string()))
.is_published(false)
.is_testing(false)
.language(Language::PYTHON)
.severity(CustomRuleRevisionAttributesSeverity::ERROR)
.short_description("c2hvcnQgZGVzY3JpcHRpb24=".to_string())
.should_use_ai_fix(false)
.tags(Some(vec!["security".to_string(), "custom".to_string()]))
.tests(Some(vec![CustomRuleRevisionTest::new(
1,
"Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==".to_string(),
"test.yaml".to_string(),
)]))
.tree_sitter_query(
"Y29uZHVjdG9yOgogICAgLSBkZXBsb3lfb25seTogdHJ1ZQ==".to_string(),
)]))]))
.short_description("c2hvcnQgZGVzY3JpcHRpb24=".to_string()),
"my-ruleset".to_string(),
CustomRulesetDataType::CUSTOM_RULESET,
));
let mut configuration = datadog::Configuration::new();
configuration.set_unstable_operation_enabled("v2.update_custom_ruleset", true);
let api = StaticAnalysisAPI::with_config(configuration);
let resp = api
.update_custom_ruleset("ruleset_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/**
* Update Custom Ruleset returns "Successfully updated" 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.updateCustomRuleset"] = true;
const apiInstance = new v2.StaticAnalysisApi(configuration);
const params: v2.StaticAnalysisApiUpdateCustomRulesetRequest = {
body: {
data: {
attributes: {
description: "bG9uZyBkZXNjcmlwdGlvbg==",
name: "my-ruleset",
rules: [
{
id: "my-rule",
lastRevision: {
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==",
},
name: "my-rule",
revisions: [
{
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==",
},
],
},
],
shortDescription: "c2hvcnQgZGVzY3JpcHRpb24=",
},
id: "my-ruleset",
type: "custom_ruleset",
},
},
rulesetName: "ruleset_name",
};
apiInstance
.updateCustomRuleset(params)
.then((data: v2.CustomRulesetResponse) => {
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"