Skip to content

Commit

Permalink
add s3Client and s3ClientAdapter to module and config
Browse files Browse the repository at this point in the history
  • Loading branch information
SteKrause committed Jun 19, 2023
1 parent c12a99f commit 60dc5ce
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 8 deletions.
12 changes: 10 additions & 2 deletions apps/server/src/modules/h5p-editor/h5p-editor-test.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import { LibraryStorage } from './libraryStorage/libraryStorage';
import { H5PAjaxEndpointService, H5PEditorService, H5PPlayerService } from './service';
import { TemporaryFileStorage } from './temporary-file-storage/temporary-file-storage';
import { H5PEditorUc } from './uc/h5p.uc';
import { S3ClientAdapter } from '../files-storage/client/s3-client.adapter';

const storages = [
{ provide: ContentStorage, useValue: new ContentStorage(path.join(os.tmpdir(), '/h5p_content')) },
ContentStorage,
{ provide: LibraryStorage, useValue: new LibraryStorage(path.join(os.tmpdir(), '/h5p_libraries')) },
{ provide: TemporaryFileStorage, useValue: new TemporaryFileStorage(path.join(os.tmpdir(), '/h5p_temporary')) },
];
Expand All @@ -37,7 +38,14 @@ const imports = [
RabbitMQWrapperTestModule,
];
const controllers = [H5PEditorController];
const providers = [H5PEditorUc, H5PPlayerService, H5PEditorService, H5PAjaxEndpointService, ...storages];
const providers = [
H5PEditorUc,
H5PPlayerService,
H5PEditorService,
H5PAjaxEndpointService,
S3ClientAdapter,
...storages,
];

@Module({
imports,
Expand Down
9 changes: 9 additions & 0 deletions apps/server/src/modules/h5p-editor/h5p-editor.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { Configuration } from '@hpi-schul-cloud/commons';
import { S3Config } from './interface/config';

const h5pEditorConfig = {
NEST_LOG_LEVEL: Configuration.get('NEST_LOG_LEVEL') as string,
INCOMING_REQUEST_TIMEOUT: Configuration.get('INCOMING_REQUEST_TIMEOUT_API') as number,
};

export const s3Config: S3Config = {
endpoint: Configuration.get('H5P_EDITOR__S3_ENDPOINT') as string,
region: Configuration.get('H5P_EDITOR__S3_REGION') as string,
bucket: Configuration.get('H5P_EDITOR__S3_BUCKET') as string,
accessKeyId: Configuration.get('H5P_EDITOR__S3_ACCESS_KEY') as string,
secretAccessKey: Configuration.get('H5P_EDITOR__S3_SECRET_KEY') as string,
};

export const config = () => h5pEditorConfig;
39 changes: 33 additions & 6 deletions apps/server/src/modules/h5p-editor/h5p-editor.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'node:path';

import { Dictionary, IPrimaryKey } from '@mikro-orm/core';
import { MikroOrmModule, MikroOrmModuleSyncOptions } from '@mikro-orm/nestjs';
import { Module, NotFoundException } from '@nestjs/common';
import { Module, NotFoundException, Scope } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { Account, Role, School, SchoolYear, System, User } from '@shared/domain';
import { RabbitMQWrapperModule } from '@shared/infra/rabbitmq';
Expand All @@ -12,14 +12,14 @@ import { CoreModule } from '@src/core';
import { Logger } from '@src/core/logger';
import { AuthenticationModule } from '@src/modules/authentication/authentication.module';
import { AuthorizationModule } from '@src/modules/authorization';

import { S3Client } from '@aws-sdk/client-s3';
import { H5PEditorController } from './controller/h5p-editor.controller';
import { config } from './h5p-editor.config';
import { config, s3Config } from './h5p-editor.config';
import { S3Config } from './interface/config';
import { H5PAjaxEndpointService } from './service';
import { H5PEditorService } from './service/h5p-editor.service';
import { H5PPlayerService } from './service/h5p-player.service';
import { H5PEditorUc } from './uc/h5p.uc';

import { ContentStorage } from './contentStorage/contentStorage';
import { LibraryStorage } from './libraryStorage/libraryStorage';
import { TemporaryFileStorage } from './temporary-file-storage/temporary-file-storage';
Expand All @@ -31,7 +31,7 @@ const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = {
};

const storages = [
{ provide: ContentStorage, useValue: new ContentStorage(path.join(os.tmpdir(), '/h5p_content')) },
ContentStorage,
{ provide: LibraryStorage, useValue: new LibraryStorage(path.join(os.tmpdir(), '/h5p_libraries')) },
{ provide: TemporaryFileStorage, useValue: new TemporaryFileStorage(path.join(os.tmpdir(), '/h5p_temporary')) },
];
Expand All @@ -57,7 +57,34 @@ const imports = [

const controllers = [H5PEditorController];

const providers = [Logger, H5PEditorUc, H5PEditorService, H5PPlayerService, H5PAjaxEndpointService, ...storages];
const providers = [
{
provide: 'S3_Client',
scope: Scope.REQUEST,
useFactory: (configProvider: S3Config) =>
new S3Client({
region: configProvider.region,
credentials: {
accessKeyId: configProvider.accessKeyId,
secretAccessKey: configProvider.secretAccessKey,
},
endpoint: configProvider.endpoint,
forcePathStyle: true,
tls: true,
}),
inject: ['S3_Config'],
},
{
provide: 'S3_Config',
useValue: s3Config,
},
Logger,
H5PEditorUc,
H5PEditorService,
H5PPlayerService,
H5PAjaxEndpointService,
...storages,
];

@Module({
imports,
Expand Down
7 changes: 7 additions & 0 deletions apps/server/src/modules/h5p-editor/interface/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface S3Config {
endpoint: string;
region: string;
bucket: string;
accessKeyId: string;
secretAccessKey: string;
}

0 comments on commit 60dc5ce

Please sign in to comment.