diff --git a/docsfera.json b/docsfera.json index 98ce373..1df2238 100644 --- a/docsfera.json +++ b/docsfera.json @@ -4531,16 +4531,6 @@ } ], "responses": { - "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/GetDatasetCatalogTaskRes" - } - } - } - }, "201": { "description": "", "content": { @@ -4556,6 +4546,241 @@ "Catalog" ], "security": [ + { + "access-token": [] + }, + { + "access-token": [] + } + ] + }, + "get": { + "operationId": "CatalogController_getRlsRules", + "parameters": [ + { + "name": "dadosfera-lang", + "in": "header", + "required": false, + "schema": { + "enum": [ + "pt-br", + "en-us" + ], + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "type": "object" + } + } + } + } + } + }, + "tags": [ + "Catalog" + ], + "security": [ + { + "access-token": [] + }, + { + "access-token": [] + } + ] + }, + "delete": { + "operationId": "CatalogController_batchRemoveRlsRules", + "parameters": [ + { + "name": "dadosfera-lang", + "in": "header", + "required": false, + "schema": { + "enum": [ + "pt-br", + "en-us" + ], + "type": "string" + } + }, + { + "name": "nimbus_dashboard_id", + "required": false, + "in": "query", + "schema": { + "type": "string" + } + }, + { + "name": "id_rls", + "required": false, + "in": "query", + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "" + } + }, + "tags": [ + "Catalog" + ], + "security": [ + { + "access-token": [] + }, + { + "access-token": [] + } + ] + } + }, + "/catalog/rls-rule/{id}": { + "get": { + "operationId": "CatalogController_getOneRlsRule", + "parameters": [ + { + "name": "dadosfera-lang", + "in": "header", + "required": false, + "schema": { + "enum": [ + "pt-br", + "en-us" + ], + "type": "string" + } + }, + { + "name": "id", + "required": true, + "in": "path", + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + } + }, + "tags": [ + "Catalog" + ], + "security": [ + { + "access-token": [] + }, + { + "access-token": [] + } + ] + }, + "delete": { + "operationId": "CatalogController_removeRlsRule", + "parameters": [ + { + "name": "dadosfera-lang", + "in": "header", + "required": false, + "schema": { + "enum": [ + "pt-br", + "en-us" + ], + "type": "string" + } + }, + { + "name": "id", + "required": true, + "in": "path", + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + } + }, + "tags": [ + "Catalog" + ], + "security": [ + { + "access-token": [] + }, + { + "access-token": [] + } + ] + } + }, + "/catalog/nimbus-dashboards": { + "get": { + "operationId": "CatalogController_getNimbusDashboards", + "parameters": [ + { + "name": "dadosfera-lang", + "in": "header", + "required": false, + "schema": { + "enum": [ + "pt-br", + "en-us" + ], + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + } + }, + "tags": [ + "Catalog" + ], + "security": [ + { + "access-token": [] + }, { "access-token": [] } @@ -5222,7 +5447,7 @@ } }, "info": { - "title": "Maestro - main", + "title": "Maestro - feat/rls", "description": "This is the Maestro API", "version": "1.0.0", "contact": {} diff --git a/package-lock.json b/package-lock.json index 161410d..16ecaed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@aws-sdk/client-secrets-manager": "^3.414.0", "@dadosfera/dadosfera-logs": "^1.0.0-beta.4", "@dadosfera/protospack": "2.5.3", - "@dadosfera/protospack-v2": "3.34.0-beta.2", + "@dadosfera/protospack-v2": "3.34.0-beta.5", "@grpc/grpc-js": "^1.9.3", "@grpc/proto-loader": "^0.7.9", "@nestjs/cli": "^9.5.0", @@ -1404,9 +1404,9 @@ } }, "node_modules/@dadosfera/protospack-v2": { - "version": "3.34.0-beta.2", - "resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.34.0-beta.2.tgz", - "integrity": "sha512-exnu5CyFZNO0ILNSlLCtUYJZ3qrr4XFBvP2BJ0fyiWd64WlpCPrEMEnJwdLVsbjm4wPeQsqLbXtGn+/Zn0tjEw==", + "version": "3.34.0-beta.5", + "resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.34.0-beta.5.tgz", + "integrity": "sha512-ku5TkrBk5StPJWLyMOpImUmlgTeaiJ1b4o09+QLCbwqShkebihACxVJyg9FXQuwBjth477Zp3uRYc79om2+QFQ==", "dependencies": { "@grpc/grpc-js": "^1.9.3", "rxjs": "^7.5.5" diff --git a/package.json b/package.json index 3548e90..39254f9 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "@aws-sdk/client-secrets-manager": "^3.414.0", "@dadosfera/dadosfera-logs": "^1.0.0-beta.4", "@dadosfera/protospack": "2.5.3", - "@dadosfera/protospack-v2": "3.34.0-beta.2", + "@dadosfera/protospack-v2": "3.34.0-beta.5", "@grpc/grpc-js": "^1.9.3", "@grpc/proto-loader": "^0.7.9", "@nestjs/cli": "^9.5.0", diff --git a/src/modules/catalog/catalog.controller.ts b/src/modules/catalog/catalog.controller.ts index ba82f97..0a594d3 100644 --- a/src/modules/catalog/catalog.controller.ts +++ b/src/modules/catalog/catalog.controller.ts @@ -31,6 +31,7 @@ import { DadosferaLogger } from '@dadosfera/dadosfera-logs'; import { PackTheMetadata } from 'src/utils/ PackTheMetadata'; import { RequestUser, User } from 'src/decorators/user.decorator'; import { + BatchRemoveRlsRulesRequest, GetDatasetCatalogTaskRes, ICatalogAllRequest, ICatalogAllResponse, @@ -49,6 +50,11 @@ import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filt import { Language } from 'src/decorators/language.decorator'; import { LanguageEnum } from 'src/utils/languages.enum'; import { ApiInternalOnlyEndpoint } from 'src/decorators/swagger.decorator'; +import { + AddRlsRuleRequest, + GetNimbusDashboardsRequest, + GetRlsRulesRequest, +} from '@dadosfera/protospack-v2/dist/lib/Catalog/interfaces/messages'; @ApiTags('Catalog') @ApiHeaders([{ name: 'dadosfera-lang', enum: LanguageEnum, required: false }]) @@ -635,8 +641,8 @@ export class CatalogController { } @Post('rls-rule') - @ApiOkResponse({ type: GetDatasetCatalogTaskRes }) - async addRlsRule(@User() user: RequestUser, @Body() body) { + @RequireAllPermissions(PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER) + async addRlsRule(@User() user: RequestUser, @Body() body: AddRlsRuleRequest) { const { customer_id, customer_name, user_id, username } = user; const metadata = PackTheMetadata({ customer_id, @@ -644,9 +650,97 @@ export class CatalogController { user_id, username, }); - console.log(body); const response = await this.catalogService.addRlsRule(body, metadata); return response; } + + @Get('rls-rule/:id') + @RequireAllPermissions(PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER) + async getOneRlsRule(@Param('id') id: string, @User() user: RequestUser) { + const { customer_id, customer_name, user_id, username } = user; + const metadata = PackTheMetadata({ + customer_id, + customer_name, + user_id, + username, + }); + const idInt = parseInt(id); + const response = await this.catalogService.getOneRlsRule(idInt, metadata); + + return response; + } + + @Get('rls-rule') + @RequireAllPermissions(PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER) + async getRlsRules( + @User() user: RequestUser, + @Query() query: GetRlsRulesRequest, + ) { + const { customer_id, customer_name, user_id, username } = user; + const metadata = PackTheMetadata({ + customer_id, + customer_name, + user_id, + username, + }); + const response = await this.catalogService.getRlsRules(query, metadata); + + return response; + } + + @Delete('rls-rule/:id') + @RequireAllPermissions(PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER) + async removeRlsRule(@Param('id') id: string, @User() user: RequestUser) { + const { customer_id, customer_name, user_id, username } = user; + const metadata = PackTheMetadata({ + customer_id, + customer_name, + user_id, + username, + }); + const idInt = parseInt(id); + const response = await this.catalogService.removeRlsRule(idInt, metadata); + + return response; + } + + @Delete('rls-rule') + @RequireAllPermissions(PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER) + async batchRemoveRlsRules( + @Query() query: BatchRemoveRlsRulesRequest, + @User() user: RequestUser, + ) { + const { customer_id, customer_name, user_id, username } = user; + const metadata = PackTheMetadata({ + customer_id, + customer_name, + user_id, + username, + }); + await this.catalogService.batchRemoveRlsRule(query, metadata); + + return { message: 'OK' }; + } + + @Get('nimbus-dashboards') + @RequireAllPermissions(PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER) + async getNimbusDashboards( + @User() user: RequestUser, + @Body() body: GetNimbusDashboardsRequest, + ) { + const { customer_id, customer_name, user_id, username } = user; + const metadata = PackTheMetadata({ + customer_id, + customer_name, + user_id, + username, + }); + const dashboards = await this.catalogService.getNimbusDashboards( + body, + metadata, + ); + + return JSON.parse(dashboards); + } } diff --git a/src/modules/catalog/catalog.service.ts b/src/modules/catalog/catalog.service.ts index dda1a5a..908c3c9 100644 --- a/src/modules/catalog/catalog.service.ts +++ b/src/modules/catalog/catalog.service.ts @@ -6,6 +6,7 @@ import { Messages, } from '@dadosfera/protospack-v2/dist/lib/Catalog'; import { + BadRequestException, HttpException, HttpStatus, Inject, @@ -18,8 +19,18 @@ import { CatalogClientConfiguration } from './catalog-client'; import { UsersService } from '../users/users.service'; import { RolesService } from '../roles/roles.service'; import { Metadata } from '@grpc/grpc-js'; -import { IUpdateDataRequest, TriggerCatalogReq } from './dtos'; -import { AddRlsUserToDashboardRequest } from '@dadosfera/protospack-v2/dist/lib/Catalog/interfaces/messages'; +import { + BatchRemoveRlsRulesRequest, + IUpdateDataRequest, + TriggerCatalogReq, +} from './dtos'; +import { + AddRlsRuleRequest, + GetNimbusDashboardsRequest, + GetOneRlsRuleRequest, + GetRlsRulesRequest, +} from '@dadosfera/protospack-v2/dist/lib/Catalog/interfaces/messages'; +import { parse } from 'path'; class CatalogService implements OnModuleInit { catalogReadService: ReadService.CatalogReadServices; @@ -334,6 +345,7 @@ class CatalogService implements OnModuleInit { } as typeof data_asset; }); } + async triggerCatalog(data: TriggerCatalogReq, metadata: Metadata) { const { session } = await lastValueFrom( this.catalogWriteService.TriggerDatasetCataloging(data, metadata), @@ -346,16 +358,70 @@ class CatalogService implements OnModuleInit { ); return res; } - async addRlsRule(data: AddRlsUserToDashboardRequest, metadata: Metadata) { - const newData: AddRlsUserToDashboardRequest = { - ...data, - rls_option: `rls_email`, - }; + + async addRlsRule(data: AddRlsRuleRequest, metadata: Metadata) { const res = await lastValueFrom( - this.catalogWriteService.AddRlsUserToDashboard(newData, metadata), + this.catalogWriteService.AddRlsRule(data, metadata), ); return res; } + + async removeRlsRule(id: number, metadata: Metadata) { + const res = await lastValueFrom( + this.catalogWriteService.RemoveRlsRule({ id }, metadata), + ); + return res; + } + + async batchRemoveRlsRule( + query: BatchRemoveRlsRulesRequest, + metadata: Metadata, + ) { + const { id_rls, nimbus_dashboard_id } = query; + + if (id_rls && nimbus_dashboard_id) { + throw new BadRequestException( + "You can't delete using both parameters. Choose either 'id_rls' or 'nimbus_dashboard_id'", + ); + } + if (id_rls) { + await lastValueFrom( + this.catalogWriteService.RemoveRlsRulesByRlsId({ id_rls }, metadata), + ); + } else if (nimbus_dashboard_id) { + await lastValueFrom( + this.catalogWriteService.RemoveRlsRulesByDashboardId( + { nimbus_dashboard_id: parseInt(nimbus_dashboard_id) }, + metadata, + ), + ); + } + return 'OK'; + } + + async getRlsRules(data: GetRlsRulesRequest, metadata: Metadata) { + const res = await lastValueFrom( + this.catalogReadService.GetRlsRules(data, metadata), + ); + return res.rls_rules; + } + + async getOneRlsRule(id: number, metadata: Metadata) { + const res = await lastValueFrom( + this.catalogReadService.GetOneRlsRule({ id }, metadata), + ); + return res.rls_rule; + } + + async getNimbusDashboards( + data: GetNimbusDashboardsRequest, + metadata: Metadata, + ) { + const res = await lastValueFrom( + this.catalogReadService.GetNimbusDashboards(data, metadata), + ); + return res.dashboards; + } } export { CatalogService }; diff --git a/src/modules/catalog/dtos/index.ts b/src/modules/catalog/dtos/index.ts index d7d135f..b869e5e 100644 --- a/src/modules/catalog/dtos/index.ts +++ b/src/modules/catalog/dtos/index.ts @@ -312,3 +312,11 @@ export class GetDatasetCatalogTaskRes { @ApiProperty() updated_by: string; } + +export class BatchRemoveRlsRulesRequest { + @ApiPropertyOptional() + nimbus_dashboard_id?: string; + + @ApiPropertyOptional() + id_rls?: string; +}