mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-23 02:59:08 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e4b27c5f76 | ||
|
|
92e449d6d3 | ||
|
|
5073b2e188 | ||
|
|
8a11eda24d | ||
|
|
9d732d4a48 | ||
|
|
5fa10a939b | ||
|
|
4be3ffe3a2 | ||
|
|
8af9c638ef | ||
|
|
97d6f914cc | ||
|
|
9ad2e3770e | ||
|
|
ea2cc8809f | ||
|
|
410e190e7c | ||
|
|
c1b213c34c | ||
|
|
a6c58eb82d | ||
|
|
b756cb5a1e | ||
|
|
46cafc2d50 | ||
|
|
a087775e3a | ||
|
|
69305610ff | ||
|
|
69008a9ffb | ||
|
|
687b4e40e1 | ||
|
|
d56544568b | ||
|
|
63fbfa6b52 | ||
|
|
2b03c4e4a9 | ||
|
|
18c3c9c58c | ||
|
|
166c45728f | ||
|
|
d0f5da0270 | ||
|
|
dade8d59e5 | ||
|
|
fe261667f8 | ||
|
|
722bb1ec7c | ||
|
|
a371db355b | ||
|
|
1ff135c0d7 |
Generated
+7
-7
@@ -12,7 +12,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-secrets-manager": "^3.112.0",
|
"@aws-sdk/client-secrets-manager": "^3.112.0",
|
||||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
||||||
"@dadosfera/protospack-v2": "3.18.7",
|
"@dadosfera/protospack-v2": "3.18.8",
|
||||||
"@grpc/grpc-js": "^1.6.7",
|
"@grpc/grpc-js": "^1.6.7",
|
||||||
"@grpc/proto-loader": "^0.6.13",
|
"@grpc/proto-loader": "^0.6.13",
|
||||||
"@nestjs/common": "^8.4.7",
|
"@nestjs/common": "^8.4.7",
|
||||||
@@ -1726,9 +1726,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@dadosfera/protospack-v2": {
|
"node_modules/@dadosfera/protospack-v2": {
|
||||||
"version": "3.18.7",
|
"version": "3.18.8",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.18.7.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.18.8.tgz",
|
||||||
"integrity": "sha512-MloW230CUyK+g+HFkSv1OuaJNT5mfEGRh7tpZjjKxO2Qxm4eKkmI9uh/cNXCDzUpRBFXzBJ+5w12bxw2UnMRSw==",
|
"integrity": "sha512-pzvuIzCrIf/ZG//lwMdCxtZ7w/ZhiLFBA3VWyN9uM7AjeqVl7LllHKV08Fw6YjNNGBmQF3DLJQTK8kMCQja4hA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@grpc/grpc-js": "^1.6.7",
|
"@grpc/grpc-js": "^1.6.7",
|
||||||
"rxjs": "^7.5.5",
|
"rxjs": "^7.5.5",
|
||||||
@@ -12306,9 +12306,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@dadosfera/protospack-v2": {
|
"@dadosfera/protospack-v2": {
|
||||||
"version": "3.18.7",
|
"version": "3.18.8",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.18.7.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.18.8.tgz",
|
||||||
"integrity": "sha512-MloW230CUyK+g+HFkSv1OuaJNT5mfEGRh7tpZjjKxO2Qxm4eKkmI9uh/cNXCDzUpRBFXzBJ+5w12bxw2UnMRSw==",
|
"integrity": "sha512-pzvuIzCrIf/ZG//lwMdCxtZ7w/ZhiLFBA3VWyN9uM7AjeqVl7LllHKV08Fw6YjNNGBmQF3DLJQTK8kMCQja4hA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@grpc/grpc-js": "^1.6.7",
|
"@grpc/grpc-js": "^1.6.7",
|
||||||
"rxjs": "^7.5.5",
|
"rxjs": "^7.5.5",
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-secrets-manager": "^3.112.0",
|
"@aws-sdk/client-secrets-manager": "^3.112.0",
|
||||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
||||||
"@dadosfera/protospack-v2": "3.18.7",
|
"@dadosfera/protospack-v2": "3.18.8",
|
||||||
"@grpc/grpc-js": "^1.6.7",
|
"@grpc/grpc-js": "^1.6.7",
|
||||||
"@grpc/proto-loader": "^0.6.13",
|
"@grpc/proto-loader": "^0.6.13",
|
||||||
"@nestjs/common": "^8.4.7",
|
"@nestjs/common": "^8.4.7",
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import { HealthModule } from './modules/health/health.module';
|
|||||||
import { CatalogModule } from './modules/catalog/catalog.module';
|
import { CatalogModule } from './modules/catalog/catalog.module';
|
||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
import { PipelinesV2Module } from './modules/pipelinesV2/pipelines.module';
|
import { PipelinesV2Module } from './modules/pipelinesV2/pipelines.module';
|
||||||
|
import { ProductboardModule } from './modules/productboard/productboard.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
controllers: [],
|
controllers: [],
|
||||||
@@ -54,6 +55,7 @@ import { PipelinesV2Module } from './modules/pipelinesV2/pipelines.module';
|
|||||||
OauthModule,
|
OauthModule,
|
||||||
PipelinesV2Module,
|
PipelinesV2Module,
|
||||||
CatalogModule,
|
CatalogModule,
|
||||||
|
ProductboardModule,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
@@ -325,6 +325,16 @@ export const PERMISSIONS_GROUPS = {
|
|||||||
'es-es': 'Eliminar atributos',
|
'es-es': 'Eliminar atributos',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
DATA_MANAGER: {
|
||||||
|
seqid: 42,
|
||||||
|
claim: 'catalog:data_manager',
|
||||||
|
usage: PermissionUsages.PUBLIC,
|
||||||
|
name: {
|
||||||
|
'pt-br': 'Vizualizar todos os recursos do catálogo.',
|
||||||
|
'en-us': 'View all data assets.',
|
||||||
|
'es-es': 'Ver todos los activos de datos',
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ import {
|
|||||||
Body,
|
Body,
|
||||||
Controller,
|
Controller,
|
||||||
Delete,
|
Delete,
|
||||||
|
ForbiddenException,
|
||||||
Get,
|
Get,
|
||||||
|
HttpException,
|
||||||
Inject,
|
Inject,
|
||||||
Param,
|
Param,
|
||||||
Post,
|
Post,
|
||||||
@@ -10,7 +12,10 @@ import {
|
|||||||
Query,
|
Query,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import { AuthenticateCondition } from '../../authentication/authentication.decorator';
|
import {
|
||||||
|
AuthenticateCondition,
|
||||||
|
Authenticated,
|
||||||
|
} from '../../authentication/authentication.decorator';
|
||||||
import { PERMISSIONS_GROUPS } from '../../authentication/permissions.enum';
|
import { PERMISSIONS_GROUPS } from '../../authentication/permissions.enum';
|
||||||
import { CatalogService } from './catalog.service';
|
import { CatalogService } from './catalog.service';
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
@@ -19,7 +24,9 @@ import { RequestUser, User } from 'src/authentication/user.decorator';
|
|||||||
|
|
||||||
@ApiTags('Catalog')
|
@ApiTags('Catalog')
|
||||||
@Controller('catalog')
|
@Controller('catalog')
|
||||||
|
@Authenticated()
|
||||||
@AuthenticateCondition((req, user) => {
|
@AuthenticateCondition((req, user) => {
|
||||||
|
if (req.path.includes('/manage_permissions/')) return true;
|
||||||
let action;
|
let action;
|
||||||
|
|
||||||
switch (req.method) {
|
switch (req.method) {
|
||||||
@@ -93,12 +100,16 @@ export class CatalogController {
|
|||||||
|
|
||||||
@Get('all')
|
@Get('all')
|
||||||
async catalogAll(@User() user: RequestUser, @Body() body, @Query() params) {
|
async catalogAll(@User() user: RequestUser, @Body() body, @Query() params) {
|
||||||
const { user_id, customer_name, customer_id, username } = user;
|
const { user_id, customer_name, customer_id, username, permissions } = user;
|
||||||
this.logger.info(`/catalog - ON CATALOG ALL ROUTE`, {
|
this.logger.info(`/catalog - ON CATALOG ALL ROUTE`, {
|
||||||
user: body.info.user_id,
|
user: body.info.user_id,
|
||||||
customer: body.info.customer,
|
customer: body.info.customer,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const is_data_manager = permissions.includes(
|
||||||
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER.seqid,
|
||||||
|
);
|
||||||
|
|
||||||
const roles = await this.catalogService.getUserRolesIds(user_id);
|
const roles = await this.catalogService.getUserRolesIds(user_id);
|
||||||
|
|
||||||
const metadata = PackTheMetadata({
|
const metadata = PackTheMetadata({
|
||||||
@@ -107,11 +118,13 @@ export class CatalogController {
|
|||||||
customer_name,
|
customer_name,
|
||||||
username,
|
username,
|
||||||
roles,
|
roles,
|
||||||
|
is_data_manager,
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = await this.catalogService.getAllOpenSearchDataAssets(
|
const res = await this.catalogService.getAllOpenSearchDataAssets(
|
||||||
params,
|
params,
|
||||||
metadata,
|
metadata,
|
||||||
|
customer_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
return res.data_assets;
|
return res.data_assets;
|
||||||
@@ -166,7 +179,11 @@ export class CatalogController {
|
|||||||
customer: body.info.customer,
|
customer: body.info.customer,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { username, user_id, customer_id, customer_name } = user;
|
const { username, user_id, customer_id, customer_name, permissions } = user;
|
||||||
|
const is_data_manager = permissions.includes(
|
||||||
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER.seqid,
|
||||||
|
);
|
||||||
|
let has_permission = false;
|
||||||
const metadata = PackTheMetadata({
|
const metadata = PackTheMetadata({
|
||||||
username,
|
username,
|
||||||
user_id,
|
user_id,
|
||||||
@@ -174,13 +191,35 @@ export class CatalogController {
|
|||||||
customer_name,
|
customer_name,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const user_roles = await this.catalogService.getUserRolesIds(user_id);
|
||||||
|
|
||||||
const res = await this.catalogService.getOneDashboardMetabase(
|
const res = await this.catalogService.getOneDashboardMetabase(
|
||||||
id,
|
id,
|
||||||
body,
|
body,
|
||||||
metadata,
|
metadata,
|
||||||
|
customer_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
return res;
|
const dashboard = res.dashboard;
|
||||||
|
|
||||||
|
if (dashboard.owner === username) has_permission = true;
|
||||||
|
|
||||||
|
for (const role of user_roles) {
|
||||||
|
if (dashboard.p_roles.includes(role)) has_permission = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dashboard.p_users.includes(user_id)) has_permission = true;
|
||||||
|
|
||||||
|
if (is_data_manager || has_permission) {
|
||||||
|
delete dashboard.p_roles;
|
||||||
|
delete dashboard.p_users;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new HttpException(
|
||||||
|
'You do not have permission to access this data asset.',
|
||||||
|
403,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('table-metadata')
|
@Get('table-metadata')
|
||||||
@@ -193,7 +232,11 @@ export class CatalogController {
|
|||||||
user: user.user_id,
|
user: user.user_id,
|
||||||
customer: user.customer_name,
|
customer: user.customer_name,
|
||||||
});
|
});
|
||||||
const { user_id, customer_name, customer_id } = user;
|
const { user_id, customer_name, customer_id, permissions, username } = user;
|
||||||
|
const is_data_manager = permissions.includes(
|
||||||
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER.seqid,
|
||||||
|
);
|
||||||
|
let has_permission = false;
|
||||||
const metadata = PackTheMetadata({
|
const metadata = PackTheMetadata({
|
||||||
user_id,
|
user_id,
|
||||||
customer_id,
|
customer_id,
|
||||||
@@ -204,12 +247,32 @@ export class CatalogController {
|
|||||||
const res = await this.catalogService.getAllTableMetadata(body);
|
const res = await this.catalogService.getAllTableMetadata(body);
|
||||||
return res;
|
return res;
|
||||||
} else {
|
} else {
|
||||||
|
const user_roles = await this.catalogService.getUserRolesIds(user_id);
|
||||||
const res = await this.catalogService.getOneTableMetadata(
|
const res = await this.catalogService.getOneTableMetadata(
|
||||||
body,
|
body,
|
||||||
query,
|
query,
|
||||||
metadata,
|
metadata,
|
||||||
|
customer_id,
|
||||||
|
);
|
||||||
|
const table = res[0];
|
||||||
|
|
||||||
|
if (table.owner === username) has_permission = true;
|
||||||
|
|
||||||
|
for (const role of user_roles) {
|
||||||
|
if (table.p_roles.includes(role)) has_permission = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (table.p_users.includes(user_id)) has_permission = true;
|
||||||
|
|
||||||
|
if (is_data_manager || has_permission) {
|
||||||
|
delete table.p_roles;
|
||||||
|
delete table.p_users;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ForbiddenException(
|
||||||
|
'You do not have permission to access this data asset.',
|
||||||
);
|
);
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { CatalogClientConfiguration } from './catalog-client';
|
|||||||
import { ClientsModule } from '@nestjs/microservices';
|
import { ClientsModule } from '@nestjs/microservices';
|
||||||
import { PipelinesModule as OldPipelineModule } from 'src/modules/pipelines/pipelines.module';
|
import { PipelinesModule as OldPipelineModule } from 'src/modules/pipelines/pipelines.module';
|
||||||
import { UsersModule } from '../users/users.module';
|
import { UsersModule } from '../users/users.module';
|
||||||
|
import { RolesModule } from '../roles/roles.module';
|
||||||
|
|
||||||
const client = new CatalogClientConfiguration();
|
const client = new CatalogClientConfiguration();
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ const client = new CatalogClientConfiguration();
|
|||||||
ClientsModule.register([client.providerOptions]),
|
ClientsModule.register([client.providerOptions]),
|
||||||
OldPipelineModule,
|
OldPipelineModule,
|
||||||
UsersModule,
|
UsersModule,
|
||||||
|
RolesModule,
|
||||||
],
|
],
|
||||||
controllers: [CatalogController],
|
controllers: [CatalogController],
|
||||||
providers: [CatalogService, DadosferaLogger],
|
providers: [CatalogService, DadosferaLogger],
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import axios from 'axios';
|
|||||||
import { lastValueFrom } from 'rxjs';
|
import { lastValueFrom } from 'rxjs';
|
||||||
import { CatalogClientConfiguration } from './catalog-client';
|
import { CatalogClientConfiguration } from './catalog-client';
|
||||||
import { UsersService } from '../users/users.service';
|
import { UsersService } from '../users/users.service';
|
||||||
|
import { RolesService } from '../roles/roles.service';
|
||||||
|
|
||||||
class CatalogService implements OnModuleInit {
|
class CatalogService implements OnModuleInit {
|
||||||
catalogReadService: ReadService.CatalogReadServices;
|
catalogReadService: ReadService.CatalogReadServices;
|
||||||
@@ -25,6 +26,7 @@ class CatalogService implements OnModuleInit {
|
|||||||
@Inject(CatalogClientConfiguration.name)
|
@Inject(CatalogClientConfiguration.name)
|
||||||
private readonly grpcClient: ClientGrpc,
|
private readonly grpcClient: ClientGrpc,
|
||||||
private readonly userService: UsersService,
|
private readonly userService: UsersService,
|
||||||
|
private readonly roleService: RolesService,
|
||||||
) {
|
) {
|
||||||
this.logger = dadosferaLogger.logger;
|
this.logger = dadosferaLogger.logger;
|
||||||
}
|
}
|
||||||
@@ -117,25 +119,86 @@ class CatalogService implements OnModuleInit {
|
|||||||
return roles_ids;
|
return roles_ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getUsernamesAndRolesByCustomerId(customerId: string) {
|
||||||
|
const resultUsers = await this.userService.findAllUsersByCustomerId(
|
||||||
|
customerId,
|
||||||
|
);
|
||||||
|
const resultRoles = await this.roleService.roleSearch(
|
||||||
|
{},
|
||||||
|
{ customer_id: customerId },
|
||||||
|
);
|
||||||
|
|
||||||
|
const customer_users = resultUsers.users.map((user) => {
|
||||||
|
return {
|
||||||
|
id: user.id,
|
||||||
|
username: user.username,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const customer_roles = resultRoles.roles.map((role) => {
|
||||||
|
return {
|
||||||
|
id: role.id,
|
||||||
|
name: role.name,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return [customer_users, customer_roles];
|
||||||
|
}
|
||||||
|
|
||||||
async getAllOpenSearchDataAssets(
|
async getAllOpenSearchDataAssets(
|
||||||
data: Messages.GetAllDataAssetsRequest,
|
data: Messages.GetAllDataAssetsRequest,
|
||||||
metadata,
|
metadata,
|
||||||
|
customer_id,
|
||||||
) {
|
) {
|
||||||
this.logger.info('CatalogService - getAllOpenSearchDashboard');
|
this.logger.info('CatalogService - getAllOpenSearchDashboard');
|
||||||
|
|
||||||
const response = await lastValueFrom(
|
const response = await lastValueFrom(
|
||||||
this.catalogReadService.GetAllDataAssets(data, metadata),
|
this.catalogReadService.GetAllDataAssets(data, metadata),
|
||||||
)
|
).catch((err) => {
|
||||||
.then((res) => {
|
throw new HttpException(
|
||||||
this.logger.info('Done');
|
err.details,
|
||||||
return JSON.parse(res.data_assets);
|
err.code === 6 ? HttpStatus.CONFLICT : 404,
|
||||||
})
|
);
|
||||||
.catch((err) => {
|
});
|
||||||
this.logger.error(err.message);
|
|
||||||
throw new Error(err);
|
const data_assets = JSON.parse(response.data_assets);
|
||||||
|
|
||||||
|
const [customer_users, customer_roles] =
|
||||||
|
await this.getUsernamesAndRolesByCustomerId(customer_id);
|
||||||
|
|
||||||
|
for (const asset of data_assets.tables) {
|
||||||
|
const condition =
|
||||||
|
asset.owner && !asset.owner.includes('@') ? true : false;
|
||||||
|
const result = condition
|
||||||
|
? await this.userService.findOneById(asset.owner).catch(() => null)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const owner = result !== null ? result.user.username : null;
|
||||||
|
|
||||||
|
const roles = [];
|
||||||
|
const users = [];
|
||||||
|
|
||||||
|
for (const role of customer_roles) {
|
||||||
|
for (const role_id of asset.roles) {
|
||||||
|
if (role.id === role_id) roles.push(role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const user of customer_users) {
|
||||||
|
for (const user_id of asset.users) {
|
||||||
|
if (user.id === user_id) users.push(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.assign(asset, {
|
||||||
|
...asset,
|
||||||
|
owner,
|
||||||
|
roles,
|
||||||
|
users,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
for (const asset of response.tables) {
|
for (const asset of data_assets.dashboards) {
|
||||||
const condition =
|
const condition =
|
||||||
asset.owner && !asset.owner.includes('@') ? true : false;
|
asset.owner && !asset.owner.includes('@') ? true : false;
|
||||||
const result = condition
|
const result = condition
|
||||||
@@ -147,22 +210,10 @@ class CatalogService implements OnModuleInit {
|
|||||||
Object.assign(asset, { ...asset, owner });
|
Object.assign(asset, { ...asset, owner });
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const asset of response.dashboards) {
|
return { data_assets };
|
||||||
const condition =
|
|
||||||
asset.owner && !asset.owner.includes('@') ? true : false;
|
|
||||||
const result = condition
|
|
||||||
? await this.userService.findOneById(asset.owner).catch(() => null)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
const owner = result !== null ? result.user.username : null;
|
|
||||||
|
|
||||||
Object.assign(asset, { ...asset, owner });
|
|
||||||
}
|
|
||||||
|
|
||||||
return { data_assets: response };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOneDashboardMetabase(id, body, metadata) {
|
async getOneDashboardMetabase(id, body, metadata, customer_id) {
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
const nimbusUrl = this._getNimbusUrl(body);
|
||||||
const { data } = await axios.get(
|
const { data } = await axios.get(
|
||||||
`${nimbusUrl}/api/catalog/dashboard-metabase/${id}`,
|
`${nimbusUrl}/api/catalog/dashboard-metabase/${id}`,
|
||||||
@@ -176,7 +227,7 @@ class CatalogService implements OnModuleInit {
|
|||||||
);
|
);
|
||||||
const opensearchTable = JSON.parse(data_asset);
|
const opensearchTable = JSON.parse(data_asset);
|
||||||
|
|
||||||
const result = opensearchTable.user_id
|
const result = opensearchTable.owner
|
||||||
? await this.userService
|
? await this.userService
|
||||||
.findOneById(opensearchTable.owner)
|
.findOneById(opensearchTable.owner)
|
||||||
.catch(() => null)
|
.catch(() => null)
|
||||||
@@ -184,12 +235,35 @@ class CatalogService implements OnModuleInit {
|
|||||||
|
|
||||||
const owner = result !== null ? result.user.username : null;
|
const owner = result !== null ? result.user.username : null;
|
||||||
|
|
||||||
return {
|
const [customer_users, customer_roles] =
|
||||||
...data,
|
await this.getUsernamesAndRolesByCustomerId(customer_id);
|
||||||
|
|
||||||
|
const users = [];
|
||||||
|
const roles = [];
|
||||||
|
|
||||||
|
for (const role of customer_roles) {
|
||||||
|
for (const role_id of opensearchTable.roles) {
|
||||||
|
if (role.id === role_id) roles.push(role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const user of customer_users) {
|
||||||
|
for (const user_id of opensearchTable.users) {
|
||||||
|
if (user.id === user_id) users.push(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.assign(data.dashboard, {
|
||||||
tags: opensearchTable.tags,
|
tags: opensearchTable.tags,
|
||||||
description: opensearchTable.description || null,
|
description: opensearchTable.description || null,
|
||||||
|
p_roles: opensearchTable.roles,
|
||||||
|
p_users: opensearchTable.users,
|
||||||
|
roles,
|
||||||
|
users,
|
||||||
owner,
|
owner,
|
||||||
};
|
});
|
||||||
|
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAllTableMetadata(body) {
|
async getAllTableMetadata(body) {
|
||||||
@@ -200,7 +274,7 @@ class CatalogService implements OnModuleInit {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOneTableMetadata(body, params, metadata) {
|
async getOneTableMetadata(body, params, metadata, customer_id) {
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
const nimbusUrl = this._getNimbusUrl(body);
|
||||||
const { data } = await axios.get(
|
const { data } = await axios.get(
|
||||||
`${nimbusUrl}/api/catalog/table-metadata/`,
|
`${nimbusUrl}/api/catalog/table-metadata/`,
|
||||||
@@ -214,7 +288,7 @@ class CatalogService implements OnModuleInit {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
const opensearchTable = JSON.parse(data_asset);
|
const opensearchTable = JSON.parse(data_asset);
|
||||||
const result = opensearchTable.user_id
|
const result = opensearchTable.owner
|
||||||
? await this.userService
|
? await this.userService
|
||||||
.findOneById(opensearchTable.owner)
|
.findOneById(opensearchTable.owner)
|
||||||
.catch(() => null)
|
.catch(() => null)
|
||||||
@@ -222,11 +296,33 @@ class CatalogService implements OnModuleInit {
|
|||||||
|
|
||||||
const owner = result !== null ? result.user.username : null;
|
const owner = result !== null ? result.user.username : null;
|
||||||
|
|
||||||
|
const [customer_users, customer_roles] =
|
||||||
|
await this.getUsernamesAndRolesByCustomerId(customer_id);
|
||||||
|
|
||||||
|
const users = [];
|
||||||
|
const roles = [];
|
||||||
|
|
||||||
|
for (const role of customer_roles) {
|
||||||
|
for (const role_id of opensearchTable.roles) {
|
||||||
|
if (role.id === role_id) roles.push(role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const user of customer_users) {
|
||||||
|
for (const user_id of opensearchTable.users) {
|
||||||
|
if (user.id === user_id) users.push(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
...data[0],
|
...data[0],
|
||||||
tags: opensearchTable.tags,
|
tags: opensearchTable.tags,
|
||||||
table_description: opensearchTable.description,
|
table_description: opensearchTable.description,
|
||||||
|
p_roles: opensearchTable.roles,
|
||||||
|
p_users: opensearchTable.users,
|
||||||
|
users,
|
||||||
|
roles,
|
||||||
owner,
|
owner,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -19,17 +19,18 @@ import { RequestUser, User } from 'src/authentication/user.decorator';
|
|||||||
import {
|
import {
|
||||||
CreateNetworkConfigReq,
|
CreateNetworkConfigReq,
|
||||||
CreateNetworkConfigRes,
|
CreateNetworkConfigRes,
|
||||||
DeleteNetworkConfigRes,
|
|
||||||
FindAllNetworkConfigsRes,
|
FindAllNetworkConfigsRes,
|
||||||
UpdateNetworkConfigReq,
|
|
||||||
UpdateNetworkConfigRes,
|
|
||||||
} from './dto/network-config';
|
} from './dto/network-config';
|
||||||
import { FileInterceptor } from '@nestjs/platform-express';
|
import { FileInterceptor } from '@nestjs/platform-express';
|
||||||
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
||||||
import { RequireAllPermissions } from 'src/authentication/authentication.decorator';
|
import {
|
||||||
|
Authenticated,
|
||||||
|
RequireAllPermissions,
|
||||||
|
} from 'src/authentication/authentication.decorator';
|
||||||
|
|
||||||
const networkConfigPermissions = PERMISSIONS_GROUPS.NETWORK_CONFIG.permissions;
|
const networkConfigPermissions = PERMISSIONS_GROUPS.NETWORK_CONFIG.permissions;
|
||||||
@ApiTags('Network Config')
|
@ApiTags('Network Config')
|
||||||
|
@Authenticated()
|
||||||
@Controller('network-config')
|
@Controller('network-config')
|
||||||
export class NetworkConfigController {
|
export class NetworkConfigController {
|
||||||
logger: any;
|
logger: any;
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import { ConnectionClientService } from '../connection/client.service';
|
|||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
import DadosferaLogger from '@dadosfera/dadosfera-logs/dist';
|
import DadosferaLogger from '@dadosfera/dadosfera-logs/dist';
|
||||||
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
|
import { Authenticated } from 'src/authentication/authentication.decorator';
|
||||||
@ApiTags('oauth')
|
@ApiTags('oauth')
|
||||||
|
@Authenticated()
|
||||||
@Controller('oauth')
|
@Controller('oauth')
|
||||||
export class OauthController {
|
export class OauthController {
|
||||||
redirectUrl: string;
|
redirectUrl: string;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { GetPublicPermissionsRes } from './dto/entities';
|
|||||||
import { PermissionsService } from './permissions.service';
|
import { PermissionsService } from './permissions.service';
|
||||||
|
|
||||||
@ApiTags('Permissions')
|
@ApiTags('Permissions')
|
||||||
|
@Authenticated()
|
||||||
@Controller('permissions')
|
@Controller('permissions')
|
||||||
@ApiHeader({
|
@ApiHeader({
|
||||||
name: 'dadosfera-lang',
|
name: 'dadosfera-lang',
|
||||||
@@ -22,7 +23,6 @@ import { PermissionsService } from './permissions.service';
|
|||||||
required: false,
|
required: false,
|
||||||
description: 'Defaults to pt-br',
|
description: 'Defaults to pt-br',
|
||||||
})
|
})
|
||||||
@Authenticated()
|
|
||||||
export class PermissionsController {
|
export class PermissionsController {
|
||||||
logger: DadosferaLogger;
|
logger: DadosferaLogger;
|
||||||
|
|
||||||
@@ -36,7 +36,6 @@ export class PermissionsController {
|
|||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@ApiOkResponse({ type: GetPublicPermissionsRes })
|
@ApiOkResponse({ type: GetPublicPermissionsRes })
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
|
||||||
getPublicPermissions(
|
getPublicPermissions(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Headers('dadosfera-lang') language,
|
@Headers('dadosfera-lang') language,
|
||||||
|
|||||||
@@ -9,7 +9,10 @@ import {
|
|||||||
Put,
|
Put,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import { AuthenticateCondition } from 'src/authentication/authentication.decorator';
|
import {
|
||||||
|
AuthenticateCondition,
|
||||||
|
Authenticated,
|
||||||
|
} from 'src/authentication/authentication.decorator';
|
||||||
import { PERMISSIONS_GROUPS } from '../../authentication/permissions.enum';
|
import { PERMISSIONS_GROUPS } from '../../authentication/permissions.enum';
|
||||||
import { PipelinesService } from './pipelines.service';
|
import { PipelinesService } from './pipelines.service';
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
@@ -17,6 +20,7 @@ import { RequestUser, User } from 'src/authentication/user.decorator';
|
|||||||
|
|
||||||
@ApiTags('Pipelines')
|
@ApiTags('Pipelines')
|
||||||
@Controller('pipelines')
|
@Controller('pipelines')
|
||||||
|
@Authenticated()
|
||||||
@AuthenticateCondition((req, user) => {
|
@AuthenticateCondition((req, user) => {
|
||||||
let action;
|
let action;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
export class INote {
|
||||||
|
@ApiProperty()
|
||||||
|
title: string;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
content: string;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
tags: string[];
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { ProductboardController } from './productboard.controller';
|
||||||
|
|
||||||
|
describe('ProductboardController', () => {
|
||||||
|
let controller: ProductboardController;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
controllers: [ProductboardController],
|
||||||
|
providers: [],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
controller = module.get<ProductboardController>(ProductboardController);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(controller).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import { Body, Controller, HttpException, Post } from '@nestjs/common';
|
||||||
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
|
import axios from 'axios';
|
||||||
|
import { User, RequestUser } from 'src/authentication/user.decorator';
|
||||||
|
import { getSecreteFromSecreteManager } from 'src/utils/SecretManager';
|
||||||
|
import { INote } from './dtos';
|
||||||
|
|
||||||
|
@ApiTags('Productboard')
|
||||||
|
@Controller('productboard')
|
||||||
|
export class ProductboardController {
|
||||||
|
@Post('notes')
|
||||||
|
async sendNote(@Body() note: INote, @User() user: RequestUser) {
|
||||||
|
const { title, content, tags } = note;
|
||||||
|
const { username, customer_name } = user;
|
||||||
|
|
||||||
|
const email = username.includes('@')
|
||||||
|
? username
|
||||||
|
: username + `@${customer_name}.default`;
|
||||||
|
|
||||||
|
const path = process.env.PB_TOKEN_PATH;
|
||||||
|
const token = await getSecreteFromSecreteManager(path);
|
||||||
|
|
||||||
|
const response = await axios
|
||||||
|
.post(
|
||||||
|
`https://api.productboard.com/notes`,
|
||||||
|
{
|
||||||
|
title,
|
||||||
|
content,
|
||||||
|
tags,
|
||||||
|
user: {
|
||||||
|
email,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: 'Bearer ' + token,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.catch(() => null);
|
||||||
|
|
||||||
|
if (!response) {
|
||||||
|
throw new HttpException(
|
||||||
|
'Your request could not be submitted, please try again in a few moments or contact support.',
|
||||||
|
502,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { ProductboardController } from './productboard.controller';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
controllers: [ProductboardController],
|
||||||
|
providers: [],
|
||||||
|
})
|
||||||
|
export class ProductboardModule {}
|
||||||
@@ -36,9 +36,9 @@ export enum TrueOrFalseEnum {
|
|||||||
}
|
}
|
||||||
export class GetRolesByCustomerReq {
|
export class GetRolesByCustomerReq {
|
||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
permissionId: string[];
|
permissionId?: string[];
|
||||||
@ApiPropertyOptional({ enum: TrueOrFalseEnum })
|
@ApiPropertyOptional({ enum: TrueOrFalseEnum })
|
||||||
getUsers: TrueOrFalseEnum;
|
getUsers?: TrueOrFalseEnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GetRolesByCustomerRes {
|
export class GetRolesByCustomerRes {
|
||||||
|
|||||||
@@ -53,8 +53,8 @@ import { LanguageEnum } from 'src/utils/languages.enum';
|
|||||||
required: false,
|
required: false,
|
||||||
description: 'Defaults to pt-br',
|
description: 'Defaults to pt-br',
|
||||||
})
|
})
|
||||||
@UseFilters(new GrpcToHttpExceptionFilter())
|
|
||||||
@Authenticated()
|
@Authenticated()
|
||||||
|
@UseFilters(new GrpcToHttpExceptionFilter())
|
||||||
@Controller('roles')
|
@Controller('roles')
|
||||||
export class RolesController {
|
export class RolesController {
|
||||||
logger: DadosferaLogger;
|
logger: DadosferaLogger;
|
||||||
@@ -69,7 +69,6 @@ export class RolesController {
|
|||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@ApiOkResponse({ type: GetRolesByCustomerRes })
|
@ApiOkResponse({ type: GetRolesByCustomerRes })
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
|
||||||
async searchRoles(
|
async searchRoles(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Query() filters: GetRolesByCustomerReq,
|
@Query() filters: GetRolesByCustomerReq,
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export class RolesService {
|
|||||||
|
|
||||||
async roleSearch(
|
async roleSearch(
|
||||||
filters: GetRolesByCustomerReq,
|
filters: GetRolesByCustomerReq,
|
||||||
{ customer_id, access_token }: RequestUser,
|
{ customer_id, access_token }: any,
|
||||||
) {
|
) {
|
||||||
const meta = new Metadata();
|
const meta = new Metadata();
|
||||||
meta.add('access_token', access_token);
|
meta.add('access_token', access_token);
|
||||||
|
|||||||
@@ -21,7 +21,10 @@ import {
|
|||||||
ApiTags,
|
ApiTags,
|
||||||
} from '@nestjs/swagger';
|
} from '@nestjs/swagger';
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
import { RequireAllPermissions } from 'src/authentication/authentication.decorator';
|
import {
|
||||||
|
Authenticated,
|
||||||
|
RequireAllPermissions,
|
||||||
|
} from 'src/authentication/authentication.decorator';
|
||||||
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
||||||
import { RequestUser, User } from 'src/authentication/user.decorator';
|
import { RequestUser, User } from 'src/authentication/user.decorator';
|
||||||
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
||||||
@@ -56,6 +59,7 @@ import { Metadata } from '@grpc/grpc-js';
|
|||||||
required: false,
|
required: false,
|
||||||
description: 'Defaults to pt-br',
|
description: 'Defaults to pt-br',
|
||||||
})
|
})
|
||||||
|
@Authenticated()
|
||||||
@UseFilters(GrpcToHttpExceptionFilter)
|
@UseFilters(GrpcToHttpExceptionFilter)
|
||||||
export class UsersController {
|
export class UsersController {
|
||||||
logger: DadosferaLogger;
|
logger: DadosferaLogger;
|
||||||
@@ -69,7 +73,6 @@ export class UsersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
|
||||||
@ApiOkResponse({
|
@ApiOkResponse({
|
||||||
type: GetAllUsersByCustomerIdRes,
|
type: GetAllUsersByCustomerIdRes,
|
||||||
description: 'List of users of a customer',
|
description: 'List of users of a customer',
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ interface IMetadata {
|
|||||||
language?: string;
|
language?: string;
|
||||||
details?: string;
|
details?: string;
|
||||||
roles?: string[];
|
roles?: string[];
|
||||||
|
is_data_manager?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PackTheMetadata(info: IMetadata): Metadata {
|
export function PackTheMetadata(info: IMetadata): Metadata {
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import {
|
||||||
|
SecretsManagerClient,
|
||||||
|
GetSecretValueCommand,
|
||||||
|
} from '@aws-sdk/client-secrets-manager';
|
||||||
|
|
||||||
|
export async function getSecreteFromSecreteManager(path: string) {
|
||||||
|
const secretsManagerClient = new SecretsManagerClient({});
|
||||||
|
|
||||||
|
const getSecretComand = new GetSecretValueCommand({
|
||||||
|
SecretId: `${path}`,
|
||||||
|
});
|
||||||
|
const res = await secretsManagerClient
|
||||||
|
.send(getSecretComand)
|
||||||
|
.catch(() => null);
|
||||||
|
|
||||||
|
return res?.SecretString;
|
||||||
|
}
|
||||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user