Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Identity testing part1
  • Loading branch information
Bret Ambrose committed May 6, 2025
commit d0ca844f598f8dd8f7d5516880c2f5c5428805e7
2 changes: 1 addition & 1 deletion awsiot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class ServiceStreamOptions(Generic[T]):
subscription_status_listener: 'Optional[mqtt_request_response.SubscriptionStatusListener]' = None
deserialization_failure_listener: 'Optional[Callable[[V2DeserializationFailure], None]]' = None

def validate(self):
def _validate(self):
"""
Stringently type-checks an instance's field values.
"""
Expand Down
202 changes: 195 additions & 7 deletions awsiot/iotidentity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

# This file is generated

import awscrt
import awsiot
import concurrent.futures
import json
import typing

class IotIdentityClient(awsiot.MqttServiceClient):
Expand Down Expand Up @@ -33,6 +35,7 @@ def publish_create_certificate_from_csr(self, request, qos):
request is successfully published. The Future's result will be an
exception if the request cannot be published.
"""
request._validate()

return self._publish_operation(
topic='$aws/certificates/create-from-csr/json',
Expand All @@ -56,11 +59,12 @@ def publish_create_keys_and_certificate(self, request, qos):
request is successfully published. The Future's result will be an
exception if the request cannot be published.
"""
request._validate()

return self._publish_operation(
topic='$aws/certificates/create/json',
qos=qos,
payload=None)
payload=request.to_payload())

def publish_register_thing(self, request, qos):
# type: (RegisterThingRequest, int) -> concurrent.futures.Future
Expand All @@ -79,8 +83,7 @@ def publish_register_thing(self, request, qos):
request is successfully published. The Future's result will be an
exception if the request cannot be published.
"""
if not request.template_name:
raise ValueError("request.template_name is required")
request._validate()

return self._publish_operation(
topic='$aws/provisioning-templates/{0.template_name}/provision/json'.format(request),
Expand Down Expand Up @@ -109,6 +112,7 @@ def subscribe_to_create_certificate_from_csr_accepted(self, request, qos, callba
to `unsubscribe()` to stop receiving messages. Note that messages
may arrive before the subscription is acknowledged.
"""
request._validate()

if not callable(callback):
raise ValueError("callback is required")
Expand Down Expand Up @@ -141,6 +145,7 @@ def subscribe_to_create_certificate_from_csr_rejected(self, request, qos, callba
to `unsubscribe()` to stop receiving messages. Note that messages
may arrive before the subscription is acknowledged.
"""
request._validate()

if not callable(callback):
raise ValueError("callback is required")
Expand Down Expand Up @@ -173,6 +178,7 @@ def subscribe_to_create_keys_and_certificate_accepted(self, request, qos, callba
to `unsubscribe()` to stop receiving messages. Note that messages
may arrive before the subscription is acknowledged.
"""
request._validate()

if not callable(callback):
raise ValueError("callback is required")
Expand Down Expand Up @@ -205,6 +211,7 @@ def subscribe_to_create_keys_and_certificate_rejected(self, request, qos, callba
to `unsubscribe()` to stop receiving messages. Note that messages
may arrive before the subscription is acknowledged.
"""
request._validate()

if not callable(callback):
raise ValueError("callback is required")
Expand Down Expand Up @@ -237,8 +244,7 @@ def subscribe_to_register_thing_accepted(self, request, qos, callback):
to `unsubscribe()` to stop receiving messages. Note that messages
may arrive before the subscription is acknowledged.
"""
if not request.template_name:
raise ValueError("request.template_name is required")
request._validate()

if not callable(callback):
raise ValueError("callback is required")
Expand Down Expand Up @@ -271,8 +277,7 @@ def subscribe_to_register_thing_rejected(self, request, qos, callback):
to `unsubscribe()` to stop receiving messages. Note that messages
may arrive before the subscription is acknowledged.
"""
if not request.template_name:
raise ValueError("request.template_name is required")
request._validate()

if not callable(callback):
raise ValueError("callback is required")
Expand Down Expand Up @@ -313,6 +318,9 @@ def to_payload(self):
payload['certificateSigningRequest'] = self.certificate_signing_request
return payload

def _validate(self):
return

class CreateCertificateFromCsrResponse(awsiot.ModeledClass):
"""

Expand Down Expand Up @@ -357,6 +365,9 @@ def from_payload(cls, payload):
new.certificate_pem = val
return new

def _validate(self):
return

class CreateCertificateFromCsrSubscriptionRequest(awsiot.ModeledClass):
"""

Expand All @@ -373,6 +384,9 @@ def __init__(self, *args, **kwargs):
for key, val in zip([], args):
setattr(self, key, val)

def _validate(self):
return

class CreateKeysAndCertificateRequest(awsiot.ModeledClass):
"""

Expand All @@ -389,6 +403,14 @@ def __init__(self, *args, **kwargs):
for key, val in zip([], args):
setattr(self, key, val)

def to_payload(self):
# type: () -> typing.Dict[str, typing.Any]
payload = {} # type: typing.Dict[str, typing.Any]
return payload

def _validate(self):
return

class CreateKeysAndCertificateResponse(awsiot.ModeledClass):
"""

Expand Down Expand Up @@ -439,6 +461,9 @@ def from_payload(cls, payload):
new.private_key = val
return new

def _validate(self):
return

class CreateKeysAndCertificateSubscriptionRequest(awsiot.ModeledClass):
"""

Expand All @@ -455,6 +480,9 @@ def __init__(self, *args, **kwargs):
for key, val in zip([], args):
setattr(self, key, val)

def _validate(self):
return

class ErrorResponse(awsiot.ModeledClass):
"""

Expand Down Expand Up @@ -499,6 +527,9 @@ def from_payload(cls, payload):
new.status_code = val
return new

def _validate(self):
return

class RegisterThingRequest(awsiot.ModeledClass):
"""

Expand Down Expand Up @@ -537,6 +568,11 @@ def to_payload(self):
payload['parameters'] = self.parameters
return payload

def _validate(self):
if not self.template_name:
raise ValueError("template_name is required")
return

class RegisterThingResponse(awsiot.ModeledClass):
"""

Expand Down Expand Up @@ -575,6 +611,9 @@ def from_payload(cls, payload):
new.thing_name = val
return new

def _validate(self):
return

class RegisterThingSubscriptionRequest(awsiot.ModeledClass):
"""

Expand All @@ -598,6 +637,11 @@ def __init__(self, *args, **kwargs):
for key, val in zip(['template_name'], args):
setattr(self, key, val)

def _validate(self):
if not self.template_name:
raise ValueError("template_name is required")
return

class V2ErrorResponse(awsiot.ModeledClass):
"""

Expand Down Expand Up @@ -642,3 +686,147 @@ def from_payload(cls, payload):
new.status_code = val
return new

def _validate(self):
return

class IotIdentityClientV2:
"""

An AWS IoT service that assists with provisioning a device and installing unique client certificates on it

AWS Docs: https://docs.aws.amazon.com/iot/latest/developerguide/provision-wo-cert.html

"""

def __init__(self, protocol_client: awscrt.mqtt.Connection or awscrt.mqtt5.Client, options: awscrt.mqtt_request_response.ClientOptions):
self._rr_client = awscrt.mqtt_request_response.Client(protocol_client, options)

def create_certificate_from_csr(self, request : CreateCertificateFromCsrRequest) -> concurrent.futures.Future :
"""

Creates a certificate from a certificate signing request (CSR). AWS IoT provides client certificates that are signed by the Amazon Root certificate authority (CA). The new certificate has a PENDING_ACTIVATION status. When you call RegisterThing to provision a thing with this certificate, the certificate status changes to ACTIVE or INACTIVE as described in the template.

API Docs: https://docs.aws.amazon.com/iot/latest/developerguide/provision-wo-cert.html#fleet-provision-api

Args:
request: `CreateCertificateFromCsrRequest` instance.

Returns:
A Future whose result will be an instance of `CreateCertificateFromCsrResponse`.
"""
request._validate()

publish_topic = '$aws/certificates/create-from-csr/json'
accepted_topic = publish_topic + "/accepted";
rejected_topic = publish_topic + "/rejected";

subscription0 = '$aws/certificates/create-from-csr/json/accepted';
subscription1 = '$aws/certificates/create-from-csr/json/rejected';

request_options = awscrt.mqtt_request_response.RequestOptions(
subscription_topic_filters = [
subscription0,
subscription1,
],
response_paths = [
awscrt.mqtt_request_response.ResponsePath(
accepted_topic,
),
awscrt.mqtt_request_response.ResponsePath(
rejected_topic,
)
],
publish_topic = publish_topic,
payload = json.dumps(request.to_payload()).encode(),
)

internal_unmodeled_future = self._rr_client.make_request(request_options)

return awsiot.create_v2_service_modeled_future(internal_unmodeled_future, "create_certificate_from_csr", accepted_topic, CreateCertificateFromCsrResponse, V2ErrorResponse)

def create_keys_and_certificate(self, request : CreateKeysAndCertificateRequest) -> concurrent.futures.Future :
"""

Creates new keys and a certificate. AWS IoT provides client certificates that are signed by the Amazon Root certificate authority (CA). The new certificate has a PENDING_ACTIVATION status. When you call RegisterThing to provision a thing with this certificate, the certificate status changes to ACTIVE or INACTIVE as described in the template.

API Docs: https://docs.aws.amazon.com/iot/latest/developerguide/provision-wo-cert.html#fleet-provision-api

Args:
request: `CreateKeysAndCertificateRequest` instance.

Returns:
A Future whose result will be an instance of `CreateKeysAndCertificateResponse`.
"""
request._validate()

publish_topic = '$aws/certificates/create/json'
accepted_topic = publish_topic + "/accepted";
rejected_topic = publish_topic + "/rejected";

subscription0 = '$aws/certificates/create/json/accepted';
subscription1 = '$aws/certificates/create/json/rejected';

request_options = awscrt.mqtt_request_response.RequestOptions(
subscription_topic_filters = [
subscription0,
subscription1,
],
response_paths = [
awscrt.mqtt_request_response.ResponsePath(
accepted_topic,
),
awscrt.mqtt_request_response.ResponsePath(
rejected_topic,
)
],
publish_topic = publish_topic,
payload = json.dumps(request.to_payload()).encode(),
)

internal_unmodeled_future = self._rr_client.make_request(request_options)

return awsiot.create_v2_service_modeled_future(internal_unmodeled_future, "create_keys_and_certificate", accepted_topic, CreateKeysAndCertificateResponse, V2ErrorResponse)

def register_thing(self, request : RegisterThingRequest) -> concurrent.futures.Future :
"""

Provisions an AWS IoT thing using a pre-defined template.

API Docs: https://docs.aws.amazon.com/iot/latest/developerguide/provision-wo-cert.html#fleet-provision-api

Args:
request: `RegisterThingRequest` instance.

Returns:
A Future whose result will be an instance of `RegisterThingResponse`.
"""
request._validate()

publish_topic = '$aws/provisioning-templates/{0.template_name}/provision/json'.format(request)
accepted_topic = publish_topic + "/accepted";
rejected_topic = publish_topic + "/rejected";

subscription0 = '$aws/provisioning-templates/{0.template_name}/provision/json/accepted'.format(request);
subscription1 = '$aws/provisioning-templates/{0.template_name}/provision/json/rejected'.format(request);

request_options = awscrt.mqtt_request_response.RequestOptions(
subscription_topic_filters = [
subscription0,
subscription1,
],
response_paths = [
awscrt.mqtt_request_response.ResponsePath(
accepted_topic,
),
awscrt.mqtt_request_response.ResponsePath(
rejected_topic,
)
],
publish_topic = publish_topic,
payload = json.dumps(request.to_payload()).encode(),
)

internal_unmodeled_future = self._rr_client.make_request(request_options)

return awsiot.create_v2_service_modeled_future(internal_unmodeled_future, "register_thing", accepted_topic, RegisterThingResponse, V2ErrorResponse)

Loading
Loading