paulbsd-salt/states/_modules/pki.py
2021-07-18 10:02:15 +02:00

50 lines
965 B
Python

#!/usr/bin/python3
# vim:syntax=python
import os
import requests
def write_file_content(content=None,
filename=None):
ret = None
try:
with open(filename, "w") as f:
ret = f.write(content)
except Exception as err:
pass
return
def get_file_content(checkfile=None):
ret = None
try:
with open(checkfile, 'r') as f:
ret = f.read()
except FileNotFoundError as err:
pass
return ret
def get_pki_cert(url="http://pki",
username=None,
password=None,
domains=None):
ret = None
try:
res = requests.request(method="GET",
url=f"{url}/domain/{domains}",
auth=(username, password))
resj = res.json()
return resj["certificate"], resj["privatekey"]
except Exception as err:
pass
return None, None