Automatically download certificate on Python device
This commit is contained in:
@ -56,3 +56,16 @@ def enroll_device(csr: str):
|
||||
if res.status_code < 200 or res.status_code > 299:
|
||||
print(res.text)
|
||||
raise Exception(f"Enrollment failed with status {res.status_code}")
|
||||
|
||||
def device_certificate() -> str:
|
||||
"""
|
||||
Retrieve device certificate
|
||||
"""
|
||||
res = requests.get(
|
||||
f"{args.secure_origin}/devices_api/mgmt/get_certificate?id={args.dev_id}",
|
||||
verify=args.root_ca_path,
|
||||
)
|
||||
if res.status_code < 200 or res.status_code > 299:
|
||||
print(res.text)
|
||||
raise Exception(f"Failed to check enrollment with status {res.status_code}")
|
||||
return res.text
|
||||
|
@ -72,3 +72,12 @@ if status == "Pending":
|
||||
exit(0)
|
||||
|
||||
print("Device is successfully enrolled!")
|
||||
|
||||
print("Check device certificate")
|
||||
if not os.path.isfile(args.dev_crt_path):
|
||||
print("Retrieve certificate...")
|
||||
cert = api.device_certificate()
|
||||
with open(args.dev_crt_path, "w") as f:
|
||||
f.write(cert)
|
||||
|
||||
print("Done. ready to operate.")
|
Reference in New Issue
Block a user