CF_API_BASE = "https://api.cloudflare.com/client/v4"
load_dotenv()
ORIGIN_CA_KEY = os.getenv("ORIGIN_CA_KEY")
def get_headers(origin_ca_key):
return {
"X-Auth-User-Service-Key": origin_ca_key,
"Content-Type": "application/json",
}
def issue_origin_ca_cert(origin_ca_key, domains):
url = f"{CF_API_BASE}/certificates"
payload = {
"hostnames": domains,
"requested_validity": 5475,
"request_type": "origin-rsa"
}
resp = requests.post(url, json=payload, headers=get_headers(origin_ca_key))
if resp.status_code != 200:
print(f"[ERROR] Cloudflare API error (issue origin ca cert): {resp.text}")
return None, None, None
result = resp.json()["result"]
return result["certificate"], result["private_key"], result.get("id", "new")
CF_API_BASE = "https://api.cloudflare.com/client/v4"
load_dotenv()
ORIGIN_CA_KEY = os.getenv("ORIGIN_CA_KEY")
def get_headers(origin_ca_key):
return {
"X-Auth-User-Service-Key": origin_ca_key,
"Content-Type": "application/json",
}
def issue_origin_ca_cert(origin_ca_key, domains):
url = f"{CF_API_BASE}/certificates"
payload = {
"hostnames": domains,
"requested_validity": 5475,
"request_type": "origin-rsa"
}
resp = requests.post(url, json=payload, headers=get_headers(origin_ca_key))
if resp.status_code != 200:
print(f"[ERROR] Cloudflare API error (issue origin ca cert): {resp.text}")
return None, None, None
result = resp.json()["result"]
return result["certificate"], result["private_key"], result.get("id", "new")