diff --git a/.github/workflows/deploy-manually.yml b/.github/workflows/deploy-manually.yml index b35183b..2674a93 100644 --- a/.github/workflows/deploy-manually.yml +++ b/.github/workflows/deploy-manually.yml @@ -10,7 +10,6 @@ on: required: true type: choice options: - - dev - stg - stg2 - prd diff --git a/docsfera.json b/docsfera.json index 16a63e0..e4ffcaa 100644 --- a/docsfera.json +++ b/docsfera.json @@ -505,18 +505,16 @@ "schema": { "type": "string" } - } - ], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/DeleteConnectorDto" - } + }, + { + "name": "version", + "required": true, + "in": "query", + "schema": { + "type": "string" } } - }, + ], "responses": { "200": { "description": "" @@ -3235,9 +3233,9 @@ } }, "info": { - "title": "Maestro - feature/update-pipeline-cron", + "title": "Maestro - stg2", "description": "Documentation for Maestro gateway", - "version": "25.11.2022 - 12:58", + "version": "0.0.0", "contact": {} }, "tags": [], @@ -3505,17 +3503,6 @@ "tags" ] }, - "DeleteConnectorDto": { - "type": "object", - "properties": { - "version": { - "type": "string" - } - }, - "required": [ - "version" - ] - }, "PermissionGroupPermission": { "type": "object", "properties": { diff --git a/src/main.ts b/src/main.ts index ec71f7f..b2c84c6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -30,12 +30,8 @@ async function bootstrap() { await app.listen(3333); } -function configureSwagger(app: INestApplication) { - const date = new Date(); - const swaggerVersion = `${date.getDate()}.${ - date.getMonth() + 1 - }.${date.getFullYear()} - ${date.getHours()}:${date.getMinutes()}`; +function configureSwagger(app: INestApplication) { let branchName = ''; try { branchName = execSync('git rev-parse --abbrev-ref HEAD') @@ -50,7 +46,6 @@ function configureSwagger(app: INestApplication) { const config = new DocumentBuilder() .setTitle(swaggerTitle) .setDescription('Documentation for Maestro gateway') - .setVersion(swaggerVersion) .addBearerAuth( { type: 'http', scheme: 'bearer', bearerFormat: 'JWT' }, 'Authorization', diff --git a/src/modules/connection/client.service.ts b/src/modules/connection/client.service.ts index 241296b..7cb416d 100644 --- a/src/modules/connection/client.service.ts +++ b/src/modules/connection/client.service.ts @@ -1,9 +1,4 @@ -import { - OnModuleInit, - Inject, - HttpException, - HttpStatus, -} from '@nestjs/common'; +import { OnModuleInit, Inject } from '@nestjs/common'; import { ClientGrpc } from '@nestjs/microservices'; import { ConnectionManager } from '@dadosfera/protospack-v2'; import { lastValueFrom } from 'rxjs'; @@ -86,12 +81,7 @@ export class ConnectionClientService implements OnModuleInit { }, metadata, ), - ).catch((err) => { - throw new HttpException( - err.details, - err.code === 6 ? HttpStatus.CONFLICT : 400, - ); - }); + ); } async updateConnection( @@ -112,12 +102,7 @@ export class ConnectionClientService implements OnModuleInit { }, metadata, ), - ).catch((err) => { - throw new HttpException( - err.details, - err.code === 6 ? HttpStatus.CONFLICT : 400, - ); - }); + ); } async deleteConnection({ body, metadata }): Promise { @@ -130,12 +115,7 @@ export class ConnectionClientService implements OnModuleInit { }, metadata, ), - ).catch((err) => { - throw new HttpException( - err.details, - err.code === 6 ? HttpStatus.CONFLICT : 400, - ); - }); + ); } async getAllConnections({ body, metadata }): Promise { @@ -146,12 +126,7 @@ export class ConnectionClientService implements OnModuleInit { { search, filters: JSON.stringify(filters), size, page }, metadata, ), - ).catch((err) => { - throw new HttpException( - err.details, - err.code === 6 ? HttpStatus.CONFLICT : 400, - ); - }); + ); } async getConnectionDetails({ @@ -162,12 +137,7 @@ export class ConnectionClientService implements OnModuleInit { return lastValueFrom( this.connectionServiceRead.GetConnectionDetails({ id }, metadata), - ).catch((err) => { - throw new HttpException( - err.details, - err.code === 6 ? HttpStatus.CONFLICT : 400, - ); - }); + ); } async INTERNAL_getAllConnections({ diff --git a/src/modules/connection/connection.controller.ts b/src/modules/connection/connection.controller.ts index 1d614bd..a0dfdfe 100644 --- a/src/modules/connection/connection.controller.ts +++ b/src/modules/connection/connection.controller.ts @@ -9,6 +9,7 @@ import { Get, Headers, Query, + UseFilters, } from '@nestjs/common'; import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; import { ConnectionClientService } from './client.service'; @@ -28,8 +29,10 @@ import { } from './dtos/connection'; import { CreateConnectionDto } from './dtos/connection'; import { PackTheMetadata } from 'src/utils/ PackTheMetadata'; +import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter'; const connectionPermissions = PERMISSIONS_GROUPS.CONNECTION.permissions; +@UseFilters(new GrpcToHttpExceptionFilter()) @ApiTags('connections') @ApiBearerAuth() @Authenticated() diff --git a/src/modules/connector/client.service.ts b/src/modules/connector/client.service.ts index fdd1cdb..bac423c 100644 --- a/src/modules/connector/client.service.ts +++ b/src/modules/connector/client.service.ts @@ -83,163 +83,30 @@ export class ConnectorClientService implements OnModuleInit { ); }); const responseParsed = JSON.parse(res.message); - const connectorErrors = responseParsed.items - .filter((i) => i.update._index === 'connectors' && i.update.error) + const connectorsResponse = responseParsed.items.filter( + (i) => i.update._index === process.env.CONNECTORS_INDEX, + ); + const connectorErrors = connectorsResponse + .filter((i) => i.update.error) .map((i) => ({ id: i.update._id, reason: i.update.error, status: i.error.status, })); - const connectionControlsErrors = responseParsed.items - .filter( - (i) => i.update._index === 'connection_controls' && i.update.error, - ) - .map((i) => ({ - id: i.update._id, - reason: i.update.error, - status: i.error.status, - })); - const connectionStepsErrors = responseParsed.items - .filter((i) => i.update._index === 'connection_steps' && i.update.error) - .map((i) => ({ - id: i.update._id, - reason: i.update.error, - status: i.error.status, - })); - const configControlsErrors = responseParsed.items - .filter((i) => i.update._index === 'config_controls' && i.update.error) - .map((i) => ({ - id: i.update._id, - reason: i.update.error, - status: i.error.status, - })); - const connectorCreated = responseParsed.items - .filter( - (i) => - i.update._index === 'connectors' && i.update.result === 'created', - ) - .map((i) => ({ - id: i.update._id, - })); - const connectionControlsCreated = responseParsed.items - .filter( - (i) => - i.update._index === 'connection_controls' && - i.update.result === 'created', - ) - .map((i) => ({ - id: i.update._id, - })); - const connectionStepsCreated = responseParsed.items - .filter( - (i) => - i.update._index === 'connection_steps' && - i.update.result === 'created', - ) - .map((i) => ({ - id: i.update._id, - })); - const configControlsCreated = responseParsed.items - .filter( - (i) => - i.update._index === 'config_controls' && - i.update.result === 'created', - ) - .map((i) => ({ - id: i.update._id, - })); - const connectorUpdated = responseParsed.items - .filter( - (i) => - i.update._index === 'connectors' && i.update.result === 'updated', - ) - .map((i) => ({ - id: i.update._id, - })); - const connectionControlsUpdated = responseParsed.items - .filter( - (i) => - i.update._index === 'connection_controls' && - i.update.result === 'updated', - ) - .map((i) => ({ - id: i.update._id, - })); - const connectionStepsUpdated = responseParsed.items - .filter( - (i) => - i.update._index === 'connection_steps' && - i.update.result === 'updated', - ) - .map((i) => ({ - id: i.update._id, - })); - const configControlsUpdated = responseParsed.items - .filter( - (i) => - i.update._index === 'config_controls' && - i.update.result === 'updated', - ) - .map((i) => ({ - id: i.update._id, - })); - const connectorNoop = responseParsed.items - .filter( - (i) => i.update._index === 'connectors' && i.update.result === 'noop', - ) - .map((i) => ({ - id: i.update._id, - })); - const connectionControlsNoop = responseParsed.items - .filter( - (i) => - i.update._index === 'connection_controls' && - i.update.result === 'noop', - ) - .map((i) => ({ - id: i.update._id, - })); - const connectionStepsNoop = responseParsed.items - .filter( - (i) => - i.update._index === 'connection_steps' && i.update.result === 'noop', - ) - .map((i) => ({ - id: i.update._id, - })); - const configControlsNoop = responseParsed.items - .filter( - (i) => - i.update._index === 'config_controls' && i.update.result === 'noop', - ) - .map((i) => ({ - id: i.update._id, - })); + const connectorCreated = connectorsResponse + .filter((i) => i.update.result === 'created') + .map((i) => i.update._id); + const connectorUpdated = connectorsResponse + .filter((i) => i.update.result === 'updated') + .map((i) => i.update._id); + const connectorNoop = connectorsResponse + .filter((i) => i.update.result === 'noop') + .map((i) => i.update._id); return { - errors: { - connectors: connectorErrors, - connection_controls: connectionControlsErrors, - connection_steps: connectionStepsErrors, - config_controls: configControlsErrors, - }, - created: { - connectors: connectorCreated, - connection_controls: connectionControlsCreated, - connection_steps: connectionStepsCreated, - config_controls: configControlsCreated, - }, - updated: { - connectors: connectorUpdated, - connection_controls: connectionControlsUpdated, - connection_steps: connectionStepsUpdated, - config_controls: configControlsUpdated, - }, - noop: { - connectors: connectorNoop, - connection_controls: connectionControlsNoop, - connection_steps: connectionStepsNoop, - config_controls: configControlsNoop, - }, + errors: connectorErrors, + created: connectorCreated, + updated: connectorUpdated, + noop: connectorNoop, }; } @@ -318,12 +185,7 @@ export class ConnectorClientService implements OnModuleInit { version, plugin, }), - ).catch((err) => { - throw new HttpException( - err.details, - err.code === 6 ? HttpStatus.CONFLICT : 400, - ); - }); + ); } async updateConnector({ plugin, changes }) { diff --git a/src/modules/connector/connector.controller.ts b/src/modules/connector/connector.controller.ts index 89efd1c..c95ff54 100644 --- a/src/modules/connector/connector.controller.ts +++ b/src/modules/connector/connector.controller.ts @@ -19,7 +19,6 @@ import { ApiBearerAuth, ApiConsumes, ApiTags } from '@nestjs/swagger'; import { ConnectorClientService } from './client.service'; import { AddTagDto } from './dtos/add-tag'; import { CreateConnectorDto } from './dtos/create-connector'; -import { DeleteConnectorDto } from './dtos/delete-connector'; import { GetAllDto } from './dtos/get-all'; import { RemoveTagDto } from './dtos/remove-tag'; import { UpdateDto } from './dtos/update'; @@ -274,7 +273,7 @@ export class ConnectorController { @RequireAllPermissions(PERMISSIONS_GROUPS.CONNECTORS.permissions.DELETE) async deleteConnector( @Param('plugin') plugin: string, - @Body() { version }: DeleteConnectorDto, + @Query('version') version: string, ) { this.logger.info('/upload - Upload Connector Route'); diff --git a/src/utils/ErrorBuilder.ts b/src/utils/ErrorBuilder.ts index 8b3956e..16567e1 100644 --- a/src/utils/ErrorBuilder.ts +++ b/src/utils/ErrorBuilder.ts @@ -214,6 +214,16 @@ export function EnrichErrorCode(code: string) { message: 'Id encontra-se num formato inválido', code, }; + case ErrorCodes.CONNECTION.NOT_FOUND: + case ErrorCodes.CONNECTION.PLATFORM_NOT_FOUND: + return { + statusCode: HttpStatus.NOT_FOUND, + error: 'Conexão não encontrada', + message: + 'Não encontramos a conexão solicitada. Caso o erro persista, entre em contato com o suporte', + code, + }; + case ErrorCodes.CONNECTION_TEST.ERROR: return { statusCode: HttpStatus.BAD_REQUEST, diff --git a/src/utils/errorCodes.ts b/src/utils/errorCodes.ts index 9abe020..087ddba 100644 --- a/src/utils/errorCodes.ts +++ b/src/utils/errorCodes.ts @@ -60,6 +60,10 @@ const PIPELINE = { const INPUT = { NOT_FOUND: 'INPUT.NOT_FOUND', }; +const CONNECTION = { + NOT_FOUND: 'CONNECTION.NOT_FOUND', + PLATFORM_NOT_FOUND: 'CONNECTION.PLATFORM_NOT_FOUND', +}; const TRANSFORMATION = { NOT_FOUND: 'TRANSFORMATION.NOT_FOUND', }; @@ -77,6 +81,7 @@ const ErrorCodes = { PIPELINE, INPUT, TRANSFORMATION, + CONNECTION, }; export default ErrorCodes;