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

refactor: Make base classmethods private #142

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion docs-source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

import os
import sys


#sys.path.insert(0, os.path.abspath('../laceworksdk'))

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'Lacework Python SDK'
copyright = '2023, Lacework'
copyright = '2024, Lacework'
author = 'Jon Stewart, Tim MacDonald'

# -- General configuration ---------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions laceworksdk/api/base_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, session, object_type, endpoint_root="/api/v2"):
self._object_type = object_type
self._endpoint_root = endpoint_root

def build_dict_from_items(self, *dicts, **items):
def _build_dict_from_items(self, *dicts, **items):
"""A method to build a dictionary based on inputs, pruning items that are None.

Args:
Expand All @@ -43,7 +43,7 @@ def build_dict_from_items(self, *dicts, **items):

return result

def build_url(self, id=None, resource=None, action=None):
def _build_url(self, id=None, resource=None, action=None):
"""Builds the URL to use based on the endpoint path, resource, type, and ID.

Args:
Expand Down Expand Up @@ -147,7 +147,7 @@ def session(self):
"""Get the :class:`HttpSession` instance the object is using."""
return self._session

def validate_json(self, json, subtype=None):
def _validate_json(self, json, subtype=None):
"""TODO: A method to validate the provided JSON based on the schema of the current object."""
schema = self._get_schema(subtype)

Expand Down
16 changes: 8 additions & 8 deletions laceworksdk/api/crud_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def create(self, params=None, **request_params):
dict: JSON containing the new object info

"""
json = self.build_dict_from_items(request_params)
json = self._build_dict_from_items(request_params)

response = self._session.post(self.build_url(), json=json, params=params)
response = self._session.post(self._build_url(), json=json, params=params)

return response.json()

Expand All @@ -45,10 +45,10 @@ def get(self, id=None, resource=None, **request_params):
Returns:
dict: JSON containing the retrieved object(s)
"""
params = self.build_dict_from_items(request_params)
params = self._build_dict_from_items(request_params)

response = self._session.get(
self.build_url(id=id, resource=resource), params=params
self._build_url(id=id, resource=resource), params=params
)

return response.json()
Expand Down Expand Up @@ -77,7 +77,7 @@ def search(self, json=None):
Yields:
dict: returns a generator which yields a page of objects at a time as returned by the Lacework API.
"""
response = self._session.post(self.build_url(action="search"), json=json)
response = self._session.post(self._build_url(action="search"), json=json)

return response.json()

Expand All @@ -93,9 +93,9 @@ def update(self, id=None, params=None, **request_params):
dict: JSON containing the updated object info

"""
json = self.build_dict_from_items(request_params)
json = self._build_dict_from_items(request_params)

response = self._session.patch(self.build_url(id=id), json=json, params=params)
response = self._session.patch(self._build_url(id=id), json=json, params=params)

return response.json()

Expand All @@ -109,7 +109,7 @@ def delete(self, id, params=None):
Returns:
requests.models.Response: a Requests response object containing the response code
"""
response = self._session.delete(self.build_url(id=id), params=params)
response = self._session.delete(self._build_url(id=id), params=params)

return response

Expand Down
4 changes: 2 additions & 2 deletions laceworksdk/api/read_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ def get(self, id=None, resource=None, **request_params):
if not resource and self.RESOURCE:
resource = self.RESOURCE

params = self.build_dict_from_items(request_params)
params = self._build_dict_from_items(request_params)

response = self._session.get(
self.build_url(id=id, resource=resource), params=params
self._build_url(id=id, resource=resource), params=params
)

return response.json()
2 changes: 1 addition & 1 deletion laceworksdk/api/search_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def search(self, json=None, resource=None, **kwargs):
resource = self.RESOURCE

response = self._session.post(
self.build_url(resource=resource, action="search"), json=json
self._build_url(resource=resource, action="search"), json=json
)

while True:
Expand Down
2 changes: 1 addition & 1 deletion laceworksdk/api/v2/alert_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@ def test(self, guid):
Returns:
requests.models.Response: a Requests response object containing the response code
"""
response = self._session.post(self.build_url(resource=guid, action="test"))
response = self._session.post(self._build_url(resource=guid, action="test"))

return response
16 changes: 8 additions & 8 deletions laceworksdk/api/v2/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def get(self, start_time=None, end_time=None, limit=None, **request_params):
dict: The requested alert(s)

"""
params = self.build_dict_from_items(
params = self._build_dict_from_items(
request_params, start_time=start_time, end_time=end_time
)

response = self._session.get(self.build_url(), params=params)
response = self._session.get(self._build_url(), params=params)

return_data = {"data": []}
current_rows = 0
Expand Down Expand Up @@ -84,9 +84,9 @@ def get_details(self, id, scope, **request_params):
Returns:
dict: The requested alert details.
"""
params = self.build_dict_from_items(request_params, scope=scope)
params = self._build_dict_from_items(request_params, scope=scope)

response = self._session.get(self.build_url(id=id), params=params)
response = self._session.get(self._build_url(id=id), params=params)

return response.json()

Expand All @@ -101,10 +101,10 @@ def comment(self, id, comment):
dict: The posted comment

"""
json = self.build_dict_from_items(comment=comment)
json = self._build_dict_from_items(comment=comment)

response = self._session.post(
self.build_url(resource=id, action="comment"), json=json
self._build_url(resource=id, action="comment"), json=json
)

return response.json()
Expand All @@ -120,10 +120,10 @@ def close(self, id, reason, comment=None):
Returns:
requests.models.Response: a Requests response object containing the response code
"""
json = self.build_dict_from_items(reason=reason, comment=comment)
json = self._build_dict_from_items(reason=reason, comment=comment)

response = self._session.post(
self.build_url(resource=id, action="close"), json=json
self._build_url(resource=id, action="close"), json=json
)

return response.json()
6 changes: 3 additions & 3 deletions laceworksdk/api/v2/audit_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def get(self, start_time=None, end_time=None, **request_params):
Returns:
dict: The audit logs for the requested time period.
"""
params = self.build_dict_from_items(
params = self._build_dict_from_items(
request_params, start_time=start_time, end_time=end_time
)

response = self._session.get(self.build_url(), params=params)
response = self._session.get(self._build_url(), params=params)

return response.json()

Expand All @@ -63,5 +63,5 @@ def search(self, json=None):
dict: returns a generator which yields a page of objects at a time as returned by the Lacework API.
"""

response = self._session.post(self.build_url(action="search"), json=json)
response = self._session.post(self._build_url(action="search"), json=json)
return response.json()
14 changes: 7 additions & 7 deletions laceworksdk/api/v2/cloud_activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def get(self, start_time=None, end_time=None, **request_params):
dict: The requested cloud activity data.

"""
params = self.build_dict_from_items(
params = self._build_dict_from_items(
request_params, start_time=start_time, end_time=end_time
)

response = self._session.get(self.build_url(), params=params)
response = self._session.get(self._build_url(), params=params)

return response.json()

Expand All @@ -57,11 +57,11 @@ def get_pages(self, start_time=None, end_time=None, **request_params):
Yields:
dict: a generator which yields a dict of cloud activities.
"""
params = self.build_dict_from_items(
params = self._build_dict_from_items(
request_params, start_time=start_time, end_time=end_time
)

for page in self._session.get_pages(self.build_url(), params=params):
for page in self._session.get_pages(self._build_url(), params=params):
yield page.json()

def get_data_items(self, start_time=None, end_time=None, **request_params):
Expand All @@ -79,13 +79,13 @@ def get_data_items(self, start_time=None, end_time=None, **request_params):
Yields:
dict: a generator which yields multipe dicts of cloud activities.
"""
params = self.build_dict_from_items(
params = self._build_dict_from_items(
request_params,
start_time=start_time,
end_time=end_time,
)

for item in self._session.get_data_items(self.build_url(), params=params):
for item in self._session.get_data_items(self._build_url(), params=params):
yield item

def search(self, json=None):
Expand All @@ -106,5 +106,5 @@ def search(self, json=None):
dict: returns a generator which yields a page of objects at a time as returned by the Lacework API.
"""

response = self._session.post(self.build_url(action="search"), json=json)
response = self._session.post(self._build_url(action="search"), json=json)
return response.json()
4 changes: 2 additions & 2 deletions laceworksdk/api/v2/contract_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def get(self, **request_params):
request_params (dict, optional): Use to pass any additional parameters the API

"""
params = self.build_dict_from_items(request_params)
params = self._build_dict_from_items(request_params)

response = self._session.get(self.build_url(), params=params)
response = self._session.get(self._build_url(), params=params)

return response.json()
4 changes: 2 additions & 2 deletions laceworksdk/api/v2/datasources.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get(self):
Returns:
dict: All datasources
"""
response = self._session.get(self.build_url())
response = self._session.get(self._build_url())
return response.json()

def get_datasource(self, datasource):
Expand All @@ -41,7 +41,7 @@ def get_datasource(self, datasource):
Returns:
dict: The datasource schema.
"""
return self._session.get(self.build_url(resource=datasource)).json()
return self._session.get(self._build_url(resource=datasource)).json()

def list_data_sources(self):
"""A method to list the datasources that are available.
Expand Down
8 changes: 4 additions & 4 deletions laceworksdk/api/v2/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def scan(self, csp):
dict: Status of scan

"""
params = self.build_dict_from_items(csp=csp)
params = self._build_dict_from_items(csp=csp)

response = self._session.post(self.build_url(action="scan"), params=params)
response = self._session.post(self._build_url(action="scan"), params=params)

return response.json()

Expand All @@ -48,8 +48,8 @@ def status(self, csp):
dict: Status of scan

"""
params = self.build_dict_from_items(csp=csp)
params = self._build_dict_from_items(csp=csp)

response = self._session.get(self.build_url(action="scan"), params=params)
response = self._session.get(self._build_url(action="scan"), params=params)

return response.json()
2 changes: 1 addition & 1 deletion laceworksdk/api/v2/organization_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ def get(self):
dict: Organization info

"""
response = self._session.get(self.build_url())
response = self._session.get(self._build_url())

return response.json()
2 changes: 1 addition & 1 deletion laceworksdk/api/v2/policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def bulk_update(self, json):
dict: The updated policies.

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

return response.json()

Expand Down
6 changes: 3 additions & 3 deletions laceworksdk/api/v2/policy_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def create(self, policy_id, description, constraints, **request_params):
dict: The created policy exception

"""
params = self.build_dict_from_items(policy_id=policy_id)
params = self._build_dict_from_items(policy_id=policy_id)

return super().create(
params=params,
Expand Down Expand Up @@ -99,7 +99,7 @@ def update(
dict: The updated policy exception

"""
params = self.build_dict_from_items(policy_id=policy_id)
params = self._build_dict_from_items(policy_id=policy_id)

return super().update(
id=exception_id,
Expand All @@ -119,6 +119,6 @@ def delete(self, exception_id, policy_id):
Returns:
requests.models.Response: a Requests response object containing the response code
"""
params = self.build_dict_from_items(policy_id=policy_id)
params = self._build_dict_from_items(policy_id=policy_id)

return super().delete(id=exception_id, params=params)
8 changes: 4 additions & 4 deletions laceworksdk/api/v2/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def execute(self, evaluator_id=None, query_id=None, query_text=None, arguments={
for key, value in arguments.items():
json["arguments"].append({"name": key, "value": value})

response = self._session.post(self.build_url(action="execute"), json=json)
response = self._session.post(self._build_url(action="execute"), json=json)

return response.json()

Expand All @@ -113,7 +113,7 @@ def execute_by_id(self, query_id, arguments={}):
json["arguments"].append({"name": key, "value": value})

response = self._session.post(
self.build_url(resource=query_id, action="execute"), json=json
self._build_url(resource=query_id, action="execute"), json=json
)

return response.json()
Expand All @@ -129,11 +129,11 @@ def validate(self, query_text, evaluator_id=None, **request_params):
Returns:
dict: Validation Results
"""
json = self.build_dict_from_items(
json = self._build_dict_from_items(
request_params, query_text=query_text, evaluator_id=evaluator_id
)

response = self._session.post(self.build_url(action="validate"), json=json)
response = self._session.post(self._build_url(action="validate"), json=json)

return response.json()

Expand Down
4 changes: 2 additions & 2 deletions laceworksdk/api/v2/report_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ def update(self, id, report_name, report_definition, **request_params):
Returns:
dict: The updated report definition
"""
json = self.build_dict_from_items(
json = self._build_dict_from_items(
report_name=report_name,
report_definition=report_definition,
**request_params,
)

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

return response.json()

Expand Down
Loading
Loading