diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..fa2d70f --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,24 @@ +image: docker:20.10.22 + +stages: + - build + +############### +# BUILD STAGE # +############### + +build: + stage: build + image: docker:20.10.22 + variables: + DOCKER_TLS_CERTDIR: "" + services: + - docker:dind + before_script: + - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY + script: + - docker build --pull -t "$CI_REGISTRY_IMAGE" . + - docker push "$CI_REGISTRY_IMAGE" + only: + - main + when: manual diff --git a/package.json b/package.json index e47abc6..1449078 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "mobicoop-v3-logger", + "name": "@mobicoop/logger", "version": "0.0.1", "description": "Mobicoop V3 Logger Service", "author": "sbriat", diff --git a/src/modules/logger.module.ts b/src/modules/logger.module.ts index 982172a..8a1e30c 100644 --- a/src/modules/logger.module.ts +++ b/src/modules/logger.module.ts @@ -4,6 +4,8 @@ import { ConfigModule, ConfigService } from '@nestjs/config'; import { UserController } from './logger/adapters/primaries/user.controller'; import { WinstonModule } from 'nest-winston'; import * as winston from 'winston'; +import { AuthController } from './logger/adapters/primaries/auth.controller'; +import { ConfigurationController } from './logger/adapters/primaries/configuration.controller'; @Module({ imports: [ @@ -26,7 +28,7 @@ import * as winston from 'winston'; transports: [], }), ], - controllers: [UserController], + controllers: [AuthController, UserController, ConfigurationController], providers: [], exports: [], }) diff --git a/src/modules/logger/adapters/primaries/configuration.controller.ts b/src/modules/logger/adapters/primaries/configuration.controller.ts new file mode 100644 index 0000000..d4eec2c --- /dev/null +++ b/src/modules/logger/adapters/primaries/configuration.controller.ts @@ -0,0 +1,109 @@ +import { RabbitSubscribe } from '@golevelup/nestjs-rabbitmq'; +import { Controller, Inject } from '@nestjs/common'; +import { WINSTON_MODULE_PROVIDER } from 'nest-winston'; +import { Logger } from 'winston'; +import { level } from './logger/level.enum'; +import loggerOptions from './logger/logger'; + +@Controller() +export class ConfigurationController { + constructor( + @Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger, + ) {} + + @RabbitSubscribe({ + exchange: 'logging', + routingKey: 'configuration.create.info', + queue: 'logging-configuration-create-info', + }) + public async configurationCreatedInfoHandler(message: string) { + this.logger.configure( + loggerOptions('configuration', level.info, 'info', 'create'), + ); + this.logger.info(JSON.parse(message)); + } + + @RabbitSubscribe({ + exchange: 'logging', + routingKey: 'configuration.create.warning', + queue: 'logging-configuration-create-warning', + }) + public async configurationCreatedWarningHandler(message: string) { + this.logger.configure( + loggerOptions('configuration', level.warning, 'warning', 'create'), + ); + this.logger.warning(JSON.parse(message)); + } + + @RabbitSubscribe({ + exchange: 'logging', + routingKey: 'configuration.create.crit', + queue: 'logging-configuration-create-crit', + }) + public async configurationCreatedCriticalHandler(message: string) { + this.logger.configure( + loggerOptions('configuration', level.crit, 'critical', 'create'), + ); + this.logger.crit(JSON.parse(message)); + } + + @RabbitSubscribe({ + exchange: 'logging', + routingKey: 'configuration.delete.info', + queue: 'logging-configuration-delete-info', + }) + public async configurationDeletedInfoHandler(message: string) { + this.logger.configure( + loggerOptions('configuration', level.info, 'info', 'delete'), + ); + this.logger.info(JSON.parse(message)); + } + + @RabbitSubscribe({ + exchange: 'logging', + routingKey: 'configuration.delete.crit', + queue: 'logging-configuration-delete-crit', + }) + public async configurationDeletedCriticalHandler(message: string) { + this.logger.configure( + loggerOptions('configuration', level.crit, 'critical', 'delete'), + ); + this.logger.crit(JSON.parse(message)); + } + + @RabbitSubscribe({ + exchange: 'logging', + routingKey: 'configuration.read.warning', + queue: 'logging-configuration-read-warning', + }) + public async configurationReadWarningHandler(message: string) { + this.logger.configure( + loggerOptions('configuration', level.warning, 'warning', 'read'), + ); + this.logger.warning(JSON.parse(message)); + } + + @RabbitSubscribe({ + exchange: 'logging', + routingKey: 'configuration.update.info', + queue: 'logging-configuration-update-info', + }) + public async configurationUpdatedInfoHandler(message: string) { + this.logger.configure( + loggerOptions('configuration', level.info, 'info', 'update'), + ); + this.logger.info(JSON.parse(message)); + } + + @RabbitSubscribe({ + exchange: 'logging', + routingKey: 'configuration.update.crit', + queue: 'logging-configuration-update-crit', + }) + public async configurationUpdatedCriticalHandler(message: string) { + this.logger.configure( + loggerOptions('configuration', level.crit, 'critical', 'update'), + ); + this.logger.crit(JSON.parse(message)); + } +}