Skip to content

Commit aa5edbd

Browse files
authored
feat: added endpoints for AzureSubscriptions and GcpProjects (#99)
* feat: added endpoints for `AzureSubscriptions` and `GcpProjects` * fix: linting for EOF
1 parent 50ff463 commit aa5edbd

File tree

4 files changed

+108
-4
lines changed

4 files changed

+108
-4
lines changed

laceworksdk/api/read_endpoint.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from laceworksdk.api.base_endpoint import BaseEndpoint
4+
5+
6+
class ReadEndpoint(BaseEndpoint):
7+
"""
8+
A class used to implement Read functionality for Lacework API Endpoints
9+
"""
10+
11+
# If defined, this is the resource used in the URL path
12+
RESOURCE = ""
13+
14+
def __init__(self,
15+
session,
16+
object_type,
17+
endpoint_root="/api/v2"):
18+
"""
19+
:param session: An instance of the HttpSession class.
20+
:param object_type: The Lacework object type to use.
21+
:param endpoint_root: The URL endpoint root to use.
22+
"""
23+
24+
super().__init__(session, object_type, endpoint_root)
25+
26+
def get(self, id=None, resource=None, **request_params):
27+
"""
28+
A method to get objects.
29+
30+
:param guid: A string representing the object ID.
31+
:param type: A string representing the object resource type.
32+
:param request_params: A dictionary of parameters to add to the request.
33+
34+
:return response json
35+
"""
36+
37+
if not resource and self.RESOURCE:
38+
resource = self.RESOURCE
39+
40+
params = self.build_dict_from_items(
41+
request_params
42+
)
43+
44+
response = self._session.get(self.build_url(id=id, resource=resource), params=params)
45+
46+
return response.json()

laceworksdk/api/v2/configs.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Lacework Configs API wrapper.
44
"""
55

6+
from laceworksdk.api.read_endpoint import ReadEndpoint
67
from laceworksdk.api.search_endpoint import SearchEndpoint
78

89

@@ -29,7 +30,33 @@ def __init__(self, session):
2930
super().__init__()
3031
self._base_path = "Configs"
3132

33+
self.azure_subscriptions = AzureSubscriptions(session, self._base_path)
3234
self.compliance_evaluations = ComplianceEvaluationsAPI(session, self._base_path)
35+
self.gcp_projects = GcpProjects(session, self._base_path)
36+
37+
38+
class AzureSubscriptions(ReadEndpoint):
39+
"""A class used to represent the Azure Subscriptions API endpoint.
40+
41+
Methods
42+
-------
43+
get(request_params=None)
44+
A method to get AzureSubscription objects.
45+
(tenantId is an optional parameter)
46+
"""
47+
RESOURCE = "AzureSubscriptions"
48+
49+
50+
class GcpProjects(ReadEndpoint):
51+
"""A class used to represent the GCP Projects API endpoint.
52+
53+
Methods
54+
-------
55+
get(request_params=None)
56+
A method to get GcpProjects objects.
57+
(orgId is an optional parameter)
58+
"""
59+
RESOURCE = "GcpProjects"
3360

3461

3562
class ComplianceEvaluationsAPI(SearchEndpoint):

tests/api/test_read_endpoint.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,26 @@
1010

1111
class ReadEndpoint(BaseEndpoint):
1212

13-
def test_api_get(self, api_object):
14-
response = api_object.get()
13+
OBJECT_TYPE = None
14+
OBJECT_MAP = {}
15+
16+
def test_object_creation(self, api_object):
17+
18+
if self.OBJECT_TYPE:
19+
assert isinstance(api_object, self.OBJECT_TYPE)
1520

16-
assert "data" in response.keys()
21+
if len(self.OBJECT_MAP) > 0:
22+
for attribute, object_type in self.OBJECT_MAP.items():
23+
assert isinstance(getattr(api_object, attribute), object_type)
24+
25+
def test_api_get(self, api_object):
26+
if len(self.OBJECT_MAP) > 0:
27+
for attribute in self.OBJECT_MAP.keys():
28+
response = getattr(api_object, attribute).get()
29+
assert "data" in response.keys()
30+
else:
31+
response = api_object.get()
32+
assert "data" in response.keys()
1733

1834
def test_api_search(self, api_object):
1935
random_object_id = self._get_random_object(api_object, self.OBJECT_ID_NAME)

tests/api/v2/test_configs.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77

88
from laceworksdk.api.v2.configs import (
99
ConfigsAPI,
10-
ComplianceEvaluationsAPI
10+
ComplianceEvaluationsAPI,
11+
AzureSubscriptions,
12+
GcpProjects
1113
)
14+
from tests.api.test_read_endpoint import ReadEndpoint
1215
from tests.api.test_search_endpoint import SearchEndpoint
1316

1417
# Tests
@@ -30,3 +33,15 @@ class TestConfigsEndpoint(SearchEndpoint):
3033
def test_api_search_by_date(self, api_object, dataset):
3134

3235
return super().test_api_search_by_date(api_object=api_object, filters={"dataset": dataset})
36+
37+
38+
class TestConfigsLookups(ReadEndpoint):
39+
40+
OBJECT_TYPE = ConfigsAPI
41+
OBJECT_MAP = {
42+
"azure_subscriptions": AzureSubscriptions,
43+
"gcp_projects": GcpProjects
44+
}
45+
46+
def test_api_search(self, api_object):
47+
pass

0 commit comments

Comments
 (0)