From 4dc34c57e0d0a62c45f4e656a0f68f343940154f Mon Sep 17 00:00:00 2001 From: Daniel Nalborczyk Date: Tue, 5 Jul 2022 18:00:42 -0400 Subject: [PATCH] refactor: use function statements, move into module scope --- src/events/authFunctionNameExtractor.js | 86 +++++++++++++------------ 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/src/events/authFunctionNameExtractor.js b/src/events/authFunctionNameExtractor.js index cb3035520..09d830356 100644 --- a/src/events/authFunctionNameExtractor.js +++ b/src/events/authFunctionNameExtractor.js @@ -1,54 +1,60 @@ import { log } from '@serverless/utils/log.js' -export default function authFunctionNameExtractor(endpoint) { - const buildFailureResult = (warningMessage) => { - log.warning(warningMessage) +function buildFailureResult(warningMessage) { + log.warning(warningMessage) + + return { + unsupportedAuth: true, + } +} - return { unsupportedAuth: true } +function buildSuccessResult(authorizerName) { + return { + authorizerName, + } +} + +function handleStringAuthorizer(authorizerString) { + if (authorizerString.toUpperCase() === 'AWS_IAM') { + return buildFailureResult( + 'Serverless Offline does not support the AWS_IAM authorization type', + ) } - const buildSuccessResult = (authorizerName) => ({ authorizerName }) + return buildSuccessResult(authorizerString) +} - const handleStringAuthorizer = (authorizerString) => { - if (authorizerString.toUpperCase() === 'AWS_IAM') { - return buildFailureResult( - 'Serverless Offline does not support the AWS_IAM authorization type', - ) - } +function handleObjectAuthorizer(authorizerObject) { + const { arn, authorizerId, name, type } = authorizerObject - return buildSuccessResult(authorizerString) + if (type && type.toUpperCase() === 'AWS_IAM') { + return buildFailureResult( + 'Serverless Offline does not support the AWS_IAM authorization type', + ) } - const handleObjectAuthorizer = (authorizerObject) => { - const { arn, authorizerId, name, type } = authorizerObject - - if (type && type.toUpperCase() === 'AWS_IAM') { - return buildFailureResult( - 'Serverless Offline does not support the AWS_IAM authorization type', - ) - } - - if (arn) { - return buildFailureResult( - `Serverless Offline does not support non local authorizers (arn): ${arn}`, - ) - } - - if (authorizerId) { - return buildFailureResult( - `Serverless Offline does not support non local authorizers (authorizerId): ${authorizerId}`, - ) - } - - if (!name) { - return buildFailureResult( - 'Serverless Offline supports local authorizers but authorizer name is missing', - ) - } - - return buildSuccessResult(name) + if (arn) { + return buildFailureResult( + `Serverless Offline does not support non local authorizers (arn): ${arn}`, + ) } + if (authorizerId) { + return buildFailureResult( + `Serverless Offline does not support non local authorizers (authorizerId): ${authorizerId}`, + ) + } + + if (!name) { + return buildFailureResult( + 'Serverless Offline supports local authorizers but authorizer name is missing', + ) + } + + return buildSuccessResult(name) +} + +export default function authFunctionNameExtractor(endpoint) { const { authorizer } = endpoint if (!authorizer) {