added source functionality

This commit is contained in:
sirferl 2020-12-02 15:50:51 +01:00
parent 3b19863a96
commit 9b2ac32d70
1 changed files with 56 additions and 2 deletions

View File

@ -313,6 +313,15 @@ class EntrustSourcePlugin(SourcePlugin):
author = "sirferl"
author_url = "https://github.com/sirferl/lemur"
options = [
{
"name": "dummy",
"type": "str",
"required": False,
"validation": "/^[0-9]{12,12}$/",
"helpMessage": "Just to prevent error",
}
]
def __init__(self, *args, **kwargs):
"""Initialize the issuer with the appropriate details."""
@ -340,8 +349,53 @@ class EntrustSourcePlugin(SourcePlugin):
super(EntrustSourcePlugin, self).__init__(*args, **kwargs)
def get_certificates(self, options, **kwargs):
# Not needed for ENTRUST
raise NotImplementedError("Not implemented\n", self, options, **kwargs)
""" Fetch all Entrust certificates """
base_url = current_app.config.get("ENTRUST_URL")
host = base_url.replace('/enterprise/v2','')
get_url = f"{base_url}/certificates"
certs =[]
offset = 0
while True:
response = self.session.get(get_url,
params={
"status": "ACTIVE",
"isThirdParty": "false",
"fields": "uri,dn",
"offset": offset
}
)
try:
data = json.loads(response.content)
except ValueError:
# catch an empty jason object here
data = {'response': 'No detailed message'}
status_code = response.status_code
if status_code > 399:
raise Exception(f"ENTRUST error: {msg.get(status_code, status_code)}\n{data['errors']}")
# current_app.logger.info(f"recevied: {data['summary']}")
for c in data["certificates"]:
download_url = "{0}{1}".format(
host, c["uri"]
)
cert_response = self.session.get(download_url)
certificate = json.loads(cert_response.content)
# current_app.logger.info(f"Result: {certificate}")
# normalize serial
serial = str(int(certificate["serialNumber"], 16))
cert = {
"body": certificate["endEntityCert"],
"serial": serial,
"external_id": str(certificate["trackingId"]),
}
certs.append(cert)
if data["summary"]["limit"] * offset >= data["summary"]["total"]:
break
else:
offset += 1
current_app.logger.info(f"Result: {certs}")
return certs
def get_endpoints(self, options, **kwargs):
# There are no endpoints in ENTRUST