Skip to content

Commit

Permalink
Merge pull request #78 from tkishel/disco
Browse files Browse the repository at this point in the history
Disco
  • Loading branch information
tkishel authored Aug 26, 2022
2 parents dac6f6a + 55acbfe commit 51777a0
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 24 deletions.
11 changes: 6 additions & 5 deletions prismacloud/api/code_security/code_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PrismaCloudAPICodeSecurityMixin():
""" Requests and Output """

# pylint: disable=too-many-arguments,too-many-branches,too-many-locals,too-many-statements
def execute_code_security(self, action, endpoint, query_params=None, body_params=None, force=False, paginated=False):
def execute_code_security(self, action, endpoint, query_params=None, body_params=None, request_headers=None, force=False, paginated=False):
self.suppress_warnings_when_ca_bundle_false()
if not self.token:
self.login()
Expand All @@ -30,21 +30,22 @@ def execute_code_security(self, action, endpoint, query_params=None, body_params
requ_url = 'https://%s/%s?limit=%s&offset=%s' % (self.api, endpoint, limit, offset)
else:
requ_url = 'https://%s/%s' % (self.api, endpoint)
requ_headers = {'Content-Type': 'application/json'}
if not request_headers:
request_headers = {'Content-Type': 'application/json'}
if self.token:
requ_headers['authorization'] = self.token
request_headers['authorization'] = self.token
requ_params = query_params
if body_params:
requ_data = json.dumps(body_params)
else:
requ_data = body_params
api_response = requests.request(requ_action, requ_url, headers=requ_headers, params=requ_params, data=requ_data, verify=self.ca_bundle)
api_response = requests.request(requ_action, requ_url, headers=request_headers, params=requ_params, data=requ_data, verify=self.ca_bundle)
if self.debug:
print('API Respose Status Code: %s' % api_response.status_code)
if api_response.status_code in self.retry_status_codes:
for _ in range(1, self.retry_limit):
time.sleep(self.retry_pause)
api_response = requests.request(requ_action, requ_url, headers=requ_headers, params=query_params, data=requ_data, verify=self.ca_bundle)
api_response = requests.request(requ_action, requ_url, headers=request_headers, params=query_params, data=requ_data, verify=self.ca_bundle)
if api_response.ok:
break # retry loop
if api_response.ok:
Expand Down
14 changes: 14 additions & 0 deletions prismacloud/api/compute/_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,17 @@ class CloudPrismaCloudAPIComputeMixin:

def cloud_discovery_read(self):
return self.execute_compute('GET', 'api/v1/cloud/discovery')

def cloud_discovery_download(self, query_params=None):
# request_headers = {'Content-Type': 'text/csv'}
# return self.execute_compute('GET', 'api/v1/cloud/discovery/download?', request_headers=request_headers, query_params=query_params)
return self.execute_compute('GET', 'api/v1/cloud/discovery/download', query_params=query_params)

def cloud_discovery_scan(self):
return self.execute_compute('POST', 'api/v1/cloud/discovery/scan')

def cloud_discovery_scan_stop(self):
return self.execute_compute('POST', 'api/v1/cloud/discovery/stop')

def cloud_discovery_vms(self, query_params=None):
return self.execute_compute('GET', 'api/v1/cloud/discovery/vms?', query_params=query_params, paginated=True)
17 changes: 10 additions & 7 deletions prismacloud/api/compute/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def extend_login_compute(self):
self.login_compute()

# pylint: disable=too-many-arguments,too-many-branches,too-many-locals,too-many-statements
def execute_compute(self, action, endpoint, query_params=None, body_params=None, force=False, paginated=False):
def execute_compute(self, action, endpoint, query_params=None, body_params=None, request_headers=None, force=False, paginated=False):
self.suppress_warnings_when_ca_bundle_false()
if not self.token:
self.login_compute()
Expand All @@ -46,30 +46,33 @@ def execute_compute(self, action, endpoint, query_params=None, body_params=None,
requ_url = 'https://%s/%s?limit=%s&offset=%s' % (self.api_compute, endpoint, limit, offset)
else:
requ_url = 'https://%s/%s' % (self.api_compute, endpoint)
requ_headers = {'Content-Type': 'application/json'}
if not request_headers:
request_headers = {'Content-Type': 'application/json'}
if self.token:
if self.api:
# Authenticate via CSPM
requ_headers['x-redlock-auth'] = self.token
request_headers['x-redlock-auth'] = self.token
else:
# Authenticate via CWP
requ_headers['Authorization'] = "Bearer %s" % self.token
request_headers['Authorization'] = "Bearer %s" % self.token
requ_params = query_params
requ_data = json.dumps(body_params)
api_response = requests.request(requ_action, requ_url, headers=requ_headers, params=requ_params, data=requ_data, verify=self.ca_bundle)
api_response = requests.request(requ_action, requ_url, headers=request_headers, params=requ_params, data=requ_data, verify=self.ca_bundle)
if self.debug:
print('API Respose Status Code: %s' % api_response.status_code)
if api_response.status_code in self.retry_status_codes:
for _ in range(1, self.retry_limit):
time.sleep(self.retry_pause)
api_response = requests.request(requ_action, requ_url, headers=requ_headers, params=query_params, data=requ_data, verify=self.ca_bundle)
api_response = requests.request(requ_action, requ_url, headers=request_headers, params=query_params, data=requ_data, verify=self.ca_bundle)
if api_response.ok:
break # retry loop
if api_response.ok:
if api_response.headers['Content-Type'] == 'text/csv':
return api_response.content.decode('utf-8')
try:
result = json.loads(api_response.content)
except ValueError:
self.logger.error('API: (%s) responded with no response, with query %s and body params: %s' % (requ_url, query_params, body_params))
self.logger.error('API: (%s) responded with no JSON response, with query %s and body params: %s' % (requ_url, query_params, body_params))
return None
if 'Total-Count' in api_response.headers:
if self.debug:
Expand Down
25 changes: 14 additions & 11 deletions prismacloud/api/posture/posture.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def login(self, requ_url=None):
if not requ_url:
requ_url = 'https://%s/login' % self.api
requ_action = 'POST'
requ_headers = {'Content-Type': 'application/json'}
request_headers = {'Content-Type': 'application/json'}
requ_data = json.dumps({'username': self.username, 'password': self.password})
api_response = requests.request(requ_action, requ_url, headers=requ_headers, data=requ_data, verify=self.ca_bundle)
api_response = requests.request(requ_action, requ_url, headers=request_headers, data=requ_data, verify=self.ca_bundle)
if api_response.status_code in self.retry_status_codes:
for _ in range(1, self.retry_limit):
time.sleep(self.retry_pause)
api_response = requests.request(requ_action, requ_url, headers=requ_headers, data=requ_data, verify=self.ca_bundle)
api_response = requests.request(requ_action, requ_url, headers=request_headers, data=requ_data, verify=self.ca_bundle)
if api_response.ok:
break
if api_response.ok:
Expand All @@ -42,12 +42,12 @@ def extend_login(self):
self.suppress_warnings_when_ca_bundle_false()
requ_url = 'https://%s/auth_token/extend' % self.api
requ_action = 'GET'
requ_headers = {'Content-Type': 'application/json', 'x-redlock-auth': self.token}
api_response = requests.request(requ_action, requ_url, headers=requ_headers, verify=self.ca_bundle)
request_headers = {'Content-Type': 'application/json', 'x-redlock-auth': self.token}
api_response = requests.request(requ_action, requ_url, headers=request_headers, verify=self.ca_bundle)
if api_response.status_code in self.retry_status_codes:
for _ in range(1, self.retry_limit):
time.sleep(self.retry_pause)
api_response = requests.request(requ_action, requ_url, headers=requ_headers, verify=self.ca_bundle)
api_response = requests.request(requ_action, requ_url, headers=request_headers, verify=self.ca_bundle)
if api_response.ok:
break
if api_response.ok:
Expand All @@ -60,7 +60,7 @@ def extend_login(self):
print('Extending API Token')

# pylint: disable=too-many-arguments, too-many-locals
def execute(self, action, endpoint, query_params=None, body_params=None, force=False, paginated=False):
def execute(self, action, endpoint, query_params=None, body_params=None, request_headers=None, force=False, paginated=False):
self.suppress_warnings_when_ca_bundle_false()
if not self.token:
self.login()
Expand All @@ -75,24 +75,27 @@ def execute(self, action, endpoint, query_params=None, body_params=None, force=F
self.extend_login()
requ_action = action
requ_url = 'https://%s/%s' % (self.api, endpoint)
requ_headers = {'Content-Type': 'application/json'}
if not request_headers:
request_headers = {'Content-Type': 'application/json'}
if self.token:
requ_headers['x-redlock-auth'] = self.token
request_headers['x-redlock-auth'] = self.token
requ_params = query_params
if body_params:
requ_data = json.dumps(body_params)
else:
requ_data = body_params
api_response = requests.request(requ_action, requ_url, headers=requ_headers, params=requ_params, data=requ_data, verify=self.ca_bundle)
api_response = requests.request(requ_action, requ_url, headers=request_headers, params=requ_params, data=requ_data, verify=self.ca_bundle)
if self.debug:
print('API Respose Status Code: %s' % api_response.status_code)
if api_response.status_code in self.retry_status_codes:
for _ in range(1, self.retry_limit):
time.sleep(self.retry_pause)
api_response = requests.request(requ_action, requ_url, headers=requ_headers, params=query_params, data=requ_data, verify=self.ca_bundle)
api_response = requests.request(requ_action, requ_url, headers=request_headers, params=query_params, data=requ_data, verify=self.ca_bundle)
if api_response.ok:
break # retry loop
if api_response.ok:
if api_response.headers['Content-Type'] == 'text/csv':
return api_response.content.decode('utf-8')
try:
result = json.loads(api_response.content)
except ValueError:
Expand Down
2 changes: 1 addition & 1 deletion prismacloud/api/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
""" version file """

version = '4.2.0'
version = '4.1.1'

0 comments on commit 51777a0

Please sign in to comment.