diff --git a/src/main.ts b/src/main.ts index 4ae9097..7f60009 100644 --- a/src/main.ts +++ b/src/main.ts @@ -33,7 +33,7 @@ async function bootstrap() { .addBearerAuth() .addServer( process.env.ENV === 'local' - ? 'http://127.0.0.1:3333' + ? 'http://localhost:3333' : 'https://maestro.dev.dadosfera.ai', ) .build(); diff --git a/src/modules/network-config/dto/network-config.ts b/src/modules/network-config/dto/network-config.ts index 72146e8..ab974d8 100644 --- a/src/modules/network-config/dto/network-config.ts +++ b/src/modules/network-config/dto/network-config.ts @@ -81,9 +81,18 @@ export class CreateNetworkConfigReq extends PickType(NetworkConfigDto, [ 'description', 'type', 'network_type_id', + 'plugin', ]) { - @ApiProperty() - properties: NetworkConfigOpenVpnProperties; + @ApiProperty({ + type: 'file', + properties: { + file: { + type: 'string', + format: 'binary', + }, + }, + }) + OVPN_FILE: any; } export class CreateNetworkConfigRes { @ApiProperty() diff --git a/src/modules/network-config/network-config.controller.ts b/src/modules/network-config/network-config.controller.ts index 7547ae3..3948f50 100644 --- a/src/modules/network-config/network-config.controller.ts +++ b/src/modules/network-config/network-config.controller.ts @@ -9,10 +9,12 @@ import { Patch, Post, Query, + UploadedFile, + UseInterceptors, } from '@nestjs/common'; import { NetworkConfigService } from './network-config.service'; import { DadosferaLogger } from '@dadosfera/dadosfera-logs'; -import { ApiOkResponse, ApiTags } from '@nestjs/swagger'; +import { ApiConsumes, ApiOkResponse, ApiTags } from '@nestjs/swagger'; import { RequestUser, User } from 'src/authentication/user.decorator'; import { CreateNetworkConfigReq, @@ -22,6 +24,7 @@ import { UpdateNetworkConfigReq, UpdateNetworkConfigRes, } from './dto/network-config'; +import { FileInterceptor } from '@nestjs/platform-express'; @ApiTags('Network Config') @Controller('network-config') @@ -87,15 +90,18 @@ export class NetworkConfigController { @Post() @ApiOkResponse({ type: CreateNetworkConfigRes }) + @ApiConsumes('multipart/form-data') + @UseInterceptors(FileInterceptor('OVPN_FILE')) async createNetworkConfigs( @User() user: RequestUser, @Body() body: CreateNetworkConfigReq, + @UploadedFile() file: Express.Multer.File, ) { this.logger.info('POST /network-config', { user: user.user_id, customer: user.customer_name, }); - return this.networkConfigService.createNetworkConfig(body, { + return this.networkConfigService.createNetworkConfig(body, file, { customer_name: user.customer_name, customer_id: user.customer_id, }); diff --git a/src/modules/network-config/network-config.service.ts b/src/modules/network-config/network-config.service.ts index f4cb42a..d54f943 100644 --- a/src/modules/network-config/network-config.service.ts +++ b/src/modules/network-config/network-config.service.ts @@ -88,9 +88,13 @@ export class NetworkConfigService { async createNetworkConfig( body: CreateNetworkConfigReq, + file: Express.Multer.File, { customer_name, customer_id }, ): Promise { - const { description, name, properties, type, network_type_id } = body; + const { description, name, type, network_type_id, plugin } = body; + + const OVPN_FILE_STRING = Buffer.from(file.buffer).toString(); + const meta = new Metadata(); meta.add('customer_id', customer_id); meta.add('customer_name', customer_name); @@ -100,7 +104,10 @@ export class NetworkConfigService { customer_name, description, name, - properties: JSON.stringify(properties), + properties: JSON.stringify({ + OVPN_FILE: OVPN_FILE_STRING, + plugin, + }), type, network_type_id, },