Skip to content

Commit

Permalink
move API_KEY_HEADER_NAME to konfig-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiechayes committed Sep 28, 2023
1 parent 811698c commit ad98f7a
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion generator/konfig-dash/api/src/functions/prCreate/prCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { App } from 'octokit'

import { findRepository } from 'konfig-lib'
import { CORS_HEADERS_ORIGIN } from 'src/lib/cors-headers'
import { validateApiKey, API_KEY_HEADER_NAME } from 'src/lib/api-keys'
import { validateApiKey } from 'src/lib/api-keys'
import { API_KEY_HEADER_NAME } from 'konfig-lib'
import {
PrCreateResponseBodyType,
PrCreateResponseBody,
Expand Down
3 changes: 2 additions & 1 deletion generator/konfig-dash/api/src/functions/prMerge/prMerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { logger } from 'src/lib/logger'
import { App } from 'octokit'

import { findRepository } from 'konfig-lib'
import { validateApiKey, API_KEY_HEADER_NAME } from 'src/lib/api-keys'
import { validateApiKey } from 'src/lib/api-keys'
import { API_KEY_HEADER_NAME } from 'konfig-lib'
import { CORS_HEADERS_ORIGIN } from 'src/lib/cors-headers'
import {
PrMergeResponseBodyType,
Expand Down
2 changes: 1 addition & 1 deletion generator/konfig-dash/api/src/lib/api-keys.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const API_KEY_HEADER_NAME = 'x-konfig-api-key'
import { API_KEY_HEADER_NAME } from 'konfig-lib'

const apiKeys: Record<string, string> = {
qXx6mYhoJgbj8brJe11NeBNsul375Nv3: 'humanloop',
Expand Down
3 changes: 2 additions & 1 deletion generator/konfig-dash/bash-scripts/guard-api-key-leak.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ for apiKey in "${apiKeys[@]}"; do
--exclude=../../../generator/konfig-dash/.redwood/prebuild/api/src/lib/api-keys.js \
--exclude=../../../generator/konfig-dash/api/dist/lib/api-keys.js.map \
--exclude=../../../generator/konfig-dash/api/dist/lib/api-keys.js \
--exclude=../../../generator/konfig-dash/api/src/lib/api-keys.ts)
--exclude=../../../generator/konfig-dash/api/src/lib/api-keys.ts
)
if [ -n "$files" ]; then
foundKey=true
echo "ERROR: Security risk detected. API key leaked in the following file(s):"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
PrCreateRequestBodyType,
PrCreateResponseBody,
} from 'konfig-openapi-spec'
import { API_KEY_HEADER_NAME } from 'konfig-lib'

export default class PrCreate extends Command {
static description = 'Creates a github pull request'
Expand Down Expand Up @@ -72,7 +73,7 @@ export default class PrCreate extends Command {

CliUx.ux.action.start(`Creating ${suffix}`)
const result = await axios.post(url, body, {
headers: { 'x-konfig-api-key': apiKey },
headers: { [API_KEY_HEADER_NAME]: apiKey },
})
CliUx.ux.action.stop()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
PrMergeRequestBodyType,
PrMergeResponseBody,
} from 'konfig-openapi-spec'
import { API_KEY_HEADER_NAME } from 'konfig-lib'

export default class PrMerge extends Command {
static description = 'Merges a github pull request'
Expand Down Expand Up @@ -62,7 +63,7 @@ export default class PrMerge extends Command {

CliUx.ux.action.start(`Merging ${suffix}`)
const result = await axios.post(url, body, {
headers: { 'x-konfig-api-key': apiKey },
headers: { [API_KEY_HEADER_NAME]: apiKey },
})
CliUx.ux.action.stop()

Expand Down
1 change: 1 addition & 0 deletions generator/konfig-dash/packages/konfig-lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ export * from './forEachReferenceUntyped'
export * from './recurseObject'
export * from './snaptrade-demo'
export * from './util/find-repository'
export * from './util/konfig-api-key-header'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const API_KEY_HEADER_NAME = 'x-konfig-api-key'

0 comments on commit ad98f7a

Please sign in to comment.