mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-22 20:59:08 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6b3e02890 | ||
|
|
d06910515b | ||
|
|
d1b328d481 | ||
|
|
945955a71c | ||
|
|
cdba41dffa | ||
|
|
5020e8913e | ||
|
|
89369270b9 | ||
|
|
52f17725af | ||
|
|
6da213aebc | ||
|
|
a353a1b45c | ||
|
|
b36ff624b5 | ||
|
|
03c09a525b | ||
|
|
9ea610a405 | ||
|
|
cd97bcbac0 | ||
|
|
52bf2bdef3 | ||
|
|
161d1fa05d | ||
|
|
642bf462ad | ||
|
|
6d61d74d0c | ||
|
|
2bc060b13d | ||
|
|
28efdf95d9 | ||
|
|
1ef9fd4298 | ||
|
|
5c24ec5560 | ||
|
|
962e094a65 | ||
|
|
131b166d8d | ||
|
|
5419f3690c | ||
|
|
6f3eb7965b | ||
|
|
909f0d4a4e | ||
|
|
8c8fdf5f88 | ||
|
|
e9582a51c2 | ||
|
|
0590c20af8 | ||
|
|
05eefe866b | ||
|
|
fa023756c7 | ||
|
|
7f967e5e75 | ||
|
|
2a0b17e45a | ||
|
|
b1f6d765b2 | ||
|
|
3c9ed08515 | ||
|
|
c7ca8297c9 | ||
|
|
d269e9efe4 |
+206
-10
@@ -288,6 +288,71 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/auth/session/{session}": {
|
||||||
|
"get": {
|
||||||
|
"operationId": "AuthController_getSession",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "session",
|
||||||
|
"required": true,
|
||||||
|
"in": "path",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"Auth"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/auth/oauth/google": {
|
||||||
|
"get": {
|
||||||
|
"operationId": "AuthController_googleOauth",
|
||||||
|
"parameters": [],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "boolean"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"Auth"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/auth/oauth/google/callback": {
|
||||||
|
"get": {
|
||||||
|
"operationId": "AuthController_googleOauthCallback",
|
||||||
|
"parameters": [],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"Auth"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
"/connectors": {
|
"/connectors": {
|
||||||
"post": {
|
"post": {
|
||||||
"operationId": "ConnectorController_uploadConnector",
|
"operationId": "ConnectorController_uploadConnector",
|
||||||
@@ -1587,6 +1652,17 @@
|
|||||||
],
|
],
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "canUntoggleLogic",
|
||||||
|
"required": false,
|
||||||
|
"in": "query",
|
||||||
|
"schema": {
|
||||||
|
"enum": [
|
||||||
|
"data_assets_sharing"
|
||||||
|
],
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
@@ -2433,16 +2509,71 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/pipelinesV2/upload": {
|
"/pipelinesV2/init-upload": {
|
||||||
"post": {
|
"post": {
|
||||||
"operationId": "PipelinesController_uploadFile",
|
"operationId": "PipelinesController_initUploadFile",
|
||||||
"parameters": [],
|
"parameters": [],
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
"required": true,
|
"required": true,
|
||||||
"content": {
|
"content": {
|
||||||
"multipart/form-data": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/components/schemas/IUploadCSVFile"
|
"$ref": "#/components/schemas/IInitUploadCSVFile"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"201": {
|
||||||
|
"description": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"PipelinesV2"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/pipelinesV2/complete-upload": {
|
||||||
|
"post": {
|
||||||
|
"operationId": "PipelinesController_completeUploadFile",
|
||||||
|
"parameters": [],
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ICompleteUploadCSVFile"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"201": {
|
||||||
|
"description": "",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"PipelinesV2"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/pipelinesV2/file": {
|
||||||
|
"post": {
|
||||||
|
"operationId": "PipelinesController_uploadedFile",
|
||||||
|
"parameters": [],
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ICreatePipelineCSVFile"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2788,7 +2919,16 @@
|
|||||||
"/catalog/data-asset/{id}": {
|
"/catalog/data-asset/{id}": {
|
||||||
"get": {
|
"get": {
|
||||||
"operationId": "CatalogController_getDataAsset",
|
"operationId": "CatalogController_getDataAsset",
|
||||||
"parameters": [],
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "shared",
|
||||||
|
"required": true,
|
||||||
|
"in": "query",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": ""
|
"description": ""
|
||||||
@@ -3993,6 +4133,10 @@
|
|||||||
},
|
},
|
||||||
"usage": {
|
"usage": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"canUntoggle": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Whether this role can be untoggled"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
@@ -4470,6 +4614,10 @@
|
|||||||
},
|
},
|
||||||
"usage": {
|
"usage": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"canUntoggle": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Whether this role can be untoggled"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
@@ -4560,6 +4708,10 @@
|
|||||||
},
|
},
|
||||||
"usage": {
|
"usage": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"canUntoggle": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Whether this role can be untoggled"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
@@ -5223,16 +5375,52 @@
|
|||||||
"updated_at"
|
"updated_at"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"IUploadCSVFile": {
|
"IInitUploadCSVFile": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"file": {
|
"file_name": {
|
||||||
"type": "string",
|
"type": "string"
|
||||||
"format": "binary"
|
|
||||||
},
|
},
|
||||||
|
"parts": {
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"file_name",
|
||||||
|
"parts"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"ICompleteUploadCSVFile": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"upload_id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"file_name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"parts": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"upload_id",
|
||||||
|
"file_name",
|
||||||
|
"parts"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"ICreatePipelineCSVFile": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
"name": {
|
"name": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"file_name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"description": {
|
"description": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
@@ -5247,8 +5435,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"file",
|
|
||||||
"name",
|
"name",
|
||||||
|
"file_name",
|
||||||
"description",
|
"description",
|
||||||
"encoding",
|
"encoding",
|
||||||
"sep",
|
"sep",
|
||||||
@@ -5797,6 +5985,14 @@
|
|||||||
},
|
},
|
||||||
"embed": {
|
"embed": {
|
||||||
"$ref": "#/components/schemas/EmbedObject"
|
"$ref": "#/components/schemas/EmbedObject"
|
||||||
|
},
|
||||||
|
"share_type": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"none",
|
||||||
|
"public",
|
||||||
|
"private"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
|
|||||||
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.27.1",
|
"@dadosfera/protospack-v2": "3.29.0",
|
||||||
"@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",
|
||||||
@@ -1727,9 +1727,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@dadosfera/protospack-v2": {
|
"node_modules/@dadosfera/protospack-v2": {
|
||||||
"version": "3.27.1",
|
"version": "3.29.0",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.27.1.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.29.0.tgz",
|
||||||
"integrity": "sha512-bAhHSS1cquIJadHiWSO1FFJFfugrJXEIWKFzE7PByeC9XldGru/qlART7KXbxqYHQq8lALKJy1ILyMyG91BsTA==",
|
"integrity": "sha512-G66u9V+/+5rQb+fpJdDXydTaji2Mlr0Ro5TTYcQleITKU9DjF1WZs/jP/Qu0Y224nCb8HhePvaVl/Rr0wtLt4w==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@grpc/grpc-js": "^1.6.7",
|
"@grpc/grpc-js": "^1.6.7",
|
||||||
"rxjs": "^7.5.5",
|
"rxjs": "^7.5.5",
|
||||||
@@ -12284,9 +12284,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@dadosfera/protospack-v2": {
|
"@dadosfera/protospack-v2": {
|
||||||
"version": "3.27.1",
|
"version": "3.29.0",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.27.1.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.29.0.tgz",
|
||||||
"integrity": "sha512-bAhHSS1cquIJadHiWSO1FFJFfugrJXEIWKFzE7PByeC9XldGru/qlART7KXbxqYHQq8lALKJy1ILyMyG91BsTA==",
|
"integrity": "sha512-G66u9V+/+5rQb+fpJdDXydTaji2Mlr0Ro5TTYcQleITKU9DjF1WZs/jP/Qu0Y224nCb8HhePvaVl/Rr0wtLt4w==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@grpc/grpc-js": "^1.6.7",
|
"@grpc/grpc-js": "^1.6.7",
|
||||||
"rxjs": "^7.5.5",
|
"rxjs": "^7.5.5",
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,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.27.1",
|
"@dadosfera/protospack-v2": "3.29.0",
|
||||||
"@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",
|
||||||
|
|||||||
@@ -336,6 +336,16 @@ export const PERMISSIONS_GROUPS = {
|
|||||||
'es-es': 'Gestor de catálogos. Puede ver y editar todos los activos.',
|
'es-es': 'Gestor de catálogos. Puede ver y editar todos los activos.',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
EMBED_ANALYTICS: {
|
||||||
|
seqid: 44,
|
||||||
|
claim: 'catalog:embed',
|
||||||
|
usage: PermissionUsages.INTERNAL,
|
||||||
|
name: {
|
||||||
|
'pt-br': 'Acessar Módulo de Incorporação de Ativos',
|
||||||
|
'en-us': 'Access Embedding analytics Module',
|
||||||
|
'es-es': 'Acceder al Módulo de Incorporación de Activos',
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -556,7 +566,34 @@ export const PERMISSIONS_GROUPS = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
export interface DadosferaModule {
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
key: string;
|
||||||
|
permissionSeqId: number;
|
||||||
|
}
|
||||||
|
export const DADOSFERA_MODULES: Array<DadosferaModule> = [
|
||||||
|
{
|
||||||
|
name: 'Intelligence Module',
|
||||||
|
description: 'Orchest Module',
|
||||||
|
key: 'intelligence',
|
||||||
|
permissionSeqId: PERMISSIONS_GROUPS.ANALYZE.permissions.INTELLIGENCE.seqid,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Proccessing Module',
|
||||||
|
description: 'Proccessing Module',
|
||||||
|
key: 'process',
|
||||||
|
permissionSeqId:
|
||||||
|
PERMISSIONS_GROUPS.PROCESS.permissions.TRANSFORMATION.seqid,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Embedded Analytics',
|
||||||
|
description: 'Embedded Analytics Module',
|
||||||
|
key: 'embedded-analytics',
|
||||||
|
permissionSeqId:
|
||||||
|
PERMISSIONS_GROUPS.PROCESS.permissions.TRANSFORMATION.seqid,
|
||||||
|
},
|
||||||
|
];
|
||||||
// traverses the object searching for duplicate seqids or claims (executes at runtime)
|
// traverses the object searching for duplicate seqids or claims (executes at runtime)
|
||||||
let nextAvailableSeqid = 0;
|
let nextAvailableSeqid = 0;
|
||||||
const seqids = Object.values(PERMISSIONS_GROUPS).flatMap((namespace) =>
|
const seqids = Object.values(PERMISSIONS_GROUPS).flatMap((namespace) =>
|
||||||
@@ -576,4 +613,9 @@ Object.values(PERMISSIONS_GROUPS).map((namespace) =>
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
DADOSFERA_MODULES.map((m) => m.key).forEach((m, i, arr) => {
|
||||||
|
if (arr.indexOf(m) !== i)
|
||||||
|
throw new Error(`DADOSFERA_MODULES[${i}] does not have a unique key`);
|
||||||
|
});
|
||||||
|
|
||||||
logger.log(`next available seqid ${nextAvailableSeqid + 1}`);
|
logger.log(`next available seqid ${nextAvailableSeqid + 1}`);
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
# Auth
|
||||||
|
|
||||||
|
## SSO/oAuth
|
||||||
|
|
||||||
|
### Strategy
|
||||||
|
We are using [PassportJs](https://www.passportjs.org/) to handle oAuth authentications.
|
||||||
|
|
||||||
|
When the client (front end) makes a `GET /auth/oauth/{strategy}` Passport automatically redirects the user to the `strategy` login page. To do that we must configure and use a **Passport Strategy**. We must also have a callback route, conventionally `GET /auth/oauth/{strategy}/callback`, so the oAuth app can report the status of the user's login.
|
||||||
|
|
||||||
|
- If the oAuth is successfull we call DUC's `AuthOauthSignIn` request that gets the tokens from Cognito and saves them on cache temporarily under a key we call `session`. Duc returns that `session` to maestro which then redirects the user to our app login page with that `session` as a query param.
|
||||||
|
|
||||||
|
- If the oAuth login is not successfull for some reason or the user **does not** exist on DUC's database we redirect the user to our login page with an `error` and `error_description` as query params.
|
||||||
|
|
||||||
|
### Routes
|
||||||
|
|
||||||
|
So in order to have an SSO login, besides configuring the Strategy, we must have two routes for each Strategy, like in the example below:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
@Get('oauth/google')
|
||||||
|
@UseGuards(AuthGuard('google-login'))
|
||||||
|
googleOauth() {
|
||||||
|
this.logger.info('/oauth/google');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('oauth/google/callback')
|
||||||
|
@UseGuards(AuthGuard('google-login'))
|
||||||
|
@Redirect()
|
||||||
|
async googleOauthCallback(@Req() req) {
|
||||||
|
const { url, email, token, language = 'pt-br' } = await this.callback(req);
|
||||||
|
if (url.searchParams.get('error')) {
|
||||||
|
this.logger.error('/oauth/google - ERROR');
|
||||||
|
return { url: url.href };
|
||||||
|
}
|
||||||
|
// ... Rest of the logic
|
||||||
|
return { url: url.href };
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -8,6 +8,10 @@ import {
|
|||||||
Inject,
|
Inject,
|
||||||
UseFilters,
|
UseFilters,
|
||||||
Get,
|
Get,
|
||||||
|
UseGuards,
|
||||||
|
Redirect,
|
||||||
|
Req,
|
||||||
|
Param,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import {
|
import {
|
||||||
@@ -29,19 +33,23 @@ import { AuthClientService } from './auth.service';
|
|||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
import { GrpcToHttpExceptionFilter } from '../../error/grpc-to-http-exception.filter';
|
import { GrpcToHttpExceptionFilter } from '../../error/grpc-to-http-exception.filter';
|
||||||
import { RequestUser, User } from 'src/authentication/user.decorator';
|
import { RequestUser, User } from 'src/authentication/user.decorator';
|
||||||
import { Metadata } from '@grpc/grpc-js';
|
|
||||||
import {
|
import {
|
||||||
AuthRefreshAccessTokenReq,
|
AuthRefreshAccessTokenReq,
|
||||||
AuthSignInReq,
|
AuthSignInReq,
|
||||||
AuthSignInRes,
|
AuthSignInRes,
|
||||||
} from './dtos/login';
|
} from './dtos/login';
|
||||||
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
|
import { AuthGuard } from '@nestjs/passport';
|
||||||
|
import { Request } from 'express';
|
||||||
|
import ErrorCodes, { OauthErrors } from 'src/utils/errorCodes';
|
||||||
|
import jwt from 'jsonwebtoken';
|
||||||
|
|
||||||
@ApiTags('Auth')
|
@ApiTags('Auth')
|
||||||
@UseFilters(new GrpcToHttpExceptionFilter())
|
@UseFilters(new GrpcToHttpExceptionFilter())
|
||||||
@Controller('auth')
|
@Controller('auth')
|
||||||
export class AuthController {
|
export class AuthController {
|
||||||
logger: DadosferaLogger;
|
logger: DadosferaLogger;
|
||||||
|
redirectUrl: string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(DadosferaLogger)
|
@Inject(DadosferaLogger)
|
||||||
@@ -49,6 +57,17 @@ export class AuthController {
|
|||||||
private authClient: AuthClientService,
|
private authClient: AuthClientService,
|
||||||
) {
|
) {
|
||||||
this.logger = dadosferaLogger.logger;
|
this.logger = dadosferaLogger.logger;
|
||||||
|
|
||||||
|
switch (process.env.ENV) {
|
||||||
|
case 'stg':
|
||||||
|
this.redirectUrl = `https://app.${process.env.ENV}.dadosfera.ai/auth/login`;
|
||||||
|
break;
|
||||||
|
case 'prd':
|
||||||
|
this.redirectUrl = `https://app.dadosfera.ai/auth/login`;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this.redirectUrl = `http://localhost:4200/auth/login`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('sign-in')
|
@Post('sign-in')
|
||||||
@@ -58,8 +77,7 @@ export class AuthController {
|
|||||||
@Headers('Dadosfera-Lang') language: string,
|
@Headers('Dadosfera-Lang') language: string,
|
||||||
): Promise<AuthSignInRes> {
|
): Promise<AuthSignInRes> {
|
||||||
this.logger.info('/auth - SignIn');
|
this.logger.info('/auth - SignIn');
|
||||||
const metadata = new Metadata();
|
const metadata = PackTheMetadata({ language: language || 'pt-br' });
|
||||||
metadata.add('language', language || 'pt-br');
|
|
||||||
return this.authClient.signIn({ username, password, totp }, metadata);
|
return this.authClient.signIn({ username, password, totp }, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,12 +133,18 @@ export class AuthController {
|
|||||||
|
|
||||||
@Post('reset-password')
|
@Post('reset-password')
|
||||||
@HttpCode(HttpStatus.OK)
|
@HttpCode(HttpStatus.OK)
|
||||||
async resetPassword(@Body() body: AuthResetPasswordRequest) {
|
async resetPassword(
|
||||||
|
@Body() body: AuthResetPasswordRequest,
|
||||||
|
@Headers('dadosfera-lang') language,
|
||||||
|
) {
|
||||||
this.logger.info('/auth - reset-password');
|
this.logger.info('/auth - reset-password');
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
language: language,
|
||||||
|
});
|
||||||
|
|
||||||
const { username } = body;
|
const { username } = body;
|
||||||
|
|
||||||
return this.authClient.resetPassword({ username });
|
return this.authClient.resetPassword({ username }, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('verify-reset-password-code')
|
@Post('verify-reset-password-code')
|
||||||
@@ -200,8 +224,99 @@ export class AuthController {
|
|||||||
|
|
||||||
@Authenticated()
|
@Authenticated()
|
||||||
@Get('verify-access-token')
|
@Get('verify-access-token')
|
||||||
@HttpCode(HttpStatus.OK)
|
|
||||||
verifyAccessToken() {
|
verifyAccessToken() {
|
||||||
return { access_token_status: 'valid' };
|
return { access_token_status: 'valid' };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('session/:session')
|
||||||
|
getSession(@Param('session') session: string) {
|
||||||
|
return this.authClient.getSession(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('oauth/google')
|
||||||
|
@UseGuards(AuthGuard('google-login'))
|
||||||
|
googleOauth() {
|
||||||
|
this.logger.info('/oauth/google');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('oauth/google/callback')
|
||||||
|
@UseGuards(AuthGuard('google-login'))
|
||||||
|
@Redirect()
|
||||||
|
async googleOauthCallback(@Req() req) {
|
||||||
|
const { url, email, token, language = 'pt-br' } = await this.callback(req);
|
||||||
|
if (url.searchParams.get('error')) {
|
||||||
|
this.logger.error('/oauth/google - ERROR');
|
||||||
|
return { url: url.href };
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.authClient
|
||||||
|
.oauthSignIn({
|
||||||
|
username: email,
|
||||||
|
token,
|
||||||
|
})
|
||||||
|
.then(({ session }) => {
|
||||||
|
this.logger.info('/oauth/google - SUCESS');
|
||||||
|
url.searchParams.set('session', session);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
this.logger.error('/oauth/google - ERROR');
|
||||||
|
let error = OauthErrors.INVALID_CREDENTIALS[language].error;
|
||||||
|
let error_description =
|
||||||
|
OauthErrors.INVALID_CREDENTIALS[language].error_description;
|
||||||
|
switch (err.details) {
|
||||||
|
case ErrorCodes.USER.NOT_FOUND:
|
||||||
|
error = OauthErrors.USER_NOT_FOUND[language].error;
|
||||||
|
error_description =
|
||||||
|
OauthErrors.USER_NOT_FOUND[language].error_description(email);
|
||||||
|
break;
|
||||||
|
case ErrorCodes.AUTH.UNAUTHORIZED:
|
||||||
|
error = OauthErrors.INVALID_SESSION[language].error;
|
||||||
|
error_description =
|
||||||
|
OauthErrors.INVALID_SESSION[language].error_description;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
url.searchParams.set('error', error);
|
||||||
|
url.searchParams.set('error_description', error_description);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
return { url: url.href };
|
||||||
|
}
|
||||||
|
|
||||||
|
async callback(req: Request) {
|
||||||
|
const { error, state } = req.query;
|
||||||
|
const { authInfo } = req;
|
||||||
|
const url = new URL(this.redirectUrl);
|
||||||
|
let email, token, error_title, error_description;
|
||||||
|
let language: 'pt-br' | 'en-us' = 'pt-br';
|
||||||
|
|
||||||
|
const stateObject = jwt.verify(
|
||||||
|
state as string,
|
||||||
|
process.env.JWT_PRIVATE_KEY,
|
||||||
|
);
|
||||||
|
if (typeof stateObject != 'string') language = stateObject.language;
|
||||||
|
|
||||||
|
if (error || !authInfo) {
|
||||||
|
this.logger.error(error);
|
||||||
|
if (!authInfo) this.logger.error('No authInfo', { request: req });
|
||||||
|
|
||||||
|
error_title = OauthErrors.INVALID_CREDENTIALS[language].error;
|
||||||
|
error_description =
|
||||||
|
OauthErrors.INVALID_CREDENTIALS[language].error_description;
|
||||||
|
if (error) error_description += ` - [${error}]`;
|
||||||
|
} else {
|
||||||
|
const { accessToken } = authInfo as any;
|
||||||
|
const { _json: userInfo } = req.user as any;
|
||||||
|
|
||||||
|
email = userInfo.email;
|
||||||
|
token = accessToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error_title) {
|
||||||
|
url.searchParams.set('error', error_title);
|
||||||
|
url.searchParams.set('error_description', error_description);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { token, email, url, language };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,19 @@ import { AuthController } from './auth.controller';
|
|||||||
import { AuthClientService } from './auth.service';
|
import { AuthClientService } from './auth.service';
|
||||||
|
|
||||||
import { DucClient } from '../duc/client.config';
|
import { DucClient } from '../duc/client.config';
|
||||||
|
import { GoogleLoginStrategy } from './passport-strategies/google-strategy';
|
||||||
|
import { getOauthSecrets } from 'src/utils/OauthSecrets';
|
||||||
const client = new DucClient();
|
const client = new DucClient();
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [ClientsModule.register([client.providerOptions])],
|
imports: [ClientsModule.register([client.providerOptions])],
|
||||||
controllers: [AuthController],
|
controllers: [AuthController],
|
||||||
providers: [AuthClientService, DadosferaLogger],
|
providers: [
|
||||||
|
AuthClientService,
|
||||||
|
DadosferaLogger,
|
||||||
|
GoogleLoginStrategy,
|
||||||
|
{ provide: 'OAUTH_SECRETS', useValue: getOauthSecrets() },
|
||||||
|
],
|
||||||
exports: [AuthClientService],
|
exports: [AuthClientService],
|
||||||
})
|
})
|
||||||
export class AuthModule {}
|
export class AuthModule {}
|
||||||
|
|||||||
@@ -90,10 +90,15 @@ export class AuthClientService implements OnModuleInit {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async resetPassword({ username }: AuthResetPasswordRequest) {
|
async resetPassword(
|
||||||
|
{ username }: AuthResetPasswordRequest,
|
||||||
|
metadata: Metadata,
|
||||||
|
) {
|
||||||
this.logger.info('resetPassword');
|
this.logger.info('resetPassword');
|
||||||
|
|
||||||
return lastValueFrom(this.authService.AuthResetPassword({ username }));
|
return lastValueFrom(
|
||||||
|
this.authService.AuthResetPassword({ username }, metadata),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async verifyResetPasswordCode({
|
async verifyResetPasswordCode({
|
||||||
@@ -152,4 +157,13 @@ export class AuthClientService implements OnModuleInit {
|
|||||||
this.authService.AuthVerifyTotpMfa({ accessToken, totp }),
|
this.authService.AuthVerifyTotpMfa({ accessToken, totp }),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getSession(session: string) {
|
||||||
|
return lastValueFrom(this.authService.AuthGetSession({ session }));
|
||||||
|
}
|
||||||
|
|
||||||
|
async oauthSignIn(data: { username: string; token: string }) {
|
||||||
|
const { username, token } = data;
|
||||||
|
return lastValueFrom(this.authService.AuthOauthSignIn({ token, username }));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import {
|
||||||
|
AuthenticateOptionsGoogle,
|
||||||
|
Profile,
|
||||||
|
Strategy,
|
||||||
|
StrategyOptions,
|
||||||
|
} from 'passport-google-oauth20';
|
||||||
|
import { PassportStrategy } from '@nestjs/passport';
|
||||||
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
|
import { OauthSecrets } from 'src/utils/OauthSecrets';
|
||||||
|
import { Request } from 'express';
|
||||||
|
import jwt from 'jsonwebtoken';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class GoogleLoginStrategy extends PassportStrategy(
|
||||||
|
Strategy,
|
||||||
|
'google-login',
|
||||||
|
) {
|
||||||
|
redirect_uri: string;
|
||||||
|
constructor(
|
||||||
|
@Inject('OAUTH_SECRETS')
|
||||||
|
private readonly oauthSecrets: OauthSecrets,
|
||||||
|
) {
|
||||||
|
const options: StrategyOptions = {
|
||||||
|
clientID: oauthSecrets['google-login'].client_id,
|
||||||
|
clientSecret: oauthSecrets['google-login'].client_secret,
|
||||||
|
callbackURL: oauthSecrets['google-login'].redirect_uri,
|
||||||
|
scope: ['email', 'profile', 'openid'],
|
||||||
|
};
|
||||||
|
const verify = (
|
||||||
|
accessToken: string,
|
||||||
|
refreshToken: string,
|
||||||
|
profile: Profile,
|
||||||
|
done,
|
||||||
|
) => {
|
||||||
|
return done(null, profile, { accessToken, refreshToken });
|
||||||
|
};
|
||||||
|
|
||||||
|
super(options, verify);
|
||||||
|
}
|
||||||
|
|
||||||
|
authenticate(req: Request, options: AuthenticateOptionsGoogle) {
|
||||||
|
const language = req.headers['dadosfera-lang'] || req.query.language;
|
||||||
|
options.state = jwt.sign({ language }, process.env.JWT_PRIVATE_KEY);
|
||||||
|
super.authenticate(req, options);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,8 @@ import {
|
|||||||
import { credentials } from '@grpc/grpc-js';
|
import { credentials } from '@grpc/grpc-js';
|
||||||
import { Catalog } from '@dadosfera/protospack-v2';
|
import { Catalog } from '@dadosfera/protospack-v2';
|
||||||
|
|
||||||
|
const isLocalConnection = !!process.env.PIFACTORY_URL?.includes('0.0.0.0');
|
||||||
|
|
||||||
export class CatalogClientConfiguration {
|
export class CatalogClientConfiguration {
|
||||||
public name = 'CatalogClientConfiguration';
|
public name = 'CatalogClientConfiguration';
|
||||||
private config: GrpcOptions = {
|
private config: GrpcOptions = {
|
||||||
@@ -16,10 +18,7 @@ export class CatalogClientConfiguration {
|
|||||||
Catalog.ProtoPackages.ReadPackage,
|
Catalog.ProtoPackages.ReadPackage,
|
||||||
Catalog.ProtoPackages.WritePackage,
|
Catalog.ProtoPackages.WritePackage,
|
||||||
],
|
],
|
||||||
credentials:
|
credentials: isLocalConnection ? undefined : credentials.createSsl(),
|
||||||
process.env.LOCAL_ENV || process.env.ENV === 'local'
|
|
||||||
? undefined
|
|
||||||
: credentials.createSsl(),
|
|
||||||
protoPath: [
|
protoPath: [
|
||||||
Catalog.ProtoPaths.ReadFilePath,
|
Catalog.ProtoPaths.ReadFilePath,
|
||||||
Catalog.ProtoPaths.WriteFilePath,
|
Catalog.ProtoPaths.WriteFilePath,
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import {
|
import {
|
||||||
|
BadRequestException,
|
||||||
Body,
|
Body,
|
||||||
Controller,
|
Controller,
|
||||||
Delete,
|
Delete,
|
||||||
|
ForbiddenException,
|
||||||
Get,
|
Get,
|
||||||
Headers,
|
Headers,
|
||||||
HttpException,
|
HttpException,
|
||||||
Inject,
|
Inject,
|
||||||
|
NotFoundException,
|
||||||
Param,
|
Param,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
@@ -98,7 +101,7 @@ export class CatalogController {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!pipeline || !object) {
|
if (!pipeline || !object) {
|
||||||
throw new HttpException('Query params not provided', 400);
|
throw new BadRequestException('Query params not provided');
|
||||||
}
|
}
|
||||||
|
|
||||||
const is_data_manager = permissions.includes(
|
const is_data_manager = permissions.includes(
|
||||||
@@ -136,9 +139,8 @@ export class CatalogController {
|
|||||||
return { data_asset };
|
return { data_asset };
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,12 +174,12 @@ export class CatalogController {
|
|||||||
)
|
)
|
||||||
async getDataAsset(
|
async getDataAsset(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Headers() headers,
|
|
||||||
@Param('id') id,
|
@Param('id') id,
|
||||||
|
@Query('shared') shared?: 'true',
|
||||||
) {
|
) {
|
||||||
const { username, user_id, customer_id, customer_name, permissions } = user;
|
const { username, user_id, customer_id, customer_name, permissions } = user;
|
||||||
|
|
||||||
this.logger.info(`/catalog - ON GET ONE DASHBOARD METABASE ROUTE`, {
|
this.logger.info(`GET /data-asset/${id}`, {
|
||||||
username,
|
username,
|
||||||
customer_name,
|
customer_name,
|
||||||
});
|
});
|
||||||
@@ -200,25 +202,24 @@ export class CatalogController {
|
|||||||
id,
|
id,
|
||||||
metadata,
|
metadata,
|
||||||
});
|
});
|
||||||
|
has_permission =
|
||||||
|
is_data_manager ||
|
||||||
|
data_asset?.owner === username ||
|
||||||
|
(user_roles as Array<any>).some((r) => data_asset.p_roles.includes(r)) ||
|
||||||
|
data_asset.p_users.includes(user_id);
|
||||||
|
if (
|
||||||
|
shared === 'true' &&
|
||||||
|
(data_asset.share_type === undefined || data_asset.share_type === 'none')
|
||||||
|
)
|
||||||
|
throw new NotFoundException();
|
||||||
|
if (!has_permission)
|
||||||
|
throw new ForbiddenException(
|
||||||
|
'You do not have permission to access this data asset.',
|
||||||
|
);
|
||||||
|
delete data_asset.p_roles;
|
||||||
|
delete data_asset.p_users;
|
||||||
|
|
||||||
if (data_asset?.owner === username) has_permission = true;
|
return { data_asset };
|
||||||
|
|
||||||
for (const role of user_roles) {
|
|
||||||
if (data_asset.p_roles.includes(role)) has_permission = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data_asset.p_users.includes(user_id)) has_permission = true;
|
|
||||||
|
|
||||||
if (is_data_manager || has_permission) {
|
|
||||||
delete data_asset.p_roles;
|
|
||||||
delete data_asset.p_users;
|
|
||||||
return { data_asset };
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new HttpException(
|
|
||||||
'You do not have permission to access this data asset.',
|
|
||||||
403,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('data-asset/rls/:id')
|
@Get('data-asset/rls/:id')
|
||||||
@@ -271,9 +272,8 @@ export class CatalogController {
|
|||||||
return { data_asset };
|
return { data_asset };
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,7 +376,7 @@ export class CatalogController {
|
|||||||
async updateDataAsset(
|
async updateDataAsset(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Headers('Dadosfera-Lang') language,
|
@Headers('Dadosfera-Lang') language,
|
||||||
@Param('id') id,
|
@Param('id') data_asset_id,
|
||||||
@Body() body: IUpdateDataRequest,
|
@Body() body: IUpdateDataRequest,
|
||||||
): Promise<IOneDataAsset> {
|
): Promise<IOneDataAsset> {
|
||||||
const { customer_id, customer_name, user_id, username } = user;
|
const { customer_id, customer_name, user_id, username } = user;
|
||||||
@@ -390,7 +390,7 @@ export class CatalogController {
|
|||||||
|
|
||||||
const result = await this.catalogService.updateOneDataAsset({
|
const result = await this.catalogService.updateOneDataAsset({
|
||||||
body,
|
body,
|
||||||
data_asset_id: id,
|
data_asset_id,
|
||||||
customer_id,
|
customer_id,
|
||||||
metadata,
|
metadata,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
import { CreateDataAssetRequest } from '@dadosfera/protospack-v2/dist/lib/Catalog/interfaces/messages';
|
import { CreateDataAssetRequest } from '@dadosfera/protospack-v2/dist/lib/Catalog/interfaces/messages';
|
||||||
|
|
||||||
|
export enum DataAssetShareType {
|
||||||
|
none = 'none',
|
||||||
|
public = 'public',
|
||||||
|
private = 'private',
|
||||||
|
}
|
||||||
export class EmbedObject {
|
export class EmbedObject {
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
url: string;
|
url: string;
|
||||||
@@ -135,6 +140,8 @@ export class IUpdateDataRequest {
|
|||||||
tags: string[];
|
tags: string[];
|
||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
embed: EmbedObject;
|
embed: EmbedObject;
|
||||||
|
@ApiPropertyOptional({ enum: DataAssetShareType })
|
||||||
|
share_type: DataAssetShareType;
|
||||||
}
|
}
|
||||||
export class ICreateDataAsset implements CreateDataAssetRequest {
|
export class ICreateDataAsset implements CreateDataAssetRequest {
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
|
|||||||
@@ -6,14 +6,15 @@ import {
|
|||||||
} from '@nestjs/microservices';
|
} from '@nestjs/microservices';
|
||||||
import { ConnectionTest } from '@dadosfera/protospack-v2';
|
import { ConnectionTest } from '@dadosfera/protospack-v2';
|
||||||
|
|
||||||
|
const isLocalConnection = !!process.env.INFACTORY_URL?.includes('0.0.0.0');
|
||||||
|
|
||||||
export class ConnectionTestClientConfiguration {
|
export class ConnectionTestClientConfiguration {
|
||||||
private config: GrpcOptions = {
|
private config: GrpcOptions = {
|
||||||
transport: Transport.GRPC,
|
transport: Transport.GRPC,
|
||||||
options: {
|
options: {
|
||||||
url: process.env.INFACTORY_URL,
|
url: process.env.INFACTORY_URL,
|
||||||
package: [ConnectionTest.ProtoPackages.ReadPackage],
|
package: [ConnectionTest.ProtoPackages.ReadPackage],
|
||||||
credentials:
|
credentials: isLocalConnection ? undefined : credentials.createSsl(),
|
||||||
process.env.ENV === 'local' ? undefined : credentials.createSsl(),
|
|
||||||
protoPath: [ConnectionTest.ProtoPaths.ReadFilePath],
|
protoPath: [ConnectionTest.ProtoPaths.ReadFilePath],
|
||||||
loader: {
|
loader: {
|
||||||
keepCase: true,
|
keepCase: true,
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import {
|
|||||||
} from '@nestjs/microservices';
|
} from '@nestjs/microservices';
|
||||||
import { ConnectionManager } from '@dadosfera/protospack-v2';
|
import { ConnectionManager } from '@dadosfera/protospack-v2';
|
||||||
|
|
||||||
|
const isLocalConnection = !!process.env.INFACTORY_URL?.includes('0.0.0.0');
|
||||||
|
|
||||||
export class ConnectionClientConfiguration {
|
export class ConnectionClientConfiguration {
|
||||||
public name = 'ConnectionClientConfiguration';
|
public name = 'ConnectionClientConfiguration';
|
||||||
private config: GrpcOptions = {
|
private config: GrpcOptions = {
|
||||||
@@ -16,10 +18,7 @@ export class ConnectionClientConfiguration {
|
|||||||
ConnectionManager.ProtoPackages.WritePackage,
|
ConnectionManager.ProtoPackages.WritePackage,
|
||||||
ConnectionManager.ProtoPackages.ReadPackage,
|
ConnectionManager.ProtoPackages.ReadPackage,
|
||||||
],
|
],
|
||||||
credentials:
|
credentials: isLocalConnection ? undefined : credentials.createSsl(),
|
||||||
process.env.LOCAL_ENV || process.env.ENV === 'local'
|
|
||||||
? undefined
|
|
||||||
: credentials.createSsl(),
|
|
||||||
protoPath: [
|
protoPath: [
|
||||||
ConnectionManager.ProtoPaths.WriteFilePath,
|
ConnectionManager.ProtoPaths.WriteFilePath,
|
||||||
ConnectionManager.ProtoPaths.ReadFilePath,
|
ConnectionManager.ProtoPaths.ReadFilePath,
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import {
|
|||||||
} from '@nestjs/microservices';
|
} from '@nestjs/microservices';
|
||||||
import { ConnectorManager } from '@dadosfera/protospack-v2';
|
import { ConnectorManager } from '@dadosfera/protospack-v2';
|
||||||
|
|
||||||
|
const isLocalConnection = !!process.env.INFACTORY_URL?.includes('0.0.0.0');
|
||||||
|
|
||||||
export class ConnectorClientConfiguration {
|
export class ConnectorClientConfiguration {
|
||||||
public name = 'ConnectorClientConfiguration';
|
public name = 'ConnectorClientConfiguration';
|
||||||
private config: GrpcOptions = {
|
private config: GrpcOptions = {
|
||||||
@@ -16,10 +18,7 @@ export class ConnectorClientConfiguration {
|
|||||||
ConnectorManager.ProtoPackages.WritePackage,
|
ConnectorManager.ProtoPackages.WritePackage,
|
||||||
ConnectorManager.ProtoPackages.ReadPackage,
|
ConnectorManager.ProtoPackages.ReadPackage,
|
||||||
],
|
],
|
||||||
credentials:
|
credentials: isLocalConnection ? undefined : credentials.createSsl(),
|
||||||
process.env.LOCAL_ENV || process.env.ENV === 'local'
|
|
||||||
? undefined
|
|
||||||
: credentials.createSsl(),
|
|
||||||
protoPath: [
|
protoPath: [
|
||||||
ConnectorManager.ProtoPaths.WriteFilePath,
|
ConnectorManager.ProtoPaths.WriteFilePath,
|
||||||
ConnectorManager.ProtoPaths.ReadFilePath,
|
ConnectorManager.ProtoPaths.ReadFilePath,
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import {
|
|||||||
ProtoPaths,
|
ProtoPaths,
|
||||||
} from '@dadosfera/protospack-v2/dist/lib/Duc';
|
} from '@dadosfera/protospack-v2/dist/lib/Duc';
|
||||||
|
|
||||||
|
const isLocalConnection = !!process.env.DUC_URL?.includes('0.0.0.0');
|
||||||
|
|
||||||
export class DucClient {
|
export class DucClient {
|
||||||
public name = 'DucClient';
|
public name = 'DucClient';
|
||||||
|
|
||||||
@@ -17,10 +19,7 @@ export class DucClient {
|
|||||||
options: {
|
options: {
|
||||||
url: process.env.DUC_URL,
|
url: process.env.DUC_URL,
|
||||||
package: [ProtoPackages.WritePackage, ProtoPackages.ReadPackage],
|
package: [ProtoPackages.WritePackage, ProtoPackages.ReadPackage],
|
||||||
credentials:
|
credentials: isLocalConnection ? undefined : credentials.createSsl(),
|
||||||
process.env.LOCAL_ENV || process.env.ENV === 'local'
|
|
||||||
? undefined
|
|
||||||
: credentials.createSsl(),
|
|
||||||
protoPath: [ProtoPaths.WriteFilePath, ProtoPaths.ReadFilePath],
|
protoPath: [ProtoPaths.WriteFilePath, ProtoPaths.ReadFilePath],
|
||||||
loader: {
|
loader: {
|
||||||
keepCase: true,
|
keepCase: true,
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ import { Input } from '@dadosfera/protospack-v2';
|
|||||||
import { credentials } from '@grpc/grpc-js';
|
import { credentials } from '@grpc/grpc-js';
|
||||||
import {
|
import {
|
||||||
ClientProviderOptions,
|
ClientProviderOptions,
|
||||||
GrpcOptions,
|
|
||||||
Transport,
|
Transport,
|
||||||
|
type GrpcOptions,
|
||||||
} from '@nestjs/microservices';
|
} from '@nestjs/microservices';
|
||||||
|
|
||||||
|
const isLocalConnection = !!process.env.INFACTORY_URL?.includes('0.0.0.0');
|
||||||
export class InputsGrpcClient {
|
export class InputsGrpcClient {
|
||||||
public readonly name = 'InputsGrpcClient';
|
public readonly name = 'InputsGrpcClient';
|
||||||
private config: GrpcOptions = {
|
private config: GrpcOptions = {
|
||||||
@@ -16,10 +17,7 @@ export class InputsGrpcClient {
|
|||||||
Input.ProtoPackages.WritePackage,
|
Input.ProtoPackages.WritePackage,
|
||||||
Input.ProtoPackages.ReadPackage,
|
Input.ProtoPackages.ReadPackage,
|
||||||
],
|
],
|
||||||
credentials:
|
credentials: isLocalConnection ? undefined : credentials.createSsl(),
|
||||||
process.env.LOCAL_ENV || process.env.ENV === 'local'
|
|
||||||
? undefined
|
|
||||||
: credentials.createSsl(),
|
|
||||||
protoPath: [
|
protoPath: [
|
||||||
Input.ProtoPaths.WriteFilePath,
|
Input.ProtoPaths.WriteFilePath,
|
||||||
Input.ProtoPaths.ReadFilePath,
|
Input.ProtoPaths.ReadFilePath,
|
||||||
|
|||||||
@@ -15,9 +15,55 @@ export class MixpanelController {
|
|||||||
delete body.info;
|
delete body.info;
|
||||||
const mixpanel = init(this.mixpanelToken);
|
const mixpanel = init(this.mixpanelToken);
|
||||||
|
|
||||||
|
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, {
|
await mixpanel.people.set(user.username, {
|
||||||
$name: user.username,
|
$first_name: firstName,
|
||||||
$email: user.username,
|
$last_name: lastName,
|
||||||
|
$name: this.getFullName(firstName, lastName),
|
||||||
|
$email: user.username.includes('@')
|
||||||
|
? user.username
|
||||||
|
: user.username + '@dadosfera.ai',
|
||||||
customer_name: user.customer_name,
|
customer_name: user.customer_name,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -30,4 +76,16 @@ export class MixpanelController {
|
|||||||
|
|
||||||
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,5 +1,5 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { getSecreteFromSecreteManager } from 'src/utils/SecretManager';
|
import { getSecretFromSecretsManager } from 'src/utils/SecretManager';
|
||||||
import { MixpanelController } from './mixpanel.controller';
|
import { MixpanelController } from './mixpanel.controller';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
@@ -7,7 +7,7 @@ import { MixpanelController } from './mixpanel.controller';
|
|||||||
providers: [
|
providers: [
|
||||||
{
|
{
|
||||||
provide: 'MIXPANEL_TOKEN',
|
provide: 'MIXPANEL_TOKEN',
|
||||||
useValue: getSecreteFromSecreteManager(
|
useValue: getSecretFromSecretsManager(
|
||||||
`${process.env.ENV}/root/mixpanel_token`,
|
`${process.env.ENV}/root/mixpanel_token`,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ export class FacebookStrategy extends PassportStrategy(Strategy) {
|
|||||||
req,
|
req,
|
||||||
'application',
|
'application',
|
||||||
);
|
);
|
||||||
options.scope = 'ads_read ads_management';
|
options.scope =
|
||||||
|
'pages_show_list ads_read pages_read_engagement ads_management';
|
||||||
super.authenticate(req, options);
|
super.authenticate(req, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import {
|
|||||||
import { PipelinePackages, PipelineProtoFilePath } from 'protospack';
|
import { PipelinePackages, PipelineProtoFilePath } from 'protospack';
|
||||||
import { credentials } from '@grpc/grpc-js';
|
import { credentials } from '@grpc/grpc-js';
|
||||||
|
|
||||||
|
const isLocalConnection = !!process.env.PIFACTORY_URL?.includes('0.0.0.0');
|
||||||
|
|
||||||
export class PipelinesClientConfiguration {
|
export class PipelinesClientConfiguration {
|
||||||
public name = 'PipelinesClientConfiguration';
|
public name = 'PipelinesClientConfiguration';
|
||||||
private config: GrpcOptions = {
|
private config: GrpcOptions = {
|
||||||
@@ -13,10 +15,7 @@ export class PipelinesClientConfiguration {
|
|||||||
options: {
|
options: {
|
||||||
url: process.env.PIFACTORY_URL,
|
url: process.env.PIFACTORY_URL,
|
||||||
package: PipelinePackages,
|
package: PipelinePackages,
|
||||||
credentials:
|
credentials: isLocalConnection ? undefined : credentials.createSsl(),
|
||||||
process.env.LOCAL_ENV || process.env.ENV === 'local'
|
|
||||||
? undefined
|
|
||||||
: credentials.createSsl(),
|
|
||||||
protoPath: PipelineProtoFilePath,
|
protoPath: PipelineProtoFilePath,
|
||||||
loader: {
|
loader: {
|
||||||
keepCase: true,
|
keepCase: true,
|
||||||
|
|||||||
@@ -67,13 +67,32 @@ export interface IGetPipelineLogsRequest {
|
|||||||
details: string;
|
details: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class IUploadCSVFile {
|
export class IInitUploadCSVFile {
|
||||||
@ApiProperty({ format: 'binary' })
|
@ApiProperty()
|
||||||
file: string;
|
file_name: string;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
parts: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ICompleteUploadCSVFile {
|
||||||
|
@ApiProperty()
|
||||||
|
upload_id: string;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
file_name: string;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
parts: { ETag: string; PartNumber: number }[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ICreatePipelineCSVFile {
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
file_name: string;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
description: string;
|
description: string;
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import {
|
|||||||
} from '@dadosfera/protospack-v2/dist/lib/PipelineV2';
|
} from '@dadosfera/protospack-v2/dist/lib/PipelineV2';
|
||||||
import { credentials } from '@grpc/grpc-js';
|
import { credentials } from '@grpc/grpc-js';
|
||||||
|
|
||||||
|
const isLocalConnection = !!process.env.PIFACTORY_URL?.includes('0.0.0.0');
|
||||||
|
|
||||||
export class PipelinesClientConfiguration {
|
export class PipelinesClientConfiguration {
|
||||||
public name = 'PipelinesClientConfiguration';
|
public name = 'PipelinesClientConfiguration';
|
||||||
private config: GrpcOptions = {
|
private config: GrpcOptions = {
|
||||||
@@ -16,10 +18,7 @@ export class PipelinesClientConfiguration {
|
|||||||
options: {
|
options: {
|
||||||
url: process.env.PIFACTORY_URL,
|
url: process.env.PIFACTORY_URL,
|
||||||
package: [ProtoPackages.ReadPackage, ProtoPackages.WritePackage],
|
package: [ProtoPackages.ReadPackage, ProtoPackages.WritePackage],
|
||||||
credentials:
|
credentials: isLocalConnection ? undefined : credentials.createSsl(),
|
||||||
process.env.LOCAL_ENV || process.env.ENV === 'local'
|
|
||||||
? undefined
|
|
||||||
: credentials.createSsl(),
|
|
||||||
protoPath: [ProtoPaths.ReadFilePath, ProtoPaths.WriteFilePath],
|
protoPath: [ProtoPaths.ReadFilePath, ProtoPaths.WriteFilePath],
|
||||||
loader: {
|
loader: {
|
||||||
keepCase: true,
|
keepCase: true,
|
||||||
|
|||||||
@@ -13,12 +13,9 @@ import {
|
|||||||
HttpCode,
|
HttpCode,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
Patch,
|
Patch,
|
||||||
UseInterceptors,
|
|
||||||
UploadedFile,
|
|
||||||
HttpException,
|
HttpException,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import {
|
import {
|
||||||
ApiConsumes,
|
|
||||||
ApiCreatedResponse,
|
ApiCreatedResponse,
|
||||||
ApiNoContentResponse,
|
ApiNoContentResponse,
|
||||||
ApiTags,
|
ApiTags,
|
||||||
@@ -36,12 +33,13 @@ 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 {
|
||||||
|
ICompleteUploadCSVFile,
|
||||||
|
ICreatePipelineCSVFile,
|
||||||
ICreatePipelineV2Req,
|
ICreatePipelineV2Req,
|
||||||
IPipelineV2,
|
IPipelineV2,
|
||||||
IUploadCSVFile,
|
IInitUploadCSVFile,
|
||||||
} from './interfaces';
|
} from './interfaces';
|
||||||
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
||||||
import { FileInterceptor } from '@nestjs/platform-express';
|
|
||||||
|
|
||||||
@UseFilters(new GrpcToHttpExceptionFilter())
|
@UseFilters(new GrpcToHttpExceptionFilter())
|
||||||
@ApiTags('PipelinesV2')
|
@ApiTags('PipelinesV2')
|
||||||
@@ -300,37 +298,27 @@ export class PipelinesController {
|
|||||||
this.logger.info('PipelinesController - delete: OK');
|
this.logger.info('PipelinesController - delete: OK');
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('/upload')
|
@Post('/init-upload')
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.PIPELINE.permissions.CREATE)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.PIPELINE.permissions.CREATE)
|
||||||
@ApiConsumes('multipart/form-data')
|
async initUploadFile(
|
||||||
@UseInterceptors(
|
|
||||||
FileInterceptor('file', { limits: { fileSize: 50 * 1000 * 1000 + 1 } }),
|
|
||||||
)
|
|
||||||
async uploadFile(
|
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@UploadedFile() file,
|
@Body() body: IInitUploadCSVFile,
|
||||||
@Body() body: IUploadCSVFile,
|
|
||||||
) {
|
) {
|
||||||
this.logger.info('/upload - Upload Connector Route');
|
this.logger.info('/upload - Init Upload File Route');
|
||||||
const metadata = PackTheMetadata({ ...user });
|
const metadata = PackTheMetadata({ ...user });
|
||||||
|
|
||||||
const parts_of_file_name = file.originalname.split('.');
|
const { file_name, parts } = body;
|
||||||
const file_format = parts_of_file_name.pop();
|
|
||||||
const file_name = parts_of_file_name.join('.');
|
|
||||||
let name = `${new Date().getTime()}_${file_name}`;
|
|
||||||
body.name ? (name = `${new Date().getTime()}_${body.name}`) : name;
|
|
||||||
|
|
||||||
const source_prefix = `${user.customer_name}/${name}.${file_format}`;
|
const { urls, upload_id } =
|
||||||
|
await this.pipelinesClientService.initUploadFile(
|
||||||
|
{
|
||||||
|
name: file_name,
|
||||||
|
parts: String(parts),
|
||||||
|
},
|
||||||
|
metadata,
|
||||||
|
);
|
||||||
|
|
||||||
const response = await this.pipelinesClientService.uploadFile(
|
if (!urls) {
|
||||||
{
|
|
||||||
file,
|
|
||||||
name,
|
|
||||||
},
|
|
||||||
metadata,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!response.url) {
|
|
||||||
this.logger.info('pipeline/upload - Failed File pipeline');
|
this.logger.info('pipeline/upload - Failed File pipeline');
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
'Upload failed, try again in a few minutes, if the problem persists, contact support.',
|
'Upload failed, try again in a few minutes, if the problem persists, contact support.',
|
||||||
@@ -338,7 +326,37 @@ export class PipelinesController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { sep, header, encoding, description } = body;
|
return { urls: JSON.parse(urls), upload_id };
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('/complete-upload')
|
||||||
|
@RequireAllPermissions(PERMISSIONS_GROUPS.PIPELINE.permissions.CREATE)
|
||||||
|
async completeUploadFile(
|
||||||
|
@User() user: RequestUser,
|
||||||
|
@Body() body: ICompleteUploadCSVFile,
|
||||||
|
) {
|
||||||
|
this.logger.info('/upload - Complete Upload File Route');
|
||||||
|
const metadata = PackTheMetadata({ ...user });
|
||||||
|
|
||||||
|
const { upload_id, parts, file_name } = body;
|
||||||
|
|
||||||
|
return await this.pipelinesClientService.completeUploadFile(
|
||||||
|
{ upload_id, parts, file_name },
|
||||||
|
metadata,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('/file')
|
||||||
|
@RequireAllPermissions(PERMISSIONS_GROUPS.PIPELINE.permissions.CREATE)
|
||||||
|
async uploadedFile(
|
||||||
|
@User() user: RequestUser,
|
||||||
|
@Body() body: ICreatePipelineCSVFile,
|
||||||
|
) {
|
||||||
|
this.logger.info('/upload - Upload Connector Route');
|
||||||
|
const metadata = PackTheMetadata({ ...user });
|
||||||
|
|
||||||
|
const { name, sep, header, encoding, description, file_name } = body;
|
||||||
|
const source_prefix = `${user.customer_name}/${file_name}`;
|
||||||
|
|
||||||
const upload_pipeline = {
|
const upload_pipeline = {
|
||||||
connection_id: process.env.UPLOAD_FILE_AGENT_CONNECTION,
|
connection_id: process.env.UPLOAD_FILE_AGENT_CONNECTION,
|
||||||
@@ -346,7 +364,7 @@ export class PipelinesController {
|
|||||||
connector_plugin: 'aws_s3',
|
connector_plugin: 'aws_s3',
|
||||||
connector_version: '1.0.0',
|
connector_version: '1.0.0',
|
||||||
image_url: 'https://assets.dadosfera.ai/images/connectors/csv.svg',
|
image_url: 'https://assets.dadosfera.ai/images/connectors/csv.svg',
|
||||||
name: body.name || file_name,
|
name,
|
||||||
description,
|
description,
|
||||||
transformations_ids: [],
|
transformations_ids: [],
|
||||||
tags: [],
|
tags: [],
|
||||||
|
|||||||
@@ -261,13 +261,10 @@ export class PipelinesService implements OnModuleInit {
|
|||||||
return { objects: JSON.parse(objects) };
|
return { objects: JSON.parse(objects) };
|
||||||
}
|
}
|
||||||
|
|
||||||
async uploadFile(uploadFile, metadata) {
|
async initUploadFile(uploadFile, metadata) {
|
||||||
const body: Messages.PipelineV2UploadFileRequest = {
|
const body: Messages.PipelineV2UploadFileRequest = {
|
||||||
file: {
|
|
||||||
buffer: uploadFile.file.buffer,
|
|
||||||
mimetypes: uploadFile.file.mimetype,
|
|
||||||
},
|
|
||||||
name: uploadFile.name,
|
name: uploadFile.name,
|
||||||
|
parts: uploadFile.parts,
|
||||||
};
|
};
|
||||||
|
|
||||||
return lastValueFrom(
|
return lastValueFrom(
|
||||||
@@ -293,4 +290,21 @@ export class PipelinesService implements OnModuleInit {
|
|||||||
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async completeUploadFile(uploadFile, metadata) {
|
||||||
|
const body: Messages.PipelineV2CompleteUploadFileRequest = {
|
||||||
|
upload_id: uploadFile.upload_id,
|
||||||
|
parts: JSON.stringify(uploadFile.parts),
|
||||||
|
name: uploadFile.file_name,
|
||||||
|
};
|
||||||
|
|
||||||
|
return lastValueFrom(
|
||||||
|
this.pipelineWriteService.PipelineV2CompleteUploadFile(body, metadata),
|
||||||
|
).catch((err) => {
|
||||||
|
throw new HttpException(
|
||||||
|
err.details,
|
||||||
|
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Body, Controller, HttpException, Post } from '@nestjs/common';
|
|||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { User, RequestUser } from 'src/authentication/user.decorator';
|
import { User, RequestUser } from 'src/authentication/user.decorator';
|
||||||
import { getSecreteFromSecreteManager } from 'src/utils/SecretManager';
|
import { getSecretFromSecretsManager } from 'src/utils/SecretManager';
|
||||||
import { INote } from './dtos';
|
import { INote } from './dtos';
|
||||||
|
|
||||||
@ApiTags('Productboard')
|
@ApiTags('Productboard')
|
||||||
@@ -18,7 +18,7 @@ export class ProductboardController {
|
|||||||
: username + `@${customer_name}.default`;
|
: username + `@${customer_name}.default`;
|
||||||
|
|
||||||
const path = process.env.PB_TOKEN_PATH;
|
const path = process.env.PB_TOKEN_PATH;
|
||||||
const token = await getSecreteFromSecreteManager(path);
|
const token = await getSecretFromSecretsManager(path);
|
||||||
|
|
||||||
const response = await axios
|
const response = await axios
|
||||||
.post(
|
.post(
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ export class RoleDto {
|
|||||||
customer?: Customer;
|
customer?: Customer;
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
usage: string;
|
usage: string;
|
||||||
|
@ApiPropertyOptional({ description: 'Whether this role can be untoggled' })
|
||||||
|
canUntoggle?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CustomerRole extends OmitType(RoleDto, ['customer']) {}
|
export class CustomerRole extends OmitType(RoleDto, ['customer']) {}
|
||||||
@@ -34,11 +36,17 @@ export enum TrueOrFalseEnum {
|
|||||||
true = 'true',
|
true = 'true',
|
||||||
false = 'false',
|
false = 'false',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum CanUntoggleLogicEnum {
|
||||||
|
data_assets_sharing = 'data_assets_sharing',
|
||||||
|
}
|
||||||
export class GetRolesByCustomerReq {
|
export class GetRolesByCustomerReq {
|
||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
permissionId?: string[];
|
permissionId?: string[];
|
||||||
@ApiPropertyOptional({ enum: TrueOrFalseEnum })
|
@ApiPropertyOptional({ enum: TrueOrFalseEnum })
|
||||||
getUsers?: TrueOrFalseEnum;
|
getUsers?: TrueOrFalseEnum;
|
||||||
|
@ApiPropertyOptional({ enum: CanUntoggleLogicEnum })
|
||||||
|
canUntoggleLogic?: CanUntoggleLogicEnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GetRolesByCustomerRes {
|
export class GetRolesByCustomerRes {
|
||||||
|
|||||||
@@ -71,12 +71,12 @@ export class RolesController {
|
|||||||
@ApiOkResponse({ type: GetRolesByCustomerRes })
|
@ApiOkResponse({ type: GetRolesByCustomerRes })
|
||||||
async searchRoles(
|
async searchRoles(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Query() filters: GetRolesByCustomerReq,
|
@Query() params: GetRolesByCustomerReq,
|
||||||
@Headers('dadosfera-lang') language,
|
@Headers('dadosfera-lang') language,
|
||||||
) {
|
) {
|
||||||
this.logger.info('searchRoles', { user });
|
this.logger.info('searchRoles', { user });
|
||||||
this.rolesService.setLanguage(language);
|
this.rolesService.setLanguage(language);
|
||||||
return await this.rolesService.roleSearch(filters, user);
|
return await this.rolesService.roleSearch(params, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
|
|||||||
@@ -70,12 +70,7 @@ export class RolesService {
|
|||||||
return { role: roleTreated };
|
return { role: roleTreated };
|
||||||
}
|
}
|
||||||
|
|
||||||
async roleSearch(
|
async roleSearch(filters: GetRolesByCustomerReq, { customer_id }) {
|
||||||
filters: GetRolesByCustomerReq,
|
|
||||||
{ customer_id, access_token }: any,
|
|
||||||
) {
|
|
||||||
const meta = new Metadata();
|
|
||||||
meta.add('access_token', access_token);
|
|
||||||
let { permissionId: permissionIds } = filters;
|
let { permissionId: permissionIds } = filters;
|
||||||
if (permissionIds && !Array.isArray(permissionIds))
|
if (permissionIds && !Array.isArray(permissionIds))
|
||||||
permissionIds = [permissionIds];
|
permissionIds = [permissionIds];
|
||||||
@@ -89,15 +84,13 @@ export class RolesService {
|
|||||||
return seqId;
|
return seqId;
|
||||||
}) || [];
|
}) || [];
|
||||||
const roles = await lastValueFrom(
|
const roles = await lastValueFrom(
|
||||||
this.rolesClientService.RoleSearch(
|
this.rolesClientService.RoleSearch({
|
||||||
{
|
customerId: customer_id,
|
||||||
customerId: customer_id,
|
getUsers: isGetUsers,
|
||||||
getUsers: isGetUsers,
|
permissionIds: [],
|
||||||
permissionIds: [],
|
permissionSeqIds,
|
||||||
permissionSeqIds,
|
canUntoggleLogic: filters.canUntoggleLogic,
|
||||||
},
|
}),
|
||||||
meta,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
const rolesTreated = this.getRolesPermissionsName(roles.roles);
|
const rolesTreated = this.getRolesPermissionsName(roles.roles);
|
||||||
return { roles: rolesTreated };
|
return { roles: rolesTreated };
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import {
|
|||||||
import { credentials } from '@grpc/grpc-js';
|
import { credentials } from '@grpc/grpc-js';
|
||||||
import { Transformation } from '@dadosfera/protospack-v2';
|
import { Transformation } from '@dadosfera/protospack-v2';
|
||||||
|
|
||||||
|
const isLocalConnection = !!process.env.INFACTORY_URL?.includes('0.0.0.0');
|
||||||
|
|
||||||
export class TransformationsClientConfiguration {
|
export class TransformationsClientConfiguration {
|
||||||
public name = 'TransformationsClientConfiguration';
|
public name = 'TransformationsClientConfiguration';
|
||||||
private config: GrpcOptions = {
|
private config: GrpcOptions = {
|
||||||
@@ -13,10 +15,7 @@ export class TransformationsClientConfiguration {
|
|||||||
options: {
|
options: {
|
||||||
url: process.env.INFACTORY_URL,
|
url: process.env.INFACTORY_URL,
|
||||||
package: [Transformation.ProtoPackages.WritePackage],
|
package: [Transformation.ProtoPackages.WritePackage],
|
||||||
credentials:
|
credentials: isLocalConnection ? undefined : credentials.createSsl(),
|
||||||
process.env.LOCAL_ENV || process.env.ENV === 'local'
|
|
||||||
? undefined
|
|
||||||
: credentials.createSsl(),
|
|
||||||
protoPath: [Transformation.ProtoPaths.WriteFilePath],
|
protoPath: [Transformation.ProtoPaths.WriteFilePath],
|
||||||
loader: {
|
loader: {
|
||||||
enums: String,
|
enums: String,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import {
|
|||||||
SecretsManagerClient,
|
SecretsManagerClient,
|
||||||
GetSecretValueCommand,
|
GetSecretValueCommand,
|
||||||
} from '@aws-sdk/client-secrets-manager';
|
} from '@aws-sdk/client-secrets-manager';
|
||||||
|
let cachedSecrets: OauthSecrets;
|
||||||
|
|
||||||
class OauthSecretsObject {
|
class OauthSecretsObject {
|
||||||
client_id = '';
|
client_id = '';
|
||||||
@@ -15,8 +16,10 @@ export class OauthSecrets {
|
|||||||
mailchimp = new OauthSecretsObject();
|
mailchimp = new OauthSecretsObject();
|
||||||
facebook = new OauthSecretsObject();
|
facebook = new OauthSecretsObject();
|
||||||
salesforce = new OauthSecretsObject();
|
salesforce = new OauthSecretsObject();
|
||||||
|
'google-login' = new OauthSecretsObject();
|
||||||
}
|
}
|
||||||
export async function getOauthSecrets() {
|
export async function getOauthSecrets() {
|
||||||
|
if (cachedSecrets) return cachedSecrets;
|
||||||
const secrets = new OauthSecrets();
|
const secrets = new OauthSecrets();
|
||||||
const path = process.env.SM_OAUTH_PATH;
|
const path = process.env.SM_OAUTH_PATH;
|
||||||
const secretsManagerClient = new SecretsManagerClient({});
|
const secretsManagerClient = new SecretsManagerClient({});
|
||||||
@@ -37,5 +40,6 @@ export async function getOauthSecrets() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cachedSecrets = secrets;
|
||||||
return secrets;
|
return secrets;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
GetSecretValueCommand,
|
GetSecretValueCommand,
|
||||||
} from '@aws-sdk/client-secrets-manager';
|
} from '@aws-sdk/client-secrets-manager';
|
||||||
|
|
||||||
export async function getSecreteFromSecreteManager(path: string) {
|
export async function getSecretFromSecretsManager(path: string) {
|
||||||
const secretsManagerClient = new SecretsManagerClient({});
|
const secretsManagerClient = new SecretsManagerClient({});
|
||||||
|
|
||||||
const getSecretComand = new GetSecretValueCommand({
|
const getSecretComand = new GetSecretValueCommand({
|
||||||
|
|||||||
@@ -89,3 +89,37 @@ const ErrorCodes = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default ErrorCodes;
|
export default ErrorCodes;
|
||||||
|
|
||||||
|
export const OauthErrors = {
|
||||||
|
INVALID_CREDENTIALS: {
|
||||||
|
'pt-br': {
|
||||||
|
error: 'Erro ao autorizar',
|
||||||
|
error_description: 'Credenciais inválidas. Tente novamente',
|
||||||
|
},
|
||||||
|
'en-us': {
|
||||||
|
error: 'Authorization Error',
|
||||||
|
error_description: 'Invalid credentials. Please try again',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
USER_NOT_FOUND: {
|
||||||
|
'pt-br': {
|
||||||
|
error: 'Erro ao autorizar',
|
||||||
|
error_description: (email) => `Usuário não existe na Dadosfera: ${email}`,
|
||||||
|
},
|
||||||
|
'en-us': {
|
||||||
|
error: 'Authorization Error',
|
||||||
|
error_description: (email) =>
|
||||||
|
`User does not exist on Dadosfera: ${email}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
INVALID_SESSION: {
|
||||||
|
'pt-br': {
|
||||||
|
error: 'Erro ao autorizar',
|
||||||
|
error_description: 'Sessão inválida!',
|
||||||
|
},
|
||||||
|
'en-us': {
|
||||||
|
error: 'Authorization Error',
|
||||||
|
error_description: 'Invalid session!',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user