1
1
from ..models import MutableBaseModel , CreatableModelMixin , NewBaseModel
2
2
3
+ from copy import deepcopy
3
4
import logging
4
5
import json
6
+
5
7
from ..errors import ServerError
6
8
7
9
log = logging .getLogger (__name__ )
10
12
class DefenseMutableModel (MutableBaseModel ):
11
13
_change_object_http_method = "PATCH"
12
14
15
+ def _parse (self , obj ):
16
+ if type (obj ) == dict and self .info_key in obj :
17
+ return obj [self .info_key ]
18
+
13
19
def _update_object (self ):
20
+ if self ._change_object_http_method != "PATCH" :
21
+ return self ._update_entire_object ()
22
+ else :
23
+ return self ._patch_object ()
24
+
25
+ def _update_entire_object (self ):
26
+ if self .__class__ .primary_key in self ._dirty_attributes .keys () or self ._model_unique_id is None :
27
+ new_object_info = deepcopy (self ._info )
28
+ try :
29
+ if not self ._new_object_needs_primary_key :
30
+ del (new_object_info [self .__class__ .primary_key ])
31
+ except Exception :
32
+ pass
33
+ log .debug ("Creating a new {0:s} object" .format (self .__class__ .__name__ ))
34
+ ret = self ._cb .api_json_request (self .__class__ ._new_object_http_method , self .urlobject ,
35
+ data = {self .info_key : new_object_info })
36
+ else :
37
+ log .debug ("Updating {0:s} with unique ID {1:s}" .format (self .__class__ .__name__ , str (self ._model_unique_id )))
38
+ ret = self ._cb .api_json_request (self .__class__ ._change_object_http_method ,
39
+ self ._build_api_request_uri (), data = {self .info_key : self ._info })
40
+
41
+ return self ._refresh_if_needed (ret )
42
+
43
+ def _patch_object (self ):
14
44
if self .__class__ .primary_key in self ._dirty_attributes .keys () or self ._model_unique_id is None :
15
45
log .debug ("Creating a new {0:s} object" .format (self .__class__ .__name__ ))
16
46
ret = self ._cb .api_json_request (self .__class__ ._new_object_http_method , self .urlobject ,
@@ -71,10 +101,6 @@ class Device(DefenseMutableModel):
71
101
def __init__ (self , cb , model_unique_id , initial_data = None ):
72
102
super (Device , self ).__init__ (cb , model_unique_id , initial_data )
73
103
74
- def _parse (self , obj ):
75
- if type (obj ) == dict and "deviceInfo" in obj :
76
- return obj ["deviceInfo" ]
77
-
78
104
def lr_session (self ):
79
105
"""
80
106
Retrieve a Live Response session object for this Device.
@@ -90,11 +116,20 @@ def lr_session(self):
90
116
class Event (NewBaseModel ):
91
117
urlobject = "/integrationServices/v3/event"
92
118
primary_key = "eventId"
119
+ info_key = "eventInfo"
120
+
121
+ def _parse (self , obj ):
122
+ if type (obj ) == dict and self .info_key in obj :
123
+ return obj [self .info_key ]
93
124
94
125
def __init__ (self , cb , model_unique_id , initial_data = None ):
95
126
super (Event , self ).__init__ (cb , model_unique_id , initial_data )
96
127
97
- def _parse (self , obj ):
98
- if type (obj ) == dict and "eventInfo" in obj :
99
- return obj ["eventInfo" ]
128
+
129
+ class Policy (DefenseMutableModel , CreatableModelMixin ):
130
+ urlobject = "/integrationServices/v3/policy"
131
+ info_key = "policyInfo"
132
+ swagger_meta_file = "defense/models/policyInfo.yaml"
133
+ _change_object_http_method = "PUT"
134
+
100
135
0 commit comments