Skip to content

Commit

Permalink
Service class updates (#33)
Browse files Browse the repository at this point in the history
* Service Class fixes (#30)

* Default parameter debugging. Ran the code through the DRYer.

* Param defaults, fixes to GetDeviceDetails, DRYer

* Parameter defaults, DRYer, Unit testing

* Parameter cleanup, IDs fix, DRYer, Unit testing

* Param, partition, content-type fixes. Unit tests.

* Parameter cleanup, DRYer

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, More to do here

* Param cleanup, IDs fixes, DRYer

* Param cleanup, IDs fixes, DRYer

* Param cleanup, IDs fix, DRYer

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit test prep

* Param cleanup, IDs fix, DRYer, Basic unit tests

* Quick run thru the DRYer

* Unit testing fixes, updated service classes (#32)

* Default parameter debugging. Ran the code through the DRYer.

* Param defaults, fixes to GetDeviceDetails, DRYer

* Parameter defaults, DRYer, Unit testing

* Parameter cleanup, IDs fix, DRYer, Unit testing

* Param, partition, content-type fixes. Unit tests.

* Parameter cleanup, DRYer

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, More to do here

* Param cleanup, IDs fixes, DRYer

* Param cleanup, IDs fixes, DRYer

* Param cleanup, IDs fix, DRYer

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit test prep

* Param cleanup, IDs fix, DRYer, Basic unit tests

* Quick run thru the DRYer

* Updated service class unit tests (#31)

* Package layout updates

* Package updates

* Cleaning up tabs

* README and LICENSE updates

* More package testing

* Broken link fixes

* Uber class custom headers, Content-Type retained

* v0.1.8 - Uber class custom headers

* Uber class fix for octet-stream file uploads

* README.md updates

* Package development status alignment

* Typo fix in README.md

* Minor README.md text edits

* Initial unit tests: Service and Uber Auth / Revoke

* Initial unit tests: CCAWS - GetAWSSettings

* Uber class fix for non-JSON API responses

* Updated to support GitHub workflow execution

* Working directory fix

* Fixed authorization unit test 500 error

* Adjusted workflow directory

* Added working directory

* Changed working directory

* Working directory debugging

* Debugging workflows

* Lessee if this werks...

* Reverted linting.yml change

* Now there's a test package

* Pytest  debugging

* Trying it another way

* Another variation

* Fix to reduce flakiness in test_authorization.py

* Comment typo

* New unit tests for: AWS Accounts APIs

* New unit tests, requires updated svc classes

* Added coverage to test workflow

* GitHub workflow debugging

* Workaround for GitHub to CS API rate limiting

* Added pytest skips for rate limit barriers

* Added pytest skips for rate limit barriers

* Added pytest skips for rate limit barriers

Co-authored-by: Shawn Wells <[email protected]>

Co-authored-by: Shawn Wells <[email protected]>

* Pytest fixes (#34)

* Default parameter debugging. Ran the code through the DRYer.

* Param defaults, fixes to GetDeviceDetails, DRYer

* Parameter defaults, DRYer, Unit testing

* Parameter cleanup, IDs fix, DRYer, Unit testing

* Param, partition, content-type fixes. Unit tests.

* Parameter cleanup, DRYer

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, More to do here

* Param cleanup, IDs fixes, DRYer

* Param cleanup, IDs fixes, DRYer

* Param cleanup, IDs fix, DRYer

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit test prep

* Param cleanup, IDs fix, DRYer, Basic unit tests

* Quick run thru the DRYer

* Updated service class unit tests (#31)

* Package layout updates

* Package updates

* Cleaning up tabs

* README and LICENSE updates

* More package testing

* Broken link fixes

* Uber class custom headers, Content-Type retained

* v0.1.8 - Uber class custom headers

* Uber class fix for octet-stream file uploads

* README.md updates

* Package development status alignment

* Typo fix in README.md

* Minor README.md text edits

* Initial unit tests: Service and Uber Auth / Revoke

* Initial unit tests: CCAWS - GetAWSSettings

* Uber class fix for non-JSON API responses

* Updated to support GitHub workflow execution

* Working directory fix

* Fixed authorization unit test 500 error

* Adjusted workflow directory

* Added working directory

* Changed working directory

* Working directory debugging

* Debugging workflows

* Lessee if this werks...

* Reverted linting.yml change

* Now there's a test package

* Pytest  debugging

* Trying it another way

* Another variation

* Fix to reduce flakiness in test_authorization.py

* Comment typo

* New unit tests for: AWS Accounts APIs

* New unit tests, requires updated svc classes

* Added coverage to test workflow

* GitHub workflow debugging

* Workaround for GitHub to CS API rate limiting

* Added pytest skips for rate limit barriers

* Added pytest skips for rate limit barriers

* Added pytest skips for rate limit barriers

Co-authored-by: Shawn Wells <[email protected]>

* Minor pytest fixes

* Minor pytest fixes

Co-authored-by: Shawn Wells <[email protected]>

* Another minor PyTest fix (#35)

* Default parameter debugging. Ran the code through the DRYer.

* Param defaults, fixes to GetDeviceDetails, DRYer

* Parameter defaults, DRYer, Unit testing

* Parameter cleanup, IDs fix, DRYer, Unit testing

* Param, partition, content-type fixes. Unit tests.

* Parameter cleanup, DRYer

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, More to do here

* Param cleanup, IDs fixes, DRYer

* Param cleanup, IDs fixes, DRYer

* Param cleanup, IDs fix, DRYer

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit test prep

* Param cleanup, IDs fix, DRYer, Basic unit tests

* Quick run thru the DRYer

* Minor pytest fixes

* Minor pytest fixes

* GitHub workflow fix

* Version update (#36)

* Default parameter debugging. Ran the code through the DRYer.

* Param defaults, fixes to GetDeviceDetails, DRYer

* Parameter defaults, DRYer, Unit testing

* Parameter cleanup, IDs fix, DRYer, Unit testing

* Param, partition, content-type fixes. Unit tests.

* Parameter cleanup, DRYer

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, More to do here

* Param cleanup, IDs fixes, DRYer

* Param cleanup, IDs fixes, DRYer

* Param cleanup, IDs fix, DRYer

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit testing

* Param cleanup, IDs fix, DRYer, Unit test prep

* Param cleanup, IDs fix, DRYer, Basic unit tests

* Quick run thru the DRYer

* Minor pytest fixes

* Minor pytest fixes

* GitHub workflow fix

* v 0.2.0 - Updated services classes

Co-authored-by: Shawn Wells <[email protected]>
  • Loading branch information
jshcodes and shawndwells authored Dec 28, 2020
1 parent 9cbaed5 commit c900816
Show file tree
Hide file tree
Showing 23 changed files with 650 additions and 770 deletions.
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

0 comments on commit c900816

Please sign in to comment.