Skip to content

Commit

Permalink
Merge pull request #5 from mondaycom/maorba/feature/align_api_with_si…
Browse files Browse the repository at this point in the history
…decar

Maorba/feature/align api with sidecar
  • Loading branch information
maorb-dev authored May 8, 2024
2 parents a9c9c5c + 263c8f2 commit a073181
Show file tree
Hide file tree
Showing 27 changed files with 343 additions and 159 deletions.
112 changes: 97 additions & 15 deletions build/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ components:
nullable: true
SetStorageForKeyRequestBody:
properties:
shared:
type: boolean
previousVersion:
type: string
value:
type: string
required:
Expand Down Expand Up @@ -97,8 +93,6 @@ components:
description: Construct a type with a set of properties K of type T
WriteLogRequestBody:
properties:
params:
$ref: "#/components/schemas/Record_string.unknown_"
error:
anyOf:
- type: string
Expand All @@ -110,7 +104,7 @@ components:
required:
- method
type: object
SetEnvironmentForKeyRequestBody:
SetEnvironmentVariableForKeyRequestBody:
properties:
value:
$ref: "#/components/schemas/JsonValue"
Expand Down Expand Up @@ -210,7 +204,27 @@ paths:
content:
application/json:
schema:
$ref: "#/components/schemas/JsonValue"
anyOf:
- properties:
error: {}
success:
type: boolean
version:
type: string
required:
- success
- version
type: object
- properties:
version: {}
success:
type: boolean
error:
type: string
required:
- success
- error
type: object
tags:
- Storage
security: []
Expand All @@ -225,6 +239,16 @@ paths:
required: true
schema:
type: string
- in: query
name: shared
required: false
schema:
type: boolean
- in: query
name: previousVersion
required: false
schema:
type: string
requestBody:
required: true
content:
Expand All @@ -240,7 +264,32 @@ paths:
content:
application/json:
schema:
type: string
anyOf:
- properties:
newCounterValue: {}
message: {}
success:
type: boolean
error:
type: string
required:
- success
- error
type: object
- properties:
error: {}
success:
type: boolean
newCounterValue:
type: number
format: double
message:
type: string
required:
- success
- newCounterValue
- message
type: object
tags:
- Storage
security: []
Expand Down Expand Up @@ -313,7 +362,7 @@ paths:
content:
application/json:
schema:
type: string
type: boolean
tags:
- SecureStorage
security: []
Expand Down Expand Up @@ -359,6 +408,22 @@ paths:
required: true
schema:
type: string
/secrets:
get:
operationId: getSecretKeys
responses:
"200":
description: OK
content:
application/json:
schema:
items:
type: string
type: array
tags:
- Secret
security: []
parameters: []
/test/secrets/{name}:
put:
operationId: setSecretTestRoute
Expand Down Expand Up @@ -446,15 +511,16 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/WriteLogRequestBody"
/environments/{name}:
/environment-variables/{name}:
get:
operationId: getEnvironment
operationId: getEnvironmentVariable
responses:
"200":
description: OK
content:
application/json:
schema: {}
schema:
$ref: "#/components/schemas/JsonValue"
"404":
description: ""
content:
Expand All @@ -467,14 +533,30 @@ paths:
- reason
type: object
tags:
- Environment
- EnvironmentVariables
security: []
parameters:
- in: path
name: name
required: true
schema:
type: string
/environment-variables:
get:
operationId: getEnvironmentVariableKeys
responses:
"200":
description: Ok
content:
application/json:
schema:
items:
type: string
type: array
tags:
- EnvironmentVariables
security: []
parameters: []
/test/environments/{name}:
put:
operationId: setEnvironmentTestRoute
Expand All @@ -495,7 +577,7 @@ paths:
content:
application/json:
schema:
$ref: "#/components/schemas/SetEnvironmentForKeyRequestBody"
$ref: "#/components/schemas/SetEnvironmentVariableForKeyRequestBody"
servers:
- url: http://localhost:59999
description: monday-code Local dev server
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ import { OperationId, SuccessResponse } from '@tsoa/runtime';
import { ReasonPhrases, StatusCodes } from 'http-status-codes';
import { Body, Path, Put, Route, Tags } from 'tsoa';

import { EnvironmentService } from './environment.service';
import { EnvironmentVariablesService } from './environment-variables.service';

import type { SetEnvironmentForKeyRequestBody } from 'domain/environment/environment.types';
import type { SetEnvironmentVariableForKeyRequestBody } from 'domain/environment-variables/environment-variables.types';

@Route('test/environments')
@Tags('TestRoutes')
export class EnvironmentTestController {
export class EnvironmentVariablesTestController {
@Put('{name}')
@OperationId('setEnvironmentTestRoute')
@SuccessResponse(StatusCodes.NO_CONTENT, ReasonPhrases.NO_CONTENT)
public async setEnvironmentForKey(
@Path() name: string,
@Body() body: SetEnvironmentForKeyRequestBody
@Body() body: SetEnvironmentVariableForKeyRequestBody
): Promise<void> {
const { value } = body;
EnvironmentService.setEnvironmentForKey(name, value);
EnvironmentVariablesService.setEnvironmentVariableForKey(name, value);
}
}

// TODO: what is this? needed?
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`;
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { z } from 'zod';

import { jsonValueSchema } from 'shared/schemas/general.schema';

export const getEnvironmentForKeyRequestSchema = {
export const getEnvironmentVariableForKeyRequestSchema = {
params: z.object({
key: z.string()
})
};

export const setEnvironmentForKeyRequestSchema = {
export const setEnvironmentVariableForKeyRequestSchema = {
params: z.object({
key: z.string()
}),
Expand Down
36 changes: 36 additions & 0 deletions src/domain/environment-variables/environment-variables.service.ts
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);
}
}
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;
};
3 changes: 0 additions & 3 deletions src/domain/environment/environment.consts.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/domain/environment/environment.controller.ts

This file was deleted.

32 changes: 0 additions & 32 deletions src/domain/environment/environment.service.ts

This file was deleted.

Loading

0 comments on commit a073181

Please sign in to comment.