Start to implement devices enrollment
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
import requests
|
||||
from src.args import args
|
||||
import src.constants as constants
|
||||
|
||||
|
||||
def get_secure_origin() -> str:
|
||||
res = requests.get(f"{args.unsecure_origin}/secure_origin")
|
||||
@ -7,8 +9,32 @@ def get_secure_origin() -> str:
|
||||
raise Exception(f"Get secure origin failed with status {res.status_code}")
|
||||
return res.text
|
||||
|
||||
|
||||
def get_root_ca() -> str:
|
||||
res = requests.get(f"{args.unsecure_origin}/pki/root_ca.pem")
|
||||
res = requests.get(f"{args.unsecure_origin}/pki/root_ca.crt")
|
||||
if res.status_code < 200 or res.status_code > 299:
|
||||
raise Exception(f"Get root CA failed with status {res.status_code}")
|
||||
return res.text
|
||||
|
||||
|
||||
def device_info():
|
||||
"""
|
||||
Get device information to return with enrollment and sync requests
|
||||
"""
|
||||
return {
|
||||
"reference": constants.DEV_REFERENCE,
|
||||
"version": constants.DEV_VERSION,
|
||||
"max_relays": len(args.relay_gpios_list),
|
||||
}
|
||||
|
||||
|
||||
def enroll_device(csr: str) -> str:
|
||||
res = requests.post(
|
||||
f"{args.secure_origin}/devices_api/mgmt/enroll",
|
||||
json={"csr": csr, "info": device_info()},
|
||||
verify=args.root_ca_path,
|
||||
)
|
||||
if res.status_code < 200 or res.status_code > 299:
|
||||
print(res.text)
|
||||
raise Exception(f"Enrollment failed with status {res.status_code}")
|
||||
return res.text
|
||||
|
Reference in New Issue
Block a user