1 #!/usr/bin/env python
\r
8 def __init__(self, name):
\r
9 self.client = boto3.client('iot')
\r
14 assert not self.exists(), "Thing already exists"
\r
15 result = self.client.create_thing(thingName=self.name)
\r
16 self.arn = result['thingArn']
\r
19 assert self.exists(), "Thing does not exist"
\r
20 principals = self.list_principals()
\r
21 for principal in principals:
\r
22 self.detach_principal(principal)
\r
23 self.client.delete_thing(thingName=self.name)
\r
26 list_of_things = self.client.list_things()['things']
\r
27 for thing in list_of_things:
\r
28 if thing['thingName'] == self.name:
\r
32 def attach_principal(self, arn):
\r
33 assert self.exists(), "Thing does not exist"
\r
34 self.client.attach_thing_principal(thingName=self.name, principal=arn)
\r
36 def detach_principal(self, arn):
\r
37 assert self.exists(), "Thing does not exist"
\r
38 self.client.detach_thing_principal(thingName=self.name, principal=arn)
\r
40 def list_principals(self):
\r
41 assert self.exists(), "Thing does not exist"
\r
42 principals = self.client.list_thing_principals(thingName=self.name)
\r
43 principals = principals['principals']
\r