Can get a single device enrollment status
This commit is contained in:
@@ -27,6 +27,15 @@ if not os.path.isfile(args.root_ca_path):
|
||||
with open(args.root_ca_path, "w") as f:
|
||||
f.write(origin)
|
||||
|
||||
print("Check device ID")
|
||||
if not os.path.isfile(args.dev_id_path):
|
||||
print("Generate device id...")
|
||||
with open(args.dev_id_path, "w") as f:
|
||||
f.write(f"PyDev {utils.rand_str(10)}")
|
||||
|
||||
with open(args.dev_id_path, "r") as f:
|
||||
args.dev_id = f.read()
|
||||
|
||||
print("Check private key")
|
||||
if not os.path.isfile(args.dev_priv_key_path):
|
||||
print("Generate private key...")
|
||||
@@ -39,19 +48,27 @@ if not os.path.isfile(args.dev_csr_path):
|
||||
print("Generate CSR...")
|
||||
with open(args.dev_priv_key_path, "r") as f:
|
||||
priv_key = "".join(f.readlines())
|
||||
csr = pki.gen_csr(priv_key=priv_key, cn=f"PyDev {utils.rand_str(10)}")
|
||||
csr = pki.gen_csr(priv_key=priv_key, cn=args.dev_id)
|
||||
with open(args.dev_csr_path, "w") as f:
|
||||
f.write(csr)
|
||||
|
||||
print("Check device enrollment...")
|
||||
if not os.path.isfile(args.dev_enroll_marker):
|
||||
status = api.device_enrollment_status()
|
||||
|
||||
if status == "Unknown":
|
||||
print("Device is unknown on the system, need to submit a CSR...")
|
||||
with open(args.dev_csr_path, "r") as f:
|
||||
csr = "".join(f.read())
|
||||
|
||||
print("Enrolling device...")
|
||||
crt = api.enroll_device(csr)
|
||||
|
||||
with open(args.dev_enroll_marker, "w") as f:
|
||||
f.write("submitted")
|
||||
print("Done. Please accept the device on central system web UI")
|
||||
exit(0)
|
||||
|
||||
# TODO : "intelligent" enrollment management (re-enroll if cancelled)
|
||||
if status == "Pending":
|
||||
print(
|
||||
"Device is enrolled, but not validated yet. Please accept the device on central system web UI"
|
||||
)
|
||||
exit(0)
|
||||
|
||||
print("Device is successfully enrolled!")
|
||||
|
||||
Reference in New Issue
Block a user