mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-23 16:09:08 +00:00
FIX: network_config migration
This commit is contained in:
@@ -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({}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user