1# coding: utf-8
2# Copyright (c) 2016, 2021, Oracle and/or its affiliates.  All rights reserved.
3# This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
5
6from oci.util import formatted_flat_dict, NONE_SENTINEL, value_allowed_none_or_none_sentinel  # noqa: F401
7from oci.decorators import init_model_state_from_kwargs
8
9
10@init_model_state_from_kwargs
11class CustomProtectionRule(object):
12    """
13    The details of a custom protection rule.
14    """
15
16    #: A constant which can be used with the lifecycle_state property of a CustomProtectionRule.
17    #: This constant has a value of "CREATING"
18    LIFECYCLE_STATE_CREATING = "CREATING"
19
20    #: A constant which can be used with the lifecycle_state property of a CustomProtectionRule.
21    #: This constant has a value of "ACTIVE"
22    LIFECYCLE_STATE_ACTIVE = "ACTIVE"
23
24    #: A constant which can be used with the lifecycle_state property of a CustomProtectionRule.
25    #: This constant has a value of "FAILED"
26    LIFECYCLE_STATE_FAILED = "FAILED"
27
28    #: A constant which can be used with the lifecycle_state property of a CustomProtectionRule.
29    #: This constant has a value of "UPDATING"
30    LIFECYCLE_STATE_UPDATING = "UPDATING"
31
32    #: A constant which can be used with the lifecycle_state property of a CustomProtectionRule.
33    #: This constant has a value of "DELETING"
34    LIFECYCLE_STATE_DELETING = "DELETING"
35
36    #: A constant which can be used with the lifecycle_state property of a CustomProtectionRule.
37    #: This constant has a value of "DELETED"
38    LIFECYCLE_STATE_DELETED = "DELETED"
39
40    def __init__(self, **kwargs):
41        """
42        Initializes a new CustomProtectionRule object with values from keyword arguments.
43        The following keyword arguments are supported (corresponding to the getters/setters of this class):
44
45        :param id:
46            The value to assign to the id property of this CustomProtectionRule.
47        :type id: str
48
49        :param compartment_id:
50            The value to assign to the compartment_id property of this CustomProtectionRule.
51        :type compartment_id: str
52
53        :param display_name:
54            The value to assign to the display_name property of this CustomProtectionRule.
55        :type display_name: str
56
57        :param description:
58            The value to assign to the description property of this CustomProtectionRule.
59        :type description: str
60
61        :param mod_security_rule_ids:
62            The value to assign to the mod_security_rule_ids property of this CustomProtectionRule.
63        :type mod_security_rule_ids: list[str]
64
65        :param template:
66            The value to assign to the template property of this CustomProtectionRule.
67        :type template: str
68
69        :param lifecycle_state:
70            The value to assign to the lifecycle_state property of this CustomProtectionRule.
71            Allowed values for this property are: "CREATING", "ACTIVE", "FAILED", "UPDATING", "DELETING", "DELETED", 'UNKNOWN_ENUM_VALUE'.
72            Any unrecognized values returned by a service will be mapped to 'UNKNOWN_ENUM_VALUE'.
73        :type lifecycle_state: str
74
75        :param time_created:
76            The value to assign to the time_created property of this CustomProtectionRule.
77        :type time_created: datetime
78
79        :param freeform_tags:
80            The value to assign to the freeform_tags property of this CustomProtectionRule.
81        :type freeform_tags: dict(str, str)
82
83        :param defined_tags:
84            The value to assign to the defined_tags property of this CustomProtectionRule.
85        :type defined_tags: dict(str, dict(str, object))
86
87        """
88        self.swagger_types = {
89            'id': 'str',
90            'compartment_id': 'str',
91            'display_name': 'str',
92            'description': 'str',
93            'mod_security_rule_ids': 'list[str]',
94            'template': 'str',
95            'lifecycle_state': 'str',
96            'time_created': 'datetime',
97            'freeform_tags': 'dict(str, str)',
98            'defined_tags': 'dict(str, dict(str, object))'
99        }
100
101        self.attribute_map = {
102            'id': 'id',
103            'compartment_id': 'compartmentId',
104            'display_name': 'displayName',
105            'description': 'description',
106            'mod_security_rule_ids': 'modSecurityRuleIds',
107            'template': 'template',
108            'lifecycle_state': 'lifecycleState',
109            'time_created': 'timeCreated',
110            'freeform_tags': 'freeformTags',
111            'defined_tags': 'definedTags'
112        }
113
114        self._id = None
115        self._compartment_id = None
116        self._display_name = None
117        self._description = None
118        self._mod_security_rule_ids = None
119        self._template = None
120        self._lifecycle_state = None
121        self._time_created = None
122        self._freeform_tags = None
123        self._defined_tags = None
124
125    @property
126    def id(self):
127        """
128        Gets the id of this CustomProtectionRule.
129        The `OCID`__ of the custom protection rule.
130
131        __ https://docs.cloud.oracle.com/Content/General/Concepts/identifiers.htm
132
133
134        :return: The id of this CustomProtectionRule.
135        :rtype: str
136        """
137        return self._id
138
139    @id.setter
140    def id(self, id):
141        """
142        Sets the id of this CustomProtectionRule.
143        The `OCID`__ of the custom protection rule.
144
145        __ https://docs.cloud.oracle.com/Content/General/Concepts/identifiers.htm
146
147
148        :param id: The id of this CustomProtectionRule.
149        :type: str
150        """
151        self._id = id
152
153    @property
154    def compartment_id(self):
155        """
156        Gets the compartment_id of this CustomProtectionRule.
157        The `OCID`__ of the custom protection rule's compartment.
158
159        __ https://docs.cloud.oracle.com/Content/General/Concepts/identifiers.htm
160
161
162        :return: The compartment_id of this CustomProtectionRule.
163        :rtype: str
164        """
165        return self._compartment_id
166
167    @compartment_id.setter
168    def compartment_id(self, compartment_id):
169        """
170        Sets the compartment_id of this CustomProtectionRule.
171        The `OCID`__ of the custom protection rule's compartment.
172
173        __ https://docs.cloud.oracle.com/Content/General/Concepts/identifiers.htm
174
175
176        :param compartment_id: The compartment_id of this CustomProtectionRule.
177        :type: str
178        """
179        self._compartment_id = compartment_id
180
181    @property
182    def display_name(self):
183        """
184        Gets the display_name of this CustomProtectionRule.
185        The user-friendly name of the custom protection rule.
186
187
188        :return: The display_name of this CustomProtectionRule.
189        :rtype: str
190        """
191        return self._display_name
192
193    @display_name.setter
194    def display_name(self, display_name):
195        """
196        Sets the display_name of this CustomProtectionRule.
197        The user-friendly name of the custom protection rule.
198
199
200        :param display_name: The display_name of this CustomProtectionRule.
201        :type: str
202        """
203        self._display_name = display_name
204
205    @property
206    def description(self):
207        """
208        Gets the description of this CustomProtectionRule.
209        The description of the custom protection rule.
210
211
212        :return: The description of this CustomProtectionRule.
213        :rtype: str
214        """
215        return self._description
216
217    @description.setter
218    def description(self, description):
219        """
220        Sets the description of this CustomProtectionRule.
221        The description of the custom protection rule.
222
223
224        :param description: The description of this CustomProtectionRule.
225        :type: str
226        """
227        self._description = description
228
229    @property
230    def mod_security_rule_ids(self):
231        """
232        Gets the mod_security_rule_ids of this CustomProtectionRule.
233        The auto-generated ID for the custom protection rule. These IDs are referenced in logs.
234
235
236        :return: The mod_security_rule_ids of this CustomProtectionRule.
237        :rtype: list[str]
238        """
239        return self._mod_security_rule_ids
240
241    @mod_security_rule_ids.setter
242    def mod_security_rule_ids(self, mod_security_rule_ids):
243        """
244        Sets the mod_security_rule_ids of this CustomProtectionRule.
245        The auto-generated ID for the custom protection rule. These IDs are referenced in logs.
246
247
248        :param mod_security_rule_ids: The mod_security_rule_ids of this CustomProtectionRule.
249        :type: list[str]
250        """
251        self._mod_security_rule_ids = mod_security_rule_ids
252
253    @property
254    def template(self):
255        """
256        Gets the template of this CustomProtectionRule.
257        The template text of the custom protection rule. All custom protection rules are expressed in ModSecurity Rule Language.
258
259        Additionally, each rule must include two placeholder variables that are updated by the WAF service upon publication of the rule.
260
261        `id: {{id_1}}` - This field is populated with a unique rule ID generated by the WAF service which identifies a `SecRule`. More than one `SecRule` can be defined in the `template` field of a CreateCustomSecurityRule call. The value of the first `SecRule` must be `id: {{id_1}}` and the `id` field of each subsequent `SecRule` should increase by one, as shown in the example.
262
263        `ctl:ruleEngine={{mode}}` - The action to be taken when the criteria of the `SecRule` are met, either `OFF`, `DETECT` or `BLOCK`. This field is automatically populated with the corresponding value of the `action` field of the `CustomProtectionRuleSetting` schema when the `WafConfig` is updated.
264
265        *Example:*
266          ```
267          SecRule REQUEST_COOKIES \"regex matching SQL injection - part 1/2\" \\
268                  \"phase:2,                                                 \\
269                  msg:'Detects chained SQL injection attempts 1/2.',        \\
270                  id: {{id_1}},                                             \\
271                  ctl:ruleEngine={{mode}},                                  \\
272                  deny\"
273          SecRule REQUEST_COOKIES \"regex matching SQL injection - part 2/2\" \\
274                  \"phase:2,                                                 \\
275                  msg:'Detects chained SQL injection attempts 2/2.',        \\
276                  id: {{id_2}},                                             \\
277                  ctl:ruleEngine={{mode}},                                  \\
278                  deny\"
279          ```
280
281
282        The example contains two `SecRules` each having distinct regex expression to match the `Cookie` header value during the second input analysis phase.
283
284        For more information about custom protection rules, see `Custom Protection Rules`__.
285
286        For more information about ModSecurity syntax, see `Making Rules: The Basic Syntax`__.
287
288        For more information about ModSecurity's open source WAF rules, see `Mod Security's OWASP Core Rule Set documentation`__.
289
290        __ https://docs.cloud.oracle.com/Content/WAF/tasks/customprotectionrules.htm
291        __ https://www.modsecurity.org/CRS/Documentation/making.html
292        __ https://www.modsecurity.org/CRS/Documentation/index.html
293
294
295        :return: The template of this CustomProtectionRule.
296        :rtype: str
297        """
298        return self._template
299
300    @template.setter
301    def template(self, template):
302        """
303        Sets the template of this CustomProtectionRule.
304        The template text of the custom protection rule. All custom protection rules are expressed in ModSecurity Rule Language.
305
306        Additionally, each rule must include two placeholder variables that are updated by the WAF service upon publication of the rule.
307
308        `id: {{id_1}}` - This field is populated with a unique rule ID generated by the WAF service which identifies a `SecRule`. More than one `SecRule` can be defined in the `template` field of a CreateCustomSecurityRule call. The value of the first `SecRule` must be `id: {{id_1}}` and the `id` field of each subsequent `SecRule` should increase by one, as shown in the example.
309
310        `ctl:ruleEngine={{mode}}` - The action to be taken when the criteria of the `SecRule` are met, either `OFF`, `DETECT` or `BLOCK`. This field is automatically populated with the corresponding value of the `action` field of the `CustomProtectionRuleSetting` schema when the `WafConfig` is updated.
311
312        *Example:*
313          ```
314          SecRule REQUEST_COOKIES \"regex matching SQL injection - part 1/2\" \\
315                  \"phase:2,                                                 \\
316                  msg:'Detects chained SQL injection attempts 1/2.',        \\
317                  id: {{id_1}},                                             \\
318                  ctl:ruleEngine={{mode}},                                  \\
319                  deny\"
320          SecRule REQUEST_COOKIES \"regex matching SQL injection - part 2/2\" \\
321                  \"phase:2,                                                 \\
322                  msg:'Detects chained SQL injection attempts 2/2.',        \\
323                  id: {{id_2}},                                             \\
324                  ctl:ruleEngine={{mode}},                                  \\
325                  deny\"
326          ```
327
328
329        The example contains two `SecRules` each having distinct regex expression to match the `Cookie` header value during the second input analysis phase.
330
331        For more information about custom protection rules, see `Custom Protection Rules`__.
332
333        For more information about ModSecurity syntax, see `Making Rules: The Basic Syntax`__.
334
335        For more information about ModSecurity's open source WAF rules, see `Mod Security's OWASP Core Rule Set documentation`__.
336
337        __ https://docs.cloud.oracle.com/Content/WAF/tasks/customprotectionrules.htm
338        __ https://www.modsecurity.org/CRS/Documentation/making.html
339        __ https://www.modsecurity.org/CRS/Documentation/index.html
340
341
342        :param template: The template of this CustomProtectionRule.
343        :type: str
344        """
345        self._template = template
346
347    @property
348    def lifecycle_state(self):
349        """
350        Gets the lifecycle_state of this CustomProtectionRule.
351        The current lifecycle state of the custom protection rule.
352
353        Allowed values for this property are: "CREATING", "ACTIVE", "FAILED", "UPDATING", "DELETING", "DELETED", 'UNKNOWN_ENUM_VALUE'.
354        Any unrecognized values returned by a service will be mapped to 'UNKNOWN_ENUM_VALUE'.
355
356
357        :return: The lifecycle_state of this CustomProtectionRule.
358        :rtype: str
359        """
360        return self._lifecycle_state
361
362    @lifecycle_state.setter
363    def lifecycle_state(self, lifecycle_state):
364        """
365        Sets the lifecycle_state of this CustomProtectionRule.
366        The current lifecycle state of the custom protection rule.
367
368
369        :param lifecycle_state: The lifecycle_state of this CustomProtectionRule.
370        :type: str
371        """
372        allowed_values = ["CREATING", "ACTIVE", "FAILED", "UPDATING", "DELETING", "DELETED"]
373        if not value_allowed_none_or_none_sentinel(lifecycle_state, allowed_values):
374            lifecycle_state = 'UNKNOWN_ENUM_VALUE'
375        self._lifecycle_state = lifecycle_state
376
377    @property
378    def time_created(self):
379        """
380        Gets the time_created of this CustomProtectionRule.
381        The date and time the protection rule was created, expressed in RFC 3339 timestamp format.
382
383
384        :return: The time_created of this CustomProtectionRule.
385        :rtype: datetime
386        """
387        return self._time_created
388
389    @time_created.setter
390    def time_created(self, time_created):
391        """
392        Sets the time_created of this CustomProtectionRule.
393        The date and time the protection rule was created, expressed in RFC 3339 timestamp format.
394
395
396        :param time_created: The time_created of this CustomProtectionRule.
397        :type: datetime
398        """
399        self._time_created = time_created
400
401    @property
402    def freeform_tags(self):
403        """
404        Gets the freeform_tags of this CustomProtectionRule.
405        Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace.
406        For more information, see `Resource Tags`__.
407
408        Example: `{\"Department\": \"Finance\"}`
409
410        __ https://docs.cloud.oracle.com/Content/General/Concepts/resourcetags.htm
411
412
413        :return: The freeform_tags of this CustomProtectionRule.
414        :rtype: dict(str, str)
415        """
416        return self._freeform_tags
417
418    @freeform_tags.setter
419    def freeform_tags(self, freeform_tags):
420        """
421        Sets the freeform_tags of this CustomProtectionRule.
422        Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace.
423        For more information, see `Resource Tags`__.
424
425        Example: `{\"Department\": \"Finance\"}`
426
427        __ https://docs.cloud.oracle.com/Content/General/Concepts/resourcetags.htm
428
429
430        :param freeform_tags: The freeform_tags of this CustomProtectionRule.
431        :type: dict(str, str)
432        """
433        self._freeform_tags = freeform_tags
434
435    @property
436    def defined_tags(self):
437        """
438        Gets the defined_tags of this CustomProtectionRule.
439        Defined tags for this resource. Each key is predefined and scoped to a namespace.
440        For more information, see `Resource Tags`__.
441
442        Example: `{\"Operations\": {\"CostCenter\": \"42\"}}`
443
444        __ https://docs.cloud.oracle.com/Content/General/Concepts/resourcetags.htm
445
446
447        :return: The defined_tags of this CustomProtectionRule.
448        :rtype: dict(str, dict(str, object))
449        """
450        return self._defined_tags
451
452    @defined_tags.setter
453    def defined_tags(self, defined_tags):
454        """
455        Sets the defined_tags of this CustomProtectionRule.
456        Defined tags for this resource. Each key is predefined and scoped to a namespace.
457        For more information, see `Resource Tags`__.
458
459        Example: `{\"Operations\": {\"CostCenter\": \"42\"}}`
460
461        __ https://docs.cloud.oracle.com/Content/General/Concepts/resourcetags.htm
462
463
464        :param defined_tags: The defined_tags of this CustomProtectionRule.
465        :type: dict(str, dict(str, object))
466        """
467        self._defined_tags = defined_tags
468
469    def __repr__(self):
470        return formatted_flat_dict(self)
471
472    def __eq__(self, other):
473        if other is None:
474            return False
475
476        return self.__dict__ == other.__dict__
477
478    def __ne__(self, other):
479        return not self == other
480