mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-24 14:49:07 +00:00
FIX: network_config migration
This commit is contained in:
Generated
+7
-7
@@ -12,7 +12,7 @@
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-secrets-manager": "^3.112.0",
|
||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.3",
|
||||
"@dadosfera/protospack-v2": "3.17.1",
|
||||
"@dadosfera/protospack-v2": "3.17.2",
|
||||
"@grpc/grpc-js": "^1.6.7",
|
||||
"@grpc/proto-loader": "^0.6.13",
|
||||
"@nestjs/common": "^8.4.7",
|
||||
@@ -1726,9 +1726,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@dadosfera/protospack-v2": {
|
||||
"version": "3.17.1",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.17.1.tgz",
|
||||
"integrity": "sha512-LClHqyQtNjWSzI4kYk2iceQPsp8DsdTRTuPqgXJGDx8T3ip52t4FiQ/vGFY5QNKaxuSc2zeLMKqq1h79YM1E6g==",
|
||||
"version": "3.17.2",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.17.2.tgz",
|
||||
"integrity": "sha512-N1hn7lIBWgc4JPEAdlQ3jt+++y61XYb9amDmgOUbfSt4803oSdAnCktrcxq3/0e/ZuSYm0qESOkKn0uNLDlGcg==",
|
||||
"dependencies": {
|
||||
"@grpc/grpc-js": "^1.6.7",
|
||||
"rxjs": "^7.5.5",
|
||||
@@ -12305,9 +12305,9 @@
|
||||
}
|
||||
},
|
||||
"@dadosfera/protospack-v2": {
|
||||
"version": "3.17.1",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.17.1.tgz",
|
||||
"integrity": "sha512-LClHqyQtNjWSzI4kYk2iceQPsp8DsdTRTuPqgXJGDx8T3ip52t4FiQ/vGFY5QNKaxuSc2zeLMKqq1h79YM1E6g==",
|
||||
"version": "3.17.2",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.17.2.tgz",
|
||||
"integrity": "sha512-N1hn7lIBWgc4JPEAdlQ3jt+++y61XYb9amDmgOUbfSt4803oSdAnCktrcxq3/0e/ZuSYm0qESOkKn0uNLDlGcg==",
|
||||
"requires": {
|
||||
"@grpc/grpc-js": "^1.6.7",
|
||||
"rxjs": "^7.5.5",
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-secrets-manager": "^3.112.0",
|
||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.3",
|
||||
"@dadosfera/protospack-v2": "3.17.1",
|
||||
"@dadosfera/protospack-v2": "3.17.2",
|
||||
"@grpc/grpc-js": "^1.6.7",
|
||||
"@grpc/proto-loader": "^0.6.13",
|
||||
"@nestjs/common": "^8.4.7",
|
||||
|
||||
@@ -22,6 +22,10 @@ import {
|
||||
} from '@dadosfera/protospack-v2/dist/lib/ConnectionManager/interfaces/messages';
|
||||
import { UsersService } from '../users/users.service';
|
||||
import { ConnectorClientService } from '../connector/client.service';
|
||||
import {
|
||||
ConnectionsApiNetworkConfig,
|
||||
NetworkConfigDto,
|
||||
} from '../network-config/dto/network-config';
|
||||
|
||||
export class ConnectionClientService implements OnModuleInit {
|
||||
private connectionServiceRead: ConnectionManager.ReadService.ConnectionManagerReadServices;
|
||||
@@ -170,7 +174,10 @@ export class ConnectionClientService implements OnModuleInit {
|
||||
);
|
||||
}
|
||||
|
||||
async catalogExistingConnection(data: ConnectionToCatalogDto) {
|
||||
async catalogExistingConnection(data: {
|
||||
connection?: ConnectionToCatalogDto;
|
||||
networkConfig?: NetworkConfigDto;
|
||||
}) {
|
||||
return lastValueFrom(
|
||||
this.connectionServiceRead.INTERNAL_CatalogExistingConnection({
|
||||
data_str: JSON.stringify(data),
|
||||
@@ -190,13 +197,16 @@ export class ConnectionClientService implements OnModuleInit {
|
||||
.then(({ connectors: connectorsStr }) =>
|
||||
JSON.parse(connectorsStr).map((c) => c),
|
||||
);
|
||||
const { customers } = await this.usersService.findaAllCustomers();
|
||||
const { customers } = await this.usersService.findAllCustomers();
|
||||
const promises: Promise<{
|
||||
customer_name: string;
|
||||
customer_id: string;
|
||||
productConnections: Record<string, any>;
|
||||
productConnections: Record<string, any>[];
|
||||
platformConnections: ConnectionApiConnection[];
|
||||
productNetworkConfigs: Record<string, any>[];
|
||||
platformNetworkConfigs: ConnectionsApiNetworkConfig[];
|
||||
}>[] = [];
|
||||
|
||||
customers.forEach((c) => {
|
||||
const customer_name = c.name;
|
||||
const customer_id = c.id;
|
||||
@@ -206,17 +216,22 @@ export class ConnectionClientService implements OnModuleInit {
|
||||
customer_id,
|
||||
platformConnections: JSON.parse(res.platformConnections),
|
||||
productConnections: JSON.parse(res.productConnections),
|
||||
productNetworkConfigs: JSON.parse(res.productNetworkConfigs),
|
||||
platformNetworkConfigs: JSON.parse(res.platformNetworkConfigs),
|
||||
})),
|
||||
);
|
||||
});
|
||||
const customer_connections = await Promise.all(promises);
|
||||
|
||||
const missingInProduct: ConnectionApiConnection[] = [];
|
||||
const productConnectionsMissing: ConnectionApiConnection[] = [];
|
||||
const productNetworkConfigsMissing: ConnectionsApiNetworkConfig[] = [];
|
||||
const migrations = customer_connections.map((cc) => {
|
||||
const {
|
||||
customer_name,
|
||||
platformConnections,
|
||||
productConnections,
|
||||
platformConnections,
|
||||
productNetworkConfigs,
|
||||
platformNetworkConfigs,
|
||||
customer_id,
|
||||
} = cc;
|
||||
|
||||
@@ -224,11 +239,46 @@ export class ConnectionClientService implements OnModuleInit {
|
||||
const productConnection = productConnections.find(
|
||||
(prc) => prc.id === plc.config_id,
|
||||
);
|
||||
if (!productConnection) missingInProduct.push(plc);
|
||||
if (!productConnection) productConnectionsMissing.push(plc);
|
||||
});
|
||||
|
||||
platformNetworkConfigs.forEach((platNetConfig) => {
|
||||
const productNetworkConfig = productNetworkConfigs.find(
|
||||
(prodNetConfig) => prodNetConfig.id === platNetConfig.config_id,
|
||||
);
|
||||
if (!productNetworkConfig)
|
||||
productNetworkConfigsMissing.push(platNetConfig);
|
||||
});
|
||||
|
||||
const updatePromises: Promise<any>[] = [];
|
||||
for (const connection of missingInProduct) {
|
||||
for (const network_config of productNetworkConfigsMissing) {
|
||||
const networkConfigToCatalog = {
|
||||
id: network_config.config_id,
|
||||
created_at: network_config.created_at,
|
||||
updated_at: network_config.updated_at,
|
||||
customer_name: cc.customer_name,
|
||||
customer_id: cc.customer_id,
|
||||
user_id: '',
|
||||
network_type_id: '',
|
||||
network_type_name: network_config.type,
|
||||
type: network_config.type,
|
||||
plugin: network_config.plugin,
|
||||
name: network_config.name,
|
||||
description: network_config.description,
|
||||
properties: undefined,
|
||||
keywords: undefined,
|
||||
tags: undefined,
|
||||
};
|
||||
|
||||
if (apply) {
|
||||
updatePromises.push(
|
||||
this.catalogExistingConnection({
|
||||
networkConfig: networkConfigToCatalog,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
for (const connection of productConnectionsMissing) {
|
||||
const connector = connectors.find(
|
||||
(c) => c._source.plugin === connection.plugin,
|
||||
);
|
||||
@@ -250,11 +300,19 @@ export class ConnectionClientService implements OnModuleInit {
|
||||
username: 'auto',
|
||||
customer_name: customer_name,
|
||||
};
|
||||
updatePromises.push(
|
||||
this.catalogExistingConnection(connectionToCatalog),
|
||||
);
|
||||
|
||||
if (apply) {
|
||||
updatePromises.push(
|
||||
this.catalogExistingConnection({ connection: connectionToCatalog }),
|
||||
);
|
||||
}
|
||||
}
|
||||
return { customer: { ...cc }, updatePromises, missingInProduct };
|
||||
return {
|
||||
customer: { ...cc },
|
||||
updatePromises,
|
||||
productConnectionsMissing,
|
||||
productNetworkConfigsMissing,
|
||||
};
|
||||
});
|
||||
const customersStatus: any[] = [];
|
||||
for (const migration of migrations) {
|
||||
@@ -265,7 +323,8 @@ export class ConnectionClientService implements OnModuleInit {
|
||||
customersStatus.push({
|
||||
customer: migration.customer.customer_name,
|
||||
status,
|
||||
missingInProduct: migration.missingInProduct,
|
||||
productConnectionsMissing: migration.productConnectionsMissing,
|
||||
productNetworkConfigsMissing: migration.productNetworkConfigsMissing,
|
||||
});
|
||||
}
|
||||
return { customersStatus };
|
||||
|
||||
@@ -46,7 +46,7 @@ export class ConnectionController {
|
||||
|
||||
@Get('connections-migration')
|
||||
@RequireAllPermissions(PERMISSIONS_GROUPS.DADOSFERA.permissions.ADMIN)
|
||||
async getAllCustomersPlatformConnections(@Query('apply') apply: string) {
|
||||
async synchronizeConnections(@Query('apply') apply: string) {
|
||||
return this.clientService.synchronizeConnections(apply === 'true');
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,12 @@ import {
|
||||
NetworkConfigEntity,
|
||||
NetworkConfigToCatalog,
|
||||
} from '@dadosfera/protospack-v2/dist/lib/NetworkConfig/interfaces/entities';
|
||||
import { ApiProperty, ApiPropertyOptional, PickType } from '@nestjs/swagger';
|
||||
import {
|
||||
ApiProperty,
|
||||
ApiPropertyOptional,
|
||||
OmitType,
|
||||
PickType,
|
||||
} from '@nestjs/swagger';
|
||||
|
||||
export enum NetworkConfigTypesEnum {
|
||||
vpn = 'vpn',
|
||||
@@ -10,6 +15,24 @@ export enum NetworkConfigTypesEnum {
|
||||
export enum NetworkConfigPluginsEnum {
|
||||
openvpn = 'openvpn',
|
||||
}
|
||||
export interface ConnectionsApiNetworkConfig {
|
||||
config_id: string;
|
||||
created_at: string;
|
||||
credentials: {
|
||||
CERTIFICATE_FILE: string;
|
||||
OVPN_CREDENTIALS: string;
|
||||
TLS_AUTH_FILE: string;
|
||||
OVPN_FILE: string;
|
||||
};
|
||||
customer_name: string;
|
||||
description: string;
|
||||
name: string;
|
||||
plugin: string;
|
||||
secret_id: string;
|
||||
sensitive_fields: string[];
|
||||
type: string;
|
||||
updated_at: string;
|
||||
}
|
||||
export class NetworkConfigDto implements NetworkConfigEntity {
|
||||
@ApiProperty()
|
||||
id: string;
|
||||
|
||||
@@ -208,7 +208,7 @@ export class UsersService implements OnModuleInit {
|
||||
});
|
||||
}
|
||||
|
||||
async findaAllCustomers() {
|
||||
async findAllCustomers() {
|
||||
return await lastValueFrom(this.customersClientService.CustomerFindAll({}));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user