-
Notifications
You must be signed in to change notification settings - Fork 0
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-8092 - implement config validation #21
Changes from 6 commits
f7081a6
5fb4178
5f355b8
173fbd7
fa3f52a
d003566
7df8094
f400d33
aa65fc6
ea88874
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
REDIS=redis://172.18.0.5:6379 | ||
REDIS_PREFIX=y | ||
REDIS=redis://localhost:6379 | ||
API_HOST=http://localhost:3030 | ||
ADMIN_API__ALLOWED_API_KEYS=randomString | ||
|
||
S3_ENDPOINT=localhost | ||
S3_BUCKET=ydocs | ||
S3_PORT=9000 | ||
S3_SSL=false | ||
S3_ACCESS_KEY=miniouser | ||
S3_SECRET_KEY=miniouser | ||
|
||
WS_PORT="3345" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
REDIS=redis://localhost:6379 | ||
API_HOST=http://localhost:3030 | ||
ADMIN_API__ALLOWED_API_KEYS=randomString | ||
|
||
S3_ENDPOINT=localhost | ||
S3_PORT=9000 | ||
S3_SSL=false | ||
S3_ACCESS_KEY=miniouser | ||
S3_SECRET_KEY=miniouser |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Transform } from 'class-transformer'; | ||
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[]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { IsUrl } from 'class-validator'; | ||
|
||
export class AuthorizationConfig { | ||
@IsUrl({ require_tld: false }) | ||
public API_HOST!: string; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { DynamicModule, Module } from '@nestjs/common'; | ||
import { ConfigModule, ConfigModuleOptions } from '@nestjs/config'; | ||
import { Configuration } from './configuration.service.js'; | ||
|
||
const getEnvConfig = (): ConfigModuleOptions => { | ||
const envConfig = { | ||
envFilePath: '.env', | ||
ignoreEnvFile: false, | ||
}; | ||
|
||
if (process.env.NODE_ENV === 'test') { | ||
envConfig.envFilePath = '.env.test'; | ||
} | ||
|
||
if (process.env.NODE_ENV === 'production') { | ||
envConfig.ignoreEnvFile = true; | ||
} | ||
|
||
return envConfig; | ||
}; | ||
|
||
@Module({}) | ||
export class ConfigurationModule { | ||
public static register<T extends object>(Constructor: new () => T): DynamicModule { | ||
return { | ||
imports: [ConfigModule.forRoot({ cache: true, ...getEnvConfig() })], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hier könnte man das cache: true auch noch nach getEnvConfig verschieben und einfach das ganze object den root übergeben. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Das stimmt |
||
providers: [ | ||
Configuration, | ||
{ | ||
provide: Constructor, | ||
useFactory: (config: Configuration): T => config.getAllValidConfigsByType(Constructor), | ||
inject: [Configuration], | ||
}, | ||
], | ||
CeEv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
exports: [Configuration, Constructor], | ||
module: ConfigurationModule, | ||
}; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
configuration und config sind sich zu ähnlich um ausdrücken zu können was für was ist.