Skip to content

Commit 3bb7f99

Browse files
authored
Updates for Lacework v4.20 (#24)
* fix: removed `policy_ui` parameters for compatibility * fix: cleanup for HTTP 204 response on search endpoints * refactor: readability improvements for tests
1 parent 33f01c7 commit 3bb7f99

File tree

7 files changed

+18
-16
lines changed

7 files changed

+18
-16
lines changed

laceworksdk/api/alert_channels.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ def search(self,
140140

141141
response = self._session.post(api_uri, data=query_data, org=org)
142142

143-
return response.json()
143+
if response.status_code == 204:
144+
return {"data": []}
145+
else:
146+
return response.json()
144147

145148
def update(self,
146149
guid,

laceworksdk/api/alert_rules.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ def search(self,
129129

130130
response = self._session.post(api_uri, data=query_data, org=org)
131131

132-
return response.json()
132+
if response.status_code == 204:
133+
return {"data": []}
134+
else:
135+
return response.json()
133136

134137
def update(self,
135138
guid,

laceworksdk/api/audit_logs.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,7 @@ def search(self,
7272

7373
response = self._session.post(api_uri, data=query_data, org=org)
7474

75-
return response.json()
75+
if response.status_code == 204:
76+
return {"data": []}
77+
else:
78+
return response.json()

laceworksdk/api/policies.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def create(self,
3636
evaluator_id,
3737
limit=None,
3838
eval_frequency=None,
39-
policy_ui=None,
4039
org=False):
4140
"""
4241
A method to create a new Lacework Query Language (LQL) policy.
@@ -55,7 +54,6 @@ def create(self,
5554
:param limit: An integer representing the number of results to return.
5655
:param eval_frequency: A string representing the frequency in which to evaluate the policy.
5756
("Hourly", "Daily")
58-
:param policy_ui: A dictionary which specifies the policyUi domain and subdomain.
5957
:param org: A boolean representing whether the request should be performed
6058
at the Organization level
6159
@@ -67,9 +65,6 @@ def create(self,
6765
# Build the Policies request URI
6866
api_uri = "/api/v2/Policies"
6967

70-
if policy_ui is None:
71-
policy_ui = {}
72-
7368
data = {
7469
"policyType": policy_type,
7570
"queryId": query_id,
@@ -80,7 +75,6 @@ def create(self,
8075
"severity": severity,
8176
"alertEnabled": int(bool(alert_enabled)),
8277
"alertProfile": alert_profile,
83-
"policyUi": policy_ui,
8478
"evaluatorId": evaluator_id
8579
}
8680

@@ -146,7 +140,6 @@ def update(self,
146140
alert_profile=None,
147141
limit=None,
148142
eval_frequency=None,
149-
policy_ui=None,
150143
org=False):
151144
"""
152145
A method to update a Lacework Query Language (LQL) policy.
@@ -165,7 +158,6 @@ def update(self,
165158
:param limit: An integer representing the number of results to return.
166159
:param eval_frequency: A string representing the frequency in which to evaluate the policy.
167160
("Hourly", "Daily")
168-
:param policy_ui: A dictionary which specifies the policyUi domain and subdomain.
169161
:param org: A boolean representing whether the request should be performed
170162
at the Organization level
171163
@@ -201,8 +193,6 @@ def update(self,
201193
data["limit"] = limit
202194
if eval_frequency:
203195
data["evalFrequency"] = eval_frequency
204-
if policy_ui:
205-
data["policyUi"] = policy_ui
206196

207197
response = self._session.patch(api_uri, org=org, data=data)
208198

laceworksdk/api/report_rules.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ def search(self,
129129

130130
response = self._session.post(api_uri, data=query_data, org=org)
131131

132-
return response.json()
132+
if response.status_code == 204:
133+
return {"data": []}
134+
else:
135+
return response.json()
133136

134137
def update(self,
135138
guid,

tests/api/v2/test_policies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
end_time = current_time.strftime("%Y-%m-%dT%H:%M:%S.000Z")
1818

1919
POLICY_ID = None
20-
RANDOM_TEXT = "".join(random.choice(string.ascii_uppercase) for _ in range(8))
20+
RANDOM_TEXT = "".join(random.choices(string.ascii_uppercase, k=8))
2121

2222
# Tests
2323

tests/api/v2/test_queries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
start_time = start_time.strftime("%Y-%m-%dT%H:%M:%S.000Z")
1717
end_time = current_time.strftime("%Y-%m-%dT%H:%M:%S.000Z")
1818

19-
RANDOM_TEXT = "".join(random.choice(string.ascii_uppercase) for _ in range(8))
19+
RANDOM_TEXT = "".join(random.choices(string.ascii_uppercase, k=8))
2020

2121
# Tests
2222

0 commit comments

Comments
 (0)