-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
andrewwoj
committed
Jun 24, 2020
1 parent
3146061
commit 5027f1d
Showing
3 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
Example script showing how to use the LaceworkClient class. | ||
""" | ||
|
||
import logging | ||
import os | ||
import random | ||
|
||
#from dotenv import load_dotenv | ||
from laceworksdk import LaceworkClient | ||
|
||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
#load_dotenv() | ||
|
||
if __name__ == "__main__": | ||
|
||
# Use enviroment variables to instantiate a LaceworkClient instance | ||
lacework_client = LaceworkClient(api_key=os.getenv("LACEWORK_API_KEY"), | ||
api_secret=os.getenv("LACEWORK_API_SECRET"), | ||
instance=os.getenv("LACEWORK_INSTANCE")) | ||
|
||
# Run Report API | ||
|
||
# Run compliance report on an AWS Account | ||
lacework_client.runreports.run_aws_report(aws_account_id="123456789") | ||
|
||
# Run compliance report on an Azure Tenant Account | ||
lacework_client.runreports.run_azure_report(azure_tenant_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") | ||
|
||
|
||
# Run compliance report on a GCP Project | ||
|
||
lacework_client.runreports.run_gcp_report(gcp_project_id="example-project-id") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
""" | ||
Lacework Run Reports API wrapper. | ||
""" | ||
|
||
import json | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class RunReportsAPI(object): | ||
""" | ||
Lacework RunReports API. | ||
""" | ||
|
||
def __init__(self, session): | ||
""" | ||
Initializes the RunReportsAPI object. | ||
:param session: An instance of the HttpSession class | ||
:return RunReportsAPI object. | ||
""" | ||
|
||
super(RunReportsAPI, self).__init__() | ||
|
||
self._session = session | ||
|
||
|
||
def run_aws_report(self, aws_account_id): | ||
""" | ||
A method to run a compliance report for an AWS account. | ||
: param aws_account_id: A string representing which AWS Account to query. | ||
:return response json | ||
""" | ||
|
||
# Build the Run Report request URI | ||
|
||
api_uri = f"/api/v1/external/runReport/aws/{aws_account_id}" | ||
|
||
response = self._session.post(api_uri) | ||
|
||
logger.debug(json.dumps(response.json(), indent=2)) | ||
|
||
return response.json() | ||
|
||
|
||
def run_azure_report(self, azure_tenant_id): | ||
""" | ||
A method to run a compliance report for an Azure Tenant account. | ||
: param azure_tenant_id: A string representing which Azure Tenant account to query. | ||
:return response json | ||
""" | ||
|
||
# Build the Run Report request URI | ||
|
||
api_uri = f"/api/v1/external/runReport/azure/{azure_tenant_id}" | ||
|
||
response = self._session.post(api_uri) | ||
|
||
logger.debug(json.dumps(response.json(), indent=2)) | ||
|
||
return response.json() | ||
|
||
def run_gcp_report(self, gcp_project_id): | ||
""" | ||
A method to run a compliance report for a GCP Project. | ||
: param gcp_project_id: A string representing which GCP Project to query. | ||
:return response json | ||
""" | ||
|
||
# Build the Run Report request URI | ||
|
||
api_uri = f"/api/v1/external/runReport/gcp/{gcp_project_id}" | ||
|
||
response = self._session.post(api_uri) | ||
|
||
logger.debug(json.dumps(response.json(), indent=2)) | ||
|
||
return response.json() |