mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-10-26 23:36:32 -04:00
Tools for configuring AWS credentials in MQTT Mutual Auth Demo (#370)
This adds aws_config_offline, which allows the user to download demo_config.h for the MQTT Mutual Auth Demo using a webpage. This also adds aws_config_quick_start, which provides a means to generate demo_config.h for the Mutual Auth Demo with boto3.
This commit is contained in:
parent
4124ac0c57
commit
58adeb2c0f
14 changed files with 1481 additions and 0 deletions
44
tools/aws_config_quick_start/thing.py
Normal file
44
tools/aws_config_quick_start/thing.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import boto3
|
||||
import json
|
||||
|
||||
|
||||
class Thing():
|
||||
def __init__(self, name):
|
||||
self.client = boto3.client('iot')
|
||||
self.name = name
|
||||
self.arn = ''
|
||||
|
||||
def create(self):
|
||||
assert not self.exists(), "Thing already exists"
|
||||
result = self.client.create_thing(thingName=self.name)
|
||||
self.arn = result['thingArn']
|
||||
|
||||
def delete(self):
|
||||
assert self.exists(), "Thing does not exist"
|
||||
principals = self.list_principals()
|
||||
for principal in principals:
|
||||
self.detach_principal(principal)
|
||||
self.client.delete_thing(thingName=self.name)
|
||||
|
||||
def exists(self):
|
||||
list_of_things = self.client.list_things()['things']
|
||||
for thing in list_of_things:
|
||||
if thing['thingName'] == self.name:
|
||||
return True
|
||||
return False
|
||||
|
||||
def attach_principal(self, arn):
|
||||
assert self.exists(), "Thing does not exist"
|
||||
self.client.attach_thing_principal(thingName=self.name, principal=arn)
|
||||
|
||||
def detach_principal(self, arn):
|
||||
assert self.exists(), "Thing does not exist"
|
||||
self.client.detach_thing_principal(thingName=self.name, principal=arn)
|
||||
|
||||
def list_principals(self):
|
||||
assert self.exists(), "Thing does not exist"
|
||||
principals = self.client.list_thing_principals(thingName=self.name)
|
||||
principals = principals['principals']
|
||||
return principals
|
||||
Loading…
Add table
Add a link
Reference in a new issue