def get_certificate()

in api/runtime/app.py [0:0]


def get_certificate():
    """
    Returns a signed certificate issued by the AWS IoT CA that can be used to connect to the AWS IoT Core Device Gateway
    when provided with a registration code and CSR
    ---
    tags:
        - Certificate issuer API
    parameters:
        - name: csr
          in: body
          type: string
          required: true
        - name: regToken
          in: body
          type: string
          required: true
        - consumes:
          - application/json
    responses:
        200:
            description: Signed certificate and assigned tenant
            schema:
                properties:
                    certificate:
                        type: string
                        description: AWS IoT signed certificate
                    tenant:
                        type: string
                        description: tenant assigned to token when the token was generated during /token
        400:
            description: Missing or invalid parameter in request
        401:
            description: Invalid or expired registration token
    """

    request = app.current_request
    body = request.json_body
    app.log.debug(body)
    if body and 'regToken' in body.keys() and body['regToken']:
        if 'csr' in body.keys() and body['csr']:
            if 'serialNumber' in body.keys() and body['serialNumber']:
                csr = body['csr']
                dynamo_response, status_code = retrieve_metadata_for_token(body)
                if status_code == 200:
                    certificate_pem = register_thing(csr, dynamo_response, body['serialNumber'])
                    response_body = {
                        "certificate": certificate_pem,
                        "tenant": dynamo_response['tenant']
                    }
                else:
                    response_body = dynamo_response
            else:
                response_body = 'Missing serial number'
                status_code = 400
        else:
            response_body = 'Missing or invalid csr'
            status_code = 400
    else:
        response_body = 'Missing or invalid registration token'
        status_code = 400
    return Response(body=response_body, status_code=status_code, headers={'Content-Type': 'application/json'})