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 32ce795..e290860 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": "" @@ -2351,6 +2349,25 @@ "PipelinesV2" ] }, + "patch": { + "operationId": "PipelinesController_updateByPatch", + "parameters": [], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + } + }, + "tags": [ + "PipelinesV2" + ] + }, "delete": { "operationId": "PipelinesController_delete", "parameters": [], @@ -3216,9 +3233,9 @@ } }, "info": { - "title": "Maestro - feat/rest-api", + "title": "Maestro - stg2", "description": "Documentation for Maestro gateway", - "version": "21.11.2022 - 13:36", + "version": "0.0.0", "contact": {} }, "tags": [], @@ -3486,17 +3503,6 @@ "tags" ] }, - "DeleteConnectorDto": { - "type": "object", - "properties": { - "version": { - "type": "string" - } - }, - "required": [ - "version" - ] - }, "PermissionGroupPermission": { "type": "object", "properties": { diff --git a/package-lock.json b/package-lock.json index 94fbd56..4d5be85 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "dependencies": { "@aws-sdk/client-secrets-manager": "^3.112.0", "@dadosfera/dadosfera-logs": "^1.0.0-beta.4", - "@dadosfera/protospack-v2": "3.20.0", + "@dadosfera/protospack-v2": "3.21.0", "@grpc/grpc-js": "^1.6.7", "@grpc/proto-loader": "^0.6.13", "@nestjs/common": "^8.4.7", @@ -1727,9 +1727,9 @@ } }, "node_modules/@dadosfera/protospack-v2": { - "version": "3.20.0", - "resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.20.0.tgz", - "integrity": "sha512-eatmjfYmfD2Rqxi3L6/XDOqkImYc9PvChTTXO03RgiOk2IDEALvacPGp6j1bce2jfNMA2LoP3Bd1ugklecDPgg==", + "version": "3.21.0", + "resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.21.0.tgz", + "integrity": "sha512-gHIRLSto813lagxqcphO4/xc82g/QkCZRslRhj5tJK4V69f/ScviBHB4CCRBRW5Md2Lql6zWuTV5R0uADFIiZA==", "dependencies": { "@grpc/grpc-js": "^1.6.7", "rxjs": "^7.5.5", @@ -12330,9 +12330,9 @@ } }, "@dadosfera/protospack-v2": { - "version": "3.20.0", - "resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.20.0.tgz", - "integrity": "sha512-eatmjfYmfD2Rqxi3L6/XDOqkImYc9PvChTTXO03RgiOk2IDEALvacPGp6j1bce2jfNMA2LoP3Bd1ugklecDPgg==", + "version": "3.21.0", + "resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.21.0.tgz", + "integrity": "sha512-gHIRLSto813lagxqcphO4/xc82g/QkCZRslRhj5tJK4V69f/ScviBHB4CCRBRW5Md2Lql6zWuTV5R0uADFIiZA==", "requires": { "@grpc/grpc-js": "^1.6.7", "rxjs": "^7.5.5", diff --git a/package.json b/package.json index e936e51..f1df8c1 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "dependencies": { "@aws-sdk/client-secrets-manager": "^3.112.0", "@dadosfera/dadosfera-logs": "^1.0.0-beta.4", - "@dadosfera/protospack-v2": "3.20.0", + "@dadosfera/protospack-v2": "3.21.0", "@grpc/grpc-js": "^1.6.7", "@grpc/proto-loader": "^0.6.13", "@nestjs/common": "^8.4.7", diff --git a/src/main.ts b/src/main.ts index cb3cf4a..7235e3b 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 eeb4cfe..a5f14d4 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, + 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/modules/pipelinesV2/pipelines.controller.ts b/src/modules/pipelinesV2/pipelines.controller.ts index 8892007..c2d828a 100644 --- a/src/modules/pipelinesV2/pipelines.controller.ts +++ b/src/modules/pipelinesV2/pipelines.controller.ts @@ -12,6 +12,7 @@ import { UseFilters, HttpCode, HttpStatus, + Patch, } from '@nestjs/common'; import { ApiCreatedResponse, @@ -45,6 +46,10 @@ import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filt action = 'UPDATE'; break; + case 'PATCH': + action = 'UPDATE'; + break; + default: action = req.method; } @@ -175,20 +180,49 @@ export class PipelinesController { @Put('/:id') async update( + @Headers('Dadosfera-Lang') language, @Body() updatePipelineDto, @Param('id') id, @User() user: RequestUser, ) { - this.logger.info('PipelinesController - findOne', { user }); + this.logger.info('PipelinesController - update', { user }); const { info } = updatePipelineDto; delete updatePipelineDto.info; - const response = await this.pipelinesClientService.update({ - ...updatePipelineDto, - info, - id, + const { customer_id, customer_name, user_id, username } = user; + if (!language) language = 'en-us'; + + const metadata = PackTheMetadata({ + customer_id, + customer_name, + user_id, + username, + language, }); + const response = await this.pipelinesClientService.update( + { + ...updatePipelineDto, + info, + id, + }, + metadata, + ); + + this.logger.info('PipelinesController - update: OK', { user }); + return response; + } + + @Patch('/:id') + async updateByPatch( + @Headers('Dadosfera-Lang') language, + @Body() updatePipelineDto, + @Param('id') id, + @User() user: RequestUser, + ) { + this.logger.info('PipelinesController - patch', { user }); + const response = await this.update(language, updatePipelineDto, id, user); + this.logger.info('PipelinesController - patch: OK', { user }); return response; } diff --git a/src/modules/pipelinesV2/pipelines.service.ts b/src/modules/pipelinesV2/pipelines.service.ts index 150017d..030c6a1 100644 --- a/src/modules/pipelinesV2/pipelines.service.ts +++ b/src/modules/pipelinesV2/pipelines.service.ts @@ -137,11 +137,17 @@ export class PipelinesService implements OnModuleInit { return findOnePipelineResponse; } - async update(UpdatePipelineRequest: Messages.PipelineV2UpdateRequest) { + async update( + UpdatePipelineRequest: Messages.PipelineV2UpdateRequest, + metadata, + ) { this.logger.info('PipelinesClientService - Update'); const updatePipelineResponse = await lastValueFrom( - this.pipelineWriteService.PipelineV2Update(UpdatePipelineRequest), + this.pipelineWriteService.PipelineV2Update( + UpdatePipelineRequest, + metadata, + ), ); this.logger.info('Done'); 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;