Compare commits

...
19 Commits
Author SHA1 Message Date
Gabriel Amorim 3d39affc61 Merge pull request #139 from dadosfera/fix/network-config-permissions
FIX: remove permission to delete VPNS
2022-09-16 11:55:50 -03:00
Gabriel Rosa 5d045b675c FIX: remove permission to delete VPNS 2022-09-15 09:48:37 -03:00
Gabriel Amorim bb61990f6e Merge pull request #138 from dadosfera/fix/permission-delete-connection
FIX: remove permission to delete connection
2022-09-15 08:50:41 -03:00
Gabriel Rosa 80442c509a FIX: remove permission to delete connection 2022-09-15 08:33:47 -03:00
Gabriel Amorim 8551239038 Merge pull request #137 from dadosfera/fix/update-user-email
FIX: update user email
2022-09-14 11:32:58 -03:00
Gabriel Rosa 4cf7c6e17b FIX: update user email 2022-09-14 10:18:03 -03:00
Gabriel Amorim 88c9c36eb0 Merge pull request #136 from dadosfera/fix/connections-migration
Fix: connections migration
2022-09-13 08:58:29 -03:00
Gabriel Rosa 4b317778f7 FIX: connections migration agora vai 2022-09-12 20:13:12 -03:00
Gabriel Rosa 2eea9787cd FIX: connections migration por favor funciona 2022-09-12 19:52:38 -03:00
Gabriel Rosa c1ab5d152f FIX: reseting productConnectionsMissing and productNetworkConfigsMissing 2022-09-12 18:58:24 -03:00
Gabriel Rosa 8798f5d54e FIX: DEBUG_ConnectionsMigrations - customer_connections 2022-09-12 18:47:42 -03:00
Gabriel Amorim 1da733b5bc Merge pull request #135 from dadosfera/fix/connections-migration
FIX: DEBUG-ConnectionsMigrations
2022-09-12 17:17:54 -03:00
Gabriel Rosa 930c8bc037 FIX: DEBUG-ConnectionsMigrations 2022-09-12 17:14:37 -03:00
Gabriel Amorim 0913741500 Merge pull request #134 from dadosfera/fix/connections-migration
Fix: connections migration
2022-09-12 16:42:08 -03:00
Gabriel Rosa 3e9d0063ae FIX: using DadosferaLogger 2022-09-12 16:35:58 -03:00
Gabriel Rosa 2bc0fe1e9e FIX: get logger from DadosferaLogger 2022-09-12 16:35:08 -03:00
Gabriel Rosa f0fb6e6b4a FIX: DEBUG-ConnectionsMigrations 2022-09-12 16:31:10 -03:00
Gabriel Amorim 74c27d9637 Merge pull request #133 from dadosfera/fix/connections-migration
FIX: get all connectors fixed
2022-09-12 16:11:08 -03:00
Gabriel Rosa 216c83d7fa FIX: get all connectors fixed 2022-09-12 16:08:11 -03:00
10 changed files with 218 additions and 171 deletions
+7 -7
View File
@@ -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.2",
"@dadosfera/protospack-v2": "3.17.5",
"@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.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==",
"version": "3.17.5",
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.17.5.tgz",
"integrity": "sha512-pVi9yCqCIngreW/z75jDqo7dladmN/z49K5m2vdd4ljS7yR21XicrCIg+YxSOwFga4wa3c8bI6WZ40Mp8ah8IA==",
"dependencies": {
"@grpc/grpc-js": "^1.6.7",
"rxjs": "^7.5.5",
@@ -12305,9 +12305,9 @@
}
},
"@dadosfera/protospack-v2": {
"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==",
"version": "3.17.5",
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.17.5.tgz",
"integrity": "sha512-pVi9yCqCIngreW/z75jDqo7dladmN/z49K5m2vdd4ljS7yR21XicrCIg+YxSOwFga4wa3c8bI6WZ40Mp8ah8IA==",
"requires": {
"@grpc/grpc-js": "^1.6.7",
"rxjs": "^7.5.5",
+1 -1
View File
@@ -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.2",
"@dadosfera/protospack-v2": "3.17.5",
"@grpc/grpc-js": "^1.6.7",
"@grpc/proto-loader": "^0.6.13",
"@nestjs/common": "^8.4.7",
+21 -20
View File
@@ -125,16 +125,17 @@ export const PERMISSIONS_GROUPS = {
'es-es': 'Crear Source',
},
},
DELETE: {
seqid: 38,
claim: 'connection:delete',
usage: PermissionUsages.PUBLIC,
name: {
'pt-br': 'Excluir Fonte',
'en-us': 'Remove Source',
'es-s': 'Eliminar Source',
},
},
//TODO descomentar quando tiver ok o DELETE de conexões
// DELETE: {
// seqid: 38,
// claim: 'connection:delete',
// usage: PermissionUsages.PUBLIC,
// name: {
// 'pt-br': 'Excluir Fonte',
// 'en-us': 'Remove Source',
// 'es-s': 'Eliminar Source',
// },
// },
UPDATE: {
seqid: 39,
claim: 'connection:update',
@@ -165,16 +166,16 @@ export const PERMISSIONS_GROUPS = {
'es-es': 'Crear VPN',
},
},
DELETE: {
seqid: 36,
claim: 'network_config:delete',
usage: PermissionUsages.PUBLIC,
name: {
'pt-br': 'Excluir VPN',
'en-us': 'Remove VPN',
'es-es': 'Eliminar VPN',
},
},
// DELETE: {
// seqid: 36,
// claim: 'network_config:delete',
// usage: PermissionUsages.PUBLIC,
// name: {
// 'pt-br': 'Excluir VPN',
// 'en-us': 'Remove VPN',
// 'es-es': 'Eliminar VPN',
// },
// },
},
},
+125 -87
View File
@@ -26,16 +26,22 @@ import {
ConnectionsApiNetworkConfig,
NetworkConfigDto,
} from '../network-config/dto/network-config';
import DadosferaLogger from '@dadosfera/dadosfera-logs/dist';
export class ConnectionClientService implements OnModuleInit {
private connectionServiceRead: ConnectionManager.ReadService.ConnectionManagerReadServices;
private connectionServiceWrite: ConnectionManager.WriteService.ConnectionManagerWriteServices;
logger: DadosferaLogger;
constructor(
@Inject(ConnectionClientConfiguration.name)
private readonly grpcClient: ClientGrpc,
private usersService: UsersService,
private connectorService: ConnectorClientService,
) {}
private dadosferaLogger: DadosferaLogger,
) {
this.logger = dadosferaLogger.logger;
}
onModuleInit() {
this.connectionServiceWrite =
@@ -198,34 +204,58 @@ export class ConnectionClientService implements OnModuleInit {
JSON.parse(connectorsStr).map((c) => c),
);
const { customers } = await this.usersService.findAllCustomers();
const promises: Promise<{
const customer_connections: {
customer_name: string;
customer_id: string;
productConnections: Record<string, any>[];
platformConnections: ConnectionApiConnection[];
productNetworkConfigs: Record<string, any>[];
platformNetworkConfigs: ConnectionsApiNetworkConfig[];
}>[] = [];
}[] = [];
for (const customer of customers) {
const { name: customer_name, id: customer_id } = customer;
customers.forEach((c) => {
const customer_name = c.name;
const customer_id = c.id;
promises.push(
this.INTERNAL_getAllConnections({ customer_name }).then((res) => ({
customer_name,
customer_id,
platformConnections: JSON.parse(res.platformConnections),
productConnections: JSON.parse(res.productConnections),
productNetworkConfigs: JSON.parse(res.productNetworkConfigs),
platformNetworkConfigs: JSON.parse(res.platformNetworkConfigs),
})),
const customer_connection = await this.INTERNAL_getAllConnections({
customer_name,
}).then((res) => ({
customer_name,
customer_id,
platformConnections: res.platformConnections
? JSON.parse(res.platformConnections)
: [],
productConnections: res.productConnections
? JSON.parse(res.productConnections)
: [],
productNetworkConfigs: res.productNetworkConfigs
? JSON.parse(res.productNetworkConfigs)
: [],
platformNetworkConfigs: res.platformNetworkConfigs
? JSON.parse(res.platformNetworkConfigs)
: [],
}));
customer_connections.push(customer_connection);
}
this.logger.info(
'DEBUG_ConnectionsMigrations - ' + JSON.stringify(customer_connections),
);
const migrations: {
customer_name: string;
status: any[];
productConnectionsMissing: ConnectionApiConnection[];
productNetworkConfigsMissing: ConnectionsApiNetworkConfig[];
}[] = [];
for (const customer_connection of customer_connections) {
const productConnectionsMissing: ConnectionApiConnection[] = [];
const productNetworkConfigsMissing: ConnectionsApiNetworkConfig[] = [];
const status: any[] = [];
let updatePromises: Promise<any>[] = [];
this.logger.info(
'DEBUG_ConnectionsMigrations - customer_connections ' +
JSON.stringify(customer_connection),
);
});
const customer_connections = await Promise.all(promises);
const productConnectionsMissing: ConnectionApiConnection[] = [];
const productNetworkConfigsMissing: ConnectionsApiNetworkConfig[] = [];
const migrations = customer_connections.map((cc) => {
const {
customer_name,
productConnections,
@@ -233,100 +263,108 @@ export class ConnectionClientService implements OnModuleInit {
productNetworkConfigs,
platformNetworkConfigs,
customer_id,
} = cc;
} = customer_connection;
platformConnections.forEach((plc) => {
platformConnections?.forEach((plc) => {
const productConnection = productConnections.find(
(prc) => prc.id === plc.config_id,
);
if (!productConnection) productConnectionsMissing.push(plc);
});
platformNetworkConfigs.forEach((platNetConfig) => {
platformNetworkConfigs?.forEach((platNetConfig) => {
const productNetworkConfig = productNetworkConfigs.find(
(prodNetConfig) => prodNetConfig.id === platNetConfig.config_id,
);
if (!productNetworkConfig)
productNetworkConfigsMissing.push(platNetConfig);
});
if (apply) {
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: customer_name,
customer_id: 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,
};
const updatePromises: Promise<any>[] = [];
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,
);
const connectionToCatalog = {
id: connection.config_id,
created_at: connection.created_at,
updated_at: new Date().toISOString(),
customer_id: customer_id,
user_id: '',
plugin: connection.plugin,
name: connection.name,
description: connection.description,
image_url: connector._source.image,
network_config_id: connection.network_config_id,
type: connection.type,
connector_id: connector._id,
connector_name: connector._source.name,
in_use: 1,
username: 'auto',
customer_name: customer_name,
};
if (apply) {
this.logger.info(
'DEBUG_ConnectionsMigrations - Creating missing network configs for customer' +
customer_name +
' - ' +
JSON.stringify(customer_connection),
);
const updateStatuses = await Promise.all(updatePromises);
status.push(...updateStatuses);
updatePromises = [];
for (const connection of productConnectionsMissing) {
const connector = connectors.find(
(c) => c._source.plugin === connection.plugin,
);
const connectionToCatalog = {
id: connection.config_id,
created_at: connection.created_at,
updated_at: new Date().toISOString(),
customer_id: customer_id,
user_id: '',
plugin: connection.plugin,
name: connection.name,
description: connection.description,
image_url: connector._source.image,
network_config_id: connection.network_config_id,
type: connection.type,
connector_id: connector._id,
connector_name: connector._source.name,
in_use: 1,
username: '',
customer_name,
};
updatePromises.push(
this.catalogExistingConnection({ connection: connectionToCatalog }),
);
}
this.logger.info(
'DEBUG_ConnectionsMigrations - Creating missing connections for customer' +
' - ' +
customer_name +
JSON.stringify(customer_connection),
);
const updateStatuses_2 = await Promise.all(updatePromises);
status.push(...updateStatuses_2);
}
return {
customer: { ...cc },
updatePromises,
this.logger.info(
'DEBUG_ConnectionsMigrations - migrations for customer ' +
customer_name +
' - ' +
JSON.stringify(customer_connection),
);
migrations.push({
customer_name,
status,
productConnectionsMissing,
productNetworkConfigsMissing,
};
});
const customersStatus: any[] = [];
for (const migration of migrations) {
let status: any[] = [];
if (apply) {
status = await Promise.all(migration.updatePromises);
}
customersStatus.push({
customer: migration.customer.customer_name,
status,
productConnectionsMissing: migration.productConnectionsMissing,
productNetworkConfigsMissing: migration.productNetworkConfigsMissing,
});
}
return { customersStatus };
return { migrations };
}
}
+20 -20
View File
@@ -103,29 +103,29 @@ export class ConnectionController {
return response;
}
@Delete('/:id')
@RequireAllPermissions(connectionPermissions.DELETE)
async deleteConnection(
@User() user: RequestUser,
@Param('id') id: string,
): Promise<ConnectionRes> {
this.logger.info('/connections - Delete Connection');
// @Delete('/:id')
// @RequireAllPermissions(connectionPermissions.DELETE)
// async deleteConnection(
// @User() user: RequestUser,
// @Param('id') id: string,
// ): Promise<ConnectionRes> {
// this.logger.info('/connections - Delete Connection');
const { user_id, customer_id, customer_name, username } = user;
const metadata = PackTheMetadata({
user_id,
customer_id,
customer_name,
username,
});
// const { user_id, customer_id, customer_name, username } = user;
// const metadata = PackTheMetadata({
// user_id,
// customer_id,
// customer_name,
// username,
// });
const response: any = await this.clientService.deleteConnection({
body: { id },
metadata,
});
// const response: any = await this.clientService.deleteConnection({
// body: { id },
// metadata,
// });
return response;
}
// return response;
// }
@Get()
async getAllConnections(
@@ -107,7 +107,7 @@ export class ConnectorController {
@Headers('dadosfera-lang') language,
@Query() queries: GetAllDto,
) {
this.logger.info('/upload - Upload Connector Route');
this.logger.info('/GET - getAllConnectors Route');
if (!language) language = 'en-us';
const { search, size, page, ...filters } = queries;
@@ -120,7 +120,7 @@ export class ConnectorController {
page: page || 1,
});
const connectors = JSON.parse(response.connectors).connectors;
const connectors = JSON.parse(response.connectors);
return {
message: response.message,
@@ -153,7 +153,7 @@ export class ConnectorController {
@Param('plugin') plugin: string,
@Query('version') version: string,
) {
this.logger.info('/upload - Upload Connector Route');
this.logger.info('/GET/:plugin - getConnector Route');
if (!language) language = 'en-us';
const pluginId = `${plugin}-${version}`;
@@ -25,7 +25,10 @@ import {
UpdateNetworkConfigRes,
} from './dto/network-config';
import { FileInterceptor } from '@nestjs/platform-express';
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
import { RequireAllPermissions } from 'src/authentication/authentication.decorator';
const networkConfigPermissions = PERMISSIONS_GROUPS.NETWORK_CONFIG.permissions;
@ApiTags('Network Config')
@Controller('network-config')
export class NetworkConfigController {
@@ -92,6 +95,7 @@ export class NetworkConfigController {
@Post()
@ApiOkResponse({ type: CreateNetworkConfigRes })
@RequireAllPermissions(networkConfigPermissions.CREATE)
@ApiConsumes('multipart/form-data')
@UseInterceptors(FileInterceptor('ovpn_file'))
async createNetworkConfigs(
@@ -111,36 +115,37 @@ export class NetworkConfigController {
});
}
@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,
);
}
// @Patch(':id')
// @ApiOkResponse({ type: UpdateNetworkConfigRes })
// @RequireAllPermissions(networkConfigPermissions.CREATE)
// 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, {
customer_name: user.customer_name,
customer_id: user.customer_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, {
// customer_name: user.customer_name,
// customer_id: user.customer_id,
// });
// }
}
+2
View File
@@ -98,6 +98,8 @@ export class UpdateUserReq {
@ApiPropertyOptional()
name?: string;
@ApiPropertyOptional()
email?: string;
@ApiPropertyOptional()
jobTitle?: string;
@ApiPropertyOptional()
department?: string;
+2 -1
View File
@@ -100,7 +100,7 @@ export class UsersService implements OnModuleInit {
}
async updateUser(req: UpdateUserReq, id: string, customerId: string) {
const { department, hierarchy, jobTitle, name, roleNames } = req;
const { department, hierarchy, jobTitle, name, roleNames, email } = req;
if (roleNames) {
await this.setRoles({ roleNames, userId: id }, customerId);
}
@@ -112,6 +112,7 @@ export class UsersService implements OnModuleInit {
department,
hierarchy,
jobTitle,
email,
}),
);
return { user: this.adjustUsersPayload([user])[0] };
+1 -1
View File
File diff suppressed because one or more lines are too long