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

BC-8404 - Move tldraw config to issolate it from server config #42

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions .env.default
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
REDIS=redis://localhost:6379
API_HOST=http://localhost:3030
ADMIN_API__ALLOWED_API_KEYS=randomString
AUTHORIZATION_API_HOST=http://localhost:3030

LOGGER_LOG_LEVEL=debug

REDIS_URL=redis://localhost:6379

S3_ACCESS_KEY=miniouser
S3_BUCKET=ydocs
S3_ENDPOINT=localhost
S3_PORT=9000
S3_SSL=false
S3_ACCESS_KEY=miniouser
S3_SECRET_KEY=miniouser
S3_SSL=false

WS_PORT=3345

TLDRAW__WEBSOCKET_URL=ws://localhost:3345
FEATURE_TLDRAW_ENABLED=true
SERVER_FEATURE_TLDRAW_ENABLED=true
SERVER_WEBSOCKET_URL=ws://localhost:3345

NEST_LOG_LEVEL=debug
EXIT_ON_ERROR=true
X_API_ALLOWED_KEYS=randomString
22 changes: 9 additions & 13 deletions .env.test
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
API_HOST=http://localhost:3030
ADMIN_API__ALLOWED_API_KEYS=randomString
AUTHORIZATION_API_HOST=http://localhost:3030

LOGGER_LOG_LEVEL=error

S3_ACCESS_KEY=miniouser
S3_BUCKET=ydocs
S3_ENDPOINT=localhost
S3_PORT=9000
S3_SSL=false
S3_ACCESS_KEY=miniouser
S3_SECRET_KEY=miniouser
S3_SSL=false

WS_PORT=3345

TLDRAW__WEBSOCKET_URL=ws://localhost:3345
TLDRAW__ASSETS_ENABLED=true
TLDRAW__ASSETS_MAX_SIZE_BYTES=10485760
TLDRAW__ASSETS_ALLOWED_MIME_TYPES_LIST="image/png,image/jpeg,image/gif,image/svg+xml"
FEATURE_TLDRAW_ENABLED=true
SERVER_FEATURE_TLDRAW_ENABLED=true
SERVER_WEBSOCKET_URL=ws://localhost:3345

NEST_LOG_LEVEL=debug
EXIT_ON_ERROR=true
X_API_ALLOWED_KEYS=randomString
5 changes: 5 additions & 0 deletions ansible/roles/tldraw-server/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
TLDRAW_ASSETS_ALLOWED_MIME_TYPES_LIST : "image/png,image/jpeg,image/gif,image/svg+xml"
TLDRAW_LOG_LEVEL: "error"
TLDRAW_METRICS_COLLECT_DEFAULT: "true"
TLDRAW_SERVER_ASSETS_ENABLED: "true"
TLDRAW_WEBSOCKET_PATH: "/tldraw-server"
19 changes: 8 additions & 11 deletions ansible/roles/tldraw-server/templates/configmap.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ metadata:
labels:
app: tldraw-server
data:
API_HOST: "http://api-svc:3030"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happend to the API_HOST?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to AUTHORIZATION_API_HOST

WS_PATH_PREFIX: "/tldraw-server"
WS_PORT: "3345"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happend to the WS_PORT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is default in code

FEATURE_PROMETHEUS_METRICS_ENABLED: "true"
AUTHORIZATION_API_HOST: "{{ API_HOST_URI }}"
LOGGER_LOG_LEVEL: "{{ TLDRAW_LOG_LEVEL }}"
METRICS_COLLECT_DEFAULT: "{{ TLDRAW_METRICS_COLLECT_DEFAULT }}"
REDIS_CLUSTER_ENABLED: "true"
REDIS_SENTINEL_SERVICE_NAME: "valkey-headless.{{ NAMESPACE }}.svc.cluster.local"
TLDRAW__WEBSOCKET_URL: "wss://{{ DOMAIN }}/tldraw-server"
TLDRAW__ASSETS_ENABLED: "true"
TLDRAW__ASSETS_MAX_SIZE_BYTES: "10485760"
TLDRAW__ASSETS_ALLOWED_MIME_TYPES_LIST: "image/png,image/jpeg,image/gif,image/svg+xml"
FEATURE_TLDRAW_ENABLED: "true"
NEST_LOG_LEVEL: "info"
EXIT_ON_ERROR: "true"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no more exit on error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is default true in code

SERVER_ASSETS_ALLOWED_MIME_TYPES_LIST: "{{ TLDRAW_ASSETS_ALLOWED_MIME_TYPES_LIST }}"
SERVER_ASSETS_ENABLED: "{{ TLDRAW_SERVER_ASSETS_ENABLED }}"
SERVER_FEATURE_TLDRAW_ENABLED: "{{ FEATURE_TLDRAW_ENABLED }}"
SERVER_WEBSOCKET_PATH: "{{ TLDRAW_WEBSOCKET_PATH }}"
SERVER_WEBSOCKET_URL: "wss://{{ DOMAIN }}{{ TLDRAW_WEBSOCKET_PATH }}"
2 changes: 1 addition & 1 deletion scripts/testing/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default async function globalSetup(): Promise<void> {

const host = await redisMemoryServer.getHost();
const port = await redisMemoryServer.getPort();
process.env.REDIS = `redis://${host}:${port}`;
process.env.REDIS_URL = `redis://${host}:${port}`;
// @ts-ignore
global.__REDISINSTANCE = redisMemoryServer;
}
4 changes: 2 additions & 2 deletions src/infra/auth-guard/strategy/x-api-key.strategy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('XApiKeyStrategy', () => {
describe('when a valid api key is provided', () => {
const setup = () => {
const CORRECT_API_KEY = '7ccd4e11-c6f6-48b0-81eb-cccf7922e7a4';
config.ADMIN_API__ALLOWED_API_KEYS = [CORRECT_API_KEY];
config.X_API_ALLOWED_KEYS = [CORRECT_API_KEY];

return { CORRECT_API_KEY, done };
};
Expand All @@ -52,7 +52,7 @@ describe('XApiKeyStrategy', () => {
describe('when a invalid api key is provided', () => {
const setup = () => {
const INVALID_API_KEY = '7ccd4e11-c6f6-48b0-81eb-cccf7922e7a4BAD';
config.ADMIN_API__ALLOWED_API_KEYS = [INVALID_API_KEY];
config.X_API_ALLOWED_KEYS = [INVALID_API_KEY];

return { INVALID_API_KEY, done };
};
Expand Down
2 changes: 1 addition & 1 deletion src/infra/auth-guard/strategy/x-api-key.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class XApiKeyStrategy extends PassportStrategy(Strategy, StrategyType.API

public constructor(private readonly config: XApiKeyConfig) {
super({ header: 'X-API-KEY' }, false);
this.allowedApiKeys = this.config.ADMIN_API__ALLOWED_API_KEYS;
this.allowedApiKeys = this.config.X_API_ALLOWED_KEYS;
}

public validate(apiKey: string, done: (error: Error | null, data: boolean | null) => void): void {
Expand Down
2 changes: 1 addition & 1 deletion src/infra/auth-guard/x-api-key.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import { IsArray } from 'class-validator';
export class XApiKeyConfig {
@Transform(({ value }) => value.split(',').map((part: string) => (part.split(':').pop() ?? '').trim()))
@IsArray()
public ADMIN_API__ALLOWED_API_KEYS!: string[];
public X_API_ALLOWED_KEYS!: string[];
}
2 changes: 1 addition & 1 deletion src/infra/authorization/authorization.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { IsUrl } from 'class-validator';

export class AuthorizationConfig {
@IsUrl({ require_tld: false })
public API_HOST!: string;
public AUTHORIZATION_API_HOST!: string;
}
2 changes: 1 addition & 1 deletion src/infra/authorization/authorization.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { AuthorizationService } from './authorization.service.js';
{
provide: AuthorizationApi,
useFactory: (config: AuthorizationConfig): AuthorizationApi => {
const apiHost = config.API_HOST;
const apiHost = config.AUTHORIZATION_API_HOST;
const configuration = new Configuration({ basePath: `${apiHost}/api/v3` });
const authorizationApi = new AuthorizationApi(configuration);

Expand Down
4 changes: 2 additions & 2 deletions src/infra/logger/logger.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export enum LoggerLogLevel {

export class LoggerConfig {
@IsEnum(LoggerLogLevel)
public NEST_LOG_LEVEL!: LoggerLogLevel;
public LOGGER_LOG_LEVEL!: LoggerLogLevel;

@IsBoolean()
@Transform(({ value }) => value === 'true')
public EXIT_ON_ERROR!: boolean;
public LOGGER_EXIT_ON_ERROR = true;
}
4 changes: 2 additions & 2 deletions src/infra/logger/logger.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { Logger } from './logger.js';
useFactory: (config: LoggerConfig) => {
return {
levels: winston.config.syslog.levels,
level: config.NEST_LOG_LEVEL,
exitOnError: config.EXIT_ON_ERROR,
level: config.LOGGER_LOG_LEVEL,
exitOnError: config.LOGGER_EXIT_ON_ERROR,
transports: [
new winston.transports.Console({
handleExceptions: true,
Expand Down
2 changes: 1 addition & 1 deletion src/infra/redis/redis.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class RedisConfig {

@IsUrl({ protocols: ['redis'], require_tld: false })
@ValidateIf((o: RedisConfig) => !o.REDIS_CLUSTER_ENABLED)
public REDIS!: string;
public REDIS_URL!: string;

@IsString()
@ValidateIf((o: RedisConfig) => o.REDIS_CLUSTER_ENABLED)
Expand Down
4 changes: 2 additions & 2 deletions src/infra/redis/redis.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Redis Service', () => {

const config = new RedisConfig();

config.REDIS = sentinelServiceName;
config.REDIS_URL = sentinelServiceName;
config.REDIS_CLUSTER_ENABLED = true;
config.REDIS_SENTINEL_SERVICE_NAME = sentinelServiceName;
config.REDIS_PREFIX = redisPrefix;
Expand Down Expand Up @@ -95,7 +95,7 @@ describe('Redis Service', () => {
const config = new RedisConfig();
const redisUrl = 'redis://localhost:6379';

config.REDIS = redisUrl;
config.REDIS_URL = redisUrl;

const resolveSrv = jest.fn();
jest.spyOn(util, 'promisify').mockReturnValueOnce(resolveSrv);
Expand Down
2 changes: 1 addition & 1 deletion src/infra/redis/redis.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class RedisService {
}

private createNewRedisInstance(): Redis {
const redisUrl = this.config.REDIS;
const redisUrl = this.config.REDIS_URL;
const redisInstance = new Redis(redisUrl);

return redisInstance;
Expand Down
2 changes: 1 addition & 1 deletion src/infra/storage/storage.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class StorageConfig {
public S3_ENDPOINT!: string;

@IsString()
public S3_BUCKET = 'ydocs';
public S3_BUCKET!: string;

@IsNumber()
@Type(() => Number)
Expand Down
2 changes: 1 addition & 1 deletion src/infra/testing/test-api-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe(TestApiClient.name, () => {
const setup = () => {
const id = '60f1b9b3b3b3b3b3b3b3b3b3';
const useAsApiKey = true;
const validApiKey: XApiKeyConfig['ADMIN_API__ALLOWED_API_KEYS'][0] = 'randomString';
const validApiKey: XApiKeyConfig['X_API_ALLOWED_KEYS'][0] = 'randomString';
const testApiClient = new TestApiClient(app, baseRoute, validApiKey, useAsApiKey);

return { testApiClient, id };
Expand Down
21 changes: 11 additions & 10 deletions src/modules/server/api/dto/tldraw-config.response.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import { ApiProperty } from '@nestjs/swagger';
import { ServerConfig } from '../../server.config.js';

export class TldrawPublicConfigResponse {
public constructor(config: TldrawPublicConfigResponse) {
this.TLDRAW__WEBSOCKET_URL = config.TLDRAW__WEBSOCKET_URL;
this.TLDRAW__ASSETS_ENABLED = config.TLDRAW__ASSETS_ENABLED;
this.TLDRAW__ASSETS_MAX_SIZE_BYTES = config.TLDRAW__ASSETS_MAX_SIZE_BYTES;
this.TLDRAW__ASSETS_ALLOWED_MIME_TYPES_LIST = config.TLDRAW__ASSETS_ALLOWED_MIME_TYPES_LIST;
this.FEATURE_TLDRAW_ENABLED = config.FEATURE_TLDRAW_ENABLED;
public constructor(config: ServerConfig) {
this.TLDRAW_WEBSOCKET_URL = config.SERVER_WEBSOCKET_URL;
this.TLDRAW_ASSETS_ENABLED = config.SERVER_ASSETS_ENABLED;
this.TLDRAW_ASSETS_MAX_SIZE_BYTES = config.SERVER_ASSETS_MAX_SIZE_BYTES;
this.TLDRAW_ASSETS_ALLOWED_MIME_TYPES_LIST = config.SERVER_ASSETS_ALLOWED_MIME_TYPES_LIST;
this.FEATURE_TLDRAW_ENABLED = config.SERVER_FEATURE_TLDRAW_ENABLED;
}

@ApiProperty()
public TLDRAW__WEBSOCKET_URL: string;
public TLDRAW_WEBSOCKET_URL: string;

@ApiProperty()
public TLDRAW__ASSETS_ENABLED: boolean;
public TLDRAW_ASSETS_ENABLED: boolean;

@ApiProperty()
public TLDRAW__ASSETS_MAX_SIZE_BYTES: number;
public TLDRAW_ASSETS_MAX_SIZE_BYTES: number;

@ApiProperty()
public TLDRAW__ASSETS_ALLOWED_MIME_TYPES_LIST: string[];
public TLDRAW_ASSETS_ALLOWED_MIME_TYPES_LIST: string[];

@ApiProperty()
public FEATURE_TLDRAW_ENABLED!: boolean;
Expand Down
8 changes: 4 additions & 4 deletions src/modules/server/api/test/tldraw-config.api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ describe('Tldraw-Config Api Test', () => {

expect(response.body).toEqual({
FEATURE_TLDRAW_ENABLED: true,
TLDRAW__ASSETS_ALLOWED_MIME_TYPES_LIST: ['image/png', 'image/jpeg', 'image/gif', 'image/svg+xml'],
TLDRAW__ASSETS_ENABLED: true,
TLDRAW__ASSETS_MAX_SIZE_BYTES: 10485760,
TLDRAW__WEBSOCKET_URL: 'ws://localhost:3345',
TLDRAW_ASSETS_ALLOWED_MIME_TYPES_LIST: ['image/png', 'image/jpeg', 'image/gif', 'image/svg+xml'],
TLDRAW_ASSETS_ENABLED: true,
TLDRAW_ASSETS_MAX_SIZE_BYTES: 10485760,
TLDRAW_WEBSOCKET_URL: 'ws://localhost:3345',
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/modules/server/api/websocket.gateway.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ describe(WebsocketGateway.name, () => {
{
provide: ServerConfig,
useValue: {
WS_PATH_PREFIX: 'tests',
WS_PORT: 3345,
SERVER_WEBSOCKET_PATH: 'tests',
SERVER_WEBSOCKET_PORT: 3345,
},
},
],
Expand Down
4 changes: 2 additions & 2 deletions src/modules/server/api/websocket.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export class WebsocketGateway implements OnModuleInit, OnModuleDestroy {
}

public async onModuleInit(): Promise<void> {
const wsPathPrefix = this.config.WS_PATH_PREFIX;
const wsPort = this.config.WS_PORT;
const wsPathPrefix = this.config.SERVER_WEBSOCKET_PATH;
const wsPort = this.config.SERVER_WEBSOCKET_PORT;

await registerYWebsocketServer(
this.webSocketServer,
Expand Down
14 changes: 7 additions & 7 deletions src/modules/server/server.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ import { IsArray, IsBoolean, IsNumber, IsString, IsUrl } from 'class-validator';

export class ServerConfig {
@IsString()
public WS_PATH_PREFIX = '';
public SERVER_WEBSOCKET_PATH = '';

@IsNumber()
@Transform(({ value }) => parseInt(value))
public WS_PORT = 3345;
public SERVER_WEBSOCKET_PORT = 3345;

@IsUrl({ protocols: ['wss', 'ws'], require_tld: false })
public TLDRAW__WEBSOCKET_URL!: string;
public SERVER_WEBSOCKET_URL!: string;

@Transform(({ value }) => value === 'true')
@IsBoolean()
public TLDRAW__ASSETS_ENABLED = true;
public SERVER_ASSETS_ENABLED = true;

@Transform(({ value }) => parseInt(value))
@IsNumber()
public TLDRAW__ASSETS_MAX_SIZE_BYTES = 10485760;
public SERVER_ASSETS_MAX_SIZE_BYTES = 10485760;

@Transform(({ value }) => value.split(','))
@IsArray()
public TLDRAW__ASSETS_ALLOWED_MIME_TYPES_LIST = ['image/png', 'image/jpeg', 'image/gif', 'image/svg+xml'];
public SERVER_ASSETS_ALLOWED_MIME_TYPES_LIST = ['image/png', 'image/jpeg', 'image/gif', 'image/svg+xml'];

@Transform(({ value }) => value === 'true')
@IsBoolean()
public FEATURE_TLDRAW_ENABLED!: boolean;
public SERVER_FEATURE_TLDRAW_ENABLED!: boolean;
}
2 changes: 1 addition & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
"exclude": ["node_modules", "test", "dist", "**/*spec.ts", "scripts"]
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"skipLibCheck": true,
}
},
"exclude": ["scripts"],
}
Loading