Skip to content

Commit

Permalink
Merge pull request #1066 from kdybicz/master
Browse files Browse the repository at this point in the history
Regression: randomly generated API key is not displayed if no API key is defined
  • Loading branch information
dherault committed Aug 26, 2020
2 parents 1f038a9 + 0d954d9 commit 3e7a932
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/ServerlessOffline.js
Expand Up @@ -265,26 +265,15 @@ export default class ServerlessOffline {
_getEvents() {
const { service } = this.#serverless

// for simple API Key authentication model
if (service.provider.apiKeys) {
serverlessLog(`Key with token: ${this.#options.apiKey}`)

if (this.#options.noAuth) {
serverlessLog(
'Authorizers are turned off. You do not need to use x-api-key header.',
)
} else {
serverlessLog('Remember to use x-api-key on the request headers')
}
}

const httpEvents = []
const lambdas = []
const scheduleEvents = []
const webSocketEvents = []

const functionKeys = service.getAllFunctions()

let hasPrivateHttpEvent = false

functionKeys.forEach((functionKey) => {
const functionDefinition = service.getFunction(functionKey)

Expand All @@ -310,6 +299,10 @@ export default class ServerlessOffline {
httpEvent.http = { ...httpApi, isHttpApi: true }
}

if (http && http.private) {
hasPrivateHttpEvent = true
}

httpEvents.push(httpEvent)
}

Expand All @@ -329,6 +322,19 @@ export default class ServerlessOffline {
})
})

// for simple API Key authentication model
if (hasPrivateHttpEvent) {
serverlessLog(`Key with token: ${this.#options.apiKey}`)

if (this.#options.noAuth) {
serverlessLog(
'Authorizers are turned off. You do not need to use x-api-key header.',
)
} else {
serverlessLog('Remember to use x-api-key on the request headers')
}
}

return {
httpEvents,
lambdas,
Expand Down

0 comments on commit 3e7a932

Please sign in to comment.