Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion vcert/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,10 @@ def process_server_response(r):
log_errors(r.content)
raise VenafiConnectionError(f"\n\tServer status: {r.status_code}"
f"\n\tURL: {r.request.url}"
f"\n\tResponse: {r.content}")
f"\n\tResponse: {r.content}",
status_code = r.status_code,
url = r.request.url,
content = r.content)

content_type = r.headers.get("content-type")
# Content-type not present, return status and reason (if any)
Expand Down
12 changes: 8 additions & 4 deletions vcert/connection_tpp_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from .common import CertField, CommonConnection, CertificateRequest, CSR_ORIGIN_LOCAL, CSR_ORIGIN_PROVIDED, \
CSR_ORIGIN_SERVICE, KeyType, CHAIN_OPTION_LAST, CHAIN_OPTION_FIRST, CHAIN_OPTION_IGNORE, Policy, ZoneConfig
from .errors import VenafiError, ServerUnexptedBehavior, ClientBadData, RetrieveCertificateTimeoutError, \
CertificateRequestError, CertificateRenewError
RetrieveCertificateNotFoundError, CertificateRequestError, CertificateRenewError
from .http_status import HTTPStatus
from .pem import parse_pem
from .policy import RPA, SPA
Expand Down Expand Up @@ -212,9 +212,13 @@ def retrieve_cert(self, cert_request):
try:
# TODO: Change _post() with post(args)
status, data = self._post(URLS.CERTIFICATE_RETRIEVE, data=retrieve_request)
except VenafiError:
log.debug(f"Certificate with id {cert_request.id} not found")
status = 0
except VenafiError as error:
log.debug(error.content)
status = error.status_code
if status == HTTPStatus.NOT_FOUND:
raise RetrieveCertificateNotFoundError(f"Certificate with id {cert_request.id} not found")
elif status == HTTPStatus.BAD_REQUEST:
raise ClientBadData(error.content)

if status == HTTPStatus.OK:
pem64 = data['CertificateData']
Expand Down
9 changes: 8 additions & 1 deletion vcert/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@


class VenafiError(Exception):
pass
def __init__(self, *args, **kwargs):
super().__init__(*args)
for (k,v) in kwargs.items():
setattr(self, k, v)


class VenafiConnectionError(VenafiError):
Expand Down Expand Up @@ -53,3 +56,7 @@ class VenafiParsingError(VenafiError):

class RetrieveCertificateTimeoutError(VenafiError):
pass


class RetrieveCertificateNotFoundError(VenafiError):
pass