in source/tools/iot-devices-cmp.py [0:0]
def get_device_status(c_iot, thing_name):
logger.info('thing_name: {}'.format(thing_name))
try:
device_status = {thing_name: {'policy': '', 'cert_id': ''}}
response = c_iot.describe_thing(thingName=thing_name)
logger.debug('response: {}'.format(response))
logger.info('exists: thing_name: {}'.format(thing_name))
response = c_iot.list_thing_principals(thingName=thing_name)
for principal in response['principals']:
#print('PRINCIPAL: {}'.format(principal))
cert_id = principal.split('/')[-1]
device_status[thing_name]['cert_id'] = cert_id
response = c_iot.describe_certificate(certificateId=principal.split('/')[-1])
response = c_iot.list_principal_policies(principal=principal)
#print('POLICIES')
for policy in response['policies']:
response = c_iot.get_policy(policyName=policy['policyName'])
device_status[thing_name]['policy'] = policy['policyName']
return device_status
except c_iot.exceptions.ResourceNotFoundException:
logger.info('replication error: thing does not exist: thing_name: {}'.format(thing_name))
return {}
except Exception as e:
logger.error('{}'.format(e))
raise Exception(e)