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

feat: added bulk_update method to Policies #104

Merged
merged 1 commit into from
Jan 19, 2023
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
57 changes: 52 additions & 5 deletions laceworksdk/api/v2/policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,35 @@ def create(self,
A method to create a new Policies object.

:param policy_type: A string representing the object policy type.
:type policy_type: str
:param query_id: A string representing the object query ID.
:type query_id: str
:param enabled: A boolean representing whether the object is enabled.
:type enabled: bool
:param title: A string representing the object title.
:type title: str
:param description: A string representing the object description.
:type description: str
:param remediation: A string representing the remediation strategy for the object.
:type remediation: str
:param severity: A string representing the object severity.
("info", "low", "medium", "high", "critical")
:type severity: str
:param alert_enabled: A boolean representing whether alerting is enabled.
:type alert_enabled: bool
:param alert_profile: A string representing the alert profile.
:type alert_profile: str
:param evaluator_id: A string representing the evaluator in which the object is to be run.
:type evaluator_id: str
:param limit: An integer representing the number of results to return.
:type limit: int
:param eval_frequency: A string representing the frequency in which to evaluate the object.
("Hourly", "Daily")
:type eval_frequency: str
:param request_params: Additional request parameters.
(provides support for parameters that may be added in the future)

:return response json
:return: response json
"""

return super().create(
Expand All @@ -78,8 +90,9 @@ def get(self,
A method to get Policies objects.

:param policy_id: A string representing the object policy ID.
:type policy_id: str

:return response json
:return: response json
"""

return super().get(id=policy_id)
Expand All @@ -90,8 +103,9 @@ def get_by_id(self,
A method to get a Policies object by policy ID.

:param policy_id: A string representing the object policy ID.
:type policy_id: str

:return response json
:return: response json
"""

return self.get(policy_id=policy_id)
Expand All @@ -114,23 +128,35 @@ def update(self, # noqa: C901
A method to update a Lacework Query Language (LQL) policy.

:param policy_id: A string representing the object policy ID.
:type policy_id: str
:param policy_type: A string representing the object policy type.
:type policy_type: str
:param query_id: A string representing the object query ID.
:type query_id: str
:param enabled: A boolean representing whether the object is enabled.
:type enabled: bool
:param title: A string representing the object title.
:type title: str
:param description: A string representing the object description.
:type description: str
:param remediation: A string representing the remediation strategy for the object.
:type remediation: str
:param severity: A string representing the object severity.
("info", "low", "medium", "high", "critical")
:type severity: str
:param alert_enabled: A boolean representing whether alerting is enabled.
:type alert_enabled: bool
:param alert_profile: A string representing the alert profile.
:type alert_profile: str
:param limit: An integer representing the number of results to return.
:type limit: int
:param eval_frequency: A string representing the frequency in which to evaluate the object.
("Hourly", "Daily")
:type eval_frequency: str
:param request_params: Additional request parameters.
(provides support for parameters that may be added in the future)

:return response json
:return: response json
"""

if enabled is not None:
Expand All @@ -155,14 +181,35 @@ def update(self, # noqa: C901
**request_params
)

def bulk_update(self,
json):
"""
A method to update Policy objects in bulk

:param json: A list of JSON objects containing policy configuration.
:type json: list(dict(str, Any))
obj:
:param policyId: A string representing the ID of the policy.
:param enabled: A boolean representing the status of the policy.
:param severity: A string representing the severity of the policy.
("info", "low", "medium", "high", "critical")

:return: response json
"""

response = self._session.patch(self.build_url(), json=json)

return response.json()

def delete(self,
policy_id):
"""
A method to delete a Policies object.

:param policy_id: A string representing the object policy ID.
:type policy_id: str

:return response json
:return: response json
"""

return super().delete(id=policy_id)
19 changes: 19 additions & 0 deletions tests/api/v2/test_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ def api_object_update_body():
}


@pytest.fixture(scope="module")
def api_object_bulk_update_body():
return [
{
"policyId": "lacework-global-24",
"enabled": True,
"severity": "medium"
},
{
"policyId": "lacework-global-218",
"enabled": True
}
]


@pytest.fixture(scope="module")
def query(api):
queries = api.queries.get()
Expand All @@ -56,5 +71,9 @@ class TestPolicies(CrudEndpoint):
def test_api_get_by_id(self, api_object):
self._get_object_classifier_test(api_object, "id", self.OBJECT_ID_NAME)

def test_api_bulk_update(self, api_object, api_object_bulk_update_body):
response = api_object.bulk_update(api_object_bulk_update_body)
assert "data" in response.keys()

def test_api_search(self):
pass