Skip to content

Commit

Permalink
Merge branch 'main' into BC-5405-labels-k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSchuhmacher authored Nov 16, 2023
2 parents 65cd19f + 88e6c5f commit 18330d5
Show file tree
Hide file tree
Showing 838 changed files with 22,233 additions and 8,234 deletions.
29 changes: 21 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,24 @@ module.exports = {
overrides: [
{
files: ['apps/**/*.ts'],
env: {
node: true,
es6: true,
},
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint/eslint-plugin'],
parserOptions: {
project: 'apps/server/tsconfig.lint.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin', 'import'],
extends: [
'airbnb-typescript/base',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'prettier',
'plugin:promise/recommended',
'plugin:import/typescript',
],
parserOptions: {
project: 'apps/server/tsconfig.lint.json',
},
env: {
node: true,
es6: true,
},
rules: {
'import/no-unresolved': 'off', // better handled by ts resolver
'import/no-extraneous-dependencies': 'off', // better handles by ts resolver
Expand All @@ -98,6 +100,17 @@ module.exports = {
allowSingleExtends: true,
},
],
'@typescript-eslint/no-restricted-imports': [
'warn',
{
patterns: [
{
group: ['@infra/*/*', '@modules/*/*', '!*.module'],
message: 'Do not deep import from a module',
},
],
},
],
},
overrides: [
{
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ jobs:
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: 'trivy-results.sarif'

end-to-end-tests:
needs:
- build_and_push
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

permissions:
contents: read
Expand Down
2 changes: 1 addition & 1 deletion ansible/roles/schulcloud-server-h5p/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- name: H5pEditorService
- name: H5PEditorProvider
kubernetes.core.k8s:
kubeconfig: ~/.kube/config
namespace: "{{ NAMESPACE }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ data:
}'

# Add Bettermarks' tools configuration as an external tool
# (stored in the 'external_tools' collection) that uses OAuth.
mongosh $DATABASE__URL --eval 'db.external_tools.replaceOne(
# (stored in the 'external-tools' collection) that uses OAuth.
mongosh $DATABASE__URL --eval 'db.external-tools.replaceOne(
{
"name": "bettermarks",
"config_type": "oauth2"
Expand Down Expand Up @@ -486,9 +486,9 @@ data:
echo "POSTed nextcloud to hydra."

# Add Nextcloud' tools configuration as an external tool
# (stored in the 'external_tools' collection) that uses OAuth.
echo "Inserting nextcloud to external_tools..."
mongosh $DATABASE__URL --eval 'db.external_tools.update(
# (stored in the 'external-tools' collection) that uses OAuth.
echo "Inserting nextcloud to external-tools..."
mongosh $DATABASE__URL --eval 'db.external-tools.update(
{
"name": "nextcloud",
"config_type": "oauth2"
Expand All @@ -512,7 +512,7 @@ data:
"upsert": true
}
);'
echo "Inserted nextcloud to external_tools."
echo "Inserted nextcloud to external-tools."

echo "Nextcloud config data init performed successfully."
fi
Expand Down
2 changes: 1 addition & 1 deletion apps/server/doc/summary.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
},
{
"title": "S3ClientModule",
"file": "../src/shared/infra/s3-client/README.md"
"file": "../src/infra/s3-client/README.md"
}
]
}
Expand Down
31 changes: 31 additions & 0 deletions apps/server/src/apps/deletion-console.app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* istanbul ignore file */
import { BootstrapConsole } from 'nestjs-console';
import { DeletionConsoleModule } from '@modules/deletion';

async function run() {
const bootstrap = new BootstrapConsole({
module: DeletionConsoleModule,
useDecorators: true,
});

const app = await bootstrap.init();

try {
await app.init();

// Execute console application with provided arguments.
await bootstrap.boot();
} catch (err) {
// eslint-disable-next-line no-console, @typescript-eslint/no-unsafe-call
console.error(err);

// Set the exit code to 1 to indicate a console app failure.
process.exitCode = 1;
}

// Always close the app, even if some exception
// has been thrown from the console app.
await app.close();
}

void run();
1 change: 1 addition & 0 deletions apps/server/src/apps/h5p-editor.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ async function bootstrap() {
const nestExpress = express();

const nestExpressAdapter = new ExpressAdapter(nestExpress);

const nestApp = await NestFactory.create(H5PEditorModule, nestExpressAdapter);
// WinstonLogger
nestApp.useLogger(await nestApp.resolve(LegacyLogger));
Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/apps/helpers/prometheus-metrics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
PrometheusMetricsConfig,
createAPIResponseTimeMetricMiddleware,
createPrometheusMetricsApp,
} from '@shared/infra/metrics';
} from '@infra/metrics';
import { Logger } from '@src/core/logger';
import express, { Express, NextFunction, Request, RequestHandler, Response } from 'express';
import {
Expand All @@ -15,9 +15,9 @@ import {
createAndStartPrometheusMetricsAppIfEnabled,
} from './prometheus-metrics';

jest.mock('@shared/infra/metrics', () => {
jest.mock('@infra/metrics', () => {
const moduleMock: unknown = {
...jest.requireActual('@shared/infra/metrics'),
...jest.requireActual('@infra/metrics'),
createAPIResponseTimeMetricMiddleware: jest.fn(),
createPrometheusMetricsApp: jest.fn(),
};
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/apps/helpers/prometheus-metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
PrometheusMetricsConfig,
createAPIResponseTimeMetricMiddleware,
createPrometheusMetricsApp,
} from '@shared/infra/metrics';
} from '@infra/metrics';
import { LogMessage, Loggable, Logger } from '@src/core/logger';
import { AppStartLoggable } from './app-start-loggable';

Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/apps/server.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { MikroORM } from '@mikro-orm/core';
import { NestFactory } from '@nestjs/core';
import { ExpressAdapter } from '@nestjs/platform-express';
import { enableOpenApiDocs } from '@shared/controller/swagger';
import { Mail, MailService } from '@shared/infra/mail';
import { Mail, MailService } from '@infra/mail';
import { LegacyLogger, Logger } from '@src/core/logger';
import { AccountService } from '@modules/account/services/account.service';
import { AccountService } from '@modules/account';
import { TeamService } from '@modules/teams/service/team.service';

Check warning on line 11 in apps/server/src/apps/server.app.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'@modules/teams/service/team.service' import is restricted from being used by a pattern. Do not deep import from a module
import { AccountValidationService } from '@modules/account/services/account.validation.service';

Check warning on line 12 in apps/server/src/apps/server.app.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'@modules/account/services/account.validation.service' import is restricted from being used by a pattern. Do not deep import from a module
import { AccountUc } from '@modules/account/uc/account.uc';

Check warning on line 13 in apps/server/src/apps/server.app.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'@modules/account/uc/account.uc' import is restricted from being used by a pattern. Do not deep import from a module
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { INestApplicationContext } from '@nestjs/common';
import { ConsoleWriterService } from '@shared/infra/console';
import { ConsoleWriterService } from '@infra/console';
import { ServerConsoleModule } from '@src/console/console.module';
import { CommanderError } from 'commander';
import { BootstrapConsole, ConsoleService } from 'nestjs-console';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { INestApplicationContext } from '@nestjs/common';

import { BootstrapConsole, ConsoleService } from 'nestjs-console';
import { ServerConsoleModule } from '@src/console/console.module';
import { ConsoleWriterService } from '@shared/infra/console';
import { ConsoleWriterService } from '@infra/console';
import { execute, TestBootstrapConsole } from './test-bootstrap.console';

describe('ServerConsole (API)', () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/console/api-test/test-bootstrap.console.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createMock } from '@golevelup/ts-jest';
import { Test, TestingModule } from '@nestjs/testing';
import { ConsoleWriterService } from '@shared/infra/console';
import { ConsoleWriterService } from '@infra/console';
import { DatabaseManagementUc } from '@modules/management/uc/database-management.uc';

Check warning on line 4 in apps/server/src/console/api-test/test-bootstrap.console.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'@modules/management/uc/database-management.uc' import is restricted from being used by a pattern. Do not deep import from a module
import { AbstractBootstrapConsole, BootstrapConsole } from 'nestjs-console';

Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/console/console.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { MikroOrmModule } from '@mikro-orm/nestjs';
import { Module, NotFoundException } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { ALL_ENTITIES } from '@shared/domain';
import { ConsoleWriterModule } from '@shared/infra/console/console-writer/console-writer.module';
import { KeycloakModule } from '@shared/infra/identity-management/keycloak/keycloak.module';
import { ConsoleWriterModule } from '@infra/console/console-writer/console-writer.module';

Check warning on line 7 in apps/server/src/console/console.module.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'@infra/console/console-writer/console-writer.module' import is restricted from being used by a pattern. Do not deep import from a module
import { KeycloakModule } from '@infra/identity-management/keycloak/keycloak.module';

Check warning on line 8 in apps/server/src/console/console.module.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'@infra/identity-management/keycloak/keycloak.module' import is restricted from being used by a pattern. Do not deep import from a module
import { DB_PASSWORD, DB_URL, DB_USERNAME, createConfigModuleOptions } from '@src/config';
import { FilesModule } from '@modules/files';
import { FileEntity } from '@modules/files/entity';

Check warning on line 11 in apps/server/src/console/console.module.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'@modules/files/entity' import is restricted from being used by a pattern. Do not deep import from a module
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/console/server.console.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ConsoleWriterService } from '@shared/infra/console';
import { ConsoleWriterService } from '@infra/console';
import { ServerConsoleModule } from './console.module';
import { ServerConsole } from './server.console';

Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/console/server.console.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
import { Command, Console } from 'nestjs-console';
import { ConsoleWriterService } from '@shared/infra/console';
import { ConsoleWriterService } from '@infra/console';

@Console({ command: 'server', description: 'sample server console' })
export class ServerConsole {
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/core/error/filter/global-error.filter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ArgumentsHost, Catch, ExceptionFilter, HttpException, InternalServerErrorException } from '@nestjs/common';
import { ApiValidationError, BusinessError } from '@shared/common';
import { IError, RpcMessage } from '@shared/infra/rabbitmq/rpc-message';
import { IError, RpcMessage } from '@infra/rabbitmq/rpc-message';
import { ErrorLogger, Loggable } from '@src/core/logger';
import { LoggingUtils } from '@src/core/logger/logging.utils';
import { Response } from 'express';
Expand Down
32 changes: 32 additions & 0 deletions apps/server/src/core/error/loggable/axios-error.loggable.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { axiosErrorFactory } from '@shared/testing/factory';
import { AxiosError } from 'axios';
import { AxiosErrorLoggable } from './axios-error.loggable';

describe(AxiosErrorLoggable.name, () => {
describe('getLogMessage', () => {
const setup = () => {
const error = {
error: 'invalid_request',
};
const type = 'mockType';
const axiosError: AxiosError = axiosErrorFactory.withError(error).build();

const axiosErrorLoggable = new AxiosErrorLoggable(axiosError, type);

return { axiosErrorLoggable, error, axiosError };
};

it('should return error log message', () => {
const { axiosErrorLoggable, error, axiosError } = setup();

const result = axiosErrorLoggable.getLogMessage();

expect(result).toEqual({
type: 'mockType',
message: axiosError.message,
data: JSON.stringify(error),
stack: 'mockStack',
});
});
});
});
20 changes: 20 additions & 0 deletions apps/server/src/core/error/loggable/axios-error.loggable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { HttpException, HttpStatus } from '@nestjs/common';
import { ErrorLogMessage, Loggable, LogMessage, ValidationErrorLogMessage } from '@src/core/logger';
import { AxiosError } from 'axios';

export class AxiosErrorLoggable extends HttpException implements Loggable {
constructor(private readonly axiosError: AxiosError, protected readonly type: string) {
super(JSON.stringify(axiosError.response?.data), axiosError.status ?? HttpStatus.INTERNAL_SERVER_ERROR, {
cause: axiosError.cause,
});
}

getLogMessage(): LogMessage | ErrorLogMessage | ValidationErrorLogMessage {
return {
message: this.axiosError.message,
type: this.type,
data: JSON.stringify(this.axiosError.response?.data),
stack: this.axiosError.stack,
};
}
}
2 changes: 2 additions & 0 deletions apps/server/src/core/error/loggable/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './error.loggable';
export * from './axios-error.loggable';
2 changes: 1 addition & 1 deletion apps/server/src/core/logger/types/logging.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type ErrorLogMessage = {
error?: Error;
type: string; // TODO: use enum
stack?: string;
data?: { [key: string]: string | number | undefined };
data?: { [key: string]: string | number | boolean | undefined };
};

export type ValidationErrorLogMessage = {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './antivirus';
export * from './antivirus';
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Module } from '@nestjs/common';
import { HttpModule } from '@nestjs/axios';
import { CalendarService } from '@shared/infra/calendar/service/calendar.service';
import { CalendarMapper } from '@shared/infra/calendar/mapper/calendar.mapper';
import { CalendarService } from './service/calendar.service';
import { CalendarMapper } from './mapper/calendar.mapper';

@Module({
imports: [HttpModule],
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ICalendarEvent } from '@shared/infra/calendar/interface/calendar-event.interface';
import { ICalendarEvent } from '@infra/calendar/interface/calendar-event.interface';
import { Test, TestingModule } from '@nestjs/testing';
import { CalendarMapper } from '@shared/infra/calendar/mapper/calendar.mapper';
import { CalendarMapper } from './calendar.mapper';

describe('CalendarMapper', () => {
let module: TestingModule;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ICalendarEvent } from '@shared/infra/calendar/interface/calendar-event.interface';
import { ICalendarEvent } from '@infra/calendar/interface/calendar-event.interface';
import { Injectable } from '@nestjs/common';
import { CalendarEventDto } from '@shared/infra/calendar/dto/calendar-event.dto';
import { CalendarEventDto } from '../dto/calendar-event.dto';

@Injectable()
export class CalendarMapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { Configuration } from '@hpi-schul-cloud/commons/lib';
import { HttpService } from '@nestjs/axios';
import { InternalServerErrorException } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { CalendarEventDto, CalendarService } from '@shared/infra/calendar';
import { ICalendarEvent } from '@shared/infra/calendar/interface/calendar-event.interface';
import { CalendarMapper } from '@shared/infra/calendar/mapper/calendar.mapper';
import { CalendarEventDto, CalendarService } from '@infra/calendar';
import { axiosResponseFactory } from '@shared/testing';
import { AxiosResponse } from 'axios';
import { of, throwError } from 'rxjs';
import { CalendarMapper } from '../mapper/calendar.mapper';
import { ICalendarEvent } from '../interface/calendar-event.interface';

describe('CalendarServiceSpec', () => {
let module: TestingModule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { Configuration } from '@hpi-schul-cloud/commons/lib';
import { HttpService } from '@nestjs/axios';
import { Injectable, InternalServerErrorException } from '@nestjs/common';
import { EntityId } from '@shared/domain';
import { CalendarEventDto } from '@shared/infra/calendar/dto/calendar-event.dto';
import { CalendarMapper } from '@shared/infra/calendar/mapper/calendar.mapper';
import { ErrorUtils } from '@src/core/error/utils';
import { AxiosRequestConfig, AxiosResponse } from 'axios';
import { Observable, firstValueFrom } from 'rxjs';
import { URL, URLSearchParams } from 'url';
import { CalendarMapper } from '../mapper/calendar.mapper';
import { CalendarEventDto } from '../dto/calendar-event.dto';
import { ICalendarEvent } from '../interface/calendar-event.interface';

@Injectable()
Expand Down
Loading

0 comments on commit 18330d5

Please sign in to comment.