if args.csr is None:
            print("Publishing to CreateKeysAndCertificate...")
            publish_future = identity_client.publish_create_keys_and_certificate(
                request=iotidentity.CreateKeysAndCertificateRequest(),
                qos=mqtt.QoS.AT_LEAST_ONCE)
            publish_future.add_done_callback(
                on_publish_create_keys_and_certificate)

            waitForCreateKeysAndCertificateResponse()

            if createKeysAndCertificateResponse is None:
                raise Exception('CreateKeysAndCertificate API did not succeed')

            registerThingRequest = iotidentity.RegisterThingRequest(
                template_name=args.templateName,
                certificate_ownership_token=createKeysAndCertificateResponse.
                certificate_ownership_token,
                parameters=json.loads(args.templateParameters))
        else:
            print("Publishing to CreateCertificateFromCsr...")
            csrPath = open(args.csr, 'r').read()
            publish_future = identity_client.publish_create_certificate_from_csr(
                request=iotidentity.CreateCertificateFromCsrRequest(
                    certificate_signing_request=csrPath),
                qos=mqtt.QoS.AT_LEAST_ONCE)
            publish_future.add_done_callback(
                on_publish_create_certificate_from_csr)

            waitForCreateCertificateFromCsrResponse()

            if createCertificateFromCsrResponse is None:
Beispiel #2
0
perm_config["SETTINGS"] = {
    "SECURE_CERT_PATH": long_term_credentials_path,
    "ROOT_CERT": root_cert_long_term_path,
    "CLAIM_CERT": claim_cert_long_term_path,
    "SECURE_KEY": private_key_long_term_path,
    "IOT_ENDPOINT": iot_endpoint,
    "IOT_TOPIC": topic,
    "DEVICE_BUILDING_NAME": args.building,
    "DEVICE_LOCATION": args.location
}
with open(join(long_term_credentials_path, "perm_config.ini"), "w") as outfile:
    perm_config.write(outfile)

register_thing_request = iotidentity.RegisterThingRequest(
    template_name=provisioning_template_name,
    certificate_ownership_token=create_keys_and_certificate_response.
    certificate_ownership_token,
    parameters={
        "SerialNumber": machine_uuid,
        "BuildingName": args.building,
        "Location": args.location
    })

print("Publishing to RegisterThing topic...")
registerthing_publish_future = identity_client.publish_register_thing(
    register_thing_request, mqtt.QoS.AT_LEAST_ONCE)
registerthing_publish_future.add_done_callback(on_publish_register_thing)

wait_for_register_thing_response()
sys.exit("Success")