Skip to content

Commit

Permalink
Updated to v1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
jazzyj123 authored Jul 9, 2024
1 parent 53e2db4 commit 12d2b33
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
11 changes: 9 additions & 2 deletions pyclearpass/api_certificateauthority.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ def get_certificate_by_cert_id_chain(self, cert_id=""):
return ClearPassAPILogin._send_request(self, url=url_path, method="get")

# API Service: Export a certificate or certificate signing request
def new_certificate_by_cert_id_export(self, cert_id="", body=({})):
def new_certificate_by_cert_id_export(
self, cert_id="", body=({}), content_type="application/json"
):
"""
Operation: Export a certificate or certificate signing request
HTTP Response Codes: 200 OK, 401 Unauthorized, 403 Forbidden, 404 Not Found, 406 Not Acceptable, 415 Unsupported Media Type, 422 Unprocessable Entity
Parameter Type: path, Name: cert_id, Description: Numeric ID of the certificate
Optional Response Content-Type Parameters: application/x-x509-ca-cert, application/x-pkcs7-certificates, application/pkcs10, application/x-pkcs12, text/plain
Required Body Parameters:['export_format']
Parameter Type: body, Name: body
Body example with descriptions and object types below (type(dict):
Expand All @@ -96,7 +99,11 @@ def new_certificate_by_cert_id_export(self, cert_id="", body=({})):
url_path = url_path.replace("{" + item + "}", dict_path[item])
body = _remove_empty_keys(keys=body)
return ClearPassAPILogin._send_request(
self, url=url_path, method="post", query=body
self,
url=url_path,
method="post",
query=body,
content_response_type=content_type,
)

# API Service: Import a code-signing, trusted, or CA certificate
Expand Down
21 changes: 15 additions & 6 deletions pyclearpass/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ def __init__(
self.api_token = api_token
self.verify_ssl = False

def _send_request(self, url, method, query=""):
def _send_request(
self, url, method, query="", content_response_type="application/json"
):
"""Sends a request to the ClearPass server
:query: must contain the json request if model required
:url: must contain the /url (e.g. /oauth)
:method: must contain the post or get request type of method
:content_response_type: by default is set as Application/Json however can be changed by the method if required and functionality exists.
:api_token optional[]: must contain the api_token for the calls.
"""
full_url_path = self.server + url
Expand All @@ -66,7 +69,10 @@ def _send_request(self, url, method, query=""):
pass

if len(self.api_token) != 0:
header = {"Authorization": "Bearer " + self.api_token}
header = {
"Authorization": "Bearer " + self.api_token,
"accept": content_response_type,
}
if method == "post":
response = requests.post(
url=full_url_path,
Expand Down Expand Up @@ -107,10 +113,13 @@ def _send_request(self, url, method, query=""):
"method needs to be supplied before sending a request to ClearPass"
)

try:
return json.loads(response.text)
except json.decoder.JSONDecodeError:
return response.text
if "json" in content_response_type:
try:
return json.loads(response.text)
except json.decoder.JSONDecodeError:
return response.text
else:
return response.content
else:
print("Problem logging into ClearPass")
return cred
Expand Down

0 comments on commit 12d2b33

Please sign in to comment.