Add group features to iot (#1402)
* Add thing group features * thing thing-group relation * clean up comments
This commit is contained in:
parent
770281aef2
commit
71af9317f2
4 changed files with 475 additions and 12 deletions
|
|
@ -38,8 +38,7 @@ class IoTResponse(BaseResponse):
|
|||
thing_types = self.iot_backend.list_thing_types(
|
||||
thing_type_name=thing_type_name
|
||||
)
|
||||
|
||||
# TODO: support next_token and max_results
|
||||
# TODO: implement pagination in the future
|
||||
next_token = None
|
||||
return json.dumps(dict(thingTypes=[_.to_dict() for _ in thing_types], nextToken=next_token))
|
||||
|
||||
|
|
@ -54,7 +53,7 @@ class IoTResponse(BaseResponse):
|
|||
attribute_value=attribute_value,
|
||||
thing_type_name=thing_type_name,
|
||||
)
|
||||
# TODO: support next_token and max_results
|
||||
# TODO: implement pagination in the future
|
||||
next_token = None
|
||||
return json.dumps(dict(things=[_.to_dict() for _ in things], nextToken=next_token))
|
||||
|
||||
|
|
@ -63,7 +62,6 @@ class IoTResponse(BaseResponse):
|
|||
thing = self.iot_backend.describe_thing(
|
||||
thing_name=thing_name,
|
||||
)
|
||||
print(thing.to_dict(include_default_client_id=True))
|
||||
return json.dumps(thing.to_dict(include_default_client_id=True))
|
||||
|
||||
def describe_thing_type(self):
|
||||
|
|
@ -135,7 +133,7 @@ class IoTResponse(BaseResponse):
|
|||
# marker = self._get_param("marker")
|
||||
# ascending_order = self._get_param("ascendingOrder")
|
||||
certificates = self.iot_backend.list_certificates()
|
||||
# TODO: handle pagination
|
||||
# TODO: implement pagination in the future
|
||||
return json.dumps(dict(certificates=[_.to_dict() for _ in certificates]))
|
||||
|
||||
def update_certificate(self):
|
||||
|
|
@ -162,7 +160,7 @@ class IoTResponse(BaseResponse):
|
|||
# ascending_order = self._get_param("ascendingOrder")
|
||||
policies = self.iot_backend.list_policies()
|
||||
|
||||
# TODO: handle pagination
|
||||
# TODO: implement pagination in the future
|
||||
return json.dumps(dict(policies=[_.to_dict() for _ in policies]))
|
||||
|
||||
def get_policy(self):
|
||||
|
|
@ -205,7 +203,7 @@ class IoTResponse(BaseResponse):
|
|||
policies = self.iot_backend.list_principal_policies(
|
||||
principal_arn=principal
|
||||
)
|
||||
# TODO: handle pagination
|
||||
# TODO: implement pagination in the future
|
||||
next_marker = None
|
||||
return json.dumps(dict(policies=[_.to_dict() for _ in policies], nextMarker=next_marker))
|
||||
|
||||
|
|
@ -217,7 +215,7 @@ class IoTResponse(BaseResponse):
|
|||
principals = self.iot_backend.list_policy_principals(
|
||||
policy_name=policy_name,
|
||||
)
|
||||
# TODO: handle pagination
|
||||
# TODO: implement pagination in the future
|
||||
next_marker = None
|
||||
return json.dumps(dict(principals=principals, nextMarker=next_marker))
|
||||
|
||||
|
|
@ -246,7 +244,7 @@ class IoTResponse(BaseResponse):
|
|||
things = self.iot_backend.list_principal_things(
|
||||
principal_arn=principal,
|
||||
)
|
||||
# TODO: handle pagination
|
||||
# TODO: implement pagination in the future
|
||||
next_token = None
|
||||
return json.dumps(dict(things=things, nextToken=next_token))
|
||||
|
||||
|
|
@ -256,3 +254,123 @@ class IoTResponse(BaseResponse):
|
|||
thing_name=thing_name,
|
||||
)
|
||||
return json.dumps(dict(principals=principals))
|
||||
|
||||
def describe_thing_group(self):
|
||||
thing_group_name = self._get_param("thingGroupName")
|
||||
thing_group = self.iot_backend.describe_thing_group(
|
||||
thing_group_name=thing_group_name,
|
||||
)
|
||||
return json.dumps(thing_group.to_dict())
|
||||
|
||||
def create_thing_group(self):
|
||||
thing_group_name = self._get_param("thingGroupName")
|
||||
parent_group_name = self._get_param("parentGroupName")
|
||||
thing_group_properties = self._get_param("thingGroupProperties")
|
||||
thing_group_name, thing_group_arn, thing_group_id = self.iot_backend.create_thing_group(
|
||||
thing_group_name=thing_group_name,
|
||||
parent_group_name=parent_group_name,
|
||||
thing_group_properties=thing_group_properties,
|
||||
)
|
||||
return json.dumps(dict(
|
||||
thingGroupName=thing_group_name,
|
||||
thingGroupArn=thing_group_arn,
|
||||
thingGroupId=thing_group_id)
|
||||
)
|
||||
|
||||
def delete_thing_group(self):
|
||||
thing_group_name = self._get_param("thingGroupName")
|
||||
expected_version = self._get_param("expectedVersion")
|
||||
self.iot_backend.delete_thing_group(
|
||||
thing_group_name=thing_group_name,
|
||||
expected_version=expected_version,
|
||||
)
|
||||
return json.dumps(dict())
|
||||
|
||||
def list_thing_groups(self):
|
||||
# next_token = self._get_param("nextToken")
|
||||
# max_results = self._get_int_param("maxResults")
|
||||
parent_group = self._get_param("parentGroup")
|
||||
name_prefix_filter = self._get_param("namePrefixFilter")
|
||||
recursive = self._get_param("recursive")
|
||||
thing_groups = self.iot_backend.list_thing_groups(
|
||||
parent_group=parent_group,
|
||||
name_prefix_filter=name_prefix_filter,
|
||||
recursive=recursive,
|
||||
)
|
||||
next_token = None
|
||||
rets = [{'groupName': _.thing_group_name, 'groupArn': _.arn} for _ in thing_groups]
|
||||
# TODO: implement pagination in the future
|
||||
return json.dumps(dict(thingGroups=rets, nextToken=next_token))
|
||||
|
||||
def update_thing_group(self):
|
||||
thing_group_name = self._get_param("thingGroupName")
|
||||
thing_group_properties = self._get_param("thingGroupProperties")
|
||||
expected_version = self._get_param("expectedVersion")
|
||||
version = self.iot_backend.update_thing_group(
|
||||
thing_group_name=thing_group_name,
|
||||
thing_group_properties=thing_group_properties,
|
||||
expected_version=expected_version,
|
||||
)
|
||||
return json.dumps(dict(version=version))
|
||||
|
||||
def add_thing_to_thing_group(self):
|
||||
thing_group_name = self._get_param("thingGroupName")
|
||||
thing_group_arn = self._get_param("thingGroupArn")
|
||||
thing_name = self._get_param("thingName")
|
||||
thing_arn = self._get_param("thingArn")
|
||||
self.iot_backend.add_thing_to_thing_group(
|
||||
thing_group_name=thing_group_name,
|
||||
thing_group_arn=thing_group_arn,
|
||||
thing_name=thing_name,
|
||||
thing_arn=thing_arn,
|
||||
)
|
||||
return json.dumps(dict())
|
||||
|
||||
def remove_thing_from_thing_group(self):
|
||||
thing_group_name = self._get_param("thingGroupName")
|
||||
thing_group_arn = self._get_param("thingGroupArn")
|
||||
thing_name = self._get_param("thingName")
|
||||
thing_arn = self._get_param("thingArn")
|
||||
self.iot_backend.remove_thing_from_thing_group(
|
||||
thing_group_name=thing_group_name,
|
||||
thing_group_arn=thing_group_arn,
|
||||
thing_name=thing_name,
|
||||
thing_arn=thing_arn,
|
||||
)
|
||||
return json.dumps(dict())
|
||||
|
||||
def list_things_in_thing_group(self):
|
||||
thing_group_name = self._get_param("thingGroupName")
|
||||
recursive = self._get_param("recursive")
|
||||
# next_token = self._get_param("nextToken")
|
||||
# max_results = self._get_int_param("maxResults")
|
||||
things = self.iot_backend.list_things_in_thing_group(
|
||||
thing_group_name=thing_group_name,
|
||||
recursive=recursive,
|
||||
)
|
||||
next_token = None
|
||||
thing_names = [_.thing_name for _ in things]
|
||||
# TODO: implement pagination in the future
|
||||
return json.dumps(dict(things=thing_names, nextToken=next_token))
|
||||
|
||||
def list_thing_groups_for_thing(self):
|
||||
thing_name = self._get_param("thingName")
|
||||
# next_token = self._get_param("nextToken")
|
||||
# max_results = self._get_int_param("maxResults")
|
||||
thing_groups = self.iot_backend.list_thing_groups_for_thing(
|
||||
thing_name=thing_name
|
||||
)
|
||||
next_token = None
|
||||
# TODO: implement pagination in the future
|
||||
return json.dumps(dict(thingGroups=thing_groups, nextToken=next_token))
|
||||
|
||||
def update_thing_groups_for_thing(self):
|
||||
thing_name = self._get_param("thingName")
|
||||
thing_groups_to_add = self._get_param("thingGroupsToAdd") or []
|
||||
thing_groups_to_remove = self._get_param("thingGroupsToRemove") or []
|
||||
self.iot_backend.update_thing_groups_for_thing(
|
||||
thing_name=thing_name,
|
||||
thing_groups_to_add=thing_groups_to_add,
|
||||
thing_groups_to_remove=thing_groups_to_remove,
|
||||
)
|
||||
return json.dumps(dict())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue