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: migrated examples to APIv2 #95

Merged
merged 1 commit into from
Nov 21, 2022
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
7 changes: 2 additions & 5 deletions examples/example_alert_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""

import logging
import os

from dotenv import load_dotenv
from laceworksdk import LaceworkClient
Expand All @@ -15,10 +14,8 @@

if __name__ == "__main__":

# Use enviroment variables to instantiate a LaceworkClient instance
lacework_client = LaceworkClient(api_key=os.getenv("LW_API_KEY"),
api_secret=os.getenv("LW_API_SECRET"),
account=os.getenv("LW_ACCOUNT"))
# Instantiate a LaceworkClient instance
lacework_client = LaceworkClient()

# Alert Channels API

Expand Down
34 changes: 34 additions & 0 deletions examples/example_alerts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
"""
Example script showing how to use the LaceworkClient class.
"""

import logging
import random

from datetime import datetime, timedelta, timezone
from dotenv import load_dotenv
from laceworksdk import LaceworkClient

logging.basicConfig(level=logging.DEBUG)

load_dotenv()

if __name__ == "__main__":

# Instantiate a LaceworkClient instance
lacework_client = LaceworkClient()

# Build start/end times
current_time = datetime.now(timezone.utc)
start_time = current_time - timedelta(days=1)
start_time = start_time.strftime("%Y-%m-%dT%H:%M:%S%z")
end_time = current_time.strftime("%Y-%m-%dT%H:%M:%S%z")

# Alerts API

# Get alerts for specified time range
alerts = lacework_client.alerts.get(start_time=start_time, end_time=end_time)

# Get alert details for specified ID
alert_details = lacework_client.alerts.get_details(random.choice(alerts["data"])["alertId"])
7 changes: 2 additions & 5 deletions examples/example_audit_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""

import logging
import os

from datetime import datetime, timedelta, timezone
from dotenv import load_dotenv
Expand All @@ -16,10 +15,8 @@

if __name__ == "__main__":

# Use enviroment variables to instantiate a LaceworkClient instance
lacework_client = LaceworkClient(api_key=os.getenv("LW_API_KEY"),
api_secret=os.getenv("LW_API_SECRET"),
account=os.getenv("LW_ACCOUNT"))
# Instantiate a LaceworkClient instance
lacework_client = LaceworkClient()

# Build start/end times
current_time = datetime.now(timezone.utc)
Expand Down
27 changes: 27 additions & 0 deletions examples/example_cloud_accounts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
"""
Example script showing how to use the LaceworkClient class.
"""

import logging
import random

from dotenv import load_dotenv
from laceworksdk import LaceworkClient

logging.basicConfig(level=logging.DEBUG)

load_dotenv()

if __name__ == "__main__":

# Instantiate a LaceworkClient instance
lacework_client = LaceworkClient()

# Cloud Accounts API

# Get all Cloud Accounts
integrations = lacework_client.cloud_accounts.get()

# Get Cloud Account by ID
integration_by_id = lacework_client.cloud_accounts.get_by_guid((random.choice(integrations["data"])["INTG_GUID"]))
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""

import logging
import os

from datetime import datetime, timedelta, timezone
from dotenv import load_dotenv
Expand All @@ -16,27 +15,25 @@

if __name__ == "__main__":

# Use enviroment variables to instantiate a LaceworkClient instance
lacework_client = LaceworkClient(api_key=os.getenv("LW_API_KEY"),
api_secret=os.getenv("LW_API_SECRET"),
account=os.getenv("LW_ACCOUNT"))
# Instantiate a LaceworkClient instance
lacework_client = LaceworkClient()

# Build start/end times
current_time = datetime.now(timezone.utc)
start_time = current_time - timedelta(days=7)
start_time = start_time.strftime("%Y-%m-%dT%H:%M:%SZ")
end_time = current_time.strftime("%Y-%m-%dT%H:%M:%SZ")

# CloudTrail API
# Cloud Activities API

# Get CloudTrail
lacework_client.cloudtrail.get()
# Get Cloud Activities
lacework_client.cloud_activities.get()

# Get CloudTrail by date range
lacework_client.cloudtrail.get(start_time=start_time, end_time=end_time)
# Get Cloud Activities by date range
lacework_client.cloud_activities.get(start_time=start_time, end_time=end_time)

# Search CloudTrail
lacework_client.cloudtrail.search(json={
# Search Cloud Activities
lacework_client.cloud_activities.search(json={
"timeFilter": {
"startTime": start_time,
"endTime": end_time
Expand Down
32 changes: 0 additions & 32 deletions examples/example_compliance.py

This file was deleted.

26 changes: 0 additions & 26 deletions examples/example_compliance_config.py

This file was deleted.

37 changes: 0 additions & 37 deletions examples/example_events.py

This file was deleted.

33 changes: 0 additions & 33 deletions examples/example_integrations.py

This file was deleted.

9 changes: 3 additions & 6 deletions examples/example_query_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""

import logging
import os
import random
import string

Expand All @@ -21,18 +20,16 @@

if __name__ == "__main__":

# Use enviroment variables to instantiate a LaceworkClient instance
lacework_client = LaceworkClient(api_key=os.getenv("LW_API_KEY"),
api_secret=os.getenv("LW_API_SECRET"),
account=os.getenv("LW_ACCOUNT"))
# Instantiate a LaceworkClient instance
lacework_client = LaceworkClient()

# Queries/Policies API

# Create a Query
query_response = lacework_client.queries.create(
evaluator_id="Cloudtrail",
query_id=QUERY_ID,
query_text=f"""{QUERY_ID} {{
query_text=f"""{{
source {{CloudTrailRawEvents e}}
filter {{EVENT_SOURCE = 'iam.amazonaws.com' AND
EVENT:userIdentity.name::String NOT LIKE 'Terraform-Service-Acct'}}
Expand Down
25 changes: 25 additions & 0 deletions examples/example_reports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
"""
Example script showing how to use the LaceworkClient class.
"""

import logging

from dotenv import load_dotenv
from laceworksdk import LaceworkClient

logging.basicConfig(level=logging.DEBUG)

load_dotenv()

if __name__ == "__main__":

# Instantiate a LaceworkClient instance
lacework_client = LaceworkClient()

# Reports API

# Get latest compliance report in JSON format for AWS account
lacework_client.reports.get(
primary_query_id="123456798012", format="json", report_type="AWS_CIS_14"
)
31 changes: 0 additions & 31 deletions examples/example_run_reports.py

This file was deleted.

7 changes: 2 additions & 5 deletions examples/example_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""

import logging
import os

from dotenv import load_dotenv
from laceworksdk import LaceworkClient
Expand All @@ -15,10 +14,8 @@

if __name__ == "__main__":

# Use enviroment variables to instantiate a LaceworkClient instance
lacework_client = LaceworkClient(api_key=os.getenv("LW_API_KEY"),
api_secret=os.getenv("LW_API_SECRET"),
account=os.getenv("LW_ACCOUNT"))
# Instantiate a LaceworkClient instance
lacework_client = LaceworkClient()

# Schemas API

Expand Down
Loading