Skip to content

Commit

Permalink
Add support for RunReports API
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewwoj committed Jun 24, 2020
1 parent 3146061 commit 5027f1d
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
36 changes: 36 additions & 0 deletions examples/example_runreport.py
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")


2 changes: 2 additions & 0 deletions laceworksdk/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .compliance import ComplianceAPI
from .download_file import DownloadFileAPI
from .events import EventsAPI
from .runreports import RunReportsAPI
from .token import TokenAPI
from .vulnerability import VulnerabilityAPI

Expand Down Expand Up @@ -42,5 +43,6 @@ def __init__(self,
self.compliance = ComplianceAPI(self._session)
self.events = EventsAPI(self._session)
self.files = DownloadFileAPI(self._session)
self.runreports = RunReportsAPI(self._session)
self.tokens = TokenAPI(self._session)
self.vulnerabilties = VulnerabilityAPI(self._session)
86 changes: 86 additions & 0 deletions laceworksdk/api/runreports.py
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()

0 comments on commit 5027f1d

Please sign in to comment.