mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-19 03:39:09 +00:00
Merge branch 'ft/connection-manager' of github.com:dadosfera/maestro into ft/connection-manager
This commit is contained in:
Generated
+7
-7
@@ -38,7 +38,7 @@
|
||||
"passport-hubspot-oauth2": "^1.0.3",
|
||||
"passport-mailchimp": "^1.1.0",
|
||||
"protospack": "2.5.2",
|
||||
"protospack-v2": "^3.9.0-beta.8",
|
||||
"protospack-v2": "^3.9.0-beta.11",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"rxjs": "^7.5.5",
|
||||
@@ -9018,9 +9018,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/protospack-v2": {
|
||||
"version": "3.9.0-beta.8",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/protospack-v2/-/protospack-v2-3.9.0-beta.8.tgz",
|
||||
"integrity": "sha512-C3h62JYRm8Xh5X6mPnKF7ZZA0Ds0qMdu/gFYBu+FEfME5segFgbuiivepkqoVQ3MUoN1gIyV0J5ezmV9kXPPTw==",
|
||||
"version": "3.9.0-beta.11",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/protospack-v2/-/protospack-v2-3.9.0-beta.11.tgz",
|
||||
"integrity": "sha512-l2tU5vIlwnr7zgqsX8szMJoOzE9CdBYRJEj48yZc1AK9xVcXZa7+/Ik4n/N/JTAjKsCmQspbxuBezSbKcCpsvA==",
|
||||
"dependencies": {
|
||||
"@grpc/grpc-js": "^1.6.7",
|
||||
"rxjs": "^7.5.5",
|
||||
@@ -17247,9 +17247,9 @@
|
||||
}
|
||||
},
|
||||
"protospack-v2": {
|
||||
"version": "3.9.0-beta.8",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/protospack-v2/-/protospack-v2-3.9.0-beta.8.tgz",
|
||||
"integrity": "sha512-C3h62JYRm8Xh5X6mPnKF7ZZA0Ds0qMdu/gFYBu+FEfME5segFgbuiivepkqoVQ3MUoN1gIyV0J5ezmV9kXPPTw==",
|
||||
"version": "3.9.0-beta.11",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/protospack-v2/-/protospack-v2-3.9.0-beta.11.tgz",
|
||||
"integrity": "sha512-l2tU5vIlwnr7zgqsX8szMJoOzE9CdBYRJEj48yZc1AK9xVcXZa7+/Ik4n/N/JTAjKsCmQspbxuBezSbKcCpsvA==",
|
||||
"requires": {
|
||||
"@grpc/grpc-js": "^1.6.7",
|
||||
"rxjs": "^7.5.5",
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@
|
||||
"passport-hubspot-oauth2": "^1.0.3",
|
||||
"passport-mailchimp": "^1.1.0",
|
||||
"protospack": "2.5.2",
|
||||
"protospack-v2": "^3.9.0-beta.8",
|
||||
"protospack-v2": "^3.9.0-beta.11",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"rxjs": "^7.5.5",
|
||||
|
||||
+3
-2
@@ -44,6 +44,7 @@ import { DadosferaLogger } from 'dadosfera-logs';
|
||||
import { TermsOfUseModule } from './modules/termsOfUse/termsOfUse.module';
|
||||
import { ConnectionModule } from './modules/connection/connection.module';
|
||||
import { ConnectionTestModule } from './modules/connection-test/connection-test.module';
|
||||
import { NetworkConfigModule } from './modules/network-config/network-config.module';
|
||||
|
||||
const inputClient = new InputsClientConfiguration();
|
||||
const outputClient = new OutputsClientConfiguration();
|
||||
@@ -93,6 +94,8 @@ const transformationClient = new TransformationsClientConfiguration();
|
||||
PermissionsModule,
|
||||
TermsOfUseModule,
|
||||
ConnectionModule,
|
||||
NetworkConfigModule,
|
||||
ConnectionTestModule,
|
||||
|
||||
ClientsModule.register([
|
||||
{
|
||||
@@ -112,8 +115,6 @@ const transformationClient = new TransformationsClientConfiguration();
|
||||
...pipelineClient.config(),
|
||||
},
|
||||
]),
|
||||
|
||||
ConnectionTestModule,
|
||||
],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import {
|
||||
ApiProperty,
|
||||
ApiPropertyOptional,
|
||||
OmitType,
|
||||
PickType,
|
||||
} from '@nestjs/swagger';
|
||||
|
||||
export enum NetworkConfigTypesEnum {
|
||||
vpn = 'vpn',
|
||||
}
|
||||
export enum NetworkConfigPluginsEnum {
|
||||
openvpn = 'openvpn',
|
||||
}
|
||||
export class NetworkConfigDto {
|
||||
@ApiProperty()
|
||||
id: string;
|
||||
@ApiProperty()
|
||||
secret_id: string;
|
||||
@ApiProperty()
|
||||
name: string;
|
||||
@ApiProperty()
|
||||
customer_name: string;
|
||||
@ApiProperty()
|
||||
description: string;
|
||||
@ApiProperty({ enum: NetworkConfigTypesEnum })
|
||||
type: string;
|
||||
@ApiProperty({ enum: NetworkConfigPluginsEnum })
|
||||
plugin: string;
|
||||
@ApiProperty()
|
||||
credentials: any;
|
||||
@ApiProperty()
|
||||
created_at: string;
|
||||
@ApiProperty()
|
||||
updated_at: string;
|
||||
}
|
||||
export class NetworkConfigNoSecrets extends OmitType(NetworkConfigDto, [
|
||||
'secret_id',
|
||||
'credentials',
|
||||
]) {}
|
||||
export class NetworkConfigOpenVpnProperties {
|
||||
@ApiProperty({ enum: NetworkConfigPluginsEnum })
|
||||
plugin: NetworkConfigPluginsEnum;
|
||||
@ApiProperty()
|
||||
OVPN_FILE: string;
|
||||
@ApiPropertyOptional()
|
||||
CERTIFICATE_FILE?: string;
|
||||
@ApiPropertyOptional()
|
||||
OVPN_CREDENTIALS?: string;
|
||||
@ApiPropertyOptional()
|
||||
TLS_AUTH_FILE?: string;
|
||||
}
|
||||
export class FindAllNetworkConfigsRes {
|
||||
@ApiProperty({ type: [NetworkConfigNoSecrets] })
|
||||
network_configs: NetworkConfigNoSecrets[];
|
||||
}
|
||||
|
||||
export class FindNetworkConfigByidRes {
|
||||
@ApiProperty()
|
||||
network_config: NetworkConfigNoSecrets;
|
||||
}
|
||||
export class CreateNetworkConfigReq extends PickType(NetworkConfigDto, [
|
||||
'name',
|
||||
'description',
|
||||
'type',
|
||||
]) {
|
||||
@ApiProperty()
|
||||
properties: NetworkConfigOpenVpnProperties;
|
||||
}
|
||||
export class CreateNetworkConfigRes {
|
||||
@ApiProperty()
|
||||
network_config: NetworkConfigNoSecrets;
|
||||
}
|
||||
|
||||
export class UpdateNetworkConfigReq {
|
||||
@ApiProperty()
|
||||
name: string;
|
||||
@ApiProperty()
|
||||
description: string;
|
||||
}
|
||||
export class UpdateNetworkConfigRes {
|
||||
@ApiProperty()
|
||||
network_config: NetworkConfigNoSecrets;
|
||||
}
|
||||
|
||||
export class DeleteNetworkConfigRes {
|
||||
@ApiProperty()
|
||||
message: string;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { credentials } from '@grpc/grpc-js';
|
||||
import {
|
||||
ClientProviderOptions,
|
||||
GrpcOptions,
|
||||
Transport,
|
||||
} from '@nestjs/microservices';
|
||||
import { NetworkConfig } from 'protospack-v2';
|
||||
|
||||
export class NetworkConfigClientConfiguration {
|
||||
private config: GrpcOptions = {
|
||||
transport: Transport.GRPC,
|
||||
options: {
|
||||
url: process.env.INFACTORY_URL,
|
||||
package: [
|
||||
NetworkConfig.ProtoPackages.ReadPackage,
|
||||
NetworkConfig.ProtoPackages.WritePackage,
|
||||
],
|
||||
credentials:
|
||||
process.env.ENV === 'local' ? undefined : credentials.createSsl(),
|
||||
protoPath: [
|
||||
NetworkConfig.ProtoPaths.ReadFilePath,
|
||||
NetworkConfig.ProtoPaths.WriteFilePath,
|
||||
],
|
||||
loader: {
|
||||
keepCase: true,
|
||||
enums: String,
|
||||
objects: true,
|
||||
arrays: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
providerOptions: ClientProviderOptions = {
|
||||
name: 'NetworkConfigGrpcClient',
|
||||
...this.config,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { NetworkConfigController } from './network-config.controller';
|
||||
|
||||
describe('NetworkConfigController', () => {
|
||||
let controller: NetworkConfigController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [NetworkConfigController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<NetworkConfigController>(NetworkConfigController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,102 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Inject,
|
||||
Param,
|
||||
Patch,
|
||||
Post,
|
||||
} from '@nestjs/common';
|
||||
import { NetworkConfigService } from './network-config.service';
|
||||
import { DadosferaLogger } from 'dadosfera-logs';
|
||||
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
||||
import { RequestUser, User } from 'src/authentication/user.decorator';
|
||||
import {
|
||||
CreateNetworkConfigReq,
|
||||
CreateNetworkConfigRes,
|
||||
DeleteNetworkConfigRes,
|
||||
FindAllNetworkConfigsRes,
|
||||
UpdateNetworkConfigReq,
|
||||
UpdateNetworkConfigRes,
|
||||
} from './dto/network-config';
|
||||
|
||||
@ApiTags('Network Config')
|
||||
@Controller('network-config')
|
||||
export class NetworkConfigController {
|
||||
logger: any;
|
||||
constructor(
|
||||
private networkConfigService: NetworkConfigService,
|
||||
@Inject(DadosferaLogger) dadosferaLogger: DadosferaLogger,
|
||||
) {
|
||||
this.logger = dadosferaLogger.logger;
|
||||
}
|
||||
@Get()
|
||||
@ApiOkResponse({ type: FindAllNetworkConfigsRes })
|
||||
async findAllNetworkConfigs(@User() user: RequestUser) {
|
||||
this.logger.info('GET /network-config', {
|
||||
user: user.user_id,
|
||||
customer: user.customer_name,
|
||||
});
|
||||
return this.networkConfigService.findAllNetworkConfigs(user.customer_name);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOkResponse({ type: FindAllNetworkConfigsRes })
|
||||
async findNetworkConfigById(
|
||||
@User() user: RequestUser,
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
this.logger.info('GET /network-config/:id', {
|
||||
user: user.user_id,
|
||||
customer: user.customer_name,
|
||||
});
|
||||
return this.networkConfigService.findNetworkConfigById(id);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOkResponse({ type: CreateNetworkConfigRes })
|
||||
async createNetworkConfigs(
|
||||
@User() user: RequestUser,
|
||||
@Body() body: CreateNetworkConfigReq,
|
||||
) {
|
||||
this.logger.info('POST /network-config', {
|
||||
user: user.user_id,
|
||||
customer: user.customer_name,
|
||||
});
|
||||
return this.networkConfigService.createNetworkConfig(
|
||||
body,
|
||||
user.customer_name,
|
||||
);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
@ApiOkResponse({ type: UpdateNetworkConfigRes })
|
||||
async updateNetworkConfig(
|
||||
@User() user: RequestUser,
|
||||
@Param('id') network_config_id: string,
|
||||
@Body() body: UpdateNetworkConfigReq,
|
||||
) {
|
||||
this.logger.info('PATCH /network-config/:id', {
|
||||
user: user.user_id,
|
||||
customer: user.customer_name,
|
||||
});
|
||||
return this.networkConfigService.updateNetworkConfig(
|
||||
body,
|
||||
network_config_id,
|
||||
);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOkResponse({ type: DeleteNetworkConfigRes })
|
||||
async deleteNetworkConfig(
|
||||
@User() user: RequestUser,
|
||||
@Param('id') network_config_id: string,
|
||||
) {
|
||||
this.logger.info('DELETE /network-config', {
|
||||
user: user.user_id,
|
||||
customer: user.customer_name,
|
||||
});
|
||||
return this.networkConfigService.deleteNetworkConfig(network_config_id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { NetworkConfigController } from './network-config.controller';
|
||||
import { NetworkConfigService } from './network-config.service';
|
||||
import { DadosferaLogger } from 'dadosfera-logs';
|
||||
import { ClientsModule } from '@nestjs/microservices';
|
||||
import { NetworkConfigClientConfiguration } from './network-config-client.config';
|
||||
const client = new NetworkConfigClientConfiguration();
|
||||
|
||||
@Module({
|
||||
controllers: [NetworkConfigController],
|
||||
providers: [NetworkConfigService, DadosferaLogger],
|
||||
imports: [ClientsModule.register([client.providerOptions])],
|
||||
})
|
||||
export class NetworkConfigModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { NetworkConfigService } from './network-config.service';
|
||||
|
||||
describe('NetworkConfigService', () => {
|
||||
let service: NetworkConfigService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [NetworkConfigService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<NetworkConfigService>(NetworkConfigService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,91 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { ClientGrpc } from '@nestjs/microservices';
|
||||
import { NetworkConfig } from 'protospack-v2';
|
||||
import { lastValueFrom } from 'rxjs';
|
||||
import {
|
||||
CreateNetworkConfigReq,
|
||||
CreateNetworkConfigRes,
|
||||
DeleteNetworkConfigRes,
|
||||
FindAllNetworkConfigsRes,
|
||||
FindNetworkConfigByidRes,
|
||||
UpdateNetworkConfigReq,
|
||||
UpdateNetworkConfigRes,
|
||||
} from './dto/network-config';
|
||||
|
||||
@Injectable()
|
||||
export class NetworkConfigService {
|
||||
private networkConfigReadClient: NetworkConfig.ReadService.NetworkConfigReadService;
|
||||
private networkConfigWriteClient: NetworkConfig.WriteService.NetworkConfigWriteService;
|
||||
constructor(
|
||||
@Inject('NetworkConfigGrpcClient') private readonly grpcClient: ClientGrpc,
|
||||
) {
|
||||
this.networkConfigReadClient =
|
||||
grpcClient.getService<NetworkConfig.ReadService.NetworkConfigReadService>(
|
||||
NetworkConfig.ProtoServices.NetworkConfigReadService,
|
||||
);
|
||||
this.networkConfigWriteClient =
|
||||
grpcClient.getService<NetworkConfig.WriteService.NetworkConfigWriteService>(
|
||||
NetworkConfig.ProtoServices.NetworkConfigWriteService,
|
||||
);
|
||||
}
|
||||
async findAllNetworkConfigs(
|
||||
customer_name: string,
|
||||
): Promise<FindAllNetworkConfigsRes> {
|
||||
return lastValueFrom(
|
||||
this.networkConfigReadClient.NetworkConfigFindByCustomer({
|
||||
customer_name,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async findNetworkConfigById(id: string): Promise<FindNetworkConfigByidRes> {
|
||||
const { network_config } = await lastValueFrom(
|
||||
this.networkConfigReadClient.NetworkConfigFindOneById({
|
||||
id,
|
||||
}),
|
||||
);
|
||||
return { network_config };
|
||||
}
|
||||
|
||||
async createNetworkConfig(
|
||||
body: CreateNetworkConfigReq,
|
||||
customer_name: string,
|
||||
): Promise<CreateNetworkConfigRes> {
|
||||
const { description, name, properties, type } = body;
|
||||
const { network_config } = await lastValueFrom(
|
||||
this.networkConfigWriteClient.NetworkConfigCreate({
|
||||
customer_name,
|
||||
description,
|
||||
name,
|
||||
properties: JSON.stringify(properties),
|
||||
type,
|
||||
}),
|
||||
);
|
||||
return { network_config };
|
||||
}
|
||||
|
||||
async updateNetworkConfig(
|
||||
body: UpdateNetworkConfigReq,
|
||||
network_config_id: string,
|
||||
): Promise<UpdateNetworkConfigRes> {
|
||||
const { description, name } = body;
|
||||
const { network_config } = await lastValueFrom(
|
||||
this.networkConfigWriteClient.NetworkConfigUpdate({
|
||||
id: network_config_id,
|
||||
description,
|
||||
name,
|
||||
}),
|
||||
);
|
||||
return { network_config };
|
||||
}
|
||||
|
||||
async deleteNetworkConfig(
|
||||
network_config_id: string,
|
||||
): Promise<DeleteNetworkConfigRes> {
|
||||
return lastValueFrom(
|
||||
this.networkConfigWriteClient.NetworkConfigDelete({
|
||||
id: network_config_id,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user