Skip to content

Commit 12d2b33

Browse files
authored
Updated to v1.0.6
1 parent 53e2db4 commit 12d2b33

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

pyclearpass/api_certificateauthority.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,14 @@ def get_certificate_by_cert_id_chain(self, cert_id=""):
7272
return ClearPassAPILogin._send_request(self, url=url_path, method="get")
7373

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

102109
# API Service: Import a code-signing, trusted, or CA certificate

pyclearpass/common.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,14 @@ def __init__(
4747
self.api_token = api_token
4848
self.verify_ssl = False
4949

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

6871
if len(self.api_token) != 0:
69-
header = {"Authorization": "Bearer " + self.api_token}
72+
header = {
73+
"Authorization": "Bearer " + self.api_token,
74+
"accept": content_response_type,
75+
}
7076
if method == "post":
7177
response = requests.post(
7278
url=full_url_path,
@@ -107,10 +113,13 @@ def _send_request(self, url, method, query=""):
107113
"method needs to be supplied before sending a request to ClearPass"
108114
)
109115

110-
try:
111-
return json.loads(response.text)
112-
except json.decoder.JSONDecodeError:
113-
return response.text
116+
if "json" in content_response_type:
117+
try:
118+
return json.loads(response.text)
119+
except json.decoder.JSONDecodeError:
120+
return response.text
121+
else:
122+
return response.content
114123
else:
115124
print("Problem logging into ClearPass")
116125
return cred

0 commit comments

Comments
 (0)