mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-14 16:39:08 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3550255c4 |
+335
-689
File diff suppressed because it is too large
Load Diff
Vendored
-1
@@ -14,7 +14,6 @@ declare global {
|
|||||||
AWS_REGION: string;
|
AWS_REGION: string;
|
||||||
OPEN_GROUP_ID: string;
|
OPEN_GROUP_ID: string;
|
||||||
OPEN_CUSTOMER_ID: string;
|
OPEN_CUSTOMER_ID: string;
|
||||||
DEDICATED_PROXY: string;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,31 +8,6 @@ charts:
|
|||||||
value: duc.stg.dadosfera.ai
|
value: duc.stg.dadosfera.ai
|
||||||
- name: hostname
|
- name: hostname
|
||||||
value: maestro.stg.dadosfera.ai
|
value: maestro.stg.dadosfera.ai
|
||||||
- name: maestro.pi_factory_url
|
|
||||||
value: pi-factory.stg.dadosfera.ai
|
|
||||||
- name: maestro.in_factory_url
|
|
||||||
value: in-factory.stg.dadosfera.ai
|
|
||||||
- name: maestro.tr_factory_url
|
|
||||||
value: in-factory.stg.dadosfera.ai
|
|
||||||
- name: maestro.open_customer_id
|
|
||||||
value: b3e3dfe5-b992-4586-a73c-c0b0c00f615d
|
|
||||||
- name: maestro.open_group_id
|
|
||||||
value: e3f98a2f-7748-4981-8505-7695c8ca8218
|
|
||||||
- name: replicaCount
|
|
||||||
value: 1
|
|
||||||
|
|
||||||
# Environment to test Network Policies
|
|
||||||
- name: private-maestro
|
|
||||||
chart: ../maestro
|
|
||||||
values:
|
|
||||||
- ../maestro/values.yaml
|
|
||||||
set:
|
|
||||||
- name: app_name
|
|
||||||
value: maestro-private
|
|
||||||
- name: maestro.duc_url
|
|
||||||
value: duc.stg.dadosfera.ai
|
|
||||||
- name: hostname
|
|
||||||
value: private-maestro.stg.dadosfera.ai
|
|
||||||
- name: maestro.pi_factory_url
|
- name: maestro.pi_factory_url
|
||||||
value: pi-factory.dadosfera.ai
|
value: pi-factory.dadosfera.ai
|
||||||
- name: maestro.in_factory_url
|
- name: maestro.in_factory_url
|
||||||
@@ -43,8 +18,5 @@ charts:
|
|||||||
value: b3e3dfe5-b992-4586-a73c-c0b0c00f615d
|
value: b3e3dfe5-b992-4586-a73c-c0b0c00f615d
|
||||||
- name: maestro.open_group_id
|
- name: maestro.open_group_id
|
||||||
value: e3f98a2f-7748-4981-8505-7695c8ca8218
|
value: e3f98a2f-7748-4981-8505-7695c8ca8218
|
||||||
# Customer id
|
|
||||||
- name: maestro.dedicated_proxy
|
|
||||||
value: 14d52fd4-d83d-4cdd-be34-bf11cc28b3bd
|
|
||||||
- name: replicaCount
|
- name: replicaCount
|
||||||
value: 1
|
value: 1
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
name: {{ .Values.app_name }}
|
name: maestro
|
||||||
namespace: applications
|
namespace: applications
|
||||||
labels:
|
labels:
|
||||||
app: {{ .Values.app_name }}
|
app: maestro
|
||||||
|
|
||||||
spec:
|
spec:
|
||||||
replicas: {{ .Values.replicaCount }}
|
replicas: {{ .Values.replicaCount }}
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
app: {{ .Values.app_name }}
|
app: maestro
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
rollingUpdate:
|
rollingUpdate:
|
||||||
@@ -20,7 +20,7 @@ spec:
|
|||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app: {{ .Values.app_name }}
|
app: maestro
|
||||||
|
|
||||||
spec:
|
spec:
|
||||||
imagePullSecrets:
|
imagePullSecrets:
|
||||||
@@ -100,8 +100,6 @@ spec:
|
|||||||
value: {{ .Values.maestro.open_customer_id }}
|
value: {{ .Values.maestro.open_customer_id }}
|
||||||
- name: OPEN_GROUP_ID
|
- name: OPEN_GROUP_ID
|
||||||
value: {{ .Values.maestro.open_group_id }}
|
value: {{ .Values.maestro.open_group_id }}
|
||||||
- name: DEDICATED_PROXY
|
|
||||||
value: {{ .Values.maestro.dedicated_proxy }}
|
|
||||||
- name: JWT_PRIVATE_KEY
|
- name: JWT_PRIVATE_KEY
|
||||||
valueFrom:
|
valueFrom:
|
||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
@@ -110,15 +108,15 @@ spec:
|
|||||||
- name: AWS_ACCESS_KEY_ID
|
- name: AWS_ACCESS_KEY_ID
|
||||||
valueFrom:
|
valueFrom:
|
||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
name: prd-{{ .Values.app_name }}
|
name: prd-maestro
|
||||||
key: AWS_ACCESS_KEY_ID
|
key: AWS_ACCESS_KEY_ID
|
||||||
- name: AWS_SECRET_ACCESS_KEY
|
- name: AWS_SECRET_ACCESS_KEY
|
||||||
valueFrom:
|
valueFrom:
|
||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
name: prd-{{ .Values.app_name }}
|
name: prd-maestro
|
||||||
key: AWS_SECRET_ACCESS_KEY
|
key: AWS_SECRET_ACCESS_KEY
|
||||||
- name: AWS_DEFAULT_REGION
|
- name: AWS_DEFAULT_REGION
|
||||||
valueFrom:
|
valueFrom:
|
||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
name: prd-{{ .Values.app_name }}
|
name: prd-maestro
|
||||||
key: AWS_DEFAULT_REGION
|
key: AWS_DEFAULT_REGION
|
||||||
|
|||||||
@@ -10,12 +10,8 @@ metadata:
|
|||||||
|
|
||||||
generation: 1
|
generation: 1
|
||||||
labels:
|
labels:
|
||||||
app: {{ .Values.app_name }}
|
app: maestro
|
||||||
{{- if .Values.maestro.dedicated_proxy}}
|
|
||||||
name: open-data-{{ .Values.app_name }}
|
|
||||||
{{- else }}
|
|
||||||
name: open-data
|
name: open-data
|
||||||
{{- end }}
|
|
||||||
namespace: applications
|
namespace: applications
|
||||||
spec:
|
spec:
|
||||||
ingressClassName: nginx
|
ingressClassName: nginx
|
||||||
@@ -25,7 +21,7 @@ spec:
|
|||||||
paths:
|
paths:
|
||||||
- backend:
|
- backend:
|
||||||
service:
|
service:
|
||||||
name: {{ .Values.app_name }}
|
name: maestro
|
||||||
port:
|
port:
|
||||||
number: {{ .Values.ingress.port }}
|
number: {{ .Values.ingress.port }}
|
||||||
path: /open-data/sharing-ocean-data
|
path: /open-data/sharing-ocean-data
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ metadata:
|
|||||||
|
|
||||||
generation: 1
|
generation: 1
|
||||||
labels:
|
labels:
|
||||||
app: {{ .Values.app_name }}
|
app: maestro
|
||||||
name: {{ .Values.app_name }}
|
name: maestro
|
||||||
namespace: applications
|
namespace: applications
|
||||||
spec:
|
spec:
|
||||||
ingressClassName: nginx
|
ingressClassName: nginx
|
||||||
@@ -20,7 +20,7 @@ spec:
|
|||||||
paths:
|
paths:
|
||||||
- backend:
|
- backend:
|
||||||
service:
|
service:
|
||||||
name: {{ .Values.app_name }}
|
name: maestro
|
||||||
port:
|
port:
|
||||||
number: {{ .Values.ingress.port }}
|
number: {{ .Values.ingress.port }}
|
||||||
path: /
|
path: /
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
apiVersion: external-secrets.io/v1beta1
|
apiVersion: external-secrets.io/v1beta1
|
||||||
kind: ExternalSecret
|
kind: ExternalSecret
|
||||||
metadata:
|
metadata:
|
||||||
name: prd-{{ .Values.app_name }}
|
name: prd-maestro
|
||||||
namespace: applications
|
namespace: applications
|
||||||
labels:
|
labels:
|
||||||
app: {{ .Values.app_name }}
|
app: maestro
|
||||||
spec:
|
spec:
|
||||||
refreshInterval: 1h
|
refreshInterval: 1h
|
||||||
secretStoreRef:
|
secretStoreRef:
|
||||||
name: secretsmanager-prd
|
name: secretsmanager-prd
|
||||||
kind: SecretStore
|
kind: SecretStore
|
||||||
target:
|
target:
|
||||||
name: prd-{{ .Values.app_name }}
|
name: prd-maestro
|
||||||
creationPolicy: Owner
|
creationPolicy: Owner
|
||||||
data:
|
data:
|
||||||
- secretKey: AWS_ACCESS_KEY_ID
|
- secretKey: AWS_ACCESS_KEY_ID
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Service
|
kind: Service
|
||||||
metadata:
|
metadata:
|
||||||
name: {{ .Values.app_name }}
|
name: maestro
|
||||||
namespace: applications
|
namespace: applications
|
||||||
labels:
|
labels:
|
||||||
app: {{ .Values.app_name }}
|
app: maestro
|
||||||
|
|
||||||
spec:
|
spec:
|
||||||
type: ClusterIP
|
type: ClusterIP
|
||||||
ports:
|
ports:
|
||||||
- name: {{ .Values.app_name }}
|
- name: maestro
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
port: {{ .Values.service.port }}
|
port: {{ .Values.service.port }}
|
||||||
targetPort: {{ .Values.service.targetPort }}
|
targetPort: {{ .Values.service.targetPort }}
|
||||||
selector:
|
selector:
|
||||||
app: {{ .Values.app_name }}
|
app: maestro
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ image:
|
|||||||
pullPolicy: IfNotPresent
|
pullPolicy: IfNotPresent
|
||||||
# Overrides the image tag whose default is the chart appVersion.
|
# Overrides the image tag whose default is the chart appVersion.
|
||||||
tag: 1.56.0
|
tag: 1.56.0
|
||||||
app_name: maestro
|
|
||||||
containerPort: 3333
|
containerPort: 3333
|
||||||
imagePullSecrets: "applications-secrets-ecr-auth-token-external-secret"
|
imagePullSecrets: "applications-secrets-ecr-auth-token-external-secret"
|
||||||
service:
|
service:
|
||||||
@@ -43,7 +42,6 @@ maestro:
|
|||||||
upload_file_agent_connection: cbc2f881-58c4-4d60-8003-0979b0b5b911
|
upload_file_agent_connection: cbc2f881-58c4-4d60-8003-0979b0b5b911
|
||||||
open_customer_id: f239718a-a271-4ef9-ae7e-02a2f0f3aa6e
|
open_customer_id: f239718a-a271-4ef9-ae7e-02a2f0f3aa6e
|
||||||
open_group_id: 401573bb-334f-44b2-b30e-88d4cea31ae9
|
open_group_id: 401573bb-334f-44b2-b30e-88d4cea31ae9
|
||||||
dedicated_proxy: ""
|
|
||||||
autoscaling:
|
autoscaling:
|
||||||
enabled: false
|
enabled: false
|
||||||
minReplicas: 1
|
minReplicas: 1
|
||||||
|
|||||||
+2
-7
@@ -29,8 +29,6 @@ import { CustomersModule } from './modules/customers/customers.module';
|
|||||||
import { OpenDataModule } from './modules/open-data/open-data.module';
|
import { OpenDataModule } from './modules/open-data/open-data.module';
|
||||||
import { ThemeModule } from './modules/theme/theme.module';
|
import { ThemeModule } from './modules/theme/theme.module';
|
||||||
import { NetworkPolicyModule } from './modules/network-policy/network-policy.module';
|
import { NetworkPolicyModule } from './modules/network-policy/network-policy.module';
|
||||||
import { AssignModule } from './modules/assign/assign.module';
|
|
||||||
import { ShareMetadataModule } from './modules/share-metadata/share-metadata.module';
|
|
||||||
import { ApiKeyModule } from './modules/api-key/api-key.module';
|
import { ApiKeyModule } from './modules/api-key/api-key.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
@@ -65,13 +63,10 @@ import { ApiKeyModule } from './modules/api-key/api-key.module';
|
|||||||
CustomersModule,
|
CustomersModule,
|
||||||
OpenDataModule,
|
OpenDataModule,
|
||||||
ThemeModule,
|
ThemeModule,
|
||||||
NetworkPolicyModule,
|
|
||||||
AssignModule,
|
|
||||||
ShareMetadataModule,
|
|
||||||
NetworkPolicyModule,
|
|
||||||
ApiKeyModule,
|
|
||||||
//Always leave HealthModule last, so it is on the bottom of swagger
|
//Always leave HealthModule last, so it is on the bottom of swagger
|
||||||
HealthModule,
|
HealthModule,
|
||||||
|
NetworkPolicyModule,
|
||||||
|
ApiKeyModule
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import {
|
|||||||
OnApplicationBootstrap,
|
OnApplicationBootstrap,
|
||||||
ExecutionContext,
|
ExecutionContext,
|
||||||
Inject,
|
Inject,
|
||||||
ForbiddenException,
|
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { Reflector } from '@nestjs/core';
|
import { Reflector } from '@nestjs/core';
|
||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
@@ -136,18 +135,6 @@ export class AuthenticationGuard
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bloquear outros customer de usar o maestor dedicado
|
|
||||||
const DEDICATED_PROXY = process.env.DEDICATED_PROXY
|
|
||||||
if (DEDICATED_PROXY !== '' && DEDICATED_PROXY !== accessTokenPayload.customer_id) {
|
|
||||||
throw new ForbiddenException();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bloquear o customer de acesso o maestro publico
|
|
||||||
const hasNetworkPolicyModule = accessTokenPayload.customer_modules.includes('network-policy');
|
|
||||||
if (hasNetworkPolicyModule && DEDICATED_PROXY === '') {
|
|
||||||
throw new ForbiddenException();
|
|
||||||
}
|
|
||||||
|
|
||||||
request.accessTokenPayload = accessTokenPayload;
|
request.accessTokenPayload = accessTokenPayload;
|
||||||
request.user = {
|
request.user = {
|
||||||
user_id: accessTokenPayload.user_id,
|
user_id: accessTokenPayload.user_id,
|
||||||
|
|||||||
@@ -603,6 +603,22 @@ export const PERMISSIONS_GROUPS = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const PUBLIC_PERMISSIONS_SEQID = [
|
||||||
|
46, // AUTH.GENERATE_TOKEN
|
||||||
|
23, 13, 29, 5, // PIPELINE
|
||||||
|
37, 38, // CONNECTION
|
||||||
|
35, // NETWORK_CONFIG
|
||||||
|
7, 19, 25, 1, // CATALOG
|
||||||
|
14, // SNOWFLAKE
|
||||||
|
11, // DATAVIZ
|
||||||
|
31, // INTELLIGENCE
|
||||||
|
34, // USERS
|
||||||
|
43, // PROCESS
|
||||||
|
47 // CUSTOMER
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
export interface DadosferaModule {
|
export interface DadosferaModule {
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
@@ -614,8 +630,7 @@ export const DADOSFERA_MODULES_KEYS = {
|
|||||||
LOG_DASHBOARD: 'logs-dashboard',
|
LOG_DASHBOARD: 'logs-dashboard',
|
||||||
ACCESS_DASHBOARD: 'access-dashboard',
|
ACCESS_DASHBOARD: 'access-dashboard',
|
||||||
DANGER_ZONE: 'danger-zone',
|
DANGER_ZONE: 'danger-zone',
|
||||||
PII: 'pii',
|
PII: 'pii'
|
||||||
PUBLIC_ASSIGN_EMBED: 'public-assign-embed',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DADOSFERA_MODULES: Array<DadosferaModule> = [
|
export const DADOSFERA_MODULES: Array<DadosferaModule> = [
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import { Controller, Get, Post, Body, Param, Delete, UseFilters, Inject } from '@nestjs/common';
|
import { Controller, Get, Post, Body, Param, Delete, UseFilters, Inject } from '@nestjs/common';
|
||||||
import { ApiKeyService } from './api-key.service';
|
import { ApiKeyService } from './api-key.service';
|
||||||
import { CreateApiKeyDto, CreateApiKeyResponseDto, ApiKeyBaseResponseDto } from './dto/api-key.dto';
|
import { CreateApiKeyDto, CreateApiKeyResponseDto, ApiKeyBaseResponseDto } from './dto/api-key.dto';
|
||||||
import { Authenticated } from 'src/decorators/authentication.decorator';
|
import { Authenticated, RequireAllPermissions } from 'src/decorators/authentication.decorator';
|
||||||
import { ApiHeaders, ApiTags, ApiResponse } from '@nestjs/swagger';
|
import { ApiHeaders, ApiTags, ApiResponse } from '@nestjs/swagger';
|
||||||
import { LanguageEnum } from 'src/utils/languages.enum';
|
import { LanguageEnum } from 'src/utils/languages.enum';
|
||||||
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
||||||
import { RequestUser, User } from 'src/decorators/user.decorator';
|
import { RequestUser, User } from 'src/decorators/user.decorator';
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
|
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
||||||
|
|
||||||
@Controller('api-key')
|
@Controller('api-key')
|
||||||
@Authenticated()
|
@Authenticated()
|
||||||
@@ -26,6 +27,7 @@ export class ApiKeyController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiResponse({ type: CreateApiKeyResponseDto })
|
@ApiResponse({ type: CreateApiKeyResponseDto })
|
||||||
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
async create(@Body() createApiKeyDto: CreateApiKeyDto, @User() user: RequestUser): Promise<CreateApiKeyResponseDto> {
|
async create(@Body() createApiKeyDto: CreateApiKeyDto, @User() user: RequestUser): Promise<CreateApiKeyResponseDto> {
|
||||||
this.logger.info('POST /api-key', {
|
this.logger.info('POST /api-key', {
|
||||||
permissions: createApiKeyDto.permissions,
|
permissions: createApiKeyDto.permissions,
|
||||||
@@ -41,6 +43,7 @@ export class ApiKeyController {
|
|||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@ApiResponse({ type: [ApiKeyBaseResponseDto] })
|
@ApiResponse({ type: [ApiKeyBaseResponseDto] })
|
||||||
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
async findAll(@User() user: RequestUser): Promise<ApiKeyBaseResponseDto[]> {
|
async findAll(@User() user: RequestUser): Promise<ApiKeyBaseResponseDto[]> {
|
||||||
this.logger.info('GET /api-key', {
|
this.logger.info('GET /api-key', {
|
||||||
method: 'findAll'
|
method: 'findAll'
|
||||||
@@ -54,6 +57,7 @@ export class ApiKeyController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
async remove(@Param('id') id: string, @User() user: RequestUser): Promise<void> {
|
async remove(@Param('id') id: string, @User() user: RequestUser): Promise<void> {
|
||||||
this.logger.info('DELETE /api-key/:id', {
|
this.logger.info('DELETE /api-key/:id', {
|
||||||
id,
|
id,
|
||||||
|
|||||||
@@ -1,38 +1,73 @@
|
|||||||
import { Injectable, Inject, OnModuleInit } from '@nestjs/common';
|
import {
|
||||||
|
Injectable,
|
||||||
|
Inject,
|
||||||
|
OnModuleInit,
|
||||||
|
BadRequestException,
|
||||||
|
} from '@nestjs/common';
|
||||||
import { ClientGrpc } from '@nestjs/microservices';
|
import { ClientGrpc } from '@nestjs/microservices';
|
||||||
import { CreateApiKeyDto, CreateApiKeyResponseDto, ApiKeyBaseResponseDto } from './dto/api-key.dto';
|
import {
|
||||||
|
CreateApiKeyDto,
|
||||||
|
CreateApiKeyResponseDto,
|
||||||
|
ApiKeyBaseResponseDto,
|
||||||
|
} from './dto/api-key.dto';
|
||||||
import { RequestUser } from 'src/decorators/user.decorator';
|
import { RequestUser } from 'src/decorators/user.decorator';
|
||||||
import { DucClient } from '../duc/client.config';
|
import { DucClient } from '../duc/client.config';
|
||||||
|
import { PackTheMetadata } from '../../utils/ PackTheMetadata';
|
||||||
import { ApiKeyWriteProtoService } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/write-service';
|
import { ApiKeyWriteProtoService } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/write-service';
|
||||||
import { lastValueFrom } from 'rxjs';
|
import { lastValueFrom } from 'rxjs';
|
||||||
import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Duc';
|
import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Duc';
|
||||||
import { PackTheMetadata } from 'src/utils/PackTheMetadata';
|
import { PUBLIC_PERMISSIONS_SEQID } from 'src/authentication/permissions.enum';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ApiKeyService implements OnModuleInit {
|
export class ApiKeyService implements OnModuleInit {
|
||||||
private apiKeyService: ApiKeyWriteProtoService;
|
private apiKeyService: ApiKeyWriteProtoService;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(DucClient.name) private readonly client: ClientGrpc,
|
@Inject(DucClient.name) private readonly client: ClientGrpc
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
onModuleInit() {
|
onModuleInit() {
|
||||||
this.apiKeyService = this.client.getService<ApiKeyWriteProtoService>(ProtoServices.ApiKeyWriteProtoService);
|
this.apiKeyService = this.client.getService<ApiKeyWriteProtoService>(
|
||||||
|
ProtoServices.ApiKeyWriteProtoService,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
create(createApiKeyDto: CreateApiKeyDto, user: RequestUser): Promise<CreateApiKeyResponseDto> {
|
create(
|
||||||
|
createApiKeyDto: CreateApiKeyDto,
|
||||||
|
user: RequestUser,
|
||||||
|
): Promise<CreateApiKeyResponseDto> {
|
||||||
const metadata = PackTheMetadata(user);
|
const metadata = PackTheMetadata(user);
|
||||||
|
|
||||||
return lastValueFrom(this.apiKeyService.CreateApiKey({
|
const invalidPermissions = [];
|
||||||
permissions: createApiKeyDto.permissions
|
for (const permission of createApiKeyDto.permissions) {
|
||||||
}, metadata));
|
if (!PUBLIC_PERMISSIONS_SEQID.includes(permission)) {
|
||||||
|
invalidPermissions.push(permission);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (invalidPermissions.length > 0) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
`Invalid permissions: ${invalidPermissions.join(', ')}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lastValueFrom(
|
||||||
|
this.apiKeyService.CreateApiKey(
|
||||||
|
{
|
||||||
|
permissions: createApiKeyDto.permissions,
|
||||||
|
},
|
||||||
|
metadata,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(user: RequestUser): Promise<ApiKeyBaseResponseDto[]> {
|
async findAll(user: RequestUser): Promise<ApiKeyBaseResponseDto[]> {
|
||||||
const metadata = PackTheMetadata(user);
|
const metadata = PackTheMetadata(user);
|
||||||
console.log(metadata)
|
console.log(metadata);
|
||||||
|
|
||||||
const data = await lastValueFrom(this.apiKeyService.ListApiKeys({}, metadata));
|
const data = await lastValueFrom(
|
||||||
|
this.apiKeyService.ListApiKeys({}, metadata),
|
||||||
|
);
|
||||||
return data.api_keys;
|
return data.api_keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
import { Controller, Post, Body, Put, Get} from '@nestjs/common';
|
|
||||||
import { AssignService } from './assign.service';
|
|
||||||
import { CreateAssignDto } from './dto/create-assign.dto';
|
|
||||||
import { Authenticated, RequireModule, RequireSomePermission } from 'src/decorators/authentication.decorator';
|
|
||||||
import { RequestUser, User } from 'src/decorators/user.decorator';
|
|
||||||
import { DADOSFERA_MODULES_KEYS, PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
|
||||||
import { PackTheMetadata } from 'src/utils/PackTheMetadata';
|
|
||||||
|
|
||||||
@Controller('assign')
|
|
||||||
@Authenticated()
|
|
||||||
export class AssignController {
|
|
||||||
constructor(private readonly assignService: AssignService) {}
|
|
||||||
|
|
||||||
@Put('/public-key')
|
|
||||||
@RequireSomePermission(
|
|
||||||
PERMISSIONS_GROUPS.USERS.permissions.ADMIN
|
|
||||||
)
|
|
||||||
@RequireModule(DADOSFERA_MODULES_KEYS.PUBLIC_ASSIGN_EMBED)
|
|
||||||
create(@Body() createAssignDto: CreateAssignDto, @User() user: RequestUser) {
|
|
||||||
const metadata = PackTheMetadata(user);
|
|
||||||
return this.assignService.create(createAssignDto, metadata);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('/public-key')
|
|
||||||
@RequireSomePermission(
|
|
||||||
PERMISSIONS_GROUPS.USERS.permissions.ADMIN
|
|
||||||
)
|
|
||||||
@RequireModule(DADOSFERA_MODULES_KEYS.PUBLIC_ASSIGN_EMBED)
|
|
||||||
async get(@User() user: RequestUser) {
|
|
||||||
const metadata = PackTheMetadata(user);
|
|
||||||
return await this.assignService.get(metadata);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import { Module } from '@nestjs/common';
|
|
||||||
import { AssignService } from './assign.service';
|
|
||||||
import { AssignController } from './assign.controller';
|
|
||||||
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
|
||||||
import { ClientsModule } from '@nestjs/microservices';
|
|
||||||
import { DucClient } from '../duc/client.config';
|
|
||||||
|
|
||||||
const client = new DucClient();
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
imports: [ClientsModule.register([client.providerOptions])],
|
|
||||||
controllers: [AssignController],
|
|
||||||
providers: [AssignService, DadosferaLogger]
|
|
||||||
})
|
|
||||||
export class AssignModule {}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
import { Inject, Injectable, OnModuleInit } from '@nestjs/common';
|
|
||||||
import { CreateAssignDto } from './dto/create-assign.dto';
|
|
||||||
import { Metadata } from '@grpc/grpc-js';
|
|
||||||
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
|
||||||
import { ClientGrpc } from '@nestjs/microservices';
|
|
||||||
import { DucClient } from 'src/modules/duc/client.config';
|
|
||||||
import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Duc';
|
|
||||||
import { lastValueFrom } from 'rxjs';import { AssingProtoService } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/write-service';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class AssignService implements OnModuleInit {
|
|
||||||
|
|
||||||
ducService: AssingProtoService;
|
|
||||||
logger: DadosferaLogger;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
@Inject(DadosferaLogger)
|
|
||||||
dadosferaLogger: DadosferaLogger,
|
|
||||||
@Inject(DucClient.name) private readonly grpcClient: ClientGrpc,
|
|
||||||
) {
|
|
||||||
this.logger = dadosferaLogger.logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
onModuleInit() {
|
|
||||||
this.ducService =this.grpcClient.getService<AssingProtoService>(
|
|
||||||
ProtoServices.AssingProtoService,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async create(createAssignDto: CreateAssignDto, metadata: Metadata) {
|
|
||||||
const data = await lastValueFrom(this.ducService.CreateOrUpdateAssignPublicKey(createAssignDto, metadata))
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async get(metadata: Metadata) {
|
|
||||||
return await lastValueFrom(this.ducService.GetAssignPublicKey(metadata))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
export class CreateAssignDto {
|
|
||||||
publicKey: string;
|
|
||||||
}
|
|
||||||
@@ -45,7 +45,7 @@ import {
|
|||||||
AuthSignInRes,
|
AuthSignInRes,
|
||||||
BulkEditRequest,
|
BulkEditRequest,
|
||||||
} from './dtos/login';
|
} from './dtos/login';
|
||||||
import { PackTheMetadata } from 'src/utils/PackTheMetadata';
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
import { AuthGuard } from '@nestjs/passport';
|
import { AuthGuard } from '@nestjs/passport';
|
||||||
import { Request } from 'express';
|
import { Request } from 'express';
|
||||||
import ErrorCodes, { OauthErrors } from 'src/utils/errorCodes';
|
import ErrorCodes, { OauthErrors } from 'src/utils/errorCodes';
|
||||||
@@ -86,9 +86,11 @@ export class AuthController {
|
|||||||
async signIn(
|
async signIn(
|
||||||
@Body() { username, password, totp }: AuthSignInReq,
|
@Body() { username, password, totp }: AuthSignInReq,
|
||||||
@Language() language: LanguageEnum,
|
@Language() language: LanguageEnum,
|
||||||
|
@Headers('origin') origin = '',
|
||||||
): Promise<AuthSignInRes> {
|
): Promise<AuthSignInRes> {
|
||||||
this.logger.info('/auth - SignIn');
|
this.logger.info('/auth - SignIn');
|
||||||
const metadata = PackTheMetadata({ language });
|
const frontHost = origin.replace(/^https?:\/\//, '');
|
||||||
|
const metadata = PackTheMetadata({ language, custom_host: frontHost });
|
||||||
this.logger.info('metadata: ' + JSON.stringify(metadata.toJSON()));
|
this.logger.info('metadata: ' + JSON.stringify(metadata.toJSON()));
|
||||||
return this.authClient.signIn({ username, password, totp }, metadata);
|
return this.authClient.signIn({ username, password, totp }, metadata);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { OnModuleInit, Inject, Injectable, ForbiddenException } from '@nestjs/common';
|
import { OnModuleInit, Inject, Injectable } from '@nestjs/common';
|
||||||
import { ClientGrpc } from '@nestjs/microservices';
|
import { ClientGrpc } from '@nestjs/microservices';
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
import { lastValueFrom } from 'rxjs';
|
import { lastValueFrom } from 'rxjs';
|
||||||
@@ -17,7 +17,6 @@ import {
|
|||||||
AuthResetPasswordRequest,
|
AuthResetPasswordRequest,
|
||||||
AuthVerifyResetPasswordCodeRequest,
|
AuthVerifyResetPasswordCodeRequest,
|
||||||
AuthConfirmResetPasswordRequest,
|
AuthConfirmResetPasswordRequest,
|
||||||
AuthSignInResponse,
|
|
||||||
} from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
} from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
||||||
import { DucClient } from '../duc/client.config';
|
import { DucClient } from '../duc/client.config';
|
||||||
import { Metadata } from '@grpc/grpc-js';
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
@@ -54,49 +53,15 @@ export class AuthClientService implements OnModuleInit {
|
|||||||
return lastValueFrom(this.authService.AuthSnowflakeSignIn(input));
|
return lastValueFrom(this.authService.AuthSnowflakeSignIn(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
checkDedicatedProxy({
|
|
||||||
customer
|
|
||||||
}: AuthSignInResponse) {
|
|
||||||
const DEDICATED_PROXY = process.env.DEDICATED_PROXY || '';
|
|
||||||
this.logger.info('SignIn - Setting customer ID for dedicated proxy: ' + DEDICATED_PROXY);
|
|
||||||
this.logger.info('Customer ID: ' + customer.id);
|
|
||||||
|
|
||||||
if (DEDICATED_PROXY !== '' && DEDICATED_PROXY !== customer.id) {
|
|
||||||
throw new ForbiddenException();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bloquear o customer de acesso o maestro publico
|
|
||||||
this.logger.info('Check if customer have network policy: ' + customer.modules);
|
|
||||||
const hasNetworkPolicyModule = customer.modules.includes('network-policy');
|
|
||||||
if (hasNetworkPolicyModule && DEDICATED_PROXY === '') {
|
|
||||||
throw new ForbiddenException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async signIn(
|
async signIn(
|
||||||
{ username, password, totp }: AuthSignInRequest,
|
{ username, password, totp }: AuthSignInRequest,
|
||||||
metadata: Metadata,
|
metadata: Metadata,
|
||||||
) {
|
) {
|
||||||
this.logger.info('SignIn');
|
this.logger.info('SignIn');
|
||||||
|
|
||||||
let result: AuthSignInResponse;
|
return lastValueFrom(
|
||||||
|
this.authService.AuthSignIn({ username, password, totp }, metadata),
|
||||||
try {
|
);
|
||||||
result = await lastValueFrom(
|
|
||||||
this.authService.AuthSignIn({ username, password, totp }, metadata),
|
|
||||||
);
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.error('SignIn - Error during sign-in');
|
|
||||||
this.logger.error(error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.customer) {
|
|
||||||
this.checkDedicatedProxy(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async refreshAccessToken(
|
async refreshAccessToken(
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import {
|
|||||||
import { DADOSFERA_MODULES_KEYS, PERMISSIONS_GROUPS } from '../../authentication/permissions.enum';
|
import { DADOSFERA_MODULES_KEYS, 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';
|
||||||
import { PackTheMetadata } from 'src/utils/PackTheMetadata';
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
import { RequestUser, User } from 'src/decorators/user.decorator';
|
import { RequestUser, User } from 'src/decorators/user.decorator';
|
||||||
import {
|
import {
|
||||||
BatchRemoveRlsRulesRequest,
|
BatchRemoveRlsRulesRequest,
|
||||||
|
|||||||
@@ -3,15 +3,12 @@ import { Module } from '@nestjs/common';
|
|||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
|
|
||||||
import { CatalogController } from './catalog.controller';
|
import { CatalogController } from './catalog.controller';
|
||||||
|
import { CatalogService } from './catalog.service';
|
||||||
import { CatalogClientConfiguration } from './catalog-client';
|
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';
|
import { RolesModule } from '../roles/roles.module';
|
||||||
import { CustomersModule } from '../customers/customers.module';
|
|
||||||
import { ShareModule } from './share/share.module';
|
|
||||||
import { CatalogService } from './catalog.service';
|
|
||||||
import { MixpanelModule } from '../mixpanel/mixpanel.module';
|
|
||||||
|
|
||||||
const client = new CatalogClientConfiguration();
|
const client = new CatalogClientConfiguration();
|
||||||
|
|
||||||
@@ -21,8 +18,6 @@ const client = new CatalogClientConfiguration();
|
|||||||
OldPipelineModule,
|
OldPipelineModule,
|
||||||
UsersModule,
|
UsersModule,
|
||||||
RolesModule,
|
RolesModule,
|
||||||
CustomersModule,
|
|
||||||
ShareModule,
|
|
||||||
],
|
],
|
||||||
controllers: [CatalogController],
|
controllers: [CatalogController],
|
||||||
providers: [CatalogService, DadosferaLogger],
|
providers: [CatalogService, DadosferaLogger],
|
||||||
|
|||||||
@@ -35,6 +35,12 @@ import {
|
|||||||
GetRlsRulesRequest,
|
GetRlsRulesRequest,
|
||||||
PiiMetadata,
|
PiiMetadata,
|
||||||
} from '@dadosfera/protospack-v2/dist/lib/Catalog/interfaces/messages';
|
} from '@dadosfera/protospack-v2/dist/lib/Catalog/interfaces/messages';
|
||||||
|
import { writeFileSync } from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import { HtmlParser } from 'src/utils/FileParser/html-parser';
|
||||||
|
import { PiiDto } from './dtos/pii.dto';
|
||||||
|
import { CsvParser } from 'src/utils/FileParser/csv-parser';
|
||||||
|
import { PDFParser } from 'src/utils/FileParser/pdf-parser';
|
||||||
import { TypeParser } from 'src/utils/FileParser/parser-types';
|
import { TypeParser } from 'src/utils/FileParser/parser-types';
|
||||||
import { ParserBuilder } from 'src/utils/FileParser/parser.builder';
|
import { ParserBuilder } from 'src/utils/FileParser/parser.builder';
|
||||||
|
|
||||||
@@ -310,7 +316,7 @@ class CatalogService implements OnModuleInit {
|
|||||||
const { documentation } = await lastValueFrom(
|
const { documentation } = await lastValueFrom(
|
||||||
this.catalogReadService.GetDatasetDoc({ id, type: undefined }, metadata),
|
this.catalogReadService.GetDatasetDoc({ id, type: undefined }, metadata),
|
||||||
);
|
);
|
||||||
|
console.log(documentation);
|
||||||
const docs = JSON.parse(documentation);
|
const docs = JSON.parse(documentation);
|
||||||
return docs;
|
return docs;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,90 +0,0 @@
|
|||||||
import {
|
|
||||||
Controller,
|
|
||||||
Get,
|
|
||||||
Inject,
|
|
||||||
Param,
|
|
||||||
Req,
|
|
||||||
UseFilters,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import {
|
|
||||||
ApiHeaders,
|
|
||||||
ApiTags,
|
|
||||||
} from '@nestjs/swagger';
|
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
|
||||||
import { RequestUser, User } from 'src/decorators/user.decorator';
|
|
||||||
import {
|
|
||||||
IColumnsMetadataResponse,
|
|
||||||
IDocsResponse,
|
|
||||||
IPreviewResponse,
|
|
||||||
|
|
||||||
} from '../dtos';
|
|
||||||
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
|
||||||
import { Language } from 'src/decorators/language.decorator';
|
|
||||||
import { LanguageEnum } from 'src/utils/languages.enum';
|
|
||||||
import { ShareService } from './share.service';
|
|
||||||
import { Request } from 'express';
|
|
||||||
|
|
||||||
@ApiTags('Catalog')
|
|
||||||
@ApiHeaders([{ name: 'dadosfera-lang', enum: LanguageEnum, required: false }])
|
|
||||||
@Controller('catalog/data-asset/share')
|
|
||||||
@UseFilters(new GrpcToHttpExceptionFilter())
|
|
||||||
export class ShareController {
|
|
||||||
logger: DadosferaLogger;
|
|
||||||
constructor(
|
|
||||||
@Inject(DadosferaLogger)
|
|
||||||
dadosferaLogger: DadosferaLogger,
|
|
||||||
private catalogShareService: ShareService,
|
|
||||||
) {
|
|
||||||
this.logger = dadosferaLogger.logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('/:id')
|
|
||||||
async getShareDataAsset(
|
|
||||||
@Param('id') id: string,
|
|
||||||
@User() user: RequestUser,
|
|
||||||
@Req() request: Request
|
|
||||||
) {
|
|
||||||
this.logger.info(`GET //:id`);
|
|
||||||
return await this.catalogShareService.getOneDataAssetPublic(id, user, request);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('/:id/columns-metadata')
|
|
||||||
async getShareDataAssetColumnsMetadata(
|
|
||||||
@Language() language: LanguageEnum,
|
|
||||||
@Param('id') id: string,
|
|
||||||
@User() user: RequestUser
|
|
||||||
): Promise<IColumnsMetadataResponse> {
|
|
||||||
this.logger.info(`GET /:id/columns-metadata`);
|
|
||||||
|
|
||||||
const columns_metadata =
|
|
||||||
await this.catalogShareService.getDatasetColumnsMetadata(id, user);
|
|
||||||
|
|
||||||
|
|
||||||
return { columns_metadata };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('/:id/preview')
|
|
||||||
async getShareDataAssetPreview(
|
|
||||||
@Language() language: LanguageEnum,
|
|
||||||
@Param('id') id: string,
|
|
||||||
@User() user: RequestUser
|
|
||||||
): Promise<IPreviewResponse> {
|
|
||||||
this.logger.info(`GET /:id/preview`);
|
|
||||||
const preview = await this.catalogShareService.getDatasetPreview(id, user);
|
|
||||||
|
|
||||||
return { preview };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('/:id/docs')
|
|
||||||
async getShareDataAssetDocs(
|
|
||||||
@Language() language: LanguageEnum,
|
|
||||||
@Param('id') id: string,
|
|
||||||
@User() user: RequestUser
|
|
||||||
): Promise<IDocsResponse> {
|
|
||||||
this.logger.info(`GET /:id/docs`);
|
|
||||||
const docs = await this.catalogShareService.getDataDocs(id, user);
|
|
||||||
|
|
||||||
return { docs };
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import { Module } from "@nestjs/common";
|
|
||||||
import { CatalogClientConfiguration } from "../catalog-client";
|
|
||||||
import { ClientsModule } from "@nestjs/microservices";
|
|
||||||
import { RolesModule } from "src/modules/roles/roles.module";
|
|
||||||
import { UsersModule } from "src/modules/users/users.module";
|
|
||||||
import { CustomersModule } from "src/modules/customers/customers.module";
|
|
||||||
import { ShareMetadataModule } from "src/modules/share-metadata/share-metadata.module";
|
|
||||||
import { ShareController } from "./share.controller";
|
|
||||||
import DadosferaLogger from "@dadosfera/dadosfera-logs";
|
|
||||||
import { ShareService } from "./share.service";
|
|
||||||
import { MixpanelModule } from "src/modules/mixpanel/mixpanel.module";
|
|
||||||
|
|
||||||
const client = new CatalogClientConfiguration();
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
imports: [
|
|
||||||
ClientsModule.register([client.providerOptions]),
|
|
||||||
UsersModule,
|
|
||||||
RolesModule,
|
|
||||||
CustomersModule,
|
|
||||||
ShareMetadataModule,
|
|
||||||
MixpanelModule
|
|
||||||
],
|
|
||||||
controllers: [ShareController],
|
|
||||||
providers: [ShareService, DadosferaLogger],
|
|
||||||
exports: [ShareModule],
|
|
||||||
})
|
|
||||||
export class ShareModule {}
|
|
||||||
@@ -1,247 +0,0 @@
|
|||||||
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
|
||||||
import {
|
|
||||||
ProtoServices,
|
|
||||||
ReadService,
|
|
||||||
} from '@dadosfera/protospack-v2/dist/lib/Catalog';
|
|
||||||
import {
|
|
||||||
ForbiddenException,
|
|
||||||
Inject,
|
|
||||||
NotFoundException,
|
|
||||||
OnModuleInit,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { CatalogClientConfiguration } from '../catalog-client';
|
|
||||||
import { ClientGrpc } from '@nestjs/microservices';
|
|
||||||
import { UsersService } from 'src/modules/users/users.service';
|
|
||||||
import { RolesService } from 'src/modules/roles/roles.service';
|
|
||||||
import { RequestUser } from 'src/decorators/user.decorator';
|
|
||||||
import { PackTheMetadata } from 'src/utils/PackTheMetadata';
|
|
||||||
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
|
||||||
import { Metadata } from '@grpc/grpc-js';
|
|
||||||
import { lastValueFrom } from 'rxjs';
|
|
||||||
import { ShareMetadataService } from 'src/modules/share-metadata/share-metadata.service';
|
|
||||||
import { isJWT } from 'class-validator';
|
|
||||||
import { MixpanelService } from 'src/modules/mixpanel/mixpanel.service';
|
|
||||||
import { Request } from 'express';
|
|
||||||
|
|
||||||
export class ShareService implements OnModuleInit {
|
|
||||||
catalogReadService: ReadService.CatalogReadServices;
|
|
||||||
logger: DadosferaLogger;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
@Inject(DadosferaLogger)
|
|
||||||
dadosferaLogger: DadosferaLogger,
|
|
||||||
@Inject(CatalogClientConfiguration.name)
|
|
||||||
private readonly grpcClient: ClientGrpc,
|
|
||||||
private readonly userService: UsersService,
|
|
||||||
private readonly roleService: RolesService,
|
|
||||||
private readonly shareMetadataService: ShareMetadataService,
|
|
||||||
private readonly mixpanelService: MixpanelService,
|
|
||||||
) {
|
|
||||||
this.logger = dadosferaLogger.logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
onModuleInit() {
|
|
||||||
this.catalogReadService =
|
|
||||||
this.grpcClient.getService<ReadService.CatalogReadServices>(
|
|
||||||
ProtoServices.CatalogReadServices,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async getDatasetColumnsMetadata(id: string, user: RequestUser) {
|
|
||||||
const shareMetadata = await this.getShareMetadata(id, user);
|
|
||||||
const metadata = PackTheMetadata({
|
|
||||||
customer_id: shareMetadata.customerId,
|
|
||||||
customer_name: shareMetadata.customerName,
|
|
||||||
});
|
|
||||||
const { columns_metadata } = await lastValueFrom(
|
|
||||||
this.catalogReadService.GetDatasetColumnsMetadata(
|
|
||||||
{ id: shareMetadata.assetId, type: undefined },
|
|
||||||
metadata,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
const result = JSON.parse(columns_metadata);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getDatasetPreview(id: string, user: RequestUser) {
|
|
||||||
const shareMetadata = await this.getShareMetadata(id, user);
|
|
||||||
const metadata = PackTheMetadata({
|
|
||||||
customer_id: shareMetadata.customerId,
|
|
||||||
customer_name: shareMetadata.customerName,
|
|
||||||
});
|
|
||||||
const { preview } = await lastValueFrom(
|
|
||||||
this.catalogReadService.GetDatasetPreview(
|
|
||||||
{ id: shareMetadata.assetId, type: undefined },
|
|
||||||
metadata,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
const result = JSON.parse(preview);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getOneDataAssetPublic(id: string, user: RequestUser, request: Request) {
|
|
||||||
this.logger.info("getOneDataAssetPublic: " + JSON.stringify({
|
|
||||||
id,
|
|
||||||
userId: user?.user_id,
|
|
||||||
customerId: user?.customer_id
|
|
||||||
}))
|
|
||||||
try {
|
|
||||||
const shareMetadata = await this.getShareMetadata(id, user);
|
|
||||||
|
|
||||||
const mixpanelTracker = {
|
|
||||||
asset: shareMetadata.assetId,
|
|
||||||
type: isJWT(id) ? 'assigned' : shareMetadata.type,
|
|
||||||
customer: shareMetadata.customerName
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user) {
|
|
||||||
await this.mixpanelService.track("share_page", user, request, mixpanelTracker);
|
|
||||||
} else {
|
|
||||||
await this.mixpanelService.trackShare(request, mixpanelTracker);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.info("shareMetadata: " + JSON.stringify(shareMetadata))
|
|
||||||
const metadata = PackTheMetadata({
|
|
||||||
customer_id: shareMetadata.customerId,
|
|
||||||
customer_name: shareMetadata.customerName,
|
|
||||||
});
|
|
||||||
|
|
||||||
const { data_asset } = await this.getOneDataAsset({
|
|
||||||
customer_id: shareMetadata.customerId,
|
|
||||||
id: shareMetadata.assetId,
|
|
||||||
metadata,
|
|
||||||
});
|
|
||||||
this.logger.info('found asset: ' + JSON.stringify(data_asset));
|
|
||||||
delete data_asset.p_roles;
|
|
||||||
delete data_asset.p_users;
|
|
||||||
data_asset.share_type = 'public';
|
|
||||||
if (data_asset.share_type !== 'public') throw new NotFoundException();
|
|
||||||
|
|
||||||
return { data_asset };
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.error(error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private async getOneDataAsset(data: {
|
|
||||||
id: string;
|
|
||||||
customer_id: string;
|
|
||||||
metadata: Metadata;
|
|
||||||
}) {
|
|
||||||
const { customer_id, id, metadata } = data;
|
|
||||||
const { data_asset } = await lastValueFrom(
|
|
||||||
this.catalogReadService.GetOneDataAsset(
|
|
||||||
{ id, type: undefined },
|
|
||||||
metadata,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
let asset = JSON.parse(data_asset);
|
|
||||||
asset = {
|
|
||||||
...asset,
|
|
||||||
p_roles: asset.roles,
|
|
||||||
p_users: asset.users,
|
|
||||||
};
|
|
||||||
asset = await this.getAssetsUsersAndRoles([asset], customer_id);
|
|
||||||
|
|
||||||
return { data_asset: asset[0] };
|
|
||||||
}
|
|
||||||
|
|
||||||
async getDataDocs(id: string, user: RequestUser) {
|
|
||||||
const shareMetadata = await this.getShareMetadata(id, user);
|
|
||||||
const metadata = PackTheMetadata({
|
|
||||||
customer_id: shareMetadata.customerId,
|
|
||||||
customer_name: shareMetadata.customerName,
|
|
||||||
});
|
|
||||||
|
|
||||||
const { documentation } = await lastValueFrom(
|
|
||||||
this.catalogReadService.GetDatasetDoc({ id, type: undefined }, metadata),
|
|
||||||
);
|
|
||||||
console.log(documentation);
|
|
||||||
const docs = JSON.parse(documentation);
|
|
||||||
return docs;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async getAssetsUsersAndRoles(
|
|
||||||
data_assets: Array<any>,
|
|
||||||
customer_id: string,
|
|
||||||
) {
|
|
||||||
const { users: customer_users } =
|
|
||||||
await this.userService.findAllUsersByCustomerId(customer_id);
|
|
||||||
const { roles: customer_roles } = await this.roleService.roleSearch(
|
|
||||||
{},
|
|
||||||
{ customer_id },
|
|
||||||
);
|
|
||||||
return data_assets.map((data_asset) => {
|
|
||||||
const owner = customer_users.find(
|
|
||||||
(u) => u.id === data_asset.owner,
|
|
||||||
)?.username;
|
|
||||||
|
|
||||||
const roles = [];
|
|
||||||
const users = [];
|
|
||||||
for (const role_id of data_asset.roles) {
|
|
||||||
const role = customer_roles.find((r) => r.id === role_id);
|
|
||||||
if (role) roles.push({ id: role.id, name: role.name });
|
|
||||||
}
|
|
||||||
for (const user_id of data_asset.users) {
|
|
||||||
const user = customer_users.find((r) => r.id === user_id);
|
|
||||||
if (user) users.push({ id: user.id, username: user.username });
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
...data_asset,
|
|
||||||
roles,
|
|
||||||
users,
|
|
||||||
owner,
|
|
||||||
} as typeof data_asset;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// private async validateShareAssign(token: string) {
|
|
||||||
// const tokenDecoded = jwt.decode(token, {
|
|
||||||
// complete: true,
|
|
||||||
// });
|
|
||||||
|
|
||||||
// jwt.verify(token, this.pemValue, {
|
|
||||||
// algorithms: ['RS256'],
|
|
||||||
// });
|
|
||||||
|
|
||||||
// const shareId = (tokenDecoded.payload as JwtPayload).sub;
|
|
||||||
// const metadata = PackTheMetadata({});
|
|
||||||
// return await this.shareMetadataService.get(shareId, metadata);
|
|
||||||
// }
|
|
||||||
|
|
||||||
private async getShareMetadata(id: string, user: RequestUser) {
|
|
||||||
const metadata = PackTheMetadata({});
|
|
||||||
this.logger.info('GET share metadata')
|
|
||||||
const info = await this.shareMetadataService.get(id, metadata);
|
|
||||||
if (isJWT(id) && info ){
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (info.type === 'private') {
|
|
||||||
if (!user) {
|
|
||||||
throw new ForbiddenException(
|
|
||||||
'You do not have permission to access this data asset.',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const is_data_manager = user.permissions.includes(
|
|
||||||
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER.seqid,
|
|
||||||
);
|
|
||||||
|
|
||||||
const is_get = user.permissions.includes(
|
|
||||||
PERMISSIONS_GROUPS.CATALOG.permissions.GET.seqid,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (is_data_manager || is_get) {
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new ForbiddenException(
|
|
||||||
'You do not have permission to access this data asset.',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -20,7 +20,7 @@ import {
|
|||||||
DatabaseConnectionPropertiesDto,
|
DatabaseConnectionPropertiesDto,
|
||||||
} from '../connection/dtos/connection';
|
} from '../connection/dtos/connection';
|
||||||
import { RequestUser } from 'src/decorators/user.decorator';
|
import { RequestUser } from 'src/decorators/user.decorator';
|
||||||
import { PackTheMetadata } from 'src/utils/PackTheMetadata';
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ConnectionTestService {
|
export class ConnectionTestService {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import {
|
|||||||
UpdateConnectionDto,
|
UpdateConnectionDto,
|
||||||
} from './dtos/connection';
|
} from './dtos/connection';
|
||||||
import { CreateConnectionDto } from './dtos/connection';
|
import { CreateConnectionDto } from './dtos/connection';
|
||||||
import { PackTheMetadata } from 'src/utils/PackTheMetadata';
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
||||||
import { Language } from 'src/decorators/language.decorator';
|
import { Language } from 'src/decorators/language.decorator';
|
||||||
import { LanguageEnum } from 'src/utils/languages.enum';
|
import { LanguageEnum } from 'src/utils/languages.enum';
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import { CustomersService } from './customers.service';
|
|||||||
import { CustomerLinkRequest, CustomerLinksResponse } from './dtos/customers';
|
import { CustomerLinkRequest, CustomerLinksResponse } from './dtos/customers';
|
||||||
import { RequestUser, User } from 'src/decorators/user.decorator';
|
import { RequestUser, User } from 'src/decorators/user.decorator';
|
||||||
import type { StringValue } from 'ms';
|
import type { StringValue } from 'ms';
|
||||||
import { PackTheMetadata } from 'src/utils/PackTheMetadata';
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
import { EnforceMfa } from './dtos/enforce-mfa';
|
import { EnforceMfa } from './dtos/enforce-mfa';
|
||||||
|
|
||||||
@ApiTags('Customers')
|
@ApiTags('Customers')
|
||||||
|
|||||||
@@ -59,14 +59,6 @@ export class CustomersService implements OnModuleInit {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCustomer(customerId: string) {
|
|
||||||
return await lastValueFrom(
|
|
||||||
this.customerService.CustomerFindOneById({
|
|
||||||
id: customerId
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async getLinks(customerId: string) {
|
async getLinks(customerId: string) {
|
||||||
try {
|
try {
|
||||||
const result = await lastValueFrom(
|
const result = await lastValueFrom(
|
||||||
@@ -149,7 +141,6 @@ export class CustomersService implements OnModuleInit {
|
|||||||
// const decoded = jwt.decode(jwt_token, { complete: true });
|
// const decoded = jwt.decode(jwt_token, { complete: true });
|
||||||
return jwt_token;
|
return jwt_token;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getMonitoringDashboardUrl(metadata: Metadata) {
|
async getMonitoringDashboardUrl(metadata: Metadata) {
|
||||||
logger.info('CustomersService - getMonitoringDashboardUrl');
|
logger.info('CustomersService - getMonitoringDashboardUrl');
|
||||||
|
|
||||||
@@ -167,7 +158,6 @@ export class CustomersService implements OnModuleInit {
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getLogsDashboardUrl(metadata: Metadata) {
|
async getLogsDashboardUrl(metadata: Metadata) {
|
||||||
logger.info('CustomersService - getMixPanelLogsDashboardUrl');
|
logger.info('CustomersService - getMixPanelLogsDashboardUrl');
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,14 @@ import { init } from 'mixpanel';
|
|||||||
import { Authenticated } from 'src/decorators/authentication.decorator';
|
import { Authenticated } from 'src/decorators/authentication.decorator';
|
||||||
import { ApiInternalOnlyController } from 'src/decorators/swagger.decorator';
|
import { ApiInternalOnlyController } from 'src/decorators/swagger.decorator';
|
||||||
import { RequestUser, User } from 'src/decorators/user.decorator';
|
import { RequestUser, User } from 'src/decorators/user.decorator';
|
||||||
import { MixpanelService } from './mixpanel.service';
|
|
||||||
|
|
||||||
@ApiInternalOnlyController()
|
@ApiInternalOnlyController()
|
||||||
|
@Authenticated()
|
||||||
@Controller('trackEvent')
|
@Controller('trackEvent')
|
||||||
export class MixpanelController {
|
export class MixpanelController {
|
||||||
constructor(
|
constructor(
|
||||||
private mixpanelService: MixpanelService
|
@Inject('MIXPANEL_TOKEN')
|
||||||
|
private readonly mixpanelToken: string,
|
||||||
) {}
|
) {}
|
||||||
@Post(':id')
|
@Post(':id')
|
||||||
async trackEvent(
|
async trackEvent(
|
||||||
@@ -19,11 +20,82 @@ export class MixpanelController {
|
|||||||
@Req() request
|
@Req() request
|
||||||
) {
|
) {
|
||||||
delete body.info;
|
delete body.info;
|
||||||
|
const mixpanel = init(this.mixpanelToken);
|
||||||
|
|
||||||
await this.mixpanelService.track(id, user, request, body)
|
const separator = user.username.includes('-') ? '-' : '.';
|
||||||
|
const removeValues = [
|
||||||
|
'.dadosferatech.dadosfera',
|
||||||
|
'.demo.dadosfera',
|
||||||
|
'.dadosferademo',
|
||||||
|
'.dadosferarh.dadosfera',
|
||||||
|
'.dadosferatech.dadosfera2',
|
||||||
|
'.dadosferatech.dadosfera',
|
||||||
|
'.dadosfera.fin',
|
||||||
|
'.dadosferafin.dadosfera',
|
||||||
|
'.praxio.dadosfera',
|
||||||
|
'.dadosfera.tech',
|
||||||
|
'.treinamentos@dadosfera.ai',
|
||||||
|
'.dadosfera2',
|
||||||
|
'.treinamentosfera',
|
||||||
|
'.dadosfera',
|
||||||
|
];
|
||||||
|
|
||||||
|
let username = user.username;
|
||||||
|
|
||||||
|
removeValues.forEach((value) => {
|
||||||
|
username = username.replace(value, '');
|
||||||
|
});
|
||||||
|
|
||||||
|
username = username.split('@')?.[0];
|
||||||
|
username = username.split('+')?.[0];
|
||||||
|
|
||||||
|
let firstName = username
|
||||||
|
.substring(0, username.indexOf(separator))
|
||||||
|
.replace('dadosfera', '');
|
||||||
|
let lastName = username
|
||||||
|
.substring(username.lastIndexOf(separator) + 1)
|
||||||
|
.replace('dadosfera', '');
|
||||||
|
|
||||||
|
if (!firstName) {
|
||||||
|
firstName = lastName;
|
||||||
|
lastName = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
firstName = this.capitalize(firstName);
|
||||||
|
lastName = this.capitalize(lastName);
|
||||||
|
|
||||||
|
await mixpanel.people.set(user.username, {
|
||||||
|
$first_name: firstName,
|
||||||
|
$last_name: lastName,
|
||||||
|
$name: this.getFullName(firstName, lastName),
|
||||||
|
$email: user.username.includes('@')
|
||||||
|
? user.username
|
||||||
|
: user.username + '@dadosfera.ai',
|
||||||
|
customer_name: user.customer_name
|
||||||
|
});
|
||||||
|
|
||||||
|
await mixpanel.track(id, {
|
||||||
|
distinct_id: user.username,
|
||||||
|
customer: user.customer_name,
|
||||||
|
env: process.env.ENV,
|
||||||
|
$ip: request.ip,
|
||||||
|
$os: request.headers['sec-ch-ua-platform'] || '',
|
||||||
|
$browser: request.headers['user-agent'],
|
||||||
|
...body,
|
||||||
|
});
|
||||||
|
|
||||||
return { id, body, user: user.username };
|
return { id, body, user: user.username };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
capitalize(sentence: string): string {
|
||||||
|
if (!sentence) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return sentence[0].toUpperCase() + sentence.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
getFullName(firstName: string, lastName: string) {
|
||||||
|
return `${firstName}${lastName ? ' ' + lastName : ''}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { getSecretFromSecretsManager } from 'src/utils/SecretManager';
|
import { getSecretFromSecretsManager } from 'src/utils/SecretManager';
|
||||||
import { MixpanelController } from './mixpanel.controller';
|
import { MixpanelController } from './mixpanel.controller';
|
||||||
import { MixpanelService } from './mixpanel.service';
|
|
||||||
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
controllers: [MixpanelController],
|
controllers: [MixpanelController],
|
||||||
@@ -10,12 +8,9 @@ import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
|||||||
{
|
{
|
||||||
provide: 'MIXPANEL_TOKEN',
|
provide: 'MIXPANEL_TOKEN',
|
||||||
useValue: getSecretFromSecretsManager(
|
useValue: getSecretFromSecretsManager(
|
||||||
`prd/root/mixpanel_token`,
|
`${process.env.ENV}/root/mixpanel_token`,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
MixpanelService,
|
|
||||||
DadosferaLogger
|
|
||||||
],
|
],
|
||||||
exports: [MixpanelService]
|
|
||||||
})
|
})
|
||||||
export class MixpanelModule {}
|
export class MixpanelModule {}
|
||||||
|
|||||||
@@ -1,118 +0,0 @@
|
|||||||
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
|
||||||
import { Inject } from '@nestjs/common';
|
|
||||||
import { Request } from 'express';
|
|
||||||
import mixpanel, { init } from 'mixpanel';
|
|
||||||
import { RequestUser } from 'src/decorators/user.decorator';
|
|
||||||
|
|
||||||
export class MixpanelService {
|
|
||||||
logger: DadosferaLogger;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
@Inject('MIXPANEL_TOKEN')
|
|
||||||
private readonly mixpanelToken: string,
|
|
||||||
@Inject(DadosferaLogger)
|
|
||||||
dadosferaLogger: DadosferaLogger,
|
|
||||||
) {
|
|
||||||
this.logger = dadosferaLogger.logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
async track(eventName: string, user: RequestUser, request: Request, body: any) {
|
|
||||||
this.logger.info("track: " + JSON.stringify({
|
|
||||||
eventName,
|
|
||||||
...body
|
|
||||||
}))
|
|
||||||
const mixpanel = init(this.mixpanelToken);
|
|
||||||
await this.setPeople(user, mixpanel);
|
|
||||||
|
|
||||||
await mixpanel.track(eventName, {
|
|
||||||
distinct_id: user.username,
|
|
||||||
customer: user.customer_name,
|
|
||||||
env: process.env.ENV,
|
|
||||||
$ip: request.ip,
|
|
||||||
$os: request.headers['sec-ch-ua-platform'] || '',
|
|
||||||
$browser: request.headers['user-agent'],
|
|
||||||
...body,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
async trackShare(request: Request, body: any) {
|
|
||||||
this.logger.info("trackShare: " + JSON.stringify(body))
|
|
||||||
const mixpanel = init(this.mixpanelToken);
|
|
||||||
|
|
||||||
await mixpanel.track("share_page", {
|
|
||||||
env: process.env.ENV,
|
|
||||||
$ip: request.ip,
|
|
||||||
$os: request.headers['sec-ch-ua-platform'] || '',
|
|
||||||
$browser: request.headers['user-agent'],
|
|
||||||
...body,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async setPeople(user: RequestUser, mixpanel: mixpanel.Mixpanel) {
|
|
||||||
const separator = user.username.includes('-') ? '-' : '.';
|
|
||||||
const removeValues = [
|
|
||||||
'.dadosferatech.dadosfera',
|
|
||||||
'.demo.dadosfera',
|
|
||||||
'.dadosferademo',
|
|
||||||
'.dadosferarh.dadosfera',
|
|
||||||
'.dadosferatech.dadosfera2',
|
|
||||||
'.dadosferatech.dadosfera',
|
|
||||||
'.dadosfera.fin',
|
|
||||||
'.dadosferafin.dadosfera',
|
|
||||||
'.praxio.dadosfera',
|
|
||||||
'.dadosfera.tech',
|
|
||||||
'.treinamentos@dadosfera.ai',
|
|
||||||
'.dadosfera2',
|
|
||||||
'.treinamentosfera',
|
|
||||||
'.dadosfera',
|
|
||||||
];
|
|
||||||
|
|
||||||
let username = user.username;
|
|
||||||
|
|
||||||
removeValues.forEach((value) => {
|
|
||||||
username = username.replace(value, '');
|
|
||||||
});
|
|
||||||
|
|
||||||
username = username.split('@')?.[0];
|
|
||||||
username = username.split('+')?.[0];
|
|
||||||
|
|
||||||
let firstName = username
|
|
||||||
.substring(0, username.indexOf(separator))
|
|
||||||
.replace('dadosfera', '');
|
|
||||||
let lastName = username
|
|
||||||
.substring(username.lastIndexOf(separator) + 1)
|
|
||||||
.replace('dadosfera', '');
|
|
||||||
|
|
||||||
if (!firstName) {
|
|
||||||
firstName = lastName;
|
|
||||||
lastName = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
firstName = this.capitalize(firstName);
|
|
||||||
lastName = this.capitalize(lastName);
|
|
||||||
|
|
||||||
await mixpanel.people.set(user.username, {
|
|
||||||
$first_name: firstName,
|
|
||||||
$last_name: lastName,
|
|
||||||
$name: this.getFullName(firstName, lastName),
|
|
||||||
$email: user.username.includes('@')
|
|
||||||
? user.username
|
|
||||||
: user.username + '@dadosfera.ai',
|
|
||||||
customer_name: user.customer_name,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private capitalize(sentence: string): string {
|
|
||||||
if (!sentence) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
return sentence[0].toUpperCase() + sentence.substring(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private getFullName(firstName: string, lastName: string) {
|
|
||||||
return `${firstName}${lastName ? ' ' + lastName : ''}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
import { NetworkPoliciesDTO } from './dto/network-policy.dto';
|
import { NetworkPoliciesDTO } from './dto/network-policy.dto';
|
||||||
import { RequestUser, User } from 'src/decorators/user.decorator';
|
import { RequestUser, User } from 'src/decorators/user.decorator';
|
||||||
import { NetworkPolicyService } from './network-policy.service';
|
import { NetworkPolicyService } from './network-policy.service';
|
||||||
import { PackTheMetadata } from 'src/utils/PackTheMetadata';
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
|
|
||||||
@Controller('network-policy')
|
@Controller('network-policy')
|
||||||
export class NetworkPolicyController {
|
export class NetworkPolicyController {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { AuthGuard } from '@nestjs/passport';
|
|||||||
import { ConnectionClientService } from '../connection/client.service';
|
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 { ApiInternalOnlyEndpoint } from 'src/decorators/swagger.decorator';
|
import { ApiInternalOnlyEndpoint } from 'src/decorators/swagger.decorator';
|
||||||
@ApiTags('oauth')
|
@ApiTags('oauth')
|
||||||
@Controller('oauth')
|
@Controller('oauth')
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { Language } from 'src/decorators/language.decorator';
|
|||||||
import { OpenDataService } from './open-data.service';
|
import { OpenDataService } from './open-data.service';
|
||||||
import { CreateUserOpenDataDTO, WordpressForm } from './dto/wordpres-form';
|
import { CreateUserOpenDataDTO, WordpressForm } from './dto/wordpres-form';
|
||||||
import { Metadata } from '@grpc/grpc-js';
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
import { PackTheMetadata } from 'src/utils/PackTheMetadata';
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
import { request } from 'http';
|
import { request } from 'http';
|
||||||
import { Request } from 'express';
|
import { Request } from 'express';
|
||||||
|
|
||||||
@@ -45,11 +45,11 @@ export class OpenDataController {
|
|||||||
) {
|
) {
|
||||||
this.logger.info('createUser for open data' + JSON.stringify(request.headers));
|
this.logger.info('createUser for open data' + JSON.stringify(request.headers));
|
||||||
|
|
||||||
// const corslist = ["https://devsbm.dadosfera.io", "https://sharingoceandata.com"];
|
const corslist = ["https://devsbm.dadosfera.io", "https://sharingoceandata.com"];
|
||||||
// if (!corslist.includes(origin)) {
|
if (!corslist.includes(origin)) {
|
||||||
// this.logger.info('block request by cors list: '+ origin);
|
this.logger.info('block request by cors list: '+ origin);
|
||||||
// throw new ForbiddenException();
|
throw new ForbiddenException();
|
||||||
// }
|
}
|
||||||
|
|
||||||
const OPENDATA_CUSTOMER_ID = process.env.OPEN_CUSTOMER_ID;
|
const OPENDATA_CUSTOMER_ID = process.env.OPEN_CUSTOMER_ID;
|
||||||
const OPENDATA_GROUP_ID = process.env.OPEN_GROUP_ID;
|
const OPENDATA_GROUP_ID = process.env.OPEN_GROUP_ID;
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import { PipelinesService } from './pipelines.service';
|
|||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
import { Messages } from '@dadosfera/protospack-v2/dist/lib/PipelineV2';
|
import { Messages } from '@dadosfera/protospack-v2/dist/lib/PipelineV2';
|
||||||
import { RequestUser, User } from 'src/decorators/user.decorator';
|
import { RequestUser, User } from 'src/decorators/user.decorator';
|
||||||
import { PackTheMetadata } from 'src/utils/PackTheMetadata';
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
|
|
||||||
import { PipelinesService as OldPipelineService } from 'src/modules/pipelines/pipelines.service';
|
import { PipelinesService as OldPipelineService } from 'src/modules/pipelines/pipelines.service';
|
||||||
import {
|
import {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { PermissionsService } from '../permissions/permissions.service';
|
|||||||
import { LanguageEnum } from 'src/utils/languages.enum';
|
import { LanguageEnum } from 'src/utils/languages.enum';
|
||||||
import { RequestUser } from 'src/decorators/user.decorator';
|
import { RequestUser } from 'src/decorators/user.decorator';
|
||||||
import { DucClient } from '../duc/client.config';
|
import { DucClient } from '../duc/client.config';
|
||||||
|
import { PUBLIC_PERMISSIONS_SEQID } from 'src/authentication/permissions.enum';
|
||||||
|
|
||||||
interface GetRolesPermissionsName {
|
interface GetRolesPermissionsName {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -103,6 +104,20 @@ export class RolesService {
|
|||||||
const meta = new Metadata();
|
const meta = new Metadata();
|
||||||
meta.add('access_token', access_token);
|
meta.add('access_token', access_token);
|
||||||
const { description, name, permissionIds, userIds } = data;
|
const { description, name, permissionIds, userIds } = data;
|
||||||
|
|
||||||
|
const invalidPermissions = [];
|
||||||
|
for (const permission of permissionIds) {
|
||||||
|
if (!PUBLIC_PERMISSIONS_SEQID.includes(permission)) {
|
||||||
|
invalidPermissions.push(permission);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (invalidPermissions.length > 0) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
`Invalid permissions: ${invalidPermissions.join(', ')}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const role = await lastValueFrom(
|
const role = await lastValueFrom(
|
||||||
this.rolesClientService.RoleCreate(
|
this.rolesClientService.RoleCreate(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
export class CreateShareMetadataDto {
|
|
||||||
assetId: string;
|
|
||||||
proposedId: string;
|
|
||||||
type: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class UpdateShareMetadataDto {
|
|
||||||
shareId: string;
|
|
||||||
type: string;
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
import { Controller, Get, Body, Param, Put, Patch } from '@nestjs/common';
|
|
||||||
import { ShareMetadataService } from './share-metadata.service';
|
|
||||||
import { Authenticated } from 'src/decorators/authentication.decorator';
|
|
||||||
import { RequestUser, User } from 'src/decorators/user.decorator';
|
|
||||||
import { PackTheMetadata } from 'src/utils/PackTheMetadata';
|
|
||||||
import { CreateShareMetadataDto, UpdateShareMetadataDto } from './dto/create-share-metadata.dto';
|
|
||||||
|
|
||||||
@Controller('share')
|
|
||||||
@Authenticated()
|
|
||||||
export class ShareMetadataController {
|
|
||||||
constructor(private readonly shareMetadataService: ShareMetadataService) {}
|
|
||||||
|
|
||||||
@Put('/')
|
|
||||||
findOrcreate(@Body() data: CreateShareMetadataDto, @User() user: RequestUser) {
|
|
||||||
const metadata = PackTheMetadata(user);
|
|
||||||
return this.shareMetadataService.create(data, metadata);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Patch('/')
|
|
||||||
updateShareType(@Body() data: UpdateShareMetadataDto, @User() user: RequestUser) {
|
|
||||||
const metadata = PackTheMetadata(user);
|
|
||||||
return this.shareMetadataService.updateShare(data, metadata);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Get('/:id')
|
|
||||||
get(@Param('id') id: string, @User() user: RequestUser) {
|
|
||||||
const metadata = PackTheMetadata(user);
|
|
||||||
return this.shareMetadataService.get(id, metadata);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
import { Module } from '@nestjs/common';
|
|
||||||
import { ShareMetadataService } from './share-metadata.service';
|
|
||||||
import { ShareMetadataController } from './share-metadata.controller';
|
|
||||||
import { DucClient } from '../duc/client.config';
|
|
||||||
import { ClientsModule } from '@nestjs/microservices';
|
|
||||||
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
|
||||||
|
|
||||||
const client = new DucClient();
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
imports: [ClientsModule.register([client.providerOptions])],
|
|
||||||
controllers: [ShareMetadataController],
|
|
||||||
providers: [ShareMetadataService, DadosferaLogger],
|
|
||||||
exports: [ShareMetadataService]
|
|
||||||
})
|
|
||||||
export class ShareMetadataModule {}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
import { Inject, Injectable, OnModuleInit } from '@nestjs/common';
|
|
||||||
import { Metadata } from '@grpc/grpc-js';
|
|
||||||
import { ClientGrpc } from '@nestjs/microservices';
|
|
||||||
import { DucClient } from '../duc/client.config';
|
|
||||||
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
|
||||||
import { ShareMetadataProtoService } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/write-service';
|
|
||||||
import { lastValueFrom } from 'rxjs';
|
|
||||||
import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Duc';
|
|
||||||
import { CreateShareMetadataDto, UpdateShareMetadataDto } from './dto/create-share-metadata.dto';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class ShareMetadataService implements OnModuleInit {
|
|
||||||
ducService: ShareMetadataProtoService;
|
|
||||||
logger: DadosferaLogger;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
@Inject(DadosferaLogger)
|
|
||||||
dadosferaLogger: DadosferaLogger,
|
|
||||||
@Inject(DucClient.name) private readonly grpcClient: ClientGrpc,
|
|
||||||
) {
|
|
||||||
this.logger = dadosferaLogger.logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
onModuleInit() {
|
|
||||||
this.ducService =this.grpcClient.getService<ShareMetadataProtoService>(
|
|
||||||
ProtoServices.ShareMetadataProtoService,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
create(createShareDto: CreateShareMetadataDto, metadata: Metadata) {
|
|
||||||
return lastValueFrom(
|
|
||||||
this.ducService.FindOrCreateShareMetadata(
|
|
||||||
{
|
|
||||||
assetId: createShareDto.assetId,
|
|
||||||
proposedId: createShareDto.proposedId,
|
|
||||||
type: createShareDto.type
|
|
||||||
},
|
|
||||||
metadata,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateShare(updateShare: UpdateShareMetadataDto, metadata: Metadata) {
|
|
||||||
return lastValueFrom(
|
|
||||||
this.ducService.ChangeShareMetadataType(
|
|
||||||
updateShare,
|
|
||||||
metadata,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
get(id: string, metadata: Metadata) {
|
|
||||||
return lastValueFrom(
|
|
||||||
this.ducService.GetShareMetadata(
|
|
||||||
{
|
|
||||||
id,
|
|
||||||
},
|
|
||||||
metadata,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -29,7 +29,7 @@ import { Language } from 'src/decorators/language.decorator';
|
|||||||
import { ApiInternalOnlyController } from 'src/decorators/swagger.decorator';
|
import { ApiInternalOnlyController } from 'src/decorators/swagger.decorator';
|
||||||
import { RequestUser, User } from 'src/decorators/user.decorator';
|
import { RequestUser, User } from 'src/decorators/user.decorator';
|
||||||
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
||||||
import { PackTheMetadata } from 'src/utils/PackTheMetadata';
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
import ErrorBuilder from 'src/utils/ErrorBuilder';
|
import ErrorBuilder from 'src/utils/ErrorBuilder';
|
||||||
import ErrorCodes from 'src/utils/errorCodes';
|
import ErrorCodes from 'src/utils/errorCodes';
|
||||||
import { LanguageEnum } from 'src/utils/languages.enum';
|
import { LanguageEnum } from 'src/utils/languages.enum';
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export class PDFParser<T> implements Parser<T> {
|
|||||||
const html = await this.htmlParser.parse(data);
|
const html = await this.htmlParser.parse(data);
|
||||||
await page.setContent(html, {
|
await page.setContent(html, {
|
||||||
waitUntil: 'networkidle0',
|
waitUntil: 'networkidle0',
|
||||||
timeout: 90000,
|
timeout: 30000,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Configurações adicionais para garantir um PDF válido
|
// Configurações adicionais para garantir um PDF válido
|
||||||
@@ -43,7 +43,7 @@ export class PDFParser<T> implements Parser<T> {
|
|||||||
pageRanges: '',
|
pageRanges: '',
|
||||||
tagged: true,
|
tagged: true,
|
||||||
outline: false,
|
outline: false,
|
||||||
timeout: 90000,
|
timeout: 30000,
|
||||||
});
|
});
|
||||||
|
|
||||||
await browser.close();
|
await browser.close();
|
||||||
|
|||||||
Reference in New Issue
Block a user