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

Service class updates #33

Merged
merged 6 commits into from
Dec 28, 2020
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name="crowdstrike-falconpy",
version="0.1.11",
version="0.2.0",
author="CrowdStrike",
maintainer="Joshua Hiller",
description="The CrowdStrike Falcon API SDK for Python 3",
Expand Down
2 changes: 1 addition & 1 deletion src/falconpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
The CrowdStrike Falcon API SDK
"""

__version__ = '0.1.11'
__version__ = '0.2.0'
__maintainer__ = 'Joshua Hiller'
__author__ = 'CrowdStrike'
__credits__ = 'CrowdStrike'
68 changes: 28 additions & 40 deletions src/falconpy/cloud_connect_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,19 @@ def __call__(self, status_code, headers, body):

return self.result_obj

def QueryAWSAccounts(self, parameters):
def QueryAWSAccounts(self, parameters={}):
""" Search for provisioned AWS Accounts by providing an FQL filter and paging details.
Returns a set of AWS accounts which match the filter criteria.
"""
# [GET] https://assets.falcon.crowdstrike.com/support/api/swagger.html#/cloud-connect-aws/QueryAWSAccounts
FULL_URL = self.base_url+'/cloud-connect-aws/combined/accounts/v1'
HEADERS = self.headers
PARAMS = parameters
result = self.Result()
try:
response = requests.request("GET", FULL_URL, params=PARAMS, headers=HEADERS, verify=False)
returned = result(response.status_code, response.headers, response.json())
returned = self.Result()(response.status_code, response.headers, response.json())
except Exception as e:
returned = result(500, {}, str(e))
returned = self.Result()(500, {}, str(e))

return returned

Expand All @@ -83,58 +82,52 @@ def GetAWSSettings(self):
# [GET] https://assets.falcon.crowdstrike.com/support/api/swagger.html#/cloud-connect-aws/GetAWSSettings
FULL_URL = self.base_url+'/cloud-connect-aws/combined/settings/v1'
HEADERS = self.headers
result = self.Result()
try:
response = requests.request("GET", FULL_URL, headers=HEADERS, verify=False)
returned = result(response.status_code, response.headers, response.json())
returned = self.Result()(response.status_code, response.headers, response.json())
except Exception as e:
returned = result(500, {}, str(e))
returned = self.Result()(500, {}, str(e))

return returned

def GetAWSAccounts(self, parameters, ids):
def GetAWSAccounts(self, ids):
""" Retrieve a set of AWS Accounts by specifying their IDs."""
# [GET] https://assets.falcon.crowdstrike.com/support/api/swagger.html#/cloud-connect-aws/GetAWSAccounts
ID_LIST = str(ids).replace(",","&ids=")
FULL_URL = self.base_url+'/cloud-connect-aws/entities/accounts/v1?ids={}'.format(ID_LIST)
HEADERS = self.headers
PARAMS = parameters
result = self.Result()
try:
response = requests.request("GET", FULL_URL, params=PARAMS, headers=HEADERS, verify=False)
returned = result(response.status_code, response.headers, response.json())
response = requests.request("GET", FULL_URL, headers=HEADERS, verify=False)
returned = self.Result()(response.status_code, response.headers, response.json())
except Exception as e:
returned = result(500, {}, str(e))
returned = self.Result()(500, {}, str(e))

return returned

def ProvisionAWSAccounts(self, parameters, body):
def ProvisionAWSAccounts(self, body, parameters={}):
""" Provision AWS Accounts by specifying details about the accounts to provision. """
# [POST] https://assets.falcon.crowdstrike.com/support/api/swagger.html#/cloud-connect-aws/ProvisionAWSAccounts
FULL_URL = self.base_url+'/cloud-connect-aws/entities/accounts/v1'
PARAMS=parameters
BODY=body
result = self.Result()
try:
response = requests.request("POST", FULL_URL, params=PARAMS, json=BODY, headers=self.headers, verify=False)
returned = result(response.status_code, response.headers, response.json())
returned = self.Result()(response.status_code, response.headers, response.json())
except Exception as e:
returned = result(500, {}, str(e))
returned = self.Result()(500, {}, str(e))

return returned

def DeleteAWSAccounts(self, parameters, ids):
def DeleteAWSAccounts(self, ids):
""" Delete a set of AWS Accounts by specifying their IDs. """
# [DELETE] https://assets.falcon.crowdstrike.com/support/api/swagger.html#/cloud-connect-aws/DeleteAWSAccounts
ID_LIST = str(ids).replace(",","&ids=")
FULL_URL = self.base_url+'/cloud-connect-aws/entities/accounts/v1?ids={}'.format(ID_LIST)
PARAMS = parameters
result = self.Result()
try:
response = requests.request("DELETE", FULL_URL, params=PARAMS, headers=self.headers, verify=False)
returned = result(response.status_code, response.headers, response.json())
response = requests.request("DELETE", FULL_URL, headers=self.headers, verify=False)
returned = self.Result()(response.status_code, response.headers, response.json())
except Exception as e:
returned = result(500, {}, str(e))
returned = self.Result()(500, {}, str(e))

return returned

Expand All @@ -143,12 +136,11 @@ def UpdateAWSAccounts(self, body):
# [PATCH] https://assets.falcon.crowdstrike.com/support/api/swagger.html#/cloud-connect-aws/UpdateAWSAccounts
FULL_URL = self.base_url+'/cloud-connect-aws/entities/accounts/v1'
BODY=body
result = self.Result()
try:
response = requests.request("PATCH", FULL_URL, json=BODY, headers=self.headers, verify=False)
returned = result(response.status_code, response.headers, response.json())
returned = self.Result()(response.status_code, response.headers, response.json())
except Exception as e:
returned = result(500, {}, str(e))
returned = self.Result()(500, {}, str(e))

return returned

Expand All @@ -158,45 +150,41 @@ def CreateOrUpdateAWSSettings(self, body):
FULL_URL = self.base_url+'/cloud-connect-aws/entities/settings/v1'
HEADERS = self.headers
BODY = body
result = self.Result()
try:
response = requests.request("POST", FULL_URL, json=BODY, headers=HEADERS, verify=False)
returned = result(response.status_code, response.headers, response.json())
returned = self.Result()(response.status_code, response.headers, response.json())
except Exception as e:
returned = result(500, {}, str(e))
returned = self.Result()(500, {}, str(e))

return returned

def VerifyAWSAccountAccess(self, parameters, body, ids):
def VerifyAWSAccountAccess(self, ids, body={}):
""" Performs an Access Verification check on the specified AWS Account IDs. """
# [POST] https://assets.falcon.crowdstrike.com/support/api/swagger.html#/cloud-connect-aws/VerifyAWSAccountAccess
ID_LIST = str(ids).replace(",","&ids=")
FULL_URL = self.base_url+'/cloud-connect-aws/entities/verify-account-access/v1?ids={}'.format(ID_LIST)
HEADERS = self.headers
PARAMS = parameters
BODY = body #payload does not appear to be required
result = self.Result()
BODY=body
try:
response = requests.request("POST", FULL_URL, json=BODY, params=PARAMS, headers=HEADERS, verify=False)
returned = result(response.status_code, response.headers, response.json())
response = requests.request("POST", FULL_URL, json=BODY, headers=HEADERS, verify=False)
returned = self.Result()(response.status_code, response.headers, response.json())
except Exception as e:
returned = result(500, {}, str(e))
returned = self.Result()(500, {}, str(e))

return returned

def QueryAWSAccountsForIDs(self, parameters):
def QueryAWSAccountsForIDs(self, parameters={}):
""" Search for provisioned AWS Accounts by providing an FQL filter and paging details.
Returns a set of AWS account IDs which match the filter criteria.
"""
# [GET] https://assets.falcon.crowdstrike.com/support/api/swagger.html#/cloud-connect-aws/QueryAWSAccountsForIDs
FULL_URL = self.base_url+'/cloud-connect-aws/queries/accounts/v1'
HEADERS = self.headers
PARAMS = parameters
result = self.Result()
try:
response = requests.request("GET", FULL_URL, params=PARAMS, headers=HEADERS, verify=False)
returned = result(response.status_code, response.headers, response.json())
returned = self.Result()(response.status_code, response.headers, response.json())
except Exception as e:
returned = result(500, {}, str(e))
returned = self.Result()(500, {}, str(e))

return returned
32 changes: 13 additions & 19 deletions src/falconpy/detects.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,17 @@ def __call__(self, status_code, headers, body):

return self.result_obj

def GetAggregateDetects(self, body, parameters):
def GetAggregateDetects(self, body):
""" Get detect aggregates as specified via json in request body. """
# [POST] https://assets.falcon.crowdstrike.com/support/api/swagger.html#/detects/GetAggregateDetects
FULL_URL = self.base_url+'/detects/aggregates/detects/GET/v1'
HEADERS = self.headers
PARAMS = parameters
BODY = body
result = self.Result()
try:
response = requests.request("POST", FULL_URL, json=BODY, params=PARAMS, headers=HEADERS, verify=False)
returned = result(response.status_code, response.headers, response.json())
response = requests.request("POST", FULL_URL, json=BODY, headers=HEADERS, verify=False)
returned = self.Result()(response.status_code, response.headers, response.json())
except Exception as e:
returned = result(500, {}, str(e))
returned = self.Result()(500, {}, str(e))

return returned

Expand All @@ -83,42 +81,38 @@ def UpdateDetectsByIdsV2(self, body):
FULL_URL = self.base_url+'/detects/entities/detects/v2'
HEADERS = self.headers
BODY = body
result = self.Result()
try:
response = requests.request("PATCH", FULL_URL, json=BODY, headers=HEADERS, verify=False)
returned = result(response.status_code, response.headers, response.json())
returned = self.Result()(response.status_code, response.headers, response.json())
except Exception as e:
returned = result(500, {}, str(e))
returned = self.Result()(500, {}, str(e))

return returned

def GetDetectSummaries(self, body, parameters):
def GetDetectSummaries(self, body):
""" View information about detections. """
# [POST] https://assets.falcon.crowdstrike.com/support/api/swagger.html#/detects/GetDetectSummaries
FULL_URL = self.base_url+'/detects/entities/summaries/GET/v1'
HEADERS = self.headers
PARAMS = parameters
BODY = body
result = self.Result()
try:
response = requests.request("POST", FULL_URL, json=BODY, params=PARAMS, headers=HEADERS, verify=False)
returned = result(response.status_code, response.headers, response.json())
response = requests.request("POST", FULL_URL, json=BODY, headers=HEADERS, verify=False)
returned = self.Result()(response.status_code, response.headers, response.json())
except Exception as e:
returned = result(500, {}, str(e))
returned = self.Result()(500, {}, str(e))

return returned

def QueryDetects(self, parameters):
def QueryDetects(self, parameters={}):
""" Search for detection IDs that match a given query. """
# [GET] https://assets.falcon.crowdstrike.com/support/api/swagger.html#/detects/QueryDetects
FULL_URL = self.base_url+'/detects/queries/detects/v1'
HEADERS = self.headers
PARAMS = parameters
result = self.Result()
try:
response = requests.request("GET", FULL_URL, params=PARAMS, headers=HEADERS, verify=False)
returned = result(response.status_code, response.headers, response.json())
returned = self.Result()(response.status_code, response.headers, response.json())
except Exception as e:
returned = result(500, {}, str(e))
returned = self.Result()(500, {}, str(e))

return returned
Loading