Last active
September 12, 2017 08:15
-
-
Save rts-rob/7c6e2a518a52feb715112d0e3e856544 to your computer and use it in GitHub Desktop.
Promisified function for validating the user agent of an AWS Lambda invocation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function validateUserAgent(event, desiredUserAgent) { | |
return new Promise(function(resolve, reject) { | |
const foundUserAgent = event.requestContext.identity.userAgent.toLowerCase(); | |
if (foundUserAgent.startsWith(desiredUserAgent.toLowerCase())) { | |
resolve(querystring.parse(event.body)); | |
} else { | |
reject(buildError(401, "This endpoint cannot be accessed via the current User Agent.")); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment