Skip to content

Commit 605cb35

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add exists, !exists, equals, and !equals operators to WAF custom rules (DataDog#3930)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent dd55c11 commit 605cb35

6 files changed

Lines changed: 158 additions & 12 deletions

.generator/schemas/v2/openapi.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4527,6 +4527,10 @@ components:
45274527
- ip_match
45284528
- "!ip_match"
45294529
- capture_data
4530+
- exists
4531+
- "!exists"
4532+
- equals
4533+
- "!equals"
45304534
example: "match_regex"
45314535
type: string
45324536
x-enum-varnames:
@@ -4541,6 +4545,10 @@ components:
45414545
- IP_MATCH
45424546
- NOT_IP_MATCH
45434547
- CAPTURE_DATA
4548+
- EXISTS
4549+
- NOT_EXISTS
4550+
- EQUALS
4551+
- NOT_EQUALS
45444552
ApplicationSecurityWafCustomRuleConditionOptions:
45454553
description: Options for the operator of this condition.
45464554
properties:
@@ -4581,6 +4589,8 @@ components:
45814589
description: "Regex to use with the condition. Only used with match_regex and !match_regex operator."
45824590
example: "path.*"
45834591
type: string
4592+
type:
4593+
$ref: "#/components/schemas/ApplicationSecurityWafCustomRuleConditionParametersType"
45844594
value:
45854595
description: |-
45864596
Store the captured value in the specified tag name. Only used with the capture_data operator.
@@ -4589,6 +4599,22 @@ components:
45894599
required:
45904600
- inputs
45914601
type: object
4602+
ApplicationSecurityWafCustomRuleConditionParametersType:
4603+
description: The type of the value to compare against. Only used with the equals and !equals operator.
4604+
enum:
4605+
- boolean
4606+
- signed
4607+
- unsigned
4608+
- float
4609+
- string
4610+
example: "string"
4611+
type: string
4612+
x-enum-varnames:
4613+
- BOOLEAN
4614+
- SIGNED
4615+
- UNSIGNED
4616+
- FLOAT
4617+
- STRING
45924618
ApplicationSecurityWafCustomRuleCreateAttributes:
45934619
description: "Create a new WAF custom rule."
45944620
properties:

api/datadogV2/model_application_security_waf_custom_rule_condition_operator.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ const (
2626
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONOPERATOR_IP_MATCH ApplicationSecurityWafCustomRuleConditionOperator = "ip_match"
2727
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONOPERATOR_NOT_IP_MATCH ApplicationSecurityWafCustomRuleConditionOperator = "!ip_match"
2828
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONOPERATOR_CAPTURE_DATA ApplicationSecurityWafCustomRuleConditionOperator = "capture_data"
29+
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONOPERATOR_EXISTS ApplicationSecurityWafCustomRuleConditionOperator = "exists"
30+
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONOPERATOR_NOT_EXISTS ApplicationSecurityWafCustomRuleConditionOperator = "!exists"
31+
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONOPERATOR_EQUALS ApplicationSecurityWafCustomRuleConditionOperator = "equals"
32+
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONOPERATOR_NOT_EQUALS ApplicationSecurityWafCustomRuleConditionOperator = "!equals"
2933
)
3034

3135
var allowedApplicationSecurityWafCustomRuleConditionOperatorEnumValues = []ApplicationSecurityWafCustomRuleConditionOperator{
@@ -40,6 +44,10 @@ var allowedApplicationSecurityWafCustomRuleConditionOperatorEnumValues = []Appli
4044
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONOPERATOR_IP_MATCH,
4145
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONOPERATOR_NOT_IP_MATCH,
4246
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONOPERATOR_CAPTURE_DATA,
47+
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONOPERATOR_EXISTS,
48+
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONOPERATOR_NOT_EXISTS,
49+
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONOPERATOR_EQUALS,
50+
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONOPERATOR_NOT_EQUALS,
4351
}
4452

4553
// GetAllowedValues reeturns the list of possible values.

api/datadogV2/model_application_security_waf_custom_rule_condition_parameters.go

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ type ApplicationSecurityWafCustomRuleConditionParameters struct {
2323
Options *ApplicationSecurityWafCustomRuleConditionOptions `json:"options,omitempty"`
2424
// Regex to use with the condition. Only used with match_regex and !match_regex operator.
2525
Regex *string `json:"regex,omitempty"`
26+
// The type of the value to compare against. Only used with the equals and !equals operator.
27+
Type *ApplicationSecurityWafCustomRuleConditionParametersType `json:"type,omitempty"`
2628
// Store the captured value in the specified tag name. Only used with the capture_data operator.
2729
Value *string `json:"value,omitempty"`
2830
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
@@ -183,6 +185,34 @@ func (o *ApplicationSecurityWafCustomRuleConditionParameters) SetRegex(v string)
183185
o.Regex = &v
184186
}
185187

188+
// GetType returns the Type field value if set, zero value otherwise.
189+
func (o *ApplicationSecurityWafCustomRuleConditionParameters) GetType() ApplicationSecurityWafCustomRuleConditionParametersType {
190+
if o == nil || o.Type == nil {
191+
var ret ApplicationSecurityWafCustomRuleConditionParametersType
192+
return ret
193+
}
194+
return *o.Type
195+
}
196+
197+
// GetTypeOk returns a tuple with the Type field value if set, nil otherwise
198+
// and a boolean to check if the value has been set.
199+
func (o *ApplicationSecurityWafCustomRuleConditionParameters) GetTypeOk() (*ApplicationSecurityWafCustomRuleConditionParametersType, bool) {
200+
if o == nil || o.Type == nil {
201+
return nil, false
202+
}
203+
return o.Type, true
204+
}
205+
206+
// HasType returns a boolean if a field has been set.
207+
func (o *ApplicationSecurityWafCustomRuleConditionParameters) HasType() bool {
208+
return o != nil && o.Type != nil
209+
}
210+
211+
// SetType gets a reference to the given ApplicationSecurityWafCustomRuleConditionParametersType and assigns it to the Type field.
212+
func (o *ApplicationSecurityWafCustomRuleConditionParameters) SetType(v ApplicationSecurityWafCustomRuleConditionParametersType) {
213+
o.Type = &v
214+
}
215+
186216
// GetValue returns the Value field value if set, zero value otherwise.
187217
func (o *ApplicationSecurityWafCustomRuleConditionParameters) GetValue() string {
188218
if o == nil || o.Value == nil {
@@ -230,6 +260,9 @@ func (o ApplicationSecurityWafCustomRuleConditionParameters) MarshalJSON() ([]by
230260
if o.Regex != nil {
231261
toSerialize["regex"] = o.Regex
232262
}
263+
if o.Type != nil {
264+
toSerialize["type"] = o.Type
265+
}
233266
if o.Value != nil {
234267
toSerialize["value"] = o.Value
235268
}
@@ -243,12 +276,13 @@ func (o ApplicationSecurityWafCustomRuleConditionParameters) MarshalJSON() ([]by
243276
// UnmarshalJSON deserializes the given payload.
244277
func (o *ApplicationSecurityWafCustomRuleConditionParameters) UnmarshalJSON(bytes []byte) (err error) {
245278
all := struct {
246-
Data *string `json:"data,omitempty"`
247-
Inputs *[]ApplicationSecurityWafCustomRuleConditionInput `json:"inputs"`
248-
List []string `json:"list,omitempty"`
249-
Options *ApplicationSecurityWafCustomRuleConditionOptions `json:"options,omitempty"`
250-
Regex *string `json:"regex,omitempty"`
251-
Value *string `json:"value,omitempty"`
279+
Data *string `json:"data,omitempty"`
280+
Inputs *[]ApplicationSecurityWafCustomRuleConditionInput `json:"inputs"`
281+
List []string `json:"list,omitempty"`
282+
Options *ApplicationSecurityWafCustomRuleConditionOptions `json:"options,omitempty"`
283+
Regex *string `json:"regex,omitempty"`
284+
Type *ApplicationSecurityWafCustomRuleConditionParametersType `json:"type,omitempty"`
285+
Value *string `json:"value,omitempty"`
252286
}{}
253287
if err = datadog.Unmarshal(bytes, &all); err != nil {
254288
return datadog.Unmarshal(bytes, &o.UnparsedObject)
@@ -258,7 +292,7 @@ func (o *ApplicationSecurityWafCustomRuleConditionParameters) UnmarshalJSON(byte
258292
}
259293
additionalProperties := make(map[string]interface{})
260294
if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil {
261-
datadog.DeleteKeys(additionalProperties, &[]string{"data", "inputs", "list", "options", "regex", "value"})
295+
datadog.DeleteKeys(additionalProperties, &[]string{"data", "inputs", "list", "options", "regex", "type", "value"})
262296
} else {
263297
return err
264298
}
@@ -272,6 +306,11 @@ func (o *ApplicationSecurityWafCustomRuleConditionParameters) UnmarshalJSON(byte
272306
}
273307
o.Options = all.Options
274308
o.Regex = all.Regex
309+
if all.Type != nil && !all.Type.IsValid() {
310+
hasInvalidField = true
311+
} else {
312+
o.Type = all.Type
313+
}
275314
o.Value = all.Value
276315

277316
if len(additionalProperties) > 0 {
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
3+
// Copyright 2019-Present Datadog, Inc.
4+
5+
package datadogV2
6+
7+
import (
8+
"fmt"
9+
10+
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
11+
)
12+
13+
// ApplicationSecurityWafCustomRuleConditionParametersType The type of the value to compare against. Only used with the equals and !equals operator.
14+
type ApplicationSecurityWafCustomRuleConditionParametersType string
15+
16+
// List of ApplicationSecurityWafCustomRuleConditionParametersType.
17+
const (
18+
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONPARAMETERSTYPE_BOOLEAN ApplicationSecurityWafCustomRuleConditionParametersType = "boolean"
19+
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONPARAMETERSTYPE_SIGNED ApplicationSecurityWafCustomRuleConditionParametersType = "signed"
20+
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONPARAMETERSTYPE_UNSIGNED ApplicationSecurityWafCustomRuleConditionParametersType = "unsigned"
21+
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONPARAMETERSTYPE_FLOAT ApplicationSecurityWafCustomRuleConditionParametersType = "float"
22+
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONPARAMETERSTYPE_STRING ApplicationSecurityWafCustomRuleConditionParametersType = "string"
23+
)
24+
25+
var allowedApplicationSecurityWafCustomRuleConditionParametersTypeEnumValues = []ApplicationSecurityWafCustomRuleConditionParametersType{
26+
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONPARAMETERSTYPE_BOOLEAN,
27+
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONPARAMETERSTYPE_SIGNED,
28+
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONPARAMETERSTYPE_UNSIGNED,
29+
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONPARAMETERSTYPE_FLOAT,
30+
APPLICATIONSECURITYWAFCUSTOMRULECONDITIONPARAMETERSTYPE_STRING,
31+
}
32+
33+
// GetAllowedValues reeturns the list of possible values.
34+
func (v *ApplicationSecurityWafCustomRuleConditionParametersType) GetAllowedValues() []ApplicationSecurityWafCustomRuleConditionParametersType {
35+
return allowedApplicationSecurityWafCustomRuleConditionParametersTypeEnumValues
36+
}
37+
38+
// UnmarshalJSON deserializes the given payload.
39+
func (v *ApplicationSecurityWafCustomRuleConditionParametersType) UnmarshalJSON(src []byte) error {
40+
var value string
41+
err := datadog.Unmarshal(src, &value)
42+
if err != nil {
43+
return err
44+
}
45+
*v = ApplicationSecurityWafCustomRuleConditionParametersType(value)
46+
return nil
47+
}
48+
49+
// NewApplicationSecurityWafCustomRuleConditionParametersTypeFromValue returns a pointer to a valid ApplicationSecurityWafCustomRuleConditionParametersType
50+
// for the value passed as argument, or an error if the value passed is not allowed by the enum.
51+
func NewApplicationSecurityWafCustomRuleConditionParametersTypeFromValue(v string) (*ApplicationSecurityWafCustomRuleConditionParametersType, error) {
52+
ev := ApplicationSecurityWafCustomRuleConditionParametersType(v)
53+
if ev.IsValid() {
54+
return &ev, nil
55+
}
56+
return nil, fmt.Errorf("invalid value '%v' for ApplicationSecurityWafCustomRuleConditionParametersType: valid values are %v", v, allowedApplicationSecurityWafCustomRuleConditionParametersTypeEnumValues)
57+
}
58+
59+
// IsValid return true if the value is valid for the enum, false otherwise.
60+
func (v ApplicationSecurityWafCustomRuleConditionParametersType) IsValid() bool {
61+
for _, existing := range allowedApplicationSecurityWafCustomRuleConditionParametersTypeEnumValues {
62+
if existing == v {
63+
return true
64+
}
65+
}
66+
return false
67+
}
68+
69+
// Ptr returns reference to ApplicationSecurityWafCustomRuleConditionParametersType value.
70+
func (v ApplicationSecurityWafCustomRuleConditionParametersType) Ptr() *ApplicationSecurityWafCustomRuleConditionParametersType {
71+
return &v
72+
}

examples/v2/application-security/CreateApplicationSecurityWafCustomRule.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func main() {
4141
MinLength: datadog.PtrInt64(0),
4242
},
4343
Regex: datadog.PtrString("path.*"),
44+
Type: datadogV2.APPLICATIONSECURITYWAFCUSTOMRULECONDITIONPARAMETERSTYPE_STRING.Ptr(),
4445
Value: datadog.PtrString("custom_tag"),
4546
},
4647
},

0 commit comments

Comments
 (0)