in example/provisioning_app.py [0:0]
def main():
# Get api id
apig = boto3.client('apigateway')
paginator = apig.get_paginator('get_rest_apis')
is_match, token = parse_apig_paginator(paginator)
while not is_match and token:
is_match, token = parse_apig_paginator(paginator, token)
if not is_match and not token:
logging.error('Cannot find api %s', API_NAME)
return
api_id = token
# Get api resource
resource_id = None
resp = apig.get_resources(restApiId=api_id)
for item in resp['items']:
if item['path'] == '/certificate':
resource_id = item['id']
if not resource_id:
logging.error('Cannot find api resource')
return
logging.info('Trying to connect...')
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
addr = ('127.0.0.1', 65432)
s.connect(addr)
data = s.recv(1024)
device_public_key = base64.b64encode(data).decode('ascii')
resp = invoke_certificate_api(api_id, resource_id, device_public_key)
if not resp:
logger.error('Fail to request the provisioning API')
else:
logging.info('Send provisioning profile to device')
s.sendto(resp.encode('ascii'), addr)
logging.info('Finish')