-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
26 changed files
with
150 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { getStage } from "./getStage"; | ||
|
||
export const buildResourceName = (resourceName: string): string => | ||
`${getStage()}-${resourceName}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const defaultStage = "dev"; | ||
export const defaultRegion = "eu-west-2"; | ||
export const projectName = "crgpt"; |
2 changes: 1 addition & 1 deletion
2
services/core/helpers/environment.ts → ...s/core/helpers/env-helpers/environment.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
export type GetArgProps = { | ||
cliArg: string; | ||
processEnvName: string; | ||
defaultValue?: string; | ||
}; | ||
|
||
export const getArg = ({ | ||
cliArg, | ||
processEnvName, | ||
defaultValue, | ||
}: GetArgProps): string => { | ||
const isNonEmptyString = (arg: unknown): arg is string => | ||
typeof arg === "string" && arg !== ""; | ||
|
||
const getCdkContext = (): Record<string, unknown> | undefined => { | ||
const cdkContextEnv = process.env.CDK_CONTEXT_JSON; | ||
|
||
return cdkContextEnv != null | ||
? (JSON.parse(cdkContextEnv) as Record<string, unknown>) | ||
: undefined; | ||
}; | ||
|
||
const findCliArg = (key: string): string | undefined => { | ||
const index = process.argv.findIndex((arg) => arg === `--${key}`); | ||
|
||
return index !== -1 && index + 1 < process.argv.length | ||
? process.argv[index + 1] | ||
: undefined; | ||
}; | ||
|
||
const argSources = [ | ||
findCliArg(cliArg), | ||
getCdkContext()?.[cliArg] as string | undefined, | ||
process.env[processEnvName], | ||
defaultValue, | ||
]; | ||
|
||
for (const arg of argSources) { | ||
if (isNonEmptyString(arg)) { | ||
return arg; | ||
} | ||
} | ||
|
||
throw new Error( | ||
`--${cliArg} CLI argument or ${processEnvName} env var required.` | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { defaultRegion } from "./config"; | ||
import { getArg } from "./getArg"; | ||
|
||
export const getRegion = (): string => | ||
getArg({ | ||
cliArg: "region", | ||
processEnvName: "REGION", | ||
defaultValue: defaultRegion, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defaultStage } from "./config"; | ||
import { getArg } from "./getArg"; | ||
|
||
export const getStage = (): string => { | ||
return getArg({ | ||
cliArg: "stage", | ||
processEnvName: "STAGE", | ||
defaultValue: defaultStage, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export * from "./buildResourceName"; | ||
export * from "./config"; | ||
export * from "./environment"; | ||
export * from "./getArg"; | ||
export * from "./getRegion"; | ||
export * from "./getStage"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from "./certificates"; | ||
export * from "./domains"; | ||
export * from "./env-helpers"; | ||
export * from "./env-helpers/environment"; | ||
export * from "./format-response"; | ||
export * from "./environment"; | ||
export * from "./lambda"; |
Oops, something went wrong.