def sign_request_body()

in lambdas/scale_out_runner/app.py [0:0]


def sign_request_body(request: Request) -> str:
    global GH_WEBHOOK_TOKEN
    if GH_WEBHOOK_TOKEN is None:
        if 'GH_WEBHOOK_TOKEN' in os.environ:
            # Local dev support:
            GH_WEBHOOK_TOKEN = os.environ['GH_WEBHOOK_TOKEN'].encode('utf-8')
        else:
            encrypted = os.environb[b'GH_WEBHOOK_TOKEN_ENCRYPTED']

            kms = boto3.client('kms')
            response = kms.decrypt(CiphertextBlob=codecs.decode(encrypted, 'base64'))
            GH_WEBHOOK_TOKEN = response['Plaintext']
    body = cast(bytes, request.raw_body)
    return hmac.new(GH_WEBHOOK_TOKEN, body, digestmod='SHA256').hexdigest()  # type: ignore