mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-25 08:50:05 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e4b27c5f76 | ||
|
|
92e449d6d3 | ||
|
|
5073b2e188 | ||
|
|
8a11eda24d | ||
|
|
9d732d4a48 | ||
|
|
5fa10a939b | ||
|
|
4be3ffe3a2 | ||
|
|
8af9c638ef | ||
|
|
97d6f914cc | ||
|
|
9ad2e3770e | ||
|
|
ea2cc8809f | ||
|
|
410e190e7c | ||
|
|
c1b213c34c | ||
|
|
a6c58eb82d | ||
|
|
b756cb5a1e | ||
|
|
46cafc2d50 |
@@ -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 {}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import {
|
|||||||
Body,
|
Body,
|
||||||
Controller,
|
Controller,
|
||||||
Delete,
|
Delete,
|
||||||
|
ForbiddenException,
|
||||||
Get,
|
Get,
|
||||||
HttpException,
|
HttpException,
|
||||||
Inject,
|
Inject,
|
||||||
@@ -11,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';
|
||||||
@@ -20,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) {
|
||||||
@@ -196,6 +202,8 @@ export class CatalogController {
|
|||||||
|
|
||||||
const dashboard = res.dashboard;
|
const dashboard = res.dashboard;
|
||||||
|
|
||||||
|
if (dashboard.owner === username) has_permission = true;
|
||||||
|
|
||||||
for (const role of user_roles) {
|
for (const role of user_roles) {
|
||||||
if (dashboard.p_roles.includes(role)) has_permission = true;
|
if (dashboard.p_roles.includes(role)) has_permission = true;
|
||||||
}
|
}
|
||||||
@@ -203,8 +211,8 @@ export class CatalogController {
|
|||||||
if (dashboard.p_users.includes(user_id)) has_permission = true;
|
if (dashboard.p_users.includes(user_id)) has_permission = true;
|
||||||
|
|
||||||
if (is_data_manager || has_permission) {
|
if (is_data_manager || has_permission) {
|
||||||
delete res[0].p_roles;
|
delete dashboard.p_roles;
|
||||||
delete res[0].p_users;
|
delete dashboard.p_users;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +232,7 @@ 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, permissions } = user;
|
const { user_id, customer_name, customer_id, permissions, username } = user;
|
||||||
const is_data_manager = permissions.includes(
|
const is_data_manager = permissions.includes(
|
||||||
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER.seqid,
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER.seqid,
|
||||||
);
|
);
|
||||||
@@ -248,6 +256,8 @@ export class CatalogController {
|
|||||||
);
|
);
|
||||||
const table = res[0];
|
const table = res[0];
|
||||||
|
|
||||||
|
if (table.owner === username) has_permission = true;
|
||||||
|
|
||||||
for (const role of user_roles) {
|
for (const role of user_roles) {
|
||||||
if (table.p_roles.includes(role)) has_permission = true;
|
if (table.p_roles.includes(role)) has_permission = true;
|
||||||
}
|
}
|
||||||
@@ -255,14 +265,13 @@ export class CatalogController {
|
|||||||
if (table.p_users.includes(user_id)) has_permission = true;
|
if (table.p_users.includes(user_id)) has_permission = true;
|
||||||
|
|
||||||
if (is_data_manager || has_permission) {
|
if (is_data_manager || has_permission) {
|
||||||
delete res[0].p_roles;
|
delete table.p_roles;
|
||||||
delete res[0].p_users;
|
delete table.p_users;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new HttpException(
|
throw new ForbiddenException(
|
||||||
'You do not have permission to access this data asset.',
|
'You do not have permission to access this data asset.',
|
||||||
403,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -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 {}
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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