Update Protospack Name and Network Config

This commit is contained in:
Victor Radael
2022-08-02 11:47:13 -03:00
parent 00687dc84e
commit 4e6883a404
19 changed files with 180 additions and 72 deletions
@@ -32,6 +32,8 @@ export class NetworkConfigDto {
created_at: string;
@ApiProperty()
updated_at: string;
@ApiProperty()
network_type_id: string;
}
export class NetworkConfigNoSecrets extends OmitType(NetworkConfigDto, [
'secret_id',
@@ -58,10 +60,27 @@ export class FindNetworkConfigByidRes {
@ApiProperty()
network_config: NetworkConfigNoSecrets;
}
export class FindNetworkConfigByidDetails extends PickType(NetworkConfigDto, [
'id',
'name',
'description',
'type',
'network_type_id',
'customer_name',
]) {
@ApiProperty()
properties: NetworkConfigOpenVpnProperties | string;
}
export class FindNetworkConfigByidDetailsRes {
@ApiProperty()
network_config: FindNetworkConfigByidDetails;
}
export class CreateNetworkConfigReq extends PickType(NetworkConfigDto, [
'name',
'description',
'type',
'network_type_id',
]) {
@ApiProperty()
properties: NetworkConfigOpenVpnProperties;
@@ -4,7 +4,7 @@ import {
GrpcOptions,
Transport,
} from '@nestjs/microservices';
import { NetworkConfig } from 'protospack-v2';
import { NetworkConfig } from '@dadosfera/protospack-v2';
export class NetworkConfigClientConfiguration {
private config: GrpcOptions = {
@@ -15,6 +15,7 @@ export class NetworkConfigClientConfiguration {
NetworkConfig.ProtoPackages.ReadPackage,
NetworkConfig.ProtoPackages.WritePackage,
],
// credentials: undefined,
credentials:
process.env.ENV === 'local' ? undefined : credentials.createSsl(),
protoPath: [
@@ -3,10 +3,12 @@ import {
Controller,
Delete,
Get,
Headers,
Inject,
Param,
Patch,
Post,
Query,
} from '@nestjs/common';
import { NetworkConfigService } from './network-config.service';
import { DadosferaLogger } from 'dadosfera-logs';
@@ -33,12 +35,23 @@ export class NetworkConfigController {
}
@Get()
@ApiOkResponse({ type: FindAllNetworkConfigsRes })
async findAllNetworkConfigs(@User() user: RequestUser) {
async findAllNetworkConfigs(
@User() user: RequestUser,
@Headers('Dadosfera-Lang') language,
@Query() queries,
) {
this.logger.info('GET /network-config', {
user: user.user_id,
customer: user.customer_name,
});
return this.networkConfigService.findAllNetworkConfigs(user.customer_name);
const { user_id, customer_id, customer_name } = user;
const { search, size, page, ...filters } = queries;
return this.networkConfigService.findAllNetworkConfigs({
body: { search, size, page, filters },
info: { user_id, customer_id, customer_name, language },
});
}
@Get(':id')
@@ -54,6 +67,24 @@ export class NetworkConfigController {
return this.networkConfigService.findNetworkConfigById(id);
}
@Get(':id/details')
@ApiOkResponse({ type: FindAllNetworkConfigsRes })
async findNetworkConfigByIdDetails(
@User() user: RequestUser,
@Headers('Dadosfera-Lang') language,
@Param('id') id: string,
) {
this.logger.info('GET /network-config/:id', {
user: user.user_id,
customer: user.customer_name,
});
return this.networkConfigService.findNetworkConfigByIdDetails(id, {
customer_name: user.customer_name,
customer_id: user.customer_id,
language,
});
}
@Post()
@ApiOkResponse({ type: CreateNetworkConfigRes })
async createNetworkConfigs(
@@ -64,10 +95,10 @@ export class NetworkConfigController {
user: user.user_id,
customer: user.customer_name,
});
return this.networkConfigService.createNetworkConfig(
body,
user.customer_name,
);
return this.networkConfigService.createNetworkConfig(body, {
customer_name: user.customer_name,
customer_id: user.customer_id,
});
}
@Patch(':id')
@@ -97,6 +128,9 @@ export class NetworkConfigController {
user: user.user_id,
customer: user.customer_name,
});
return this.networkConfigService.deleteNetworkConfig(network_config_id);
return this.networkConfigService.deleteNetworkConfig(network_config_id, {
customer_name: user.customer_name,
customer_id: user.customer_id,
});
}
}
@@ -1,12 +1,14 @@
import { Metadata } from '@grpc/grpc-js';
import { Inject, Injectable } from '@nestjs/common';
import { ClientGrpc } from '@nestjs/microservices';
import { NetworkConfig } from 'protospack-v2';
import { NetworkConfig } from '@dadosfera/protospack-v2';
import { lastValueFrom } from 'rxjs';
import {
CreateNetworkConfigReq,
CreateNetworkConfigRes,
DeleteNetworkConfigRes,
FindAllNetworkConfigsRes,
FindNetworkConfigByidDetailsRes,
FindNetworkConfigByidRes,
UpdateNetworkConfigReq,
UpdateNetworkConfigRes,
@@ -28,13 +30,25 @@ export class NetworkConfigService {
NetworkConfig.ProtoServices.NetworkConfigWriteService,
);
}
async findAllNetworkConfigs(
customer_name: string,
): Promise<FindAllNetworkConfigsRes> {
async findAllNetworkConfigs({
body,
info,
}): Promise<FindAllNetworkConfigsRes> {
const { search, page, size, filters } = body;
const { language, customer_id, customer_name, user_id } = info;
const meta = new Metadata();
meta.add('language', language);
meta.add('customer_id', customer_id);
meta.add('customer_name', customer_name);
meta.add('user_id', user_id);
return lastValueFrom(
this.networkConfigReadClient.NetworkConfigFindByCustomer({
customer_name,
}),
this.networkConfigReadClient.NetworkConfigFindAll(
{ search, filters: JSON.stringify(filters), page, size },
meta,
),
);
}
@@ -47,19 +61,51 @@ export class NetworkConfigService {
return { network_config };
}
async findNetworkConfigByIdDetails(
id: string,
info?,
): Promise<FindNetworkConfigByidDetailsRes> {
const { customer_name, customer_id, language } = info;
const meta = new Metadata();
meta.add('customer_name', customer_name);
meta.add('customer_id', customer_id);
meta.add('language', language);
const { network_config } = await lastValueFrom(
this.networkConfigReadClient.NetworkConfigFindOneDetailsById(
{ id },
meta,
),
);
Object.assign(network_config, {
properties: JSON.parse(network_config.properties),
});
return { network_config };
}
async createNetworkConfig(
body: CreateNetworkConfigReq,
customer_name: string,
{ customer_name, customer_id },
): Promise<CreateNetworkConfigRes> {
const { description, name, properties, type } = body;
const { description, name, properties, type, network_type_id } = body;
const meta = new Metadata();
meta.add('customer_id', customer_id);
meta.add('customer_name', customer_name);
const { network_config } = await lastValueFrom(
this.networkConfigWriteClient.NetworkConfigCreate({
customer_name,
description,
name,
properties: JSON.stringify(properties),
type,
}),
this.networkConfigWriteClient.NetworkConfigCreate(
{
customer_name,
description,
name,
properties: JSON.stringify(properties),
type,
network_type_id,
},
meta,
),
);
return { network_config };
}
@@ -81,11 +127,16 @@ export class NetworkConfigService {
async deleteNetworkConfig(
network_config_id: string,
{ customer_name, customer_id },
): Promise<DeleteNetworkConfigRes> {
const meta = new Metadata();
meta.add('customer_id', customer_id);
meta.add('customer_name', customer_name);
return lastValueFrom(
this.networkConfigWriteClient.NetworkConfigDelete({
id: network_config_id,
}),
this.networkConfigWriteClient.NetworkConfigDelete(
{ id: network_config_id },
meta,
),
);
}
}