Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Param cleanup, IDs fix, DRYer, Unit testing
  • Loading branch information
jshcodes committed Dec 26, 2020
commit 8a91ae4d03e2d004ac80866bc3536bbc0eefef47
74 changes: 32 additions & 42 deletions src/falconpy/device_control_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,37 +61,35 @@ def __call__(self, status_code, headers, body):

return self.result_obj

def queryCombinedDeviceControlPolicyMembers(self, parameters):
def queryCombinedDeviceControlPolicyMembers(self, parameters={}):
""" Search for members of a Device Control Policy in your environment by providing an FQL filter
and paging details. Returns a set of host details which match the filter criteria.
"""
# [GET] https://assets.falcon.crowdstrike.com/support/api/swagger.html#/device-control-policies/queryCombinedDeviceControlPolicyMembers
FULL_URL = self.base_url+'/policy/combined/device-control-members/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

def queryCombinedDeviceControlPolicies(self, parameters):
def queryCombinedDeviceControlPolicies(self, parameters={}):
""" Search for Device Control Policies in your environment by providing an FQL filter and
paging details. Returns a set of Device Control Policies which match the filter criteria.
"""
# [GET] https://assets.falcon.crowdstrike.com/support/api/swagger.html#/device-control-policies/queryCombinedDeviceControlPolicies
FULL_URL = self.base_url+'/policy/combined/device-control/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 @@ -104,12 +102,11 @@ def performDeviceControlPoliciesAction(self, parameters, body):
HEADERS = self.headers
BODY = body
PARAMS = parameters
result = self.Result()
try:
response = requests.request("POST", FULL_URL, params=PARAMS, 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

Expand All @@ -122,27 +119,25 @@ def setDeviceControlPoliciesPrecedence(self, body):
FULL_URL = self.base_url+'/policy/entities/device-control-precedence/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 getDeviceControlPolicies(self, parameters):
def getDeviceControlPolicies(self, ids):
""" Retrieve a set of Device Control Policies by specifying their IDs. """
# [GET] https://assets.falcon.crowdstrike.com/support/api/swagger.html#/device-control-policies/getDeviceControlPolicies
FULL_URL = self.base_url+'/policy/entities/device-control/v1'
ID_LIST = str(ids).replace(",","&ids=")
FULL_URL = self.base_url+'/policy/entities/device-control/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

Expand All @@ -152,27 +147,25 @@ def createDeviceControlPolicies(self, body):
FULL_URL = self.base_url+'/policy/entities/device-control/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 deleteDeviceControlPolicies(self, parameters):
def deleteDeviceControlPolicies(self, ids):
""" Delete a set of Device Control Policies by specifying their IDs. """
# [DELETE] https://assets.falcon.crowdstrike.com/support/api/swagger.html#/device-control-policies/createDeviceControlPolicies
FULL_URL = self.base_url+'/policy/entities/device-control/v1'
ID_LIST = str(ids).replace(",","&ids=")
FULL_URL = self.base_url+'/policy/entities/device-control/v1?ids={}'.format(ID_LIST)
HEADERS = self.headers
PARAMS = parameters
result = self.Result()
try:
response = requests.request("DELETE", FULL_URL, params=PARAMS, headers=HEADERS, verify=False)
returned = result(response.status_code, response.headers, response.json())
response = requests.request("DELETE", 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

Expand All @@ -182,45 +175,42 @@ def updateDeviceControlPolicies(self, body):
FULL_URL = self.base_url+'/policy/entities/device-control/v1'
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 queryDeviceControlPolicyMembers(self, parameters):
def queryDeviceControlPolicyMembers(self, parameters={}):
""" Search for members of a Device Control Policy in your environment by providing an FQL filter
and paging details. Returns a set of Agent IDs which match the filter criteria.
"""
# [GET] https://assets.falcon.crowdstrike.com/support/api/swagger.html#/device-control-policies/queryDeviceControlPolicyMembers
FULL_URL = self.base_url+'/policy/queries/device-control-members/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

def queryDeviceControlPolicies(self, parameters):
def queryDeviceControlPolicies(self, parameters={}):
""" Search for Device Control Policies in your environment by providing an FQL filter and paging details.
Returns a set of Device Control Policy IDs which match the filter criteria.
"""
# [GET] https://assets.falcon.crowdstrike.com/support/api/swagger.html#/device-control-policies/queryDeviceControlPolicyMembers
FULL_URL = self.base_url+'/policy/queries/device-control/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