INNER CODE UNIT · Python
getHash
openfaas/workshop · hmac-protected/hmac-protected/handler.py:14
def getHash(hash):
if "sha1=" in hash:
hash=hash[5:]
return hash
def handle(req):
# We receive the hashed message in form of a header
receivedHMAC = os.getenv("Http_Hmac")
# Read secret from inside the container
with open("/var/openfaas/secrets/payload-secret","r") as secretContent:
payloadKey = secretContent.read()
# Function to validate the HMAC
if validateHMAC(req, payloadKey, receivedHMAC):
return "Successfully validated: " + req
return "HMAC validation failed."