Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the usage of the filters field when creating an agent rule #2492

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2024-05-22 20:06:48.360377",
"spec_repo_commit": "94c7d978"
"regenerated": "2024-05-23 11:00:08.137912",
"spec_repo_commit": "b829bfa2"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2024-05-22 20:06:48.378411",
"spec_repo_commit": "94c7d978"
"regenerated": "2024-05-23 11:00:08.169625",
"spec_repo_commit": "b829bfa2"
}
}
}
5 changes: 5 additions & 0 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4105,6 +4105,11 @@ components:
description: The SECL expression of the Agent rule.
example: exec.file.name == \"sh\"
type: string
filters:
description: The platforms the Agent rule is supported on.
items:
type: string
type: array
name:
description: The name of the Agent rule.
example: my_agent_rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type CloudWorkloadSecurityAgentRuleCreateAttributes struct {
Enabled *bool `json:"enabled,omitempty"`
// The SECL expression of the Agent rule.
Expression string `json:"expression"`
// The platforms the Agent rule is supported on.
Filters []string `json:"filters,omitempty"`
// The name of the Agent rule.
Name string `json:"name"`
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
Expand Down Expand Up @@ -123,6 +125,34 @@ func (o *CloudWorkloadSecurityAgentRuleCreateAttributes) SetExpression(v string)
o.Expression = v
}

// GetFilters returns the Filters field value if set, zero value otherwise.
func (o *CloudWorkloadSecurityAgentRuleCreateAttributes) GetFilters() []string {
if o == nil || o.Filters == nil {
var ret []string
return ret
}
return o.Filters
}

// GetFiltersOk returns a tuple with the Filters field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *CloudWorkloadSecurityAgentRuleCreateAttributes) GetFiltersOk() (*[]string, bool) {
if o == nil || o.Filters == nil {
return nil, false
}
return &o.Filters, true
}

// HasFilters returns a boolean if a field has been set.
func (o *CloudWorkloadSecurityAgentRuleCreateAttributes) HasFilters() bool {
return o != nil && o.Filters != nil
}

// SetFilters gets a reference to the given []string and assigns it to the Filters field.
func (o *CloudWorkloadSecurityAgentRuleCreateAttributes) SetFilters(v []string) {
o.Filters = v
}

// GetName returns the Name field value.
func (o *CloudWorkloadSecurityAgentRuleCreateAttributes) GetName() string {
if o == nil {
Expand Down Expand Up @@ -159,6 +189,9 @@ func (o CloudWorkloadSecurityAgentRuleCreateAttributes) MarshalJSON() ([]byte, e
toSerialize["enabled"] = o.Enabled
}
toSerialize["expression"] = o.Expression
if o.Filters != nil {
toSerialize["filters"] = o.Filters
}
toSerialize["name"] = o.Name

for key, value := range o.AdditionalProperties {
Expand All @@ -170,10 +203,11 @@ func (o CloudWorkloadSecurityAgentRuleCreateAttributes) MarshalJSON() ([]byte, e
// UnmarshalJSON deserializes the given payload.
func (o *CloudWorkloadSecurityAgentRuleCreateAttributes) UnmarshalJSON(bytes []byte) (err error) {
all := struct {
Description *string `json:"description,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
Expression *string `json:"expression"`
Name *string `json:"name"`
Description *string `json:"description,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
Expression *string `json:"expression"`
Filters []string `json:"filters,omitempty"`
Name *string `json:"name"`
}{}
if err = datadog.Unmarshal(bytes, &all); err != nil {
return datadog.Unmarshal(bytes, &o.UnparsedObject)
Expand All @@ -186,13 +220,14 @@ func (o *CloudWorkloadSecurityAgentRuleCreateAttributes) UnmarshalJSON(bytes []b
}
additionalProperties := make(map[string]interface{})
if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil {
datadog.DeleteKeys(additionalProperties, &[]string{"description", "enabled", "expression", "name"})
datadog.DeleteKeys(additionalProperties, &[]string{"description", "enabled", "expression", "filters", "name"})
} else {
return err
}
o.Description = all.Description
o.Enabled = all.Enabled
o.Expression = *all.Expression
o.Filters = all.Filters
o.Name = *all.Name

if len(additionalProperties) > 0 {
Expand Down
5 changes: 4 additions & 1 deletion examples/v2/csm-threats/CreateCSMThreatsAgentRule.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ func main() {
Description: datadog.PtrString("My Agent rule"),
Enabled: datadog.PtrBool(true),
Expression: `exec.file.name == "sh"`,
Name: "examplecsmthreat",
Filters: []string{
`os == "linux"`,
},
Name: "examplecsmthreat",
},
Type: datadogV2.CLOUDWORKLOADSECURITYAGENTRULETYPE_AGENT_RULE,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024-04-23T17:57:44.371Z
2024-05-22T16:22:22.200Z
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
interactions:
- request:
body: |
{"data":{"attributes":{"description":"My Agent rule","enabled":true,"expression":"exec.file.name == \"sh\"","name":"testcreateacsmthreatsagentrulereturnsokresponse1713895064"},"type":"agent_rule"}}
{"data":{"attributes":{"description":"My Agent rule","enabled":true,"expression":"exec.file.name == \"sh\"","filters":["os == \"linux\""],"name":"testcreateacsmthreatsagentrulereturnsokresponse1716394942"},"type":"agent_rule"}}
form: {}
headers:
Accept:
Expand All @@ -12,10 +12,10 @@ interactions:
method: POST
url: https://api.datadoghq.com/api/v2/remote_config/products/cws/agent_rules
response:
body: '{"data":{"id":"922-a60-32v","type":"agent_rule","attributes":{"category":"Process
Activity","creationDate":1713895064438,"creator":{"name":"","handle":"frog@datadoghq.com"},"defaultRule":false,"description":"My
body: '{"data":{"id":"pn4-mo8-u5r","type":"agent_rule","attributes":{"category":"Process
Activity","creationDate":1716394942614,"creator":{"name":"","handle":"frog@datadoghq.com"},"defaultRule":false,"description":"My
Agent rule","enabled":true,"expression":"exec.file.name == \"sh\"","filters":["os
== \"linux\""],"name":"testcreateacsmthreatsagentrulereturnsokresponse1713895064","updateDate":1713895064438,"updater":{"name":"","handle":"frog@datadoghq.com"}}}}'
== \"linux\""],"name":"testcreateacsmthreatsagentrulereturnsokresponse1716394942","updateDate":1716394942614,"updater":{"name":"","handle":"frog@datadoghq.com"}}}}'
code: 200
duration: 0ms
headers:
Expand All @@ -30,7 +30,7 @@ interactions:
- '*/*'
id: 1
method: DELETE
url: https://api.datadoghq.com/api/v2/remote_config/products/cws/agent_rules/922-a60-32v
url: https://api.datadoghq.com/api/v2/remote_config/products/cws/agent_rules/pn4-mo8-u5r
response:
body: ''
code: 204
Expand Down
2 changes: 1 addition & 1 deletion tests/scenarios/features/v2/csm_threats.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Feature: CSM Threats
@team:DataDog/k9-cloud-security-platform @team:DataDog/k9-cws-backend
Scenario: Create a CSM Threats Agent rule returns "OK" response
Given new "CreateCSMThreatsAgentRule" request
And body with value {"data": {"attributes": {"description": "My Agent rule", "enabled": true, "expression": "exec.file.name == \"sh\"", "name": "{{ unique_lower_alnum }}"}, "type": "agent_rule"}}
And body with value {"data": {"attributes": {"description": "My Agent rule", "enabled": true, "expression": "exec.file.name == \"sh\"", "filters": ["os == \"linux\""], "name": "{{ unique_lower_alnum }}"}, "type": "agent_rule"}}
When the request is sent
Then the response status is 200 OK

Expand Down
Loading