From 35afb4befd108653ceca59d497ad83d196fa6576 Mon Sep 17 00:00:00 2001 From: Cedric Evers <12080057+CeEv@users.noreply.github.com> Date: Mon, 18 Nov 2024 17:24:27 +0100 Subject: [PATCH] Fix idp-console.module configs with dependencies --- apps/server/src/apps/idp-console.app.ts | 2 +- .../infra/console/console-writer.config.ts | 2 + apps/server/src/infra/console/index.ts | 3 +- apps/server/src/infra/rabbitmq/index.ts | 9 +++- .../src/infra/rabbitmq/rabbitmq.config.ts | 4 ++ ...le.module.ts => idp-console.app.module.ts} | 7 ++-- .../modules/idp-console/idp-console.config.ts | 42 +++++++++++++++++++ apps/server/src/modules/idp-console/index.ts | 3 +- .../modules/idp-console/interface/index.ts | 1 - .../interface/synchronization.config.ts | 3 -- .../src/modules/server/server.config.ts | 5 +-- .../src/modules/synchronization/index.ts | 3 +- .../synchronization/synchronization.config.ts | 2 + 13 files changed, 70 insertions(+), 16 deletions(-) create mode 100644 apps/server/src/infra/console/console-writer.config.ts rename apps/server/src/modules/idp-console/{idp-console.module.ts => idp-console.app.module.ts} (83%) create mode 100644 apps/server/src/modules/idp-console/idp-console.config.ts delete mode 100644 apps/server/src/modules/idp-console/interface/synchronization.config.ts create mode 100644 apps/server/src/modules/synchronization/synchronization.config.ts diff --git a/apps/server/src/apps/idp-console.app.ts b/apps/server/src/apps/idp-console.app.ts index da523496526..e0f4d777b2f 100644 --- a/apps/server/src/apps/idp-console.app.ts +++ b/apps/server/src/apps/idp-console.app.ts @@ -1,5 +1,5 @@ /* istanbul ignore file */ -import { IdpConsoleModule } from '@modules/idp-console'; +import { IdpConsoleModule } from '@modules/idp-console/idp-console.app.module'; import { BootstrapConsole } from 'nestjs-console'; async function run() { diff --git a/apps/server/src/infra/console/console-writer.config.ts b/apps/server/src/infra/console/console-writer.config.ts new file mode 100644 index 00000000000..6c7a031b7f3 --- /dev/null +++ b/apps/server/src/infra/console/console-writer.config.ts @@ -0,0 +1,2 @@ +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface ConsoleWriterConfig {} diff --git a/apps/server/src/infra/console/index.ts b/apps/server/src/infra/console/index.ts index 4d8ddbe3234..064512d2782 100644 --- a/apps/server/src/infra/console/index.ts +++ b/apps/server/src/infra/console/index.ts @@ -1 +1,2 @@ -export * from './console-writer'; +export { ConsoleWriterModule, ConsoleWriterService } from './console-writer'; +export { ConsoleWriterConfig } from './console-writer.config'; diff --git a/apps/server/src/infra/rabbitmq/index.ts b/apps/server/src/infra/rabbitmq/index.ts index 53e075c9516..46581047feb 100644 --- a/apps/server/src/infra/rabbitmq/index.ts +++ b/apps/server/src/infra/rabbitmq/index.ts @@ -1,6 +1,13 @@ export * from './error.mapper'; export * from './exchange'; -export * from './rabbitmq.config'; +export { + RabbitMqConfig, + FilesPreviewExchange, + FilesStorageExchange, + MailSendExchange, + AntivirusExchange, + RabbitMqURI, +} from './rabbitmq.config'; export * from './rabbitmq.module'; export * from './rpc-message'; export * from './rpc-message-producer'; diff --git a/apps/server/src/infra/rabbitmq/rabbitmq.config.ts b/apps/server/src/infra/rabbitmq/rabbitmq.config.ts index f5eee733deb..e3491f8c976 100644 --- a/apps/server/src/infra/rabbitmq/rabbitmq.config.ts +++ b/apps/server/src/infra/rabbitmq/rabbitmq.config.ts @@ -1,7 +1,11 @@ import { Configuration } from '@hpi-schul-cloud/commons/lib'; +// should be move to config interface and added reading on places that use the module export const FilesPreviewExchange = Configuration.get('FILES_STORAGE__EXCHANGE') as string; export const FilesStorageExchange = Configuration.get('FILES_STORAGE__EXCHANGE') as string; export const MailSendExchange = Configuration.get('MAIL_SEND_EXCHANGE') as string; export const AntivirusExchange = Configuration.get('ANTIVIRUS_EXCHANGE') as string; export const RabbitMqURI = Configuration.get('RABBITMQ_URI') as string; + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface RabbitMqConfig {} diff --git a/apps/server/src/modules/idp-console/idp-console.module.ts b/apps/server/src/modules/idp-console/idp-console.app.module.ts similarity index 83% rename from apps/server/src/modules/idp-console/idp-console.module.ts rename to apps/server/src/modules/idp-console/idp-console.app.module.ts index 8bbd28c36c3..5d2fb761d3d 100644 --- a/apps/server/src/modules/idp-console/idp-console.module.ts +++ b/apps/server/src/modules/idp-console/idp-console.app.module.ts @@ -1,6 +1,6 @@ import { ConsoleWriterModule } from '@infra/console'; import { RabbitMQWrapperModule } from '@infra/rabbitmq'; -import { SchulconnexClientModule } from '@infra/schulconnex-client/schulconnex-client.module'; +import { SchulconnexClientModule } from '@infra/schulconnex-client/schulconnex-client.module'; // TODO: Fix me! import { MikroOrmModule } from '@mikro-orm/nestjs'; import { AccountModule } from '@modules/account'; import { SynchronizationEntity, SynchronizationModule } from '@modules/synchronization'; @@ -8,16 +8,17 @@ import { UserModule } from '@modules/user'; import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { ALL_ENTITIES } from '@shared/domain/entity'; -import { DB_PASSWORD, DB_URL, DB_USERNAME } from '@src/config'; +import { createConfigModuleOptions, DB_PASSWORD, DB_URL, DB_USERNAME } from '@src/config'; import { LoggerModule } from '@src/core/logger'; import { ConsoleModule } from 'nestjs-console'; import { defaultMikroOrmOptions } from '@shared/common'; import { IdpSyncConsole } from './idp-sync-console'; import { SynchronizationUc } from './uc'; +import { idpConsoleConfigConfig } from './idp-console.config'; @Module({ imports: [ - ConfigModule.forRoot({ isGlobal: true }), + ConfigModule.forRoot(createConfigModuleOptions(idpConsoleConfigConfig)), SchulconnexClientModule.registerAsync(), SynchronizationModule, MikroOrmModule.forRoot({ diff --git a/apps/server/src/modules/idp-console/idp-console.config.ts b/apps/server/src/modules/idp-console/idp-console.config.ts new file mode 100644 index 00000000000..490983b4bd1 --- /dev/null +++ b/apps/server/src/modules/idp-console/idp-console.config.ts @@ -0,0 +1,42 @@ +import { ConsoleWriterConfig } from '@infra/console'; +import { LoggerConfig } from '@src/core/logger'; +import { AccountConfig } from '@modules/account'; +import { UserConfig } from '@modules/user'; +import { SynchronizationConfig } from '@modules/synchronization'; +import { SchulconnexClientConfig } from '@infra/schulconnex-client'; +import { Configuration } from '@hpi-schul-cloud/commons'; +import { LanguageType } from '@shared/domain/interface'; +import { RabbitMqConfig } from '@src/infra/rabbitmq'; + +interface IdpConsoleConfig + extends ConsoleWriterConfig, + RabbitMqConfig, + LoggerConfig, + AccountConfig, + UserConfig, + SynchronizationConfig, + SchulconnexClientConfig { + SYNCHRONIZATION_CHUNK: number; +} + +const config: IdpConsoleConfig = { + SYNCHRONIZATION_CHUNK: Configuration.get('SYNCHRONIZATION_CHUNK') as number, + NEST_LOG_LEVEL: Configuration.get('NEST_LOG_LEVEL') as string, + EXIT_ON_ERROR: Configuration.get('EXIT_ON_ERROR') as boolean, + LOGIN_BLOCK_TIME: Configuration.get('LOGIN_BLOCK_TIME') as number, + TEACHER_STUDENT_VISIBILITY__IS_CONFIGURABLE: Configuration.get( + 'TEACHER_STUDENT_VISIBILITY__IS_CONFIGURABLE' + ) as boolean, + FEATURE_IDENTITY_MANAGEMENT_LOGIN_ENABLED: Configuration.get('FEATURE_IDENTITY_MANAGEMENT_LOGIN_ENABLED') as boolean, + FEATURE_IDENTITY_MANAGEMENT_STORE_ENABLED: Configuration.get('FEATURE_IDENTITY_MANAGEMENT_STORE_ENABLED') as boolean, + AVAILABLE_LANGUAGES: (Configuration.get('I18N__AVAILABLE_LANGUAGES') as string).split(',') as LanguageType[], + TEACHER_VISIBILITY_FOR_EXTERNAL_TEAM_INVITATION: '', + SCHULCONNEX_CLIENT__PERSONEN_INFO_TIMEOUT_IN_MS: Configuration.get( + 'SCHULCONNEX_CLIENT__PERSONEN_INFO_TIMEOUT_IN_MS' + ) as number, + SCHULCONNEX_CLIENT__POLICIES_INFO_TIMEOUT_IN_MS: Configuration.get( + 'SCHULCONNEX_CLIENT__POLICIES_INFO_TIMEOUT_IN_MS' + ) as number, +}; + +export const idpConsoleConfigConfig = () => config; diff --git a/apps/server/src/modules/idp-console/index.ts b/apps/server/src/modules/idp-console/index.ts index c59204f5141..92b57a17451 100644 --- a/apps/server/src/modules/idp-console/index.ts +++ b/apps/server/src/modules/idp-console/index.ts @@ -1,2 +1 @@ -export * from './idp-console.module'; -export * from './interface'; +export { UsersSyncOptions, SystemType } from './interface'; // TODO: Why exports are needed? diff --git a/apps/server/src/modules/idp-console/interface/index.ts b/apps/server/src/modules/idp-console/interface/index.ts index 57dc47a1902..4809788082c 100644 --- a/apps/server/src/modules/idp-console/interface/index.ts +++ b/apps/server/src/modules/idp-console/interface/index.ts @@ -1,3 +1,2 @@ export * from './system-type.enum'; export * from './users-sync-options.interface'; -export * from './synchronization.config'; diff --git a/apps/server/src/modules/idp-console/interface/synchronization.config.ts b/apps/server/src/modules/idp-console/interface/synchronization.config.ts deleted file mode 100644 index 9b0e05d6aa5..00000000000 --- a/apps/server/src/modules/idp-console/interface/synchronization.config.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface SynchronizationConfig { - SYNCHRONIZATION_CHUNK: number; -} diff --git a/apps/server/src/modules/server/server.config.ts b/apps/server/src/modules/server/server.config.ts index 81bc4e337a0..49e0e11da45 100644 --- a/apps/server/src/modules/server/server.config.ts +++ b/apps/server/src/modules/server/server.config.ts @@ -12,7 +12,6 @@ import type { AuthenticationConfig } from '@modules/authentication'; import type { BoardConfig, MediaBoardConfig } from '@modules/board'; import type { CollaborativeTextEditorConfig } from '@modules/collaborative-text-editor'; import type { FilesStorageClientConfig } from '@modules/files-storage-client'; -import { SynchronizationConfig } from '@modules/idp-console'; import type { LearnroomConfig } from '@modules/learnroom'; import type { LessonConfig } from '@modules/lesson'; import { OauthConfig } from '@modules/oauth'; @@ -65,7 +64,7 @@ export interface ServerConfig SharingConfig, UserImportConfig, SchulconnexClientConfig, - SynchronizationConfig, + // SynchronizationConfig, CollaborativeTextEditorConfig, ProvisioningConfig, RoomConfig, @@ -217,7 +216,7 @@ const config: ServerConfig = { FEATURE_IDENTITY_MANAGEMENT_LOGIN_ENABLED: Configuration.get('FEATURE_IDENTITY_MANAGEMENT_LOGIN_ENABLED') as boolean, FEATURE_TSP_SYNC_ENABLED: Configuration.get('FEATURE_TSP_SYNC_ENABLED') as boolean, STUDENT_TEAM_CREATION: Configuration.get('STUDENT_TEAM_CREATION') as string, - SYNCHRONIZATION_CHUNK: Configuration.get('SYNCHRONIZATION_CHUNK') as number, + // SYNCHRONIZATION_CHUNK: Configuration.get('SYNCHRONIZATION_CHUNK') as number, // parse [:],[:]... and discard description BLOCKLIST_OF_EMAIL_DOMAINS: (Configuration.get('BLOCKLIST_OF_EMAIL_DOMAINS') as string) .split(',') diff --git a/apps/server/src/modules/synchronization/index.ts b/apps/server/src/modules/synchronization/index.ts index 9d4e28e58ca..a0741925e02 100644 --- a/apps/server/src/modules/synchronization/index.ts +++ b/apps/server/src/modules/synchronization/index.ts @@ -1,3 +1,4 @@ export { SynchronizationModule } from './synchronization.module'; -export * from './domain'; +export * from './domain'; // TODO: Fix me! export { SynchronizationEntity, SynchronizationRepo } from './repo'; +export { SynchronizationConfig } from './synchronization.config'; diff --git a/apps/server/src/modules/synchronization/synchronization.config.ts b/apps/server/src/modules/synchronization/synchronization.config.ts new file mode 100644 index 00000000000..afb9120b6c3 --- /dev/null +++ b/apps/server/src/modules/synchronization/synchronization.config.ts @@ -0,0 +1,2 @@ +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface SynchronizationConfig {}