On Python device, automatically delete invalid certificate if status leaves the "Validated" mode
This commit is contained in:
		@@ -57,6 +57,7 @@ def enroll_device(csr: str):
 | 
			
		||||
        print(res.text)
 | 
			
		||||
        raise Exception(f"Enrollment failed with status {res.status_code}")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def device_certificate() -> str:
 | 
			
		||||
    """
 | 
			
		||||
    Retrieve device certificate
 | 
			
		||||
 
 | 
			
		||||
@@ -55,6 +55,11 @@ if not os.path.isfile(args.dev_csr_path):
 | 
			
		||||
print("Check device enrollment...")
 | 
			
		||||
status = api.device_enrollment_status()
 | 
			
		||||
 | 
			
		||||
if status != "Validated":
 | 
			
		||||
    if os.path.isfile(args.dev_crt_path):
 | 
			
		||||
        print("Delete invalid certificate")
 | 
			
		||||
        os.unlink(args.dev_crt_path)
 | 
			
		||||
 | 
			
		||||
if status == "Unknown":
 | 
			
		||||
    print("Device is unknown on the system, need to submit a CSR...")
 | 
			
		||||
    with open(args.dev_csr_path, "r") as f:
 | 
			
		||||
@@ -80,4 +85,4 @@ if not os.path.isfile(args.dev_crt_path):
 | 
			
		||||
    with open(args.dev_crt_path, "w") as f:
 | 
			
		||||
        f.write(cert)
 | 
			
		||||
 | 
			
		||||
print("Done. ready to operate.")
 | 
			
		||||
print("Done. ready to operate.")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user