-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from mondaycom/maorba/feature/align_api_with_si…
…decar Maorba/feature/align api with sidecar
- Loading branch information
Showing
27 changed files
with
343 additions
and
159 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
3 changes: 3 additions & 0 deletions
3
src/domain/environment-variables/environment-variables.consts.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { VOLUME_PATH } from 'shared/config'; | ||
|
||
export const ENVIRONMENT_VARIABLES_FILE = `${VOLUME_PATH}/env.json`; |
36 changes: 36 additions & 0 deletions
36
src/domain/environment-variables/environment-variables.controller.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { OperationId, Res, SuccessResponse } from '@tsoa/runtime'; | ||
import { ReasonPhrases, StatusCodes } from 'http-status-codes'; | ||
import { Get, Path, Route, Tags } from 'tsoa'; | ||
|
||
import { EnvironmentVariablesService } from './environment-variables.service'; | ||
|
||
import type { TsoaResponse } from '@tsoa/runtime'; | ||
import type { JsonValue } from 'types/general.type'; | ||
|
||
@Route('environment-variables') | ||
@Tags('EnvironmentVariables') | ||
export class EnvironmentVariablesController { | ||
@Get('{name}') | ||
@OperationId('getEnvironmentVariable') | ||
@SuccessResponse(StatusCodes.OK, ReasonPhrases.OK) | ||
public async getEnvironmentVariableForKey( | ||
@Path() name: string, | ||
@Res() notFoundResponse: TsoaResponse<StatusCodes.NOT_FOUND, { reason: string }> | ||
): Promise<JsonValue> { | ||
const value = EnvironmentVariablesService.getEnvironmentVariableForKey(name); | ||
if (value === undefined) { | ||
return notFoundResponse(StatusCodes.NOT_FOUND, { reason: 'Environment variable not found' }); | ||
} | ||
|
||
return value; | ||
} | ||
|
||
@Get() | ||
@OperationId('getEnvironmentVariableKeys') | ||
public async getKeys(): Promise<string[]> { | ||
const keys = EnvironmentVariablesService.getEnvironmentVariableKeys(); | ||
return keys; | ||
} | ||
} | ||
|
||
// FIXME: in the sidecar, re-check env-vars and secrets are working after my fix to the "falsy" check |
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
36 changes: 36 additions & 0 deletions
36
src/domain/environment-variables/environment-variables.service.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { ENVIRONMENT_VARIABLES_FILE } from 'domain/environment-variables/environment-variables.consts'; | ||
import { initFileIfNotExists, readJsonFile, writeJsonFile } from 'utils/files'; | ||
|
||
import type { JsonValue } from 'types/general.type'; | ||
|
||
export class EnvironmentVariablesService { | ||
private static isInitialized = false; | ||
|
||
private static initialize() { | ||
if (this.isInitialized) { | ||
return; | ||
} | ||
|
||
initFileIfNotExists(ENVIRONMENT_VARIABLES_FILE); | ||
this.isInitialized = true; | ||
} | ||
|
||
static getEnvironmentVariableForKey(key: string) { | ||
this.initialize(); | ||
const environmentFile = readJsonFile(ENVIRONMENT_VARIABLES_FILE); | ||
return environmentFile[key]; | ||
} | ||
|
||
static setEnvironmentVariableForKey(key: string, value: JsonValue) { | ||
this.initialize(); | ||
const environmentFile = readJsonFile(ENVIRONMENT_VARIABLES_FILE); | ||
environmentFile[key] = value; | ||
writeJsonFile(ENVIRONMENT_VARIABLES_FILE, environmentFile); | ||
} | ||
|
||
static getEnvironmentVariableKeys(): Array<string> { | ||
this.initialize(); | ||
const environmentFile = readJsonFile(ENVIRONMENT_VARIABLES_FILE); | ||
return Object.keys(environmentFile); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/domain/environment/environment.types.ts → ...-variables/environment-variables.types.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import type { JsonValue } from 'types/general.type'; | ||
|
||
export type SetEnvironmentForKeyRequestBody = { | ||
export type SetEnvironmentVariableForKeyRequestBody = { | ||
value: JsonValue; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.