FIX: Connection and Network Flows (Create and Delete)

This commit is contained in:
Victor Radael
2022-08-17 15:58:00 -03:00
parent 6807b3e1a9
commit a9f68b87ca
6 changed files with 59 additions and 64 deletions
@@ -2,12 +2,7 @@ import {
NetworkConfigEntity,
NetworkConfigToCatalog,
} from '@dadosfera/protospack-v2/dist/lib/NetworkConfig/interfaces/entities';
import {
ApiProperty,
ApiPropertyOptional,
OmitType,
PickType,
} from '@nestjs/swagger';
import { ApiProperty, ApiPropertyOptional, PickType } from '@nestjs/swagger';
export enum NetworkConfigTypesEnum {
vpn = 'vpn',
@@ -19,37 +14,48 @@ export class NetworkConfigDto implements NetworkConfigEntity {
@ApiProperty()
id: string;
@ApiProperty()
name: string;
created_at: string;
@ApiProperty()
updated_at: string;
@ApiProperty()
customer_name: string;
@ApiProperty()
description: string;
customer_id: string;
@ApiProperty()
properties: any;
@ApiProperty()
user_id: string;
@ApiProperty()
keywords: string;
@ApiProperty()
tags: string;
@ApiProperty()
network_type_id: string;
@ApiProperty()
network_type_name: string;
@ApiProperty({ enum: NetworkConfigTypesEnum })
type: string;
@ApiProperty({ enum: NetworkConfigPluginsEnum })
plugin: string;
@ApiProperty()
properties: any;
name: string;
@ApiProperty()
created_at: string;
@ApiProperty()
updated_at: string;
@ApiProperty()
network_type_id: string;
@ApiProperty()
network_type_name: string;
@ApiProperty()
user_id: string;
@ApiProperty()
customer_id: string;
@ApiProperty()
keywords: string;
@ApiProperty()
tags: string;
description: string;
}
export class NetworkConfigNoSecrets extends OmitType(NetworkConfigDto, [
'properties',
]) {}
export class CreateNetworkConfigReq extends PickType(NetworkConfigDto, [
'network_type_id',
'network_type_name',
'name',
'description',
'type',
'plugin',
]) {
@ApiProperty({ format: 'binary' })
ovpn_file: string;
}
export class NetworkConfigOpenVpnProperties {
@ApiProperty({ enum: NetworkConfigPluginsEnum })
plugin: NetworkConfigPluginsEnum;
@@ -122,24 +128,7 @@ export class FindNetworkConfigByidDetailsRes {
@ApiProperty()
network_config: FindNetworkConfigByidDetails;
}
export class CreateNetworkConfigReq extends PickType(NetworkConfigDto, [
'name',
'description',
'type',
'network_type_id',
'plugin',
]) {
@ApiProperty({
type: 'file',
properties: {
file: {
type: 'string',
format: 'binary',
},
},
})
OVPN_FILE: any;
}
export class CreateNetworkConfigRes {
@ApiProperty()
network_config: NetworkConfigToCatalogDto;
@@ -91,19 +91,21 @@ export class NetworkConfigController {
@Post()
@ApiOkResponse({ type: CreateNetworkConfigRes })
@ApiConsumes('multipart/form-data')
@UseInterceptors(FileInterceptor('OVPN_FILE'))
@UseInterceptors(FileInterceptor('ovpn_file'))
async createNetworkConfigs(
@User() user: RequestUser,
@Body() body: CreateNetworkConfigReq,
@UploadedFile() file: Express.Multer.File,
@Body() body: CreateNetworkConfigReq,
) {
this.logger.info('POST /network-config', {
user: user.user_id,
customer: user.customer_name,
});
const { customer_id, customer_name, user_id } = user;
return this.networkConfigService.createNetworkConfig(body, file, {
customer_name: user.customer_name,
customer_id: user.customer_id,
customer_name,
customer_id,
user_id,
});
}
@@ -91,9 +91,9 @@ export class NetworkConfigService {
async createNetworkConfig(
body: CreateNetworkConfigReq,
file: Express.Multer.File,
{ customer_name, customer_id },
{ customer_name, customer_id, user_id },
): Promise<CreateNetworkConfigRes> {
const { description, name, network_type_id } = body;
const { description, name, network_type_id, network_type_name } = body;
let { type, plugin } = body;
type = type || 'vpn';
@@ -102,12 +102,14 @@ export class NetworkConfigService {
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);
meta.add('user_id', user_id);
const { network_config } = await lastValueFrom(
this.networkConfigWriteClient.NetworkConfigCreate(
{
customer_name,
description,
name,
properties: JSON.stringify({
@@ -116,6 +118,8 @@ export class NetworkConfigService {
}),
type,
network_type_id,
network_type_name,
plugin,
},
meta,
),