Skip to content

Commit

Permalink
refactor: use function statements, move into module scope
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Jul 5, 2022
1 parent bc8bc90 commit 4dc34c5
Showing 1 changed file with 46 additions and 40 deletions.
86 changes: 46 additions & 40 deletions src/events/authFunctionNameExtractor.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down

0 comments on commit 4dc34c5

Please sign in to comment.