43 lines
985 B
Python
43 lines
985 B
Python
#!/usr/bin/python3
|
|
# vim:syntax=python
|
|
|
|
import json
|
|
import base64
|
|
from urllib.request import urlopen
|
|
from urllib.request import Request
|
|
|
|
|
|
def get_file_content(checkfile=None):
|
|
try:
|
|
with open(checkfile, "r") as f:
|
|
ret = f.read()
|
|
except OSError:
|
|
return None
|
|
|
|
return ret
|
|
|
|
|
|
def write_file_content(content=None,
|
|
filename=None):
|
|
try:
|
|
with open(filename, "w") as f:
|
|
ret = f.write(content)
|
|
except OSError:
|
|
return None
|
|
|
|
return ret
|
|
|
|
|
|
def get_pki_cert(url="http://pki",
|
|
username=None,
|
|
password=None,
|
|
domains=None):
|
|
req = Request(method="GET",
|
|
url=f"{url}/domain/{domains}")
|
|
authstring = base64.b64encode(f"{username}:{password}".encode()).decode()
|
|
req.add_header("Authorization", f"Basic {authstring}")
|
|
res = urlopen(req)
|
|
resj = json.loads(res.read())
|
|
|
|
return resj["certificate"], resj["privatekey"]
|