Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: randomly generated API key is not displayed if no API key is defined #1066

Merged
merged 1 commit into from Aug 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -323,6 +316,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