mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-27 01:30:05 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cad1e4b3de | ||
|
|
b311a84bde | ||
|
|
28280dca8d | ||
|
|
450c82446e | ||
|
|
beb27a0f60 | ||
|
|
0360711ab4 | ||
|
|
b6ec2a83b2 | ||
|
|
812dc0c735 | ||
|
|
11715dd528 | ||
|
|
be476c1a6d | ||
|
|
a8414f780a | ||
|
|
1da61a4c13 | ||
|
|
7e8f5c49b5 | ||
|
|
96a485afd1 | ||
|
|
e3c203d673 | ||
|
|
d7da68241e | ||
|
|
5d924f8a92 | ||
|
|
f9b4ddd070 | ||
|
|
c0e0732b7e | ||
|
|
37ea7c2f4d | ||
|
|
d42584fcfc | ||
|
|
a28781423c | ||
|
|
8c638610c7 | ||
|
|
55ff485fd0 | ||
|
|
4877fab945 | ||
|
|
e724ef5ccc | ||
|
|
9dc96416e8 | ||
|
|
49663c4115 | ||
|
|
c16664c7f9 | ||
|
|
7245942707 | ||
|
|
c29cf5aee1 | ||
|
|
d96658c9cd | ||
|
|
cbd736b87d | ||
|
|
e4e6d95f8a | ||
|
|
a8e13c01d2 | ||
|
|
cdf2ce3cc2 | ||
|
|
c3877657ef | ||
|
|
3d39affc61 | ||
|
|
5d045b675c | ||
|
|
bb61990f6e | ||
|
|
80442c509a | ||
|
|
8551239038 | ||
|
|
4cf7c6e17b | ||
|
|
88c9c36eb0 | ||
|
|
4b317778f7 | ||
|
|
2eea9787cd | ||
|
|
c1ab5d152f | ||
|
|
8798f5d54e | ||
|
|
1da733b5bc | ||
|
|
930c8bc037 | ||
|
|
0913741500 | ||
|
|
3e9d0063ae | ||
|
|
2bc0fe1e9e | ||
|
|
f0fb6e6b4a | ||
|
|
74c27d9637 | ||
|
|
216c83d7fa | ||
|
|
08e66eeb1e | ||
|
|
cf3fd90787 | ||
|
|
bb1decb08f | ||
|
|
642cb0e70b | ||
|
|
0acf759e84 | ||
|
|
7bbb87a54a | ||
|
|
69af7ba626 |
Generated
+34
-32
@@ -11,8 +11,8 @@
|
|||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"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.3",
|
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
||||||
"@dadosfera/protospack-v2": "3.15.3",
|
"@dadosfera/protospack-v2": "3.18.7",
|
||||||
"@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",
|
||||||
@@ -1716,9 +1716,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@dadosfera/dadosfera-logs": {
|
"node_modules/@dadosfera/dadosfera-logs": {
|
||||||
"version": "1.0.0-beta.3",
|
"version": "1.0.0-beta.4",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/dadosfera-logs/-/dadosfera-logs-1.0.0-beta.3.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/dadosfera-logs/-/dadosfera-logs-1.0.0-beta.4.tgz",
|
||||||
"integrity": "sha512-VuGiQlpDulcl1+FSFoT4/6PA9Pr+DAzbFHAYesz9rPinR46ejG7ZBZk3m86NYqQtgMyurqXvgCR8GPy9FpwqFw==",
|
"integrity": "sha512-fFncbNVMbfQa2EFl7NJgmtuSRWHGtmwCbl5p++lSLvGcTIMjLGJ4HAMzSMemQhSxiiYlokdwweb7jJY7Ms62SQ==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@elastic/ecs-winston-format": "^1.3.1",
|
"@elastic/ecs-winston-format": "^1.3.1",
|
||||||
"winston": "^3.7.2",
|
"winston": "^3.7.2",
|
||||||
@@ -1726,9 +1726,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@dadosfera/protospack-v2": {
|
"node_modules/@dadosfera/protospack-v2": {
|
||||||
"version": "3.15.3",
|
"version": "3.18.7",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.15.3.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.18.7.tgz",
|
||||||
"integrity": "sha512-/TNTnjm8XIQ3DFiJc8nnSRFQE23lF8Dm+8wzL1VJIqivdQK2gUwkpEoYT0CA6PFVvVFhDrEWo/zGY55tBHXJBg==",
|
"integrity": "sha512-MloW230CUyK+g+HFkSv1OuaJNT5mfEGRh7tpZjjKxO2Qxm4eKkmI9uh/cNXCDzUpRBFXzBJ+5w12bxw2UnMRSw==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@grpc/grpc-js": "^1.6.7",
|
"@grpc/grpc-js": "^1.6.7",
|
||||||
"rxjs": "^7.5.5",
|
"rxjs": "^7.5.5",
|
||||||
@@ -7975,9 +7975,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/logform": {
|
"node_modules/logform": {
|
||||||
"version": "2.4.1",
|
"version": "2.4.2",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/logform/-/logform-2.4.1.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/logform/-/logform-2.4.2.tgz",
|
||||||
"integrity": "sha512-7XB/tqc3VRbri9pRjU6E97mQ8vC27ivJ3lct4jhyT+n0JNDd4YKldFl0D75NqDp46hk8RC7Ma1Vjv/UPf67S+A==",
|
"integrity": "sha512-W4c9himeAwXEdZ05dQNerhFz2XG80P9Oj0loPUMV23VC2it0orMHQhJm4hdnnor3rd1HsGf6a2lPwBM1zeXHGw==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@colors/colors": "1.5.0",
|
"@colors/colors": "1.5.0",
|
||||||
"fecha": "^4.2.0",
|
"fecha": "^4.2.0",
|
||||||
@@ -10337,9 +10337,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/ts-proto": {
|
"node_modules/ts-proto": {
|
||||||
"version": "1.125.0",
|
"version": "1.126.1",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/ts-proto/-/ts-proto-1.125.0.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/ts-proto/-/ts-proto-1.126.1.tgz",
|
||||||
"integrity": "sha512-ADXnF+Psk3SaLzxtXrhvKUDrNNpg7LnL5rQuQL+u9PiOQ4C2ktWLvJM0VtL4zqQ9/OHROmXjebpR0KMZAkI93w==",
|
"integrity": "sha512-PKrcgd0mCQJDY7tp+th349uYhnjs2Tz7wSqm9+DBcodl3YCKPt1pFtFmApOZdQ8WlghhgKAuJDIRQJBd6jD5YA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/object-hash": "^1.3.0",
|
"@types/object-hash": "^1.3.0",
|
||||||
"dataloader": "^1.4.0",
|
"dataloader": "^1.4.0",
|
||||||
@@ -10856,10 +10856,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/winston": {
|
"node_modules/winston": {
|
||||||
"version": "3.7.2",
|
"version": "3.8.2",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/winston/-/winston-3.7.2.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/winston/-/winston-3.8.2.tgz",
|
||||||
"integrity": "sha512-QziIqtojHBoyzUOdQvQiar1DH0Xp9nF1A1y7NVy2DGEsz82SBDtOalS0ulTRGVT14xPX3WRWkCsdcJKqNflKng==",
|
"integrity": "sha512-MsE1gRx1m5jdTTO9Ld/vND4krP2To+lgDoMEHGGa4HIlAUyXJtfc7CxQcGXVyz2IBpw5hbFkj2b/AtUdQwyRew==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@colors/colors": "1.5.0",
|
||||||
"@dabh/diagnostics": "^2.0.2",
|
"@dabh/diagnostics": "^2.0.2",
|
||||||
"async": "^3.2.3",
|
"async": "^3.2.3",
|
||||||
"is-stream": "^2.0.0",
|
"is-stream": "^2.0.0",
|
||||||
@@ -12295,9 +12296,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@dadosfera/dadosfera-logs": {
|
"@dadosfera/dadosfera-logs": {
|
||||||
"version": "1.0.0-beta.3",
|
"version": "1.0.0-beta.4",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/dadosfera-logs/-/dadosfera-logs-1.0.0-beta.3.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/dadosfera-logs/-/dadosfera-logs-1.0.0-beta.4.tgz",
|
||||||
"integrity": "sha512-VuGiQlpDulcl1+FSFoT4/6PA9Pr+DAzbFHAYesz9rPinR46ejG7ZBZk3m86NYqQtgMyurqXvgCR8GPy9FpwqFw==",
|
"integrity": "sha512-fFncbNVMbfQa2EFl7NJgmtuSRWHGtmwCbl5p++lSLvGcTIMjLGJ4HAMzSMemQhSxiiYlokdwweb7jJY7Ms62SQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@elastic/ecs-winston-format": "^1.3.1",
|
"@elastic/ecs-winston-format": "^1.3.1",
|
||||||
"winston": "^3.7.2",
|
"winston": "^3.7.2",
|
||||||
@@ -12305,9 +12306,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@dadosfera/protospack-v2": {
|
"@dadosfera/protospack-v2": {
|
||||||
"version": "3.15.3",
|
"version": "3.18.7",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.15.3.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.18.7.tgz",
|
||||||
"integrity": "sha512-/TNTnjm8XIQ3DFiJc8nnSRFQE23lF8Dm+8wzL1VJIqivdQK2gUwkpEoYT0CA6PFVvVFhDrEWo/zGY55tBHXJBg==",
|
"integrity": "sha512-MloW230CUyK+g+HFkSv1OuaJNT5mfEGRh7tpZjjKxO2Qxm4eKkmI9uh/cNXCDzUpRBFXzBJ+5w12bxw2UnMRSw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@grpc/grpc-js": "^1.6.7",
|
"@grpc/grpc-js": "^1.6.7",
|
||||||
"rxjs": "^7.5.5",
|
"rxjs": "^7.5.5",
|
||||||
@@ -16568,9 +16569,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"logform": {
|
"logform": {
|
||||||
"version": "2.4.1",
|
"version": "2.4.2",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/logform/-/logform-2.4.1.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/logform/-/logform-2.4.2.tgz",
|
||||||
"integrity": "sha512-7XB/tqc3VRbri9pRjU6E97mQ8vC27ivJ3lct4jhyT+n0JNDd4YKldFl0D75NqDp46hk8RC7Ma1Vjv/UPf67S+A==",
|
"integrity": "sha512-W4c9himeAwXEdZ05dQNerhFz2XG80P9Oj0loPUMV23VC2it0orMHQhJm4hdnnor3rd1HsGf6a2lPwBM1zeXHGw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@colors/colors": "1.5.0",
|
"@colors/colors": "1.5.0",
|
||||||
"fecha": "^4.2.0",
|
"fecha": "^4.2.0",
|
||||||
@@ -18130,9 +18131,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ts-proto": {
|
"ts-proto": {
|
||||||
"version": "1.125.0",
|
"version": "1.126.1",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/ts-proto/-/ts-proto-1.125.0.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/ts-proto/-/ts-proto-1.126.1.tgz",
|
||||||
"integrity": "sha512-ADXnF+Psk3SaLzxtXrhvKUDrNNpg7LnL5rQuQL+u9PiOQ4C2ktWLvJM0VtL4zqQ9/OHROmXjebpR0KMZAkI93w==",
|
"integrity": "sha512-PKrcgd0mCQJDY7tp+th349uYhnjs2Tz7wSqm9+DBcodl3YCKPt1pFtFmApOZdQ8WlghhgKAuJDIRQJBd6jD5YA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@types/object-hash": "^1.3.0",
|
"@types/object-hash": "^1.3.0",
|
||||||
"dataloader": "^1.4.0",
|
"dataloader": "^1.4.0",
|
||||||
@@ -18486,10 +18487,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"winston": {
|
"winston": {
|
||||||
"version": "3.7.2",
|
"version": "3.8.2",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/winston/-/winston-3.7.2.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/winston/-/winston-3.8.2.tgz",
|
||||||
"integrity": "sha512-QziIqtojHBoyzUOdQvQiar1DH0Xp9nF1A1y7NVy2DGEsz82SBDtOalS0ulTRGVT14xPX3WRWkCsdcJKqNflKng==",
|
"integrity": "sha512-MsE1gRx1m5jdTTO9Ld/vND4krP2To+lgDoMEHGGa4HIlAUyXJtfc7CxQcGXVyz2IBpw5hbFkj2b/AtUdQwyRew==",
|
||||||
"requires": {
|
"requires": {
|
||||||
|
"@colors/colors": "1.5.0",
|
||||||
"@dabh/diagnostics": "^2.0.2",
|
"@dabh/diagnostics": "^2.0.2",
|
||||||
"async": "^3.2.3",
|
"async": "^3.2.3",
|
||||||
"is-stream": "^2.0.0",
|
"is-stream": "^2.0.0",
|
||||||
|
|||||||
+2
-2
@@ -26,8 +26,8 @@
|
|||||||
},
|
},
|
||||||
"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.3",
|
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
||||||
"@dadosfera/protospack-v2": "3.15.3",
|
"@dadosfera/protospack-v2": "3.18.7",
|
||||||
"@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",
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ import { PipelinesV2Module } from './modules/pipelinesV2/pipelines.module';
|
|||||||
InputsModule,
|
InputsModule,
|
||||||
OauthModule,
|
OauthModule,
|
||||||
PipelinesV2Module,
|
PipelinesV2Module,
|
||||||
|
CatalogModule,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
RequireSomePermission,
|
RequireSomePermission,
|
||||||
} from './authentication.decorator';
|
} from './authentication.decorator';
|
||||||
import { AuthenticationGuard } from './authentication.guard';
|
import { AuthenticationGuard } from './authentication.guard';
|
||||||
import { PERMISSIONS } from './permissions.enum';
|
import { PERMISSIONS_GROUPS } from './permissions.enum';
|
||||||
import { AuthClientService } from '../modules/auth/auth.service';
|
import { AuthClientService } from '../modules/auth/auth.service';
|
||||||
|
|
||||||
import ErrorCodes from '../utils/errorCodes';
|
import ErrorCodes from '../utils/errorCodes';
|
||||||
@@ -36,15 +36,15 @@ class NoClassAuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('required-permission')
|
@Get('required-permission')
|
||||||
@RequireSomePermission(PERMISSIONS.ZENDESK.permissions.OPEN)
|
@RequireSomePermission(PERMISSIONS_GROUPS.ZENDESK.permissions.OPEN)
|
||||||
async requiredPermission(@Body() body) {
|
async requiredPermission(@Body() body) {
|
||||||
return { body };
|
return { body };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('has-all-permissions')
|
@Get('has-all-permissions')
|
||||||
@RequireAllPermissions(
|
@RequireAllPermissions(
|
||||||
PERMISSIONS.ZENDESK.permissions.OPEN,
|
PERMISSIONS_GROUPS.ZENDESK.permissions.OPEN,
|
||||||
PERMISSIONS.METABASE.permissions.OPEN,
|
PERMISSIONS_GROUPS.METABASE.permissions.OPEN,
|
||||||
)
|
)
|
||||||
async hasAllPermissions(@Body() body) {
|
async hasAllPermissions(@Body() body) {
|
||||||
return { body };
|
return { body };
|
||||||
@@ -52,8 +52,8 @@ class NoClassAuthController {
|
|||||||
|
|
||||||
@Get('has-some-permission')
|
@Get('has-some-permission')
|
||||||
@RequireSomePermission(
|
@RequireSomePermission(
|
||||||
PERMISSIONS.ZENDESK.permissions.OPEN,
|
PERMISSIONS_GROUPS.ZENDESK.permissions.OPEN,
|
||||||
PERMISSIONS.METABASE.permissions.OPEN,
|
PERMISSIONS_GROUPS.METABASE.permissions.OPEN,
|
||||||
)
|
)
|
||||||
async hasSomePermission(@Body() body) {
|
async hasSomePermission(@Body() body) {
|
||||||
return { body };
|
return { body };
|
||||||
@@ -62,7 +62,7 @@ class NoClassAuthController {
|
|||||||
|
|
||||||
@Controller('class-auth-condition')
|
@Controller('class-auth-condition')
|
||||||
@AuthenticateCondition((req) => req.get('x-on-class') === 'ok')
|
@AuthenticateCondition((req) => req.get('x-on-class') === 'ok')
|
||||||
@RequireSomePermission(PERMISSIONS.METABASE.permissions.OPEN)
|
@RequireSomePermission(PERMISSIONS_GROUPS.METABASE.permissions.OPEN)
|
||||||
class ClassAuthConditionController {
|
class ClassAuthConditionController {
|
||||||
@Get('body')
|
@Get('body')
|
||||||
async getBody(@Body() body) {
|
async getBody(@Body() body) {
|
||||||
@@ -77,7 +77,7 @@ class ClassAuthConditionController {
|
|||||||
|
|
||||||
@Get('required-permission')
|
@Get('required-permission')
|
||||||
@AuthenticateCondition((req) => req.get('x-on-route') === 'ok')
|
@AuthenticateCondition((req) => req.get('x-on-route') === 'ok')
|
||||||
@RequireSomePermission(PERMISSIONS.ZENDESK.permissions.OPEN)
|
@RequireSomePermission(PERMISSIONS_GROUPS.ZENDESK.permissions.OPEN)
|
||||||
async requiredPermission(@Body() body) {
|
async requiredPermission(@Body() body) {
|
||||||
return { body };
|
return { body };
|
||||||
}
|
}
|
||||||
@@ -440,17 +440,17 @@ describe('authentication.guard', () => {
|
|||||||
NoClassAuthTest(null, null);
|
NoClassAuthTest(null, null);
|
||||||
ClassAuthConditionTest(null, null);
|
ClassAuthConditionTest(null, null);
|
||||||
|
|
||||||
const tokenZ = CreateToken([PERMISSIONS.ZENDESK.permissions.OPEN]);
|
const tokenZ = CreateToken([PERMISSIONS_GROUPS.ZENDESK.permissions.OPEN]);
|
||||||
NoClassAuthTest(tokenZ, ['zendesk']);
|
NoClassAuthTest(tokenZ, ['zendesk']);
|
||||||
ClassAuthConditionTest(tokenZ, ['zendesk']);
|
ClassAuthConditionTest(tokenZ, ['zendesk']);
|
||||||
|
|
||||||
const tokenM = CreateToken([PERMISSIONS.METABASE.permissions.OPEN]);
|
const tokenM = CreateToken([PERMISSIONS_GROUPS.METABASE.permissions.OPEN]);
|
||||||
NoClassAuthTest(tokenM, ['metabase']);
|
NoClassAuthTest(tokenM, ['metabase']);
|
||||||
ClassAuthConditionTest(tokenM, ['metabase']);
|
ClassAuthConditionTest(tokenM, ['metabase']);
|
||||||
|
|
||||||
const tokenZM = CreateToken([
|
const tokenZM = CreateToken([
|
||||||
PERMISSIONS.ZENDESK.permissions.OPEN,
|
PERMISSIONS_GROUPS.ZENDESK.permissions.OPEN,
|
||||||
PERMISSIONS.METABASE.permissions.OPEN,
|
PERMISSIONS_GROUPS.METABASE.permissions.OPEN,
|
||||||
]);
|
]);
|
||||||
NoClassAuthTest(tokenZM, ['zendesk', 'metabase']);
|
NoClassAuthTest(tokenZM, ['zendesk', 'metabase']);
|
||||||
ClassAuthConditionTest(tokenZM, ['zendesk', 'metabase']);
|
ClassAuthConditionTest(tokenZM, ['zendesk', 'metabase']);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export interface PermissionsObjectGroup {
|
|||||||
/*export const Permissions: {
|
/*export const Permissions: {
|
||||||
[P in keyof any]: { [Q in keyof any]: Permission };
|
[P in keyof any]: { [Q in keyof any]: Permission };
|
||||||
} = {*/
|
} = {*/
|
||||||
export const PERMISSIONS = {
|
export const PERMISSIONS_GROUPS = {
|
||||||
AUTH: {
|
AUTH: {
|
||||||
title: {
|
title: {
|
||||||
'pt-br': 'Autenticação',
|
'pt-br': 'Autenticação',
|
||||||
@@ -128,7 +128,7 @@ export const PERMISSIONS = {
|
|||||||
DELETE: {
|
DELETE: {
|
||||||
seqid: 38,
|
seqid: 38,
|
||||||
claim: 'connection:delete',
|
claim: 'connection:delete',
|
||||||
usage: PermissionUsages.PUBLIC,
|
usage: PermissionUsages.INTERNAL,
|
||||||
name: {
|
name: {
|
||||||
'pt-br': 'Excluir Fonte',
|
'pt-br': 'Excluir Fonte',
|
||||||
'en-us': 'Remove Source',
|
'en-us': 'Remove Source',
|
||||||
@@ -165,16 +165,16 @@ export const PERMISSIONS = {
|
|||||||
'es-es': 'Crear VPN',
|
'es-es': 'Crear VPN',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
DELETE: {
|
// DELETE: {
|
||||||
seqid: 36,
|
// seqid: 36,
|
||||||
claim: 'network_config:delete',
|
// claim: 'network_config:delete',
|
||||||
usage: PermissionUsages.PUBLIC,
|
// usage: PermissionUsages.PUBLIC,
|
||||||
name: {
|
// name: {
|
||||||
'pt-br': 'Excluir VPN',
|
// 'pt-br': 'Excluir VPN',
|
||||||
'en-us': 'Remove VPN',
|
// 'en-us': 'Remove VPN',
|
||||||
'es-es': 'Eliminar VPN',
|
// 'es-es': 'Eliminar VPN',
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -496,17 +496,46 @@ export const PERMISSIONS = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
DADOSFERA: {
|
||||||
|
title: {
|
||||||
|
'pt-br': 'Usuários',
|
||||||
|
'en-us': 'Users',
|
||||||
|
'es-es': 'Usuarios',
|
||||||
|
},
|
||||||
|
permissions: {
|
||||||
|
CONNECTIONS_MIGRATION: {
|
||||||
|
seqid: 40,
|
||||||
|
claim: 'dadosfera:connections-migration',
|
||||||
|
usage: PermissionUsages.INTERNAL,
|
||||||
|
name: {
|
||||||
|
'pt-br': 'connections-migration',
|
||||||
|
'en-us': 'connections-migration',
|
||||||
|
'es-es': 'connections-migration',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
SYNC_USER: {
|
||||||
|
seqid: 41,
|
||||||
|
claim: 'dadosfera:sync-user',
|
||||||
|
usage: PermissionUsages.INTERNAL,
|
||||||
|
name: {
|
||||||
|
'pt-br': 'sync-user',
|
||||||
|
'en-us': 'sync-user',
|
||||||
|
'es-es': 'sync-user',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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).flatMap((namespace) =>
|
const seqids = Object.values(PERMISSIONS_GROUPS).flatMap((namespace) =>
|
||||||
Object.values(namespace.permissions).map(({ seqid }) => seqid),
|
Object.values(namespace.permissions).map(({ seqid }) => seqid),
|
||||||
);
|
);
|
||||||
const claims = Object.values(PERMISSIONS).flatMap((namespace) =>
|
const claims = Object.values(PERMISSIONS_GROUPS).flatMap((namespace) =>
|
||||||
Object.values(namespace.permissions).map(({ claim }) => claim),
|
Object.values(namespace.permissions).map(({ claim }) => claim),
|
||||||
);
|
);
|
||||||
Object.values(PERMISSIONS).map((namespace) =>
|
Object.values(PERMISSIONS_GROUPS).map((namespace) =>
|
||||||
Object.values(namespace.permissions).map(({ seqid, claim }) => {
|
Object.values(namespace.permissions).map(({ seqid, claim }) => {
|
||||||
const seqidsCount = seqids.filter((x) => x === seqid).length;
|
const seqidsCount = seqids.filter((x) => x === seqid).length;
|
||||||
assert(seqidsCount === 1, `seqid ${seqid} count is not 1`);
|
assert(seqidsCount === 1, `seqid ${seqid} count is not 1`);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { AuthClientService } from '../modules/auth/auth.service';
|
|||||||
|
|
||||||
import ErrorCodes from '../utils/errorCodes';
|
import ErrorCodes from '../utils/errorCodes';
|
||||||
import { User } from './user.decorator';
|
import { User } from './user.decorator';
|
||||||
import { PERMISSIONS } from './permissions.enum';
|
import { PERMISSIONS_GROUPS } from './permissions.enum';
|
||||||
|
|
||||||
const logger = {
|
const logger = {
|
||||||
info: (...args) => args,
|
info: (...args) => args,
|
||||||
@@ -49,7 +49,7 @@ describe('user.decorator', () => {
|
|||||||
const fakeUserPayload = {
|
const fakeUserPayload = {
|
||||||
user_id: 'd50d33c7-6c2b-463c-861f-e21667e7c125',
|
user_id: 'd50d33c7-6c2b-463c-861f-e21667e7c125',
|
||||||
username: 'super.admin',
|
username: 'super.admin',
|
||||||
permissions: [PERMISSIONS.METABASE.permissions.OPEN].map(
|
permissions: [PERMISSIONS_GROUPS.METABASE.permissions.OPEN].map(
|
||||||
({ seqid }) => seqid,
|
({ seqid }) => seqid,
|
||||||
),
|
),
|
||||||
customer_id: '9d18e8ae-24b9-41a3-9e8f-a25ce57555b11',
|
customer_id: '9d18e8ae-24b9-41a3-9e8f-a25ce57555b11',
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import {
|
|||||||
AuthVerifyTotpMfaRequest,
|
AuthVerifyTotpMfaRequest,
|
||||||
} from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
} from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
||||||
|
|
||||||
import { PERMISSIONS } from 'src/authentication/permissions.enum';
|
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
||||||
import { RequireAllPermissions } from 'src/authentication/authentication.decorator';
|
import { RequireAllPermissions } from 'src/authentication/authentication.decorator';
|
||||||
import { AuthClientService } from './auth.service';
|
import { AuthClientService } from './auth.service';
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
@@ -43,7 +43,7 @@ export class AuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post('/sso/snowflake')
|
@Post('/sso/snowflake')
|
||||||
@RequireAllPermissions(PERMISSIONS.SNOWFLAKE.permissions.OPEN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.SNOWFLAKE.permissions.OPEN)
|
||||||
@HttpCode(HttpStatus.OK)
|
@HttpCode(HttpStatus.OK)
|
||||||
async snowflakeSignIn(
|
async snowflakeSignIn(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import {
|
||||||
|
ClientsProviderAsyncOptions,
|
||||||
|
GrpcOptions,
|
||||||
|
Transport,
|
||||||
|
} from '@nestjs/microservices';
|
||||||
|
import { credentials } from '@grpc/grpc-js';
|
||||||
|
import { Catalog } from '@dadosfera/protospack-v2';
|
||||||
|
|
||||||
|
export class CatalogClientConfiguration {
|
||||||
|
public name = 'CatalogClientConfiguration';
|
||||||
|
private config: GrpcOptions = {
|
||||||
|
transport: Transport.GRPC,
|
||||||
|
options: {
|
||||||
|
url: process.env.PIFACTORY_URL,
|
||||||
|
package: [
|
||||||
|
Catalog.ProtoPackages.ReadPackage,
|
||||||
|
Catalog.ProtoPackages.WritePackage,
|
||||||
|
],
|
||||||
|
credentials:
|
||||||
|
process.env.LOCAL_ENV || process.env.ENV === 'local'
|
||||||
|
? undefined
|
||||||
|
: credentials.createSsl(),
|
||||||
|
protoPath: [
|
||||||
|
Catalog.ProtoPaths.ReadFilePath,
|
||||||
|
Catalog.ProtoPaths.WriteFilePath,
|
||||||
|
],
|
||||||
|
loader: {
|
||||||
|
keepCase: true,
|
||||||
|
enums: String,
|
||||||
|
defaults: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
providerOptions: ClientsProviderAsyncOptions = {
|
||||||
|
name: this.name,
|
||||||
|
...this.config,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -6,13 +6,16 @@ import {
|
|||||||
Inject,
|
Inject,
|
||||||
Param,
|
Param,
|
||||||
Post,
|
Post,
|
||||||
|
Put,
|
||||||
Query,
|
Query,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import { AuthenticateCondition } from '../../authentication/authentication.decorator';
|
import { AuthenticateCondition } from '../../authentication/authentication.decorator';
|
||||||
import { PERMISSIONS } from '../../authentication/permissions.enum';
|
import { PERMISSIONS_GROUPS } from '../../authentication/permissions.enum';
|
||||||
import { CatalogService } from './catalog.service';
|
import { CatalogService } from './catalog.service';
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
|
import { RequestUser, User } from 'src/authentication/user.decorator';
|
||||||
|
|
||||||
@ApiTags('Catalog')
|
@ApiTags('Catalog')
|
||||||
@Controller('catalog')
|
@Controller('catalog')
|
||||||
@@ -33,7 +36,7 @@ import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
|||||||
}
|
}
|
||||||
|
|
||||||
return user.permissions.includes(
|
return user.permissions.includes(
|
||||||
PERMISSIONS.CATALOG.permissions[action].seqid,
|
PERMISSIONS_GROUPS.CATALOG.permissions[action].seqid,
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
export class CatalogController {
|
export class CatalogController {
|
||||||
@@ -46,16 +49,72 @@ export class CatalogController {
|
|||||||
this.logger = dadosferaLogger.logger;
|
this.logger = dadosferaLogger.logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Put('manage_permissions/:id')
|
||||||
|
async manageDataAssetPermissions(
|
||||||
|
@Param('id') id: string,
|
||||||
|
@User() user: RequestUser,
|
||||||
|
@Body() body,
|
||||||
|
) {
|
||||||
|
const { customer_id, customer_name, user_id, username } = user;
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
customer_id,
|
||||||
|
customer_name,
|
||||||
|
user_id,
|
||||||
|
username,
|
||||||
|
});
|
||||||
|
const response = await this.catalogService.managePermissions(
|
||||||
|
{ ...body, id },
|
||||||
|
metadata,
|
||||||
|
);
|
||||||
|
|
||||||
|
return { data_asset: JSON.parse(response.data_asset) };
|
||||||
|
}
|
||||||
|
|
||||||
|
@Put('revoke_permissions/:id')
|
||||||
|
async revokeDataAssetPermissions(
|
||||||
|
@Param('id') id: string,
|
||||||
|
@User() user: RequestUser,
|
||||||
|
@Body() body,
|
||||||
|
) {
|
||||||
|
const { customer_id, customer_name, user_id, username } = user;
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
customer_id,
|
||||||
|
customer_name,
|
||||||
|
user_id,
|
||||||
|
username,
|
||||||
|
});
|
||||||
|
const response = await this.catalogService.revokePermissions(
|
||||||
|
{ ...body, id },
|
||||||
|
metadata,
|
||||||
|
);
|
||||||
|
|
||||||
|
return { message: response.message };
|
||||||
|
}
|
||||||
|
|
||||||
@Get('all')
|
@Get('all')
|
||||||
async catalogAll(@Body() body) {
|
async catalogAll(@User() user: RequestUser, @Body() body, @Query() params) {
|
||||||
|
const { user_id, customer_name, customer_id, username } = user;
|
||||||
this.logger.info(`/catalog - ON CATALOG ALL ROUTE`, {
|
this.logger.info(`/catalog - ON CATALOG ALL ROUTE`, {
|
||||||
user: body.info.user_id,
|
user: body.info.user_id,
|
||||||
customer: body.info.customer,
|
customer: body.info.customer,
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = await this.catalogService.catalogAll(body);
|
const roles = await this.catalogService.getUserRolesIds(user_id);
|
||||||
|
|
||||||
return res;
|
const metadata = PackTheMetadata({
|
||||||
|
user_id,
|
||||||
|
customer_id,
|
||||||
|
customer_name,
|
||||||
|
username,
|
||||||
|
roles,
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await this.catalogService.getAllOpenSearchDataAssets(
|
||||||
|
params,
|
||||||
|
metadata,
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.data_assets;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('data_apps')
|
@Get('data_apps')
|
||||||
@@ -96,30 +155,60 @@ export class CatalogController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('dashboard-metabase/:id')
|
@Get('dashboard-metabase/:id')
|
||||||
async getOneDashboardMetabase(@Body() body, @Param() params) {
|
async getOneDashboardMetabase(
|
||||||
|
@Body() body,
|
||||||
|
@Param() params,
|
||||||
|
@User() user: RequestUser,
|
||||||
|
) {
|
||||||
const { id } = params;
|
const { id } = params;
|
||||||
this.logger.info(`/catalog - ON GET ONE DASHBOARD METABASE ROUTE`, {
|
this.logger.info(`/catalog - ON GET ONE DASHBOARD METABASE ROUTE`, {
|
||||||
user: body.info.user_id,
|
user: body.info.user_id,
|
||||||
customer: body.info.customer,
|
customer: body.info.customer,
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = await this.catalogService.getOneDashboardMetabase(id, body);
|
const { username, user_id, customer_id, customer_name } = user;
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
username,
|
||||||
|
user_id,
|
||||||
|
customer_id,
|
||||||
|
customer_name,
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await this.catalogService.getOneDashboardMetabase(
|
||||||
|
id,
|
||||||
|
body,
|
||||||
|
metadata,
|
||||||
|
);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('table-metadata')
|
@Get('table-metadata')
|
||||||
async getAllTableMetadata(@Body() body, @Query() query) {
|
async getAllTableMetadata(
|
||||||
|
@Body() body,
|
||||||
|
@Query() query,
|
||||||
|
@User() user: RequestUser,
|
||||||
|
) {
|
||||||
this.logger.info(`/catalog - ON GET ALL TABLES METADATA ROUTE`, {
|
this.logger.info(`/catalog - ON GET ALL TABLES METADATA ROUTE`, {
|
||||||
user: body.info.user_id,
|
user: user.user_id,
|
||||||
customer: body.info.customer,
|
customer: user.customer_name,
|
||||||
|
});
|
||||||
|
const { user_id, customer_name, customer_id } = user;
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
user_id,
|
||||||
|
customer_id,
|
||||||
|
customer_name,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
const res = await this.catalogService.getAllTableMetadata(body);
|
const res = await this.catalogService.getAllTableMetadata(body);
|
||||||
return res;
|
return res;
|
||||||
} else {
|
} else {
|
||||||
const res = await this.catalogService.getOneTableMetadata(body, query);
|
const res = await this.catalogService.getOneTableMetadata(
|
||||||
|
body,
|
||||||
|
query,
|
||||||
|
metadata,
|
||||||
|
);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -211,15 +300,19 @@ export class CatalogController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post('data-description')
|
@Post('data-description')
|
||||||
async createDataDescription(@Body() body) {
|
async createDataDescription(@Body() body, @User() user: RequestUser) {
|
||||||
this.logger.info(`/catalog - ON CREATE DATA DESCRIPTION ROUTE`, {
|
this.logger.info(`/catalog - ON CREATE DATA DESCRIPTION ROUTE`, {
|
||||||
user: body.info.user_id,
|
user: user.user_id,
|
||||||
customer: body.info.customer,
|
customer: user.customer_name,
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = await this.catalogService.createDataDescription(body);
|
const { user_id, customer_name, customer_id } = user;
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
return res;
|
user_id,
|
||||||
|
customer_id,
|
||||||
|
customer_name,
|
||||||
|
});
|
||||||
|
return await this.catalogService.createDataDescription(body, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('data-docs')
|
@Get('data-docs')
|
||||||
@@ -322,15 +415,21 @@ export class CatalogController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post('tags')
|
@Post('tags')
|
||||||
async createTags(@Body() body) {
|
async createTags(@Body() body, @User() user: RequestUser) {
|
||||||
this.logger.info(`/catalog - ON CREATE TAG ROUTE`, {
|
this.logger.info(`/catalog - ON CREATE TAG ROUTE`, {
|
||||||
user: body.info.user_id,
|
user: user.user_id,
|
||||||
customer: body.info.customer,
|
customer: user.customer_name,
|
||||||
|
});
|
||||||
|
const { user_id, customer_name, customer_id } = user;
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
user_id,
|
||||||
|
customer_id,
|
||||||
|
customer_name,
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = await this.catalogService.createTags(body);
|
const res = await this.catalogService.createTags(body, metadata);
|
||||||
|
|
||||||
return res;
|
return res.data_assets;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('tags')
|
@Get('tags')
|
||||||
@@ -340,7 +439,14 @@ export class CatalogController {
|
|||||||
customer: body.info.customer,
|
customer: body.info.customer,
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = await this.catalogService.findAllTags(body);
|
const { user_id, customer, customer_id } = body.info;
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
user_id,
|
||||||
|
customer_id,
|
||||||
|
customer_name: customer,
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await this.catalogService.findAllTags(body, metadata);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -352,8 +458,14 @@ export class CatalogController {
|
|||||||
customer: body.info.customer,
|
customer: body.info.customer,
|
||||||
});
|
});
|
||||||
const { id } = params;
|
const { id } = params;
|
||||||
|
body.data_asset_id = id;
|
||||||
const res = await this.catalogService.deleteTags(id, body);
|
const { user_id, customer, customer_id } = body.info;
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
user_id,
|
||||||
|
customer_id,
|
||||||
|
customer_name: customer,
|
||||||
|
});
|
||||||
|
const res = await this.catalogService.deleteTags(body, metadata);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -370,14 +482,19 @@ export class CatalogController {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('table-tags')
|
@Get('table-tags/:data_asset_id')
|
||||||
async getAllTableTags(@Body() body) {
|
async getAllTableTags(@Body() body, @Param() params) {
|
||||||
this.logger.info(`/catalog - ON GET ALL TABLE TAGS ROUTE`, {
|
this.logger.info(`/catalog - ON GET ALL TABLE TAGS ROUTE`, {
|
||||||
user: body.info.user_id,
|
user: body.info.user_id,
|
||||||
customer: body.info.customer,
|
customer: body.info.customer,
|
||||||
});
|
});
|
||||||
|
const { user_id, customer, customer_id } = body.info;
|
||||||
const res = await this.catalogService.findAllTableTags(body);
|
const metadata = PackTheMetadata({
|
||||||
|
user_id,
|
||||||
|
customer_id,
|
||||||
|
customer_name: customer,
|
||||||
|
});
|
||||||
|
const res = await this.catalogService.findAllTableTags(params, metadata);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,21 @@ import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
|||||||
|
|
||||||
import { CatalogController } from './catalog.controller';
|
import { CatalogController } from './catalog.controller';
|
||||||
import { CatalogService } from './catalog.service';
|
import { CatalogService } from './catalog.service';
|
||||||
|
import { CatalogClientConfiguration } from './catalog-client';
|
||||||
|
import { ClientsModule } from '@nestjs/microservices';
|
||||||
|
import { PipelinesModule as OldPipelineModule } from 'src/modules/pipelines/pipelines.module';
|
||||||
|
import { UsersModule } from '../users/users.module';
|
||||||
|
|
||||||
|
const client = new CatalogClientConfiguration();
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
|
imports: [
|
||||||
|
ClientsModule.register([client.providerOptions]),
|
||||||
|
OldPipelineModule,
|
||||||
|
UsersModule,
|
||||||
|
],
|
||||||
controllers: [CatalogController],
|
controllers: [CatalogController],
|
||||||
providers: [CatalogService, DadosferaLogger],
|
providers: [CatalogService, DadosferaLogger],
|
||||||
|
exports: [CatalogService],
|
||||||
})
|
})
|
||||||
export class CatalogModule {}
|
export class CatalogModule {}
|
||||||
|
|||||||
@@ -1,6 +1,45 @@
|
|||||||
|
import DadosferaLogger from '@dadosfera/dadosfera-logs/dist';
|
||||||
|
import { ReadService } from '@dadosfera/protospack-v2/dist/lib/Catalog';
|
||||||
|
import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Catalog';
|
||||||
|
import { Messages } from '@dadosfera/protospack-v2/dist/lib/Catalog';
|
||||||
|
import { WriteService } from '@dadosfera/protospack-v2/dist/lib/Catalog';
|
||||||
|
import {
|
||||||
|
HttpException,
|
||||||
|
HttpStatus,
|
||||||
|
Inject,
|
||||||
|
OnModuleInit,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
import { ClientGrpc } from '@nestjs/microservices';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import { lastValueFrom } from 'rxjs';
|
||||||
|
import { CatalogClientConfiguration } from './catalog-client';
|
||||||
|
import { UsersService } from '../users/users.service';
|
||||||
|
|
||||||
|
class CatalogService implements OnModuleInit {
|
||||||
|
catalogReadService: ReadService.CatalogReadServices;
|
||||||
|
catalogWriteService: WriteService.CatalogWriteServices;
|
||||||
|
logger: any;
|
||||||
|
constructor(
|
||||||
|
@Inject(DadosferaLogger)
|
||||||
|
dadosferaLogger: DadosferaLogger,
|
||||||
|
@Inject(CatalogClientConfiguration.name)
|
||||||
|
private readonly grpcClient: ClientGrpc,
|
||||||
|
private readonly userService: UsersService,
|
||||||
|
) {
|
||||||
|
this.logger = dadosferaLogger.logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
onModuleInit() {
|
||||||
|
this.catalogReadService =
|
||||||
|
this.grpcClient.getService<ReadService.CatalogReadServices>(
|
||||||
|
ProtoServices.CatalogReadServices,
|
||||||
|
);
|
||||||
|
this.catalogWriteService =
|
||||||
|
this.grpcClient.getService<WriteService.CatalogWriteServices>(
|
||||||
|
ProtoServices.CatalogWriteServices,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
class CatalogService {
|
|
||||||
_getNimbusUrl(body) {
|
_getNimbusUrl(body) {
|
||||||
const customer = body.info.customer.toLowerCase();
|
const customer = body.info.customer.toLowerCase();
|
||||||
|
|
||||||
@@ -8,7 +47,36 @@ class CatalogService {
|
|||||||
return `https://nimbus-${customer}.dadosfera.ai`;
|
return `https://nimbus-${customer}.dadosfera.ai`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `https://nimbus-${customer}.${process.env.ENV}.dadosfera.ai`;
|
return `https://nimbus-${customer}.${process.env.ENV.replace(
|
||||||
|
'local',
|
||||||
|
'stg',
|
||||||
|
)}.dadosfera.ai`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async managePermissions(data: Messages.ManagePermissionRequest, metadata) {
|
||||||
|
this.logger.info('CatalogService - Manage Data assets permissions');
|
||||||
|
|
||||||
|
return lastValueFrom(
|
||||||
|
this.catalogWriteService.ManagePermission(data, metadata),
|
||||||
|
).catch((err) => {
|
||||||
|
throw new HttpException(
|
||||||
|
err.details,
|
||||||
|
err.code === 6 ? HttpStatus.CONFLICT : 404,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async revokePermissions(data: Messages.RevokePermissionRequest, metadata) {
|
||||||
|
this.logger.info('CatalogService - Manage Data assets permissions');
|
||||||
|
|
||||||
|
return lastValueFrom(
|
||||||
|
this.catalogWriteService.RevokePermission(data, metadata),
|
||||||
|
).catch((err) => {
|
||||||
|
throw new HttpException(
|
||||||
|
err.details,
|
||||||
|
err.code === 6 ? HttpStatus.CONFLICT : 404,
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async catalogAll(body) {
|
async catalogAll(body) {
|
||||||
@@ -41,17 +109,87 @@ class CatalogService {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOneDashboardMetabase(id, body) {
|
async getUserRolesIds(userId: string) {
|
||||||
|
const result = await this.userService.findOneById(userId).catch(() => null);
|
||||||
|
|
||||||
|
const roles_ids = result.user.roles.map((role) => role.id);
|
||||||
|
|
||||||
|
return roles_ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAllOpenSearchDataAssets(
|
||||||
|
data: Messages.GetAllDataAssetsRequest,
|
||||||
|
metadata,
|
||||||
|
) {
|
||||||
|
this.logger.info('CatalogService - getAllOpenSearchDashboard');
|
||||||
|
|
||||||
|
const response = await lastValueFrom(
|
||||||
|
this.catalogReadService.GetAllDataAssets(data, metadata),
|
||||||
|
)
|
||||||
|
.then((res) => {
|
||||||
|
this.logger.info('Done');
|
||||||
|
return JSON.parse(res.data_assets);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
this.logger.error(err.message);
|
||||||
|
throw new Error(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const asset of response.tables) {
|
||||||
|
const condition =
|
||||||
|
asset.owner && !asset.owner.includes('@') ? true : false;
|
||||||
|
const result = condition
|
||||||
|
? await this.userService.findOneById(asset.owner).catch(() => null)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const owner = result !== null ? result.user.username : null;
|
||||||
|
|
||||||
|
Object.assign(asset, { ...asset, owner });
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const asset of response.dashboards) {
|
||||||
|
const condition =
|
||||||
|
asset.owner && !asset.owner.includes('@') ? true : false;
|
||||||
|
const result = condition
|
||||||
|
? await this.userService.findOneById(asset.owner).catch(() => null)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const owner = result !== null ? result.user.username : null;
|
||||||
|
|
||||||
|
Object.assign(asset, { ...asset, owner });
|
||||||
|
}
|
||||||
|
|
||||||
|
return { data_assets: response };
|
||||||
|
}
|
||||||
|
|
||||||
|
async getOneDashboardMetabase(id, body, metadata) {
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
const nimbusUrl = this._getNimbusUrl(body);
|
||||||
const { data } = await axios.get(
|
const { data } = await axios.get(
|
||||||
`${nimbusUrl}/api/catalog/dashboard-metabase/${id}`,
|
`${nimbusUrl}/api/catalog/dashboard-metabase/${id}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
// const [, path] = data.iframe_url.split('.dadosfera');
|
const { data_asset } = await lastValueFrom(
|
||||||
// const host = `httpss://metabase-${body.info.customer.toLowerCase()}.dadosfera.ai`;
|
this.catalogReadService.GetOneDataAsset(
|
||||||
// data.iframe_url = host + path;
|
{ id, type: 'dashboard' },
|
||||||
|
metadata,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const opensearchTable = JSON.parse(data_asset);
|
||||||
|
|
||||||
return data;
|
const result = opensearchTable.user_id
|
||||||
|
? await this.userService
|
||||||
|
.findOneById(opensearchTable.owner)
|
||||||
|
.catch(() => null)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const owner = result !== null ? result.user.username : null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...data,
|
||||||
|
tags: opensearchTable.tags,
|
||||||
|
description: opensearchTable.description || null,
|
||||||
|
owner,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAllTableMetadata(body) {
|
async getAllTableMetadata(body) {
|
||||||
@@ -62,12 +200,37 @@ class CatalogService {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOneTableMetadata(body, params) {
|
async getOneTableMetadata(body, params, metadata) {
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
const nimbusUrl = this._getNimbusUrl(body);
|
||||||
const { data } = await axios.get(
|
const { data } = await axios.get(
|
||||||
`${nimbusUrl}/api/catalog/table-metadata/`,
|
`${nimbusUrl}/api/catalog/table-metadata/`,
|
||||||
{ params: params },
|
{ params: params },
|
||||||
);
|
);
|
||||||
|
if (data?.length === 1) {
|
||||||
|
const { data_asset } = await lastValueFrom(
|
||||||
|
this.catalogReadService.GetOneDataAsset(
|
||||||
|
{ id: data[0].id, type: 'dataset' },
|
||||||
|
metadata,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const opensearchTable = JSON.parse(data_asset);
|
||||||
|
const result = opensearchTable.user_id
|
||||||
|
? await this.userService
|
||||||
|
.findOneById(opensearchTable.owner)
|
||||||
|
.catch(() => null)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const owner = result !== null ? result.user.username : null;
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
...data[0],
|
||||||
|
tags: opensearchTable.tags,
|
||||||
|
table_description: opensearchTable.description,
|
||||||
|
owner,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,13 +290,34 @@ class CatalogService {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async createDataDescription(body) {
|
async createDataDescription(body, metadata) {
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
const response = await lastValueFrom(
|
||||||
const { data } = await axios.post(
|
this.catalogWriteService.UpdateDataAsset(
|
||||||
`${nimbusUrl}/api/catalog/data-description/`,
|
{
|
||||||
body,
|
id: `dataset-${body.table_id}`,
|
||||||
|
description: body.description,
|
||||||
|
tags: undefined,
|
||||||
|
},
|
||||||
|
metadata,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
return data;
|
// {
|
||||||
|
// description: 'descrição nova';
|
||||||
|
// id: 5;
|
||||||
|
// table_id: 4;
|
||||||
|
// }
|
||||||
|
// const nimbusUrl = this._getNimbusUrl(body);
|
||||||
|
// const { data } = await axios.post(
|
||||||
|
// `${nimbusUrl}/api/catalog/data-description/`,
|
||||||
|
// body,
|
||||||
|
// );
|
||||||
|
// {"id":5,"description":"descrição nova","updated_at":"2022-09-28T14:35:15.618750Z","table_id":4}
|
||||||
|
return {
|
||||||
|
id: 0,
|
||||||
|
description: body.description,
|
||||||
|
updated_at: new Date().toISOString(),
|
||||||
|
table_id: body.table_id,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDataDocs(body) {
|
async getDataDocs(body) {
|
||||||
@@ -197,31 +381,76 @@ class CatalogService {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async createTags(body) {
|
async createTags(data: Messages.TagTableRequest, metadata) {
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
this.logger.info('CatalogService - createTags');
|
||||||
const { data } = await axios.post(`${nimbusUrl}/api/catalog/tags/`, body);
|
|
||||||
return data;
|
const response = await lastValueFrom(
|
||||||
|
this.catalogWriteService.TagTable(data, metadata),
|
||||||
|
)
|
||||||
|
.then((res) => {
|
||||||
|
this.logger.info('Done');
|
||||||
|
return res;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
this.logger.error(err.message);
|
||||||
|
throw new Error(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
return { data_assets: response };
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAllTags(body) {
|
async findAllTags(data, metadata) {
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
this.logger.info('CatalogService - findAllCustomerTags');
|
||||||
const { data } = await axios.get(`${nimbusUrl}/api/catalog/tags/`, body);
|
|
||||||
return data;
|
const response = await lastValueFrom(
|
||||||
|
this.catalogReadService.GetCustomerTags(data, metadata),
|
||||||
|
)
|
||||||
|
.then((res) => {
|
||||||
|
this.logger.info('Done');
|
||||||
|
return res;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
this.logger.error(err.message);
|
||||||
|
throw new Error(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAllTableTags(body) {
|
async findAllTableTags(data, metadata) {
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
this.logger.info('CatalogService - findAllTableTags');
|
||||||
const { data } = await axios.get(
|
|
||||||
`${nimbusUrl}/api/catalog/table-tags/`,
|
const response = await lastValueFrom(
|
||||||
body,
|
this.catalogReadService.GetTableTags(data, metadata),
|
||||||
);
|
)
|
||||||
return data;
|
.then((res) => {
|
||||||
|
this.logger.info('Done');
|
||||||
|
return res;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
this.logger.error(err.message);
|
||||||
|
throw new Error(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteTags(id, body) {
|
async deleteTags(data, metadata) {
|
||||||
const nimbusUrl = this._getNimbusUrl(body);
|
this.logger.info('CatalogService - deleteTags');
|
||||||
const { data } = await axios.delete(`${nimbusUrl}/api/catalog/tags/${id}`);
|
|
||||||
return data;
|
const response = await lastValueFrom(
|
||||||
|
this.catalogWriteService.UntagTable(data, metadata),
|
||||||
|
)
|
||||||
|
.then((res) => {
|
||||||
|
this.logger.info('Done');
|
||||||
|
return res;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
this.logger.error(err.message);
|
||||||
|
throw new Error(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
async createTableTags(body) {
|
async createTableTags(body) {
|
||||||
|
|||||||
@@ -8,21 +8,40 @@ import { ClientGrpc } from '@nestjs/microservices';
|
|||||||
import { ConnectionManager } from '@dadosfera/protospack-v2';
|
import { ConnectionManager } from '@dadosfera/protospack-v2';
|
||||||
import { lastValueFrom } from 'rxjs';
|
import { lastValueFrom } from 'rxjs';
|
||||||
import {
|
import {
|
||||||
|
ConnectionApiConnection,
|
||||||
ConnectionRes,
|
ConnectionRes,
|
||||||
ConnectionsRes,
|
ConnectionsRes,
|
||||||
|
ConnectionToCatalogDto,
|
||||||
CreateConnectionDto,
|
CreateConnectionDto,
|
||||||
UpdateConnectionDto,
|
UpdateConnectionDto,
|
||||||
} from './dtos/connection';
|
} from './dtos/connection';
|
||||||
import { ConnectionClientConfiguration } from './client.config';
|
import { ConnectionClientConfiguration } from './client.config';
|
||||||
import { GetConnectionDetailsResponse } from '@dadosfera/protospack-v2/dist/lib/ConnectionManager/interfaces/messages';
|
import {
|
||||||
|
GetConnectionDetailsResponse,
|
||||||
|
INTERNAL_GetAllConnectionsResponse,
|
||||||
|
} from '@dadosfera/protospack-v2/dist/lib/ConnectionManager/interfaces/messages';
|
||||||
|
import { UsersService } from '../users/users.service';
|
||||||
|
import { ConnectorClientService } from '../connector/client.service';
|
||||||
|
import {
|
||||||
|
ConnectionsApiNetworkConfig,
|
||||||
|
NetworkConfigDto,
|
||||||
|
} from '../network-config/dto/network-config';
|
||||||
|
import DadosferaLogger from '@dadosfera/dadosfera-logs/dist';
|
||||||
|
|
||||||
export class ConnectionClientService implements OnModuleInit {
|
export class ConnectionClientService implements OnModuleInit {
|
||||||
private connectionServiceRead: ConnectionManager.ReadService.ConnectionManagerReadServices;
|
private connectionServiceRead: ConnectionManager.ReadService.ConnectionManagerReadServices;
|
||||||
private connectionServiceWrite: ConnectionManager.WriteService.ConnectionManagerWriteServices;
|
private connectionServiceWrite: ConnectionManager.WriteService.ConnectionManagerWriteServices;
|
||||||
|
logger: DadosferaLogger;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(ConnectionClientConfiguration.name)
|
@Inject(ConnectionClientConfiguration.name)
|
||||||
private readonly grpcClient: ClientGrpc,
|
private readonly grpcClient: ClientGrpc,
|
||||||
) {}
|
private usersService: UsersService,
|
||||||
|
private connectorService: ConnectorClientService,
|
||||||
|
private dadosferaLogger: DadosferaLogger,
|
||||||
|
) {
|
||||||
|
this.logger = dadosferaLogger.logger;
|
||||||
|
}
|
||||||
|
|
||||||
onModuleInit() {
|
onModuleInit() {
|
||||||
this.connectionServiceWrite =
|
this.connectionServiceWrite =
|
||||||
@@ -119,7 +138,7 @@ export class ConnectionClientService implements OnModuleInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAllConnection({ body, metadata }): Promise<ConnectionsRes> {
|
async getAllConnections({ body, metadata }): Promise<ConnectionsRes> {
|
||||||
const { search, filters, size, page } = body;
|
const { search, filters, size, page } = body;
|
||||||
|
|
||||||
return lastValueFrom(
|
return lastValueFrom(
|
||||||
@@ -150,4 +169,202 @@ export class ConnectionClientService implements OnModuleInit {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async INTERNAL_getAllConnections({
|
||||||
|
customer_name,
|
||||||
|
}: {
|
||||||
|
customer_name: string;
|
||||||
|
}): Promise<INTERNAL_GetAllConnectionsResponse> {
|
||||||
|
return lastValueFrom(
|
||||||
|
this.connectionServiceRead.INTERNAL_GetAllConnections({ customer_name }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async catalogExistingConnection(data: {
|
||||||
|
connection?: ConnectionToCatalogDto;
|
||||||
|
networkConfig?: NetworkConfigDto;
|
||||||
|
}) {
|
||||||
|
return lastValueFrom(
|
||||||
|
this.connectionServiceRead.INTERNAL_CatalogExistingConnection({
|
||||||
|
data_str: JSON.stringify(data),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async synchronizeConnections(apply: boolean) {
|
||||||
|
const connectors = await this.connectorService
|
||||||
|
.getAllConnectors({
|
||||||
|
search: undefined,
|
||||||
|
filters: undefined,
|
||||||
|
language: 'pt-br',
|
||||||
|
page: 1,
|
||||||
|
size: 500,
|
||||||
|
})
|
||||||
|
.then(({ connectors: connectorsStr }) =>
|
||||||
|
JSON.parse(connectorsStr).map((c) => c),
|
||||||
|
);
|
||||||
|
const { customers } = await this.usersService.findAllCustomers();
|
||||||
|
|
||||||
|
const customer_connections: {
|
||||||
|
customer_name: string;
|
||||||
|
customer_id: string;
|
||||||
|
productConnections: Record<string, any>[];
|
||||||
|
platformConnections: ConnectionApiConnection[];
|
||||||
|
productNetworkConfigs: Record<string, any>[];
|
||||||
|
platformNetworkConfigs: ConnectionsApiNetworkConfig[];
|
||||||
|
}[] = [];
|
||||||
|
for (const customer of customers) {
|
||||||
|
const { name: customer_name, id: customer_id } = customer;
|
||||||
|
|
||||||
|
const customer_connection = await this.INTERNAL_getAllConnections({
|
||||||
|
customer_name,
|
||||||
|
}).then((res) => ({
|
||||||
|
customer_name,
|
||||||
|
customer_id,
|
||||||
|
platformConnections: res.platformConnections
|
||||||
|
? JSON.parse(res.platformConnections)
|
||||||
|
: [],
|
||||||
|
productConnections: res.productConnections
|
||||||
|
? JSON.parse(res.productConnections)
|
||||||
|
: [],
|
||||||
|
productNetworkConfigs: res.productNetworkConfigs
|
||||||
|
? JSON.parse(res.productNetworkConfigs)
|
||||||
|
: [],
|
||||||
|
platformNetworkConfigs: res.platformNetworkConfigs
|
||||||
|
? JSON.parse(res.platformNetworkConfigs)
|
||||||
|
: [],
|
||||||
|
}));
|
||||||
|
customer_connections.push(customer_connection);
|
||||||
|
}
|
||||||
|
this.logger.info(
|
||||||
|
'DEBUG_ConnectionsMigrations - ' + JSON.stringify(customer_connections),
|
||||||
|
);
|
||||||
|
|
||||||
|
const migrations: {
|
||||||
|
customer_name: string;
|
||||||
|
status: any[];
|
||||||
|
productConnectionsMissing: ConnectionApiConnection[];
|
||||||
|
productNetworkConfigsMissing: ConnectionsApiNetworkConfig[];
|
||||||
|
}[] = [];
|
||||||
|
for (const customer_connection of customer_connections) {
|
||||||
|
const productConnectionsMissing: ConnectionApiConnection[] = [];
|
||||||
|
const productNetworkConfigsMissing: ConnectionsApiNetworkConfig[] = [];
|
||||||
|
const status: any[] = [];
|
||||||
|
let updatePromises: Promise<any>[] = [];
|
||||||
|
|
||||||
|
this.logger.info(
|
||||||
|
'DEBUG_ConnectionsMigrations - customer_connections ' +
|
||||||
|
JSON.stringify(customer_connection),
|
||||||
|
);
|
||||||
|
const {
|
||||||
|
customer_name,
|
||||||
|
productConnections,
|
||||||
|
platformConnections,
|
||||||
|
productNetworkConfigs,
|
||||||
|
platformNetworkConfigs,
|
||||||
|
customer_id,
|
||||||
|
} = customer_connection;
|
||||||
|
|
||||||
|
platformConnections?.forEach((plc) => {
|
||||||
|
const productConnection = productConnections.find(
|
||||||
|
(prc) => prc.id === plc.config_id,
|
||||||
|
);
|
||||||
|
if (!productConnection) productConnectionsMissing.push(plc);
|
||||||
|
});
|
||||||
|
platformNetworkConfigs?.forEach((platNetConfig) => {
|
||||||
|
const productNetworkConfig = productNetworkConfigs.find(
|
||||||
|
(prodNetConfig) => prodNetConfig.id === platNetConfig.config_id,
|
||||||
|
);
|
||||||
|
if (!productNetworkConfig)
|
||||||
|
productNetworkConfigsMissing.push(platNetConfig);
|
||||||
|
});
|
||||||
|
if (apply) {
|
||||||
|
for (const network_config of productNetworkConfigsMissing) {
|
||||||
|
const networkConfigToCatalog = {
|
||||||
|
id: network_config.config_id,
|
||||||
|
created_at: network_config.created_at,
|
||||||
|
updated_at: network_config.updated_at,
|
||||||
|
customer_name: customer_name,
|
||||||
|
customer_id: customer_id,
|
||||||
|
user_id: '',
|
||||||
|
network_type_id: '',
|
||||||
|
network_type_name: network_config.type,
|
||||||
|
type: network_config.type,
|
||||||
|
plugin: network_config.plugin,
|
||||||
|
name: network_config.name,
|
||||||
|
description: network_config.description,
|
||||||
|
properties: undefined,
|
||||||
|
keywords: undefined,
|
||||||
|
tags: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
updatePromises.push(
|
||||||
|
this.catalogExistingConnection({
|
||||||
|
networkConfig: networkConfigToCatalog,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.info(
|
||||||
|
'DEBUG_ConnectionsMigrations - Creating missing network configs for customer' +
|
||||||
|
customer_name +
|
||||||
|
' - ' +
|
||||||
|
JSON.stringify(customer_connection),
|
||||||
|
);
|
||||||
|
const updateStatuses = await Promise.all(updatePromises);
|
||||||
|
status.push(...updateStatuses);
|
||||||
|
updatePromises = [];
|
||||||
|
for (const connection of productConnectionsMissing) {
|
||||||
|
const connector = connectors.find(
|
||||||
|
(c) => c._source.plugin === connection.plugin,
|
||||||
|
);
|
||||||
|
const connectionToCatalog = {
|
||||||
|
id: connection.config_id,
|
||||||
|
created_at: connection.created_at,
|
||||||
|
updated_at: new Date().toISOString(),
|
||||||
|
customer_id: customer_id,
|
||||||
|
user_id: '',
|
||||||
|
plugin: connection.plugin,
|
||||||
|
name: connection.name,
|
||||||
|
description: connection.description,
|
||||||
|
image_url: connector._source.image,
|
||||||
|
network_config_id: connection.network_config_id,
|
||||||
|
type: connection.type,
|
||||||
|
connector_id: connector._id,
|
||||||
|
connector_name: connector._source.name,
|
||||||
|
in_use: 1,
|
||||||
|
username: '',
|
||||||
|
customer_name,
|
||||||
|
};
|
||||||
|
|
||||||
|
updatePromises.push(
|
||||||
|
this.catalogExistingConnection({ connection: connectionToCatalog }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.logger.info(
|
||||||
|
'DEBUG_ConnectionsMigrations - Creating missing connections for customer' +
|
||||||
|
' - ' +
|
||||||
|
customer_name +
|
||||||
|
JSON.stringify(customer_connection),
|
||||||
|
);
|
||||||
|
const updateStatuses_2 = await Promise.all(updatePromises);
|
||||||
|
status.push(...updateStatuses_2);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.info(
|
||||||
|
'DEBUG_ConnectionsMigrations - migrations for customer ' +
|
||||||
|
customer_name +
|
||||||
|
' - ' +
|
||||||
|
JSON.stringify(customer_connection),
|
||||||
|
);
|
||||||
|
migrations.push({
|
||||||
|
customer_name,
|
||||||
|
status,
|
||||||
|
productConnectionsMissing,
|
||||||
|
productNetworkConfigsMissing,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return { migrations };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
Authenticated,
|
Authenticated,
|
||||||
RequireAllPermissions,
|
RequireAllPermissions,
|
||||||
} from 'src/authentication/authentication.decorator';
|
} from 'src/authentication/authentication.decorator';
|
||||||
import { PERMISSIONS } from 'src/authentication/permissions.enum';
|
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
||||||
import { RequestUser, User } from 'src/authentication/user.decorator';
|
import { RequestUser, User } from 'src/authentication/user.decorator';
|
||||||
import { ValidationPipe } from '../../pipes/object-validation.pipe';
|
import { ValidationPipe } from '../../pipes/object-validation.pipe';
|
||||||
import {
|
import {
|
||||||
@@ -29,6 +29,7 @@ import {
|
|||||||
import { CreateConnectionDto } from './dtos/connection';
|
import { CreateConnectionDto } from './dtos/connection';
|
||||||
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
|
|
||||||
|
const connectionPermissions = PERMISSIONS_GROUPS.CONNECTION.permissions;
|
||||||
@ApiTags('connections')
|
@ApiTags('connections')
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@Authenticated()
|
@Authenticated()
|
||||||
@@ -43,8 +44,16 @@ export class ConnectionController {
|
|||||||
this.logger = dadosferaLogger.logger;
|
this.logger = dadosferaLogger.logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('connections-migration')
|
||||||
|
@RequireAllPermissions(
|
||||||
|
PERMISSIONS_GROUPS.DADOSFERA.permissions.CONNECTIONS_MIGRATION,
|
||||||
|
)
|
||||||
|
async synchronizeConnections(@Query('apply') apply: string) {
|
||||||
|
return this.clientService.synchronizeConnections(apply === 'true');
|
||||||
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
// @RequireAllPermissions(Permissions.CONNECTIONS.CREATE)
|
@RequireAllPermissions(connectionPermissions.CREATE)
|
||||||
async createConnection(
|
async createConnection(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Body(new ValidationPipe()) body: CreateConnectionDto,
|
@Body(new ValidationPipe()) body: CreateConnectionDto,
|
||||||
@@ -68,7 +77,7 @@ export class ConnectionController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Put('/:id')
|
@Put('/:id')
|
||||||
// @RequireAllPermissions(Permissions.CONNECTIONS.CREATE)
|
@RequireAllPermissions(connectionPermissions.CREATE)
|
||||||
async updateConnection(
|
async updateConnection(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Headers('Dadosfera-Lang') language: string,
|
@Headers('Dadosfera-Lang') language: string,
|
||||||
@@ -97,7 +106,7 @@ export class ConnectionController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Delete('/:id')
|
@Delete('/:id')
|
||||||
// @RequireAllPermissions(Permissions.CONNECTIONS.CREATE)
|
@RequireAllPermissions(connectionPermissions.DELETE)
|
||||||
async deleteConnection(
|
async deleteConnection(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
@@ -121,8 +130,7 @@ export class ConnectionController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
// @RequireAllPermissions(Permissions.CONNECTIONS.CREATE)
|
async getAllConnections(
|
||||||
async getAllConnection(
|
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Headers('Dadosfera-Lang') language,
|
@Headers('Dadosfera-Lang') language,
|
||||||
@Query() queries,
|
@Query() queries,
|
||||||
@@ -140,7 +148,7 @@ export class ConnectionController {
|
|||||||
username,
|
username,
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await this.clientService.getAllConnection({
|
const response = await this.clientService.getAllConnections({
|
||||||
body: { search, size, page, filters },
|
body: { search, size, page, filters },
|
||||||
metadata,
|
metadata,
|
||||||
});
|
});
|
||||||
@@ -149,7 +157,6 @@ export class ConnectionController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('/:id')
|
@Get('/:id')
|
||||||
// @RequireAllPermissions(Permissions.CONNECTIONS.CREATE)
|
|
||||||
async getConnectionDetails(
|
async getConnectionDetails(
|
||||||
@Headers('Dadosfera-Lang') language,
|
@Headers('Dadosfera-Lang') language,
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
|
|||||||
@@ -4,13 +4,19 @@ import { ConnectionClientService } from './client.service';
|
|||||||
import { ConnectionClientConfiguration } from './client.config';
|
import { ConnectionClientConfiguration } from './client.config';
|
||||||
import { ConnectionController } from './connection.controller';
|
import { ConnectionController } from './connection.controller';
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
|
import { UsersModule } from '../users/users.module';
|
||||||
|
import { ConnectorModule } from '../connector/connector.module';
|
||||||
|
|
||||||
const client = new ConnectionClientConfiguration();
|
const client = new ConnectionClientConfiguration();
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
|
imports: [
|
||||||
|
ClientsModule.register([client.providerOptions]),
|
||||||
|
UsersModule,
|
||||||
|
ConnectorModule,
|
||||||
|
],
|
||||||
controllers: [ConnectionController],
|
controllers: [ConnectionController],
|
||||||
providers: [ConnectionClientService, DadosferaLogger],
|
providers: [ConnectionClientService, DadosferaLogger],
|
||||||
imports: [ClientsModule.register([client.providerOptions])],
|
|
||||||
exports: [ConnectionClientService],
|
exports: [ConnectionClientService],
|
||||||
})
|
})
|
||||||
export class ConnectionModule {}
|
export class ConnectionModule {}
|
||||||
|
|||||||
@@ -13,7 +13,30 @@ import {
|
|||||||
GetConnectionDetailsResponse,
|
GetConnectionDetailsResponse,
|
||||||
GetConnectionResponse,
|
GetConnectionResponse,
|
||||||
} from '@dadosfera/protospack-v2/dist/lib/ConnectionManager/interfaces/messages';
|
} from '@dadosfera/protospack-v2/dist/lib/ConnectionManager/interfaces/messages';
|
||||||
|
export type ConnectionTypes = 'database' | 'file' | 'application';
|
||||||
|
export type ConnectionCredentialsType =
|
||||||
|
| 'basic_auth'
|
||||||
|
| 'iam_user'
|
||||||
|
| 'role_name'
|
||||||
|
| 'oauth'
|
||||||
|
| 'api_key'
|
||||||
|
| 'service_account'
|
||||||
|
| 'headers_authF';
|
||||||
|
export interface ConnectionApiConnection {
|
||||||
|
config_id: string;
|
||||||
|
plugin: string;
|
||||||
|
secret_id: string;
|
||||||
|
created_at: string;
|
||||||
|
network_config_id: null;
|
||||||
|
type: ConnectionTypes;
|
||||||
|
credentials_type: ConnectionCredentialsType;
|
||||||
|
credentials: Record<string, any>;
|
||||||
|
sensitive_fields: string[];
|
||||||
|
name: string;
|
||||||
|
customer_name: string;
|
||||||
|
description: string;
|
||||||
|
updated_at: string;
|
||||||
|
}
|
||||||
export class ConnectionDto implements Connection {
|
export class ConnectionDto implements Connection {
|
||||||
// ---Automatically generated information will not be sent by the frontend--- //
|
// ---Automatically generated information will not be sent by the frontend--- //
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
@@ -70,21 +93,17 @@ export class ConnectionDto implements Connection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ConnectionToCatalogDto implements ConnectionToCatalog {
|
export class ConnectionToCatalogDto implements ConnectionToCatalog {
|
||||||
// ---Automatically generated information will not be sent by the frontend--- //
|
// ---Automatically generated information - will not be sent by the frontend--- //
|
||||||
@ApiProperty()
|
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
@ApiProperty()
|
|
||||||
customer_id: string;
|
customer_id: string;
|
||||||
|
|
||||||
@ApiProperty()
|
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
|
|
||||||
@ApiProperty()
|
|
||||||
created_at: string;
|
created_at: string;
|
||||||
|
// ---Information extracted from token--- //
|
||||||
|
user_id: string;
|
||||||
|
username: string;
|
||||||
|
customer_name: string;
|
||||||
|
|
||||||
// ---Information sent by the frontend--- //
|
// ---Information sent by the frontend--- //
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
@@ -98,7 +117,6 @@ export class ConnectionToCatalogDto implements ConnectionToCatalog {
|
|||||||
network_config_id: string | null;
|
network_config_id: string | null;
|
||||||
|
|
||||||
// ---Information sent by the frontend (Heirs of Connector)--- //
|
// ---Information sent by the frontend (Heirs of Connector)--- //
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
connector_id: string;
|
connector_id: string;
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ export class ConnectorClientService implements OnModuleInit {
|
|||||||
return lastValueFrom(
|
return lastValueFrom(
|
||||||
this.connectorServiceWrite.RegisterConnector(serviceBody),
|
this.connectorServiceWrite.RegisterConnector(serviceBody),
|
||||||
).catch((err) => {
|
).catch((err) => {
|
||||||
console.log(err.details);
|
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
err.details,
|
err.details,
|
||||||
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||||
@@ -64,7 +63,6 @@ export class ConnectorClientService implements OnModuleInit {
|
|||||||
|
|
||||||
return lastValueFrom(this.connectorServiceWrite.UploadFile(body)).catch(
|
return lastValueFrom(this.connectorServiceWrite.UploadFile(body)).catch(
|
||||||
(err) => {
|
(err) => {
|
||||||
console.log(err.details);
|
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
err.details,
|
err.details,
|
||||||
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import {
|
|||||||
RequireAllPermissions,
|
RequireAllPermissions,
|
||||||
RequireSomePermission,
|
RequireSomePermission,
|
||||||
} from 'src/authentication/authentication.decorator';
|
} from 'src/authentication/authentication.decorator';
|
||||||
import { PERMISSIONS } from 'src/authentication/permissions.enum';
|
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
||||||
|
|
||||||
@ApiTags('connectors')
|
@ApiTags('connectors')
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@@ -47,7 +47,7 @@ export class ConnectorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@RequireAllPermissions(PERMISSIONS.CONNECTORS.permissions.CREATE)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.CONNECTORS.permissions.CREATE)
|
||||||
@ApiConsumes('multipart/form-data')
|
@ApiConsumes('multipart/form-data')
|
||||||
@UseInterceptors(FileInterceptor('file'))
|
@UseInterceptors(FileInterceptor('file'))
|
||||||
async uploadConnector(
|
async uploadConnector(
|
||||||
@@ -65,7 +65,7 @@ export class ConnectorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post('/uploads')
|
@Post('/uploads')
|
||||||
@RequireAllPermissions(PERMISSIONS.CONNECTORS.permissions.CREATE)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.CONNECTORS.permissions.CREATE)
|
||||||
@ApiConsumes('multipart/form-data')
|
@ApiConsumes('multipart/form-data')
|
||||||
@UseInterceptors(FilesInterceptor('files'))
|
@UseInterceptors(FilesInterceptor('files'))
|
||||||
async uploadFile(@UploadedFiles() files) {
|
async uploadFile(@UploadedFiles() files) {
|
||||||
@@ -82,11 +82,11 @@ export class ConnectorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post('/multiple-connectors-upload')
|
@Post('/multiple-connectors-upload')
|
||||||
@RequireAllPermissions(PERMISSIONS.CONNECTORS.permissions.CREATE)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.CONNECTORS.permissions.CREATE)
|
||||||
@ApiConsumes('multipart/form-data')
|
@ApiConsumes('multipart/form-data')
|
||||||
@UseInterceptors(FileInterceptor('file'))
|
@UseInterceptors(FileInterceptor('file'))
|
||||||
async uploadConnectorsFile(@UploadedFile() file: UploadConnectorsFileDto) {
|
async uploadConnectorsFile(@UploadedFile() file: UploadConnectorsFileDto) {
|
||||||
console.log(`/upload`, 'Upload Connector Route');
|
this.logger.info(`/upload`, 'Upload Connector Route');
|
||||||
|
|
||||||
const response = await this.connectorClientService.uploadConnectorsFile({
|
const response = await this.connectorClientService.uploadConnectorsFile({
|
||||||
file,
|
file,
|
||||||
@@ -97,17 +97,17 @@ export class ConnectorController {
|
|||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@RequireSomePermission(
|
@RequireSomePermission(
|
||||||
PERMISSIONS.CONNECTORS.permissions.GET,
|
PERMISSIONS_GROUPS.CONNECTORS.permissions.GET,
|
||||||
PERMISSIONS.PIPELINE.permissions.CREATE,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.CREATE,
|
||||||
PERMISSIONS.PIPELINE.permissions.GET,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.GET,
|
||||||
PERMISSIONS.PIPELINE.permissions.UPDATE,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.UPDATE,
|
||||||
PERMISSIONS.PIPELINE.permissions.DELETE,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.DELETE,
|
||||||
)
|
)
|
||||||
async getAllConnectors(
|
async getAllConnectors(
|
||||||
@Headers('dadosfera-lang') language,
|
@Headers('dadosfera-lang') language,
|
||||||
@Query() queries: GetAllDto,
|
@Query() queries: GetAllDto,
|
||||||
) {
|
) {
|
||||||
this.logger.info('/upload - Upload Connector Route');
|
this.logger.info('/GET - getAllConnectors Route');
|
||||||
if (!language) language = 'en-us';
|
if (!language) language = 'en-us';
|
||||||
|
|
||||||
const { search, size, page, ...filters } = queries;
|
const { search, size, page, ...filters } = queries;
|
||||||
@@ -120,7 +120,7 @@ export class ConnectorController {
|
|||||||
page: page || 1,
|
page: page || 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
const connectors = JSON.parse(response.connectors).connectors;
|
const connectors = JSON.parse(response.connectors);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
message: response.message,
|
message: response.message,
|
||||||
@@ -130,11 +130,11 @@ export class ConnectorController {
|
|||||||
|
|
||||||
@Get('/tags')
|
@Get('/tags')
|
||||||
@RequireSomePermission(
|
@RequireSomePermission(
|
||||||
PERMISSIONS.CONNECTORS.permissions.GET,
|
PERMISSIONS_GROUPS.CONNECTORS.permissions.GET,
|
||||||
PERMISSIONS.PIPELINE.permissions.CREATE,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.CREATE,
|
||||||
PERMISSIONS.PIPELINE.permissions.GET,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.GET,
|
||||||
PERMISSIONS.PIPELINE.permissions.UPDATE,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.UPDATE,
|
||||||
PERMISSIONS.PIPELINE.permissions.DELETE,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.DELETE,
|
||||||
)
|
)
|
||||||
async getConnectorsTags() {
|
async getConnectorsTags() {
|
||||||
return await this.connectorClientService.getConnectorsTags();
|
return await this.connectorClientService.getConnectorsTags();
|
||||||
@@ -142,18 +142,18 @@ export class ConnectorController {
|
|||||||
|
|
||||||
@Get('/:plugin')
|
@Get('/:plugin')
|
||||||
@RequireSomePermission(
|
@RequireSomePermission(
|
||||||
PERMISSIONS.CONNECTORS.permissions.GET,
|
PERMISSIONS_GROUPS.CONNECTORS.permissions.GET,
|
||||||
PERMISSIONS.PIPELINE.permissions.CREATE,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.CREATE,
|
||||||
PERMISSIONS.PIPELINE.permissions.GET,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.GET,
|
||||||
PERMISSIONS.PIPELINE.permissions.UPDATE,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.UPDATE,
|
||||||
PERMISSIONS.PIPELINE.permissions.DELETE,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.DELETE,
|
||||||
)
|
)
|
||||||
async getConnector(
|
async getConnector(
|
||||||
@Headers('dadosfera-lang') language,
|
@Headers('dadosfera-lang') language,
|
||||||
@Param('plugin') plugin: string,
|
@Param('plugin') plugin: string,
|
||||||
@Query('version') version: string,
|
@Query('version') version: string,
|
||||||
) {
|
) {
|
||||||
this.logger.info('/upload - Upload Connector Route');
|
this.logger.info('/GET/:plugin - getConnector Route');
|
||||||
if (!language) language = 'en-us';
|
if (!language) language = 'en-us';
|
||||||
|
|
||||||
const pluginId = `${plugin}-${version}`;
|
const pluginId = `${plugin}-${version}`;
|
||||||
@@ -171,11 +171,11 @@ export class ConnectorController {
|
|||||||
|
|
||||||
@Get('/:plugin/details')
|
@Get('/:plugin/details')
|
||||||
@RequireSomePermission(
|
@RequireSomePermission(
|
||||||
PERMISSIONS.CONNECTORS.permissions.GET,
|
PERMISSIONS_GROUPS.CONNECTORS.permissions.GET,
|
||||||
PERMISSIONS.PIPELINE.permissions.CREATE,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.CREATE,
|
||||||
PERMISSIONS.PIPELINE.permissions.GET,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.GET,
|
||||||
PERMISSIONS.PIPELINE.permissions.UPDATE,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.UPDATE,
|
||||||
PERMISSIONS.PIPELINE.permissions.DELETE,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.DELETE,
|
||||||
)
|
)
|
||||||
async getConnectorDetails(
|
async getConnectorDetails(
|
||||||
@Headers('dadosfera-lang') language,
|
@Headers('dadosfera-lang') language,
|
||||||
@@ -199,7 +199,7 @@ export class ConnectorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Put('/:plugin')
|
@Put('/:plugin')
|
||||||
@RequireAllPermissions(PERMISSIONS.CONNECTORS.permissions.UPDATE)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.CONNECTORS.permissions.UPDATE)
|
||||||
@ApiConsumes('multipart/form-data')
|
@ApiConsumes('multipart/form-data')
|
||||||
async updateConnector(
|
async updateConnector(
|
||||||
@Param('plugin') plugin: string,
|
@Param('plugin') plugin: string,
|
||||||
@@ -221,7 +221,7 @@ export class ConnectorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Put('/:plugin/add-tag')
|
@Put('/:plugin/add-tag')
|
||||||
@RequireAllPermissions(PERMISSIONS.CONNECTORS.permissions.UPDATE)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.CONNECTORS.permissions.UPDATE)
|
||||||
async addTagOnConnector(
|
async addTagOnConnector(
|
||||||
@Param('plugin') plugin: string,
|
@Param('plugin') plugin: string,
|
||||||
@Body() body: AddTagDto,
|
@Body() body: AddTagDto,
|
||||||
@@ -248,7 +248,7 @@ export class ConnectorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Put('/:plugin/remove-tag')
|
@Put('/:plugin/remove-tag')
|
||||||
@RequireAllPermissions(PERMISSIONS.CONNECTORS.permissions.UPDATE)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.CONNECTORS.permissions.UPDATE)
|
||||||
async removeTagOnConnector(
|
async removeTagOnConnector(
|
||||||
@Param('plugin') plugin: string,
|
@Param('plugin') plugin: string,
|
||||||
@Body() body: RemoveTagDto,
|
@Body() body: RemoveTagDto,
|
||||||
@@ -276,7 +276,7 @@ export class ConnectorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Delete('/:plugin')
|
@Delete('/:plugin')
|
||||||
@RequireAllPermissions(PERMISSIONS.CONNECTORS.permissions.DELETE)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.CONNECTORS.permissions.DELETE)
|
||||||
async deleteConnector(
|
async deleteConnector(
|
||||||
@Param('plugin') plugin: string,
|
@Param('plugin') plugin: string,
|
||||||
@Body() { version }: DeleteConnectorDto,
|
@Body() { version }: DeleteConnectorDto,
|
||||||
|
|||||||
@@ -11,5 +11,6 @@ const client = new ConnectorClientConfiguration();
|
|||||||
controllers: [ConnectorController],
|
controllers: [ConnectorController],
|
||||||
providers: [ConnectorClientService, DadosferaLogger],
|
providers: [ConnectorClientService, DadosferaLogger],
|
||||||
imports: [ClientsModule.register([client.providerOptions])],
|
imports: [ClientsModule.register([client.providerOptions])],
|
||||||
|
exports: [ConnectorClientService],
|
||||||
})
|
})
|
||||||
export class ConnectorModule {}
|
export class ConnectorModule {}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { InputsService } from './inputs.service';
|
import { InputsService } from './inputs.service';
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
import { PERMISSIONS } from '../../authentication/permissions.enum';
|
import { PERMISSIONS_GROUPS } from '../../authentication/permissions.enum';
|
||||||
import { AuthenticateCondition } from 'src/authentication/authentication.decorator';
|
import { AuthenticateCondition } from 'src/authentication/authentication.decorator';
|
||||||
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
||||||
import {
|
import {
|
||||||
@@ -36,20 +36,20 @@ import { Info } from '@dadosfera/protospack-v2/dist/lib/Input/interfaces/entitie
|
|||||||
case 'PATCH':
|
case 'PATCH':
|
||||||
return (
|
return (
|
||||||
user.permissions.includes(
|
user.permissions.includes(
|
||||||
PERMISSIONS.PIPELINE.permissions.CREATE.seqid,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.CREATE.seqid,
|
||||||
) ||
|
) ||
|
||||||
user.permissions.includes(PERMISSIONS.PIPELINE.permissions.UPDATE.seqid)
|
user.permissions.includes(PERMISSIONS_GROUPS.PIPELINE.permissions.UPDATE.seqid)
|
||||||
);
|
);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return (
|
return (
|
||||||
user.permissions.includes(
|
user.permissions.includes(
|
||||||
PERMISSIONS.PIPELINE.permissions.CREATE.seqid,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.CREATE.seqid,
|
||||||
) ||
|
) ||
|
||||||
user.permissions.includes(
|
user.permissions.includes(
|
||||||
PERMISSIONS.PIPELINE.permissions.UPDATE.seqid,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.UPDATE.seqid,
|
||||||
) ||
|
) ||
|
||||||
user.permissions.includes(PERMISSIONS.PIPELINE.permissions.GET.seqid)
|
user.permissions.includes(PERMISSIONS_GROUPS.PIPELINE.permissions.GET.seqid)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,7 +2,12 @@ import {
|
|||||||
NetworkConfigEntity,
|
NetworkConfigEntity,
|
||||||
NetworkConfigToCatalog,
|
NetworkConfigToCatalog,
|
||||||
} from '@dadosfera/protospack-v2/dist/lib/NetworkConfig/interfaces/entities';
|
} from '@dadosfera/protospack-v2/dist/lib/NetworkConfig/interfaces/entities';
|
||||||
import { ApiProperty, ApiPropertyOptional, PickType } from '@nestjs/swagger';
|
import {
|
||||||
|
ApiProperty,
|
||||||
|
ApiPropertyOptional,
|
||||||
|
OmitType,
|
||||||
|
PickType,
|
||||||
|
} from '@nestjs/swagger';
|
||||||
|
|
||||||
export enum NetworkConfigTypesEnum {
|
export enum NetworkConfigTypesEnum {
|
||||||
vpn = 'vpn',
|
vpn = 'vpn',
|
||||||
@@ -10,6 +15,24 @@ export enum NetworkConfigTypesEnum {
|
|||||||
export enum NetworkConfigPluginsEnum {
|
export enum NetworkConfigPluginsEnum {
|
||||||
openvpn = 'openvpn',
|
openvpn = 'openvpn',
|
||||||
}
|
}
|
||||||
|
export interface ConnectionsApiNetworkConfig {
|
||||||
|
config_id: string;
|
||||||
|
created_at: string;
|
||||||
|
credentials: {
|
||||||
|
CERTIFICATE_FILE: string;
|
||||||
|
OVPN_CREDENTIALS: string;
|
||||||
|
TLS_AUTH_FILE: string;
|
||||||
|
OVPN_FILE: string;
|
||||||
|
};
|
||||||
|
customer_name: string;
|
||||||
|
description: string;
|
||||||
|
name: string;
|
||||||
|
plugin: string;
|
||||||
|
secret_id: string;
|
||||||
|
sensitive_fields: string[];
|
||||||
|
type: string;
|
||||||
|
updated_at: string;
|
||||||
|
}
|
||||||
export class NetworkConfigDto implements NetworkConfigEntity {
|
export class NetworkConfigDto implements NetworkConfigEntity {
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
id: string;
|
id: string;
|
||||||
|
|||||||
@@ -25,7 +25,10 @@ import {
|
|||||||
UpdateNetworkConfigRes,
|
UpdateNetworkConfigRes,
|
||||||
} from './dto/network-config';
|
} from './dto/network-config';
|
||||||
import { FileInterceptor } from '@nestjs/platform-express';
|
import { FileInterceptor } from '@nestjs/platform-express';
|
||||||
|
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
||||||
|
import { RequireAllPermissions } from 'src/authentication/authentication.decorator';
|
||||||
|
|
||||||
|
const networkConfigPermissions = PERMISSIONS_GROUPS.NETWORK_CONFIG.permissions;
|
||||||
@ApiTags('Network Config')
|
@ApiTags('Network Config')
|
||||||
@Controller('network-config')
|
@Controller('network-config')
|
||||||
export class NetworkConfigController {
|
export class NetworkConfigController {
|
||||||
@@ -92,6 +95,7 @@ export class NetworkConfigController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOkResponse({ type: CreateNetworkConfigRes })
|
@ApiOkResponse({ type: CreateNetworkConfigRes })
|
||||||
|
@RequireAllPermissions(networkConfigPermissions.CREATE)
|
||||||
@ApiConsumes('multipart/form-data')
|
@ApiConsumes('multipart/form-data')
|
||||||
@UseInterceptors(FileInterceptor('ovpn_file'))
|
@UseInterceptors(FileInterceptor('ovpn_file'))
|
||||||
async createNetworkConfigs(
|
async createNetworkConfigs(
|
||||||
@@ -111,36 +115,37 @@ export class NetworkConfigController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id')
|
// @Patch(':id')
|
||||||
@ApiOkResponse({ type: UpdateNetworkConfigRes })
|
// @ApiOkResponse({ type: UpdateNetworkConfigRes })
|
||||||
async updateNetworkConfig(
|
// @RequireAllPermissions(networkConfigPermissions.CREATE)
|
||||||
@User() user: RequestUser,
|
// async updateNetworkConfig(
|
||||||
@Param('id') network_config_id: string,
|
// @User() user: RequestUser,
|
||||||
@Body() body: UpdateNetworkConfigReq,
|
// @Param('id') network_config_id: string,
|
||||||
) {
|
// @Body() body: UpdateNetworkConfigReq,
|
||||||
this.logger.info('PATCH /network-config/:id', {
|
// ) {
|
||||||
user: user.user_id,
|
// this.logger.info('PATCH /network-config/:id', {
|
||||||
customer: user.customer_name,
|
// user: user.user_id,
|
||||||
});
|
// customer: user.customer_name,
|
||||||
return this.networkConfigService.updateNetworkConfig(
|
// });
|
||||||
body,
|
// return this.networkConfigService.updateNetworkConfig(
|
||||||
network_config_id,
|
// body,
|
||||||
);
|
// network_config_id,
|
||||||
}
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
@Delete(':id')
|
// @Delete(':id')
|
||||||
@ApiOkResponse({ type: DeleteNetworkConfigRes })
|
// @ApiOkResponse({ type: DeleteNetworkConfigRes })
|
||||||
async deleteNetworkConfig(
|
// async deleteNetworkConfig(
|
||||||
@User() user: RequestUser,
|
// @User() user: RequestUser,
|
||||||
@Param('id') network_config_id: string,
|
// @Param('id') network_config_id: string,
|
||||||
) {
|
// ) {
|
||||||
this.logger.info('DELETE /network-config', {
|
// this.logger.info('DELETE /network-config', {
|
||||||
user: user.user_id,
|
// user: user.user_id,
|
||||||
customer: user.customer_name,
|
// customer: user.customer_name,
|
||||||
});
|
// });
|
||||||
return this.networkConfigService.deleteNetworkConfig(network_config_id, {
|
// return this.networkConfigService.deleteNetworkConfig(network_config_id, {
|
||||||
customer_name: user.customer_name,
|
// customer_name: user.customer_name,
|
||||||
customer_id: user.customer_id,
|
// customer_id: user.customer_id,
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
RequireAllPermissions,
|
RequireAllPermissions,
|
||||||
} from 'src/authentication/authentication.decorator';
|
} from 'src/authentication/authentication.decorator';
|
||||||
import {
|
import {
|
||||||
PERMISSIONS,
|
PERMISSIONS_GROUPS,
|
||||||
PermissionUsages,
|
PermissionUsages,
|
||||||
} from 'src/authentication/permissions.enum';
|
} from 'src/authentication/permissions.enum';
|
||||||
import { RequestUser, User } from 'src/authentication/user.decorator';
|
import { RequestUser, User } from 'src/authentication/user.decorator';
|
||||||
@@ -36,7 +36,7 @@ export class PermissionsController {
|
|||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@ApiOkResponse({ type: GetPublicPermissionsRes })
|
@ApiOkResponse({ type: GetPublicPermissionsRes })
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
getPublicPermissions(
|
getPublicPermissions(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Headers('dadosfera-lang') language,
|
@Headers('dadosfera-lang') language,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { PermissionsProtoService as PermissionsServiceInterface } from '@dadosfe
|
|||||||
import { InjectPermissionsRequest } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
import { InjectPermissionsRequest } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
import {
|
import {
|
||||||
PERMISSIONS,
|
PERMISSIONS_GROUPS,
|
||||||
PermissionUsages,
|
PermissionUsages,
|
||||||
PermissionsObjectGroup,
|
PermissionsObjectGroup,
|
||||||
PermissionsObjectPermissionTranslated,
|
PermissionsObjectPermissionTranslated,
|
||||||
@@ -48,7 +48,7 @@ export class PermissionsService
|
|||||||
async onApplicationBootstrap() {
|
async onApplicationBootstrap() {
|
||||||
this.logger.info('sending permissions to DUC...');
|
this.logger.info('sending permissions to DUC...');
|
||||||
|
|
||||||
const permissions = Object.values(PERMISSIONS).flatMap((namespace) =>
|
const permissions = Object.values(PERMISSIONS_GROUPS).flatMap((namespace) =>
|
||||||
Object.values(namespace.permissions),
|
Object.values(namespace.permissions),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -80,8 +80,8 @@ export class PermissionsService
|
|||||||
language: LanguageEnum = LanguageEnum.ptbr,
|
language: LanguageEnum = LanguageEnum.ptbr,
|
||||||
): PermissionGroup[] {
|
): PermissionGroup[] {
|
||||||
const groups: PermissionGroup[] = [];
|
const groups: PermissionGroup[] = [];
|
||||||
for (const key in PERMISSIONS) {
|
for (const key in PERMISSIONS_GROUPS) {
|
||||||
const permissionGroup: PermissionsObjectGroup = PERMISSIONS[key];
|
const permissionGroup: PermissionsObjectGroup = PERMISSIONS_GROUPS[key];
|
||||||
const title = permissionGroup.title[language];
|
const title = permissionGroup.title[language];
|
||||||
const permissions: PermissionGroupPermission[] = Object.values(
|
const permissions: PermissionGroupPermission[] = Object.values(
|
||||||
permissionGroup.permissions,
|
permissionGroup.permissions,
|
||||||
@@ -100,8 +100,8 @@ export class PermissionsService
|
|||||||
}
|
}
|
||||||
getAllPermissions(language: LanguageEnum = LanguageEnum.ptbr) {
|
getAllPermissions(language: LanguageEnum = LanguageEnum.ptbr) {
|
||||||
let permissions: PermissionsObjectPermissionTranslated[] = [];
|
let permissions: PermissionsObjectPermissionTranslated[] = [];
|
||||||
for (const key in PERMISSIONS) {
|
for (const key in PERMISSIONS_GROUPS) {
|
||||||
const permissionGroup: PermissionsObjectGroup = PERMISSIONS[key];
|
const permissionGroup: PermissionsObjectGroup = PERMISSIONS_GROUPS[key];
|
||||||
const permissionGroupPermissions: PermissionsObjectPermissionTranslated[] =
|
const permissionGroupPermissions: PermissionsObjectPermissionTranslated[] =
|
||||||
Object.values(permissionGroup.permissions).map((p) => ({
|
Object.values(permissionGroup.permissions).map((p) => ({
|
||||||
...p,
|
...p,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import { AuthenticateCondition } from 'src/authentication/authentication.decorator';
|
import { AuthenticateCondition } from 'src/authentication/authentication.decorator';
|
||||||
import { PERMISSIONS } from '../../authentication/permissions.enum';
|
import { PERMISSIONS_GROUPS } from '../../authentication/permissions.enum';
|
||||||
import { PipelinesService } from './pipelines.service';
|
import { PipelinesService } from './pipelines.service';
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
import { RequestUser, User } from 'src/authentication/user.decorator';
|
import { RequestUser, User } from 'src/authentication/user.decorator';
|
||||||
@@ -34,7 +34,7 @@ import { RequestUser, User } from 'src/authentication/user.decorator';
|
|||||||
}
|
}
|
||||||
|
|
||||||
return user.permissions.includes(
|
return user.permissions.includes(
|
||||||
PERMISSIONS.PIPELINE.permissions[action].seqid,
|
PERMISSIONS_GROUPS.PIPELINE.permissions[action].seqid,
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
export class PipelinesController {
|
export class PipelinesController {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiCreatedResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiCreatedResponse, ApiTags } from '@nestjs/swagger';
|
||||||
import { AuthenticateCondition } from 'src/authentication/authentication.decorator';
|
import { AuthenticateCondition } from 'src/authentication/authentication.decorator';
|
||||||
import { PERMISSIONS } from '../../authentication/permissions.enum';
|
import { PERMISSIONS_GROUPS } from '../../authentication/permissions.enum';
|
||||||
import { PipelinesService } from './pipelines.service';
|
import { PipelinesService } from './pipelines.service';
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
import { Messages } from '@dadosfera/protospack-v2/dist/lib/PipelineV2';
|
import { Messages } from '@dadosfera/protospack-v2/dist/lib/PipelineV2';
|
||||||
@@ -40,7 +40,7 @@ import { ICreatePipelineV2Req, IPipelineV2 } from './interfaces';
|
|||||||
}
|
}
|
||||||
|
|
||||||
return user.permissions.includes(
|
return user.permissions.includes(
|
||||||
PERMISSIONS.PIPELINE.permissions[action].seqid,
|
PERMISSIONS_GROUPS.PIPELINE.permissions[action].seqid,
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
export class PipelinesController {
|
export class PipelinesController {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ import {
|
|||||||
SetRoleUsersReq,
|
SetRoleUsersReq,
|
||||||
} from './dto/entities';
|
} from './dto/entities';
|
||||||
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
||||||
import { PERMISSIONS } from 'src/authentication/permissions.enum';
|
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
||||||
import {
|
import {
|
||||||
Authenticated,
|
Authenticated,
|
||||||
RequireAllPermissions,
|
RequireAllPermissions,
|
||||||
@@ -69,7 +69,7 @@ export class RolesController {
|
|||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@ApiOkResponse({ type: GetRolesByCustomerRes })
|
@ApiOkResponse({ type: GetRolesByCustomerRes })
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
async searchRoles(
|
async searchRoles(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Query() filters: GetRolesByCustomerReq,
|
@Query() filters: GetRolesByCustomerReq,
|
||||||
@@ -82,7 +82,7 @@ export class RolesController {
|
|||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiCreatedResponse({ type: CreateRoleRes })
|
@ApiCreatedResponse({ type: CreateRoleRes })
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
async createRole(
|
async createRole(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Body() body: CreateRoleReq,
|
@Body() body: CreateRoleReq,
|
||||||
@@ -95,7 +95,7 @@ export class RolesController {
|
|||||||
|
|
||||||
@Put('permissions')
|
@Put('permissions')
|
||||||
@ApiOkResponse({ type: GrantPermissionsToRoleRes })
|
@ApiOkResponse({ type: GrantPermissionsToRoleRes })
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
async grantPermissionsToRole(
|
async grantPermissionsToRole(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Body() body: GrantPermissionsToRoleReq,
|
@Body() body: GrantPermissionsToRoleReq,
|
||||||
@@ -108,7 +108,7 @@ export class RolesController {
|
|||||||
|
|
||||||
@Delete('permissions')
|
@Delete('permissions')
|
||||||
@ApiOkResponse({ type: RevokePermissionsFromRoleRes })
|
@ApiOkResponse({ type: RevokePermissionsFromRoleRes })
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
async revokePermissionsFromRole(
|
async revokePermissionsFromRole(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Body() body: RevokePermissionsFromRoleReq,
|
@Body() body: RevokePermissionsFromRoleReq,
|
||||||
@@ -121,7 +121,7 @@ export class RolesController {
|
|||||||
|
|
||||||
@Patch('permissions')
|
@Patch('permissions')
|
||||||
@ApiOkResponse({ type: SetRolePermissionsRes })
|
@ApiOkResponse({ type: SetRolePermissionsRes })
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
async setRolePermissions(
|
async setRolePermissions(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Body() body: SetRolePermissionsReq,
|
@Body() body: SetRolePermissionsReq,
|
||||||
@@ -134,7 +134,7 @@ export class RolesController {
|
|||||||
|
|
||||||
@Patch('users')
|
@Patch('users')
|
||||||
@ApiOkResponse({ type: SetRoleUsersRes })
|
@ApiOkResponse({ type: SetRoleUsersRes })
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
async setRoleUsers(
|
async setRoleUsers(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Body() body: SetRoleUsersReq,
|
@Body() body: SetRoleUsersReq,
|
||||||
@@ -147,7 +147,7 @@ export class RolesController {
|
|||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
@ApiOkResponse({ type: RoleDto })
|
@ApiOkResponse({ type: RoleDto })
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
async getRoleById(
|
async getRoleById(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
@@ -159,7 +159,7 @@ export class RolesController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
async deleteRole(
|
async deleteRole(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
@@ -172,7 +172,7 @@ export class RolesController {
|
|||||||
|
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
@ApiOkResponse({ type: UpdateRoleRes })
|
@ApiOkResponse({ type: UpdateRoleRes })
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
async updateRole(
|
async updateRole(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { ApiTags } from '@nestjs/swagger';
|
|||||||
import { TransformationsClientService } from './client.service';
|
import { TransformationsClientService } from './client.service';
|
||||||
import { IIdRequest } from './interfaces';
|
import { IIdRequest } from './interfaces';
|
||||||
import { AuthenticateCondition } from 'src/authentication/authentication.decorator';
|
import { AuthenticateCondition } from 'src/authentication/authentication.decorator';
|
||||||
import { PERMISSIONS } from '../../authentication/permissions.enum';
|
import { PERMISSIONS_GROUPS } from '../../authentication/permissions.enum';
|
||||||
import { TransformationsService } from './transformations.service';
|
import { TransformationsService } from './transformations.service';
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
import { RequestUser, User } from 'src/authentication/user.decorator';
|
import { RequestUser, User } from 'src/authentication/user.decorator';
|
||||||
@@ -36,7 +36,7 @@ import { RequestUser, User } from 'src/authentication/user.decorator';
|
|||||||
}
|
}
|
||||||
|
|
||||||
return user.permissions.includes(
|
return user.permissions.includes(
|
||||||
PERMISSIONS.TRANSFORMATIONS.permissions[action].seqid,
|
PERMISSIONS_GROUPS.TRANSFORMATIONS.permissions[action].seqid,
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
export class TransformationsController {
|
export class TransformationsController {
|
||||||
|
|||||||
@@ -98,6 +98,8 @@ export class UpdateUserReq {
|
|||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
name?: string;
|
name?: string;
|
||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
|
email?: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
jobTitle?: string;
|
jobTitle?: string;
|
||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
department?: string;
|
department?: string;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import {
|
|||||||
} from '@nestjs/swagger';
|
} from '@nestjs/swagger';
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
import { RequireAllPermissions } from 'src/authentication/authentication.decorator';
|
import { RequireAllPermissions } from 'src/authentication/authentication.decorator';
|
||||||
import { PERMISSIONS } from 'src/authentication/permissions.enum';
|
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
||||||
import { RequestUser, User } from 'src/authentication/user.decorator';
|
import { RequestUser, User } from 'src/authentication/user.decorator';
|
||||||
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
||||||
import { LanguageEnum } from 'src/utils/languages.enum';
|
import { LanguageEnum } from 'src/utils/languages.enum';
|
||||||
@@ -45,6 +45,7 @@ import {
|
|||||||
UserByCustomer,
|
UserByCustomer,
|
||||||
} from './dtos/entities';
|
} from './dtos/entities';
|
||||||
import { UsersService } from './users.service';
|
import { UsersService } from './users.service';
|
||||||
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
|
|
||||||
// TODO GET de hierarquias e do PATCH em usuário
|
// TODO GET de hierarquias e do PATCH em usuário
|
||||||
@ApiTags('Users')
|
@ApiTags('Users')
|
||||||
@@ -68,7 +69,7 @@ export class UsersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
@ApiOkResponse({
|
@ApiOkResponse({
|
||||||
type: GetAllUsersByCustomerIdRes,
|
type: GetAllUsersByCustomerIdRes,
|
||||||
description: 'List of users of a customer',
|
description: 'List of users of a customer',
|
||||||
@@ -83,7 +84,7 @@ export class UsersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('hierarchies')
|
@Get('hierarchies')
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
@ApiOkResponse({ type: GetAllHierarchiesRes })
|
@ApiOkResponse({ type: GetAllHierarchiesRes })
|
||||||
async getAllHierarchies(
|
async getAllHierarchies(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@@ -95,7 +96,7 @@ export class UsersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('departments')
|
@Get('departments')
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
@ApiOkResponse({ type: GetAllDepartmentsRes })
|
@ApiOkResponse({ type: GetAllDepartmentsRes })
|
||||||
async getAllDepartments(
|
async getAllDepartments(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@@ -107,7 +108,7 @@ export class UsersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('jobTitles')
|
@Get('jobTitles')
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
@ApiOkResponse({ type: GetAllDepartmentsRes })
|
@ApiOkResponse({ type: GetAllDepartmentsRes })
|
||||||
async getAllJobTitles(
|
async getAllJobTitles(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@@ -119,7 +120,7 @@ export class UsersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
@ApiOkResponse({
|
@ApiOkResponse({
|
||||||
type: UserByCustomer,
|
type: UserByCustomer,
|
||||||
})
|
})
|
||||||
@@ -134,33 +135,38 @@ export class UsersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
@ApiCreatedResponse({ type: CreateUserRes })
|
@ApiCreatedResponse({ type: CreateUserRes })
|
||||||
async createUser(
|
async createUser(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Body() body: CreateUserReq,
|
@Body() body: CreateUserReq,
|
||||||
@Headers('dadosfera-lang') language,
|
@Headers('dadosfera-lang') language,
|
||||||
) {
|
) {
|
||||||
|
const meta = new Metadata();
|
||||||
|
meta.add('access_token', user.access_token);
|
||||||
this.logger.info('createUser', { user });
|
this.logger.info('createUser', { user });
|
||||||
this.userService.setLanguage(language);
|
this.userService.setLanguage(language);
|
||||||
return await this.userService.createUser(body);
|
|
||||||
|
return await this.userService.createUser(body, meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('batch')
|
@Post('batch')
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
@ApiCreatedResponse({ type: BatchCreateUserRes })
|
@ApiCreatedResponse({ type: BatchCreateUserRes })
|
||||||
async batchCreateUser(
|
async batchCreateUser(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Body() body: BatchCreateUserReq,
|
@Body() body: BatchCreateUserReq,
|
||||||
@Headers('dadosfera-lang') language,
|
@Headers('dadosfera-lang') language,
|
||||||
) {
|
) {
|
||||||
|
const meta = new Metadata();
|
||||||
|
meta.add('access_token', user.access_token);
|
||||||
this.logger.info('batchCreateUser', { user });
|
this.logger.info('batchCreateUser', { user });
|
||||||
this.userService.setLanguage(language);
|
this.userService.setLanguage(language);
|
||||||
return await this.userService.batchCreateUser(body);
|
return await this.userService.batchCreateUser(body, meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post(':id/resend-invite')
|
@Post(':id/resend-invite')
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
@HttpCode(HttpStatus.OK)
|
@HttpCode(HttpStatus.OK)
|
||||||
async resendInvite(
|
async resendInvite(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@@ -173,7 +179,7 @@ export class UsersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Delete('role')
|
@Delete('role')
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
async unassignRoleToUser(
|
async unassignRoleToUser(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Query() request: UnassignRoleToUserReq,
|
@Query() request: UnassignRoleToUserReq,
|
||||||
@@ -185,7 +191,7 @@ export class UsersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
@ApiOkResponse({ type: DeleteUserRes })
|
@ApiOkResponse({ type: DeleteUserRes })
|
||||||
async deleteUser(
|
async deleteUser(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@@ -198,7 +204,7 @@ export class UsersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Patch('roles')
|
@Patch('roles')
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
@ApiOkResponse({ type: SetUserRolesRes })
|
@ApiOkResponse({ type: SetUserRolesRes })
|
||||||
async setUserRoles(
|
async setUserRoles(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@@ -211,7 +217,7 @@ export class UsersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Put('role')
|
@Put('role')
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
async assignRoleToUser(
|
async assignRoleToUser(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Body() body: AssignRoleToUserReq,
|
@Body() body: AssignRoleToUserReq,
|
||||||
@@ -223,7 +229,7 @@ export class UsersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
@RequireAllPermissions(PERMISSIONS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
@ApiOkResponse({ type: UpdateUserRes })
|
@ApiOkResponse({ type: UpdateUserRes })
|
||||||
async updateUser(
|
async updateUser(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@@ -235,4 +241,12 @@ export class UsersController {
|
|||||||
this.userService.setLanguage(language);
|
this.userService.setLanguage(language);
|
||||||
return await this.userService.updateUser(body, id, user.customer_id);
|
return await this.userService.updateUser(body, id, user.customer_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post('synchronize/:id')
|
||||||
|
@RequireAllPermissions(PERMISSIONS_GROUPS.DADOSFERA.permissions.SYNC_USER)
|
||||||
|
@ApiOkResponse({ type: UpdateUserRes })
|
||||||
|
async synchronizeUser(@User() user: RequestUser, @Param('id') id: string) {
|
||||||
|
this.logger.info('synchronizeUser', { user });
|
||||||
|
return await this.userService.synchronizeUser(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,5 +17,6 @@ const client = new DucClient();
|
|||||||
],
|
],
|
||||||
controllers: [UsersController],
|
controllers: [UsersController],
|
||||||
providers: [UsersService, DadosferaLogger],
|
providers: [UsersService, DadosferaLogger],
|
||||||
|
exports: [UsersService],
|
||||||
})
|
})
|
||||||
export class UsersModule {}
|
export class UsersModule {}
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ import { ClientGrpc } from '@nestjs/microservices';
|
|||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
|
|
||||||
import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Duc';
|
import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Duc';
|
||||||
import { UsersProtoService } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/write-service';
|
import {
|
||||||
|
CustomersProtoService,
|
||||||
|
UsersProtoService,
|
||||||
|
} from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/write-service';
|
||||||
import {
|
import {
|
||||||
AssignRoleToUserRequest,
|
AssignRoleToUserRequest,
|
||||||
IdRequest,
|
IdRequest,
|
||||||
@@ -24,6 +27,7 @@ import { LanguageEnum } from 'src/utils/languages.enum';
|
|||||||
import { UserByCustomer } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/entities';
|
import { UserByCustomer } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/entities';
|
||||||
import { EnrichErrorCode } from 'src/utils/ErrorBuilder';
|
import { EnrichErrorCode } from 'src/utils/ErrorBuilder';
|
||||||
import { DucClient } from '../duc/client.config';
|
import { DucClient } from '../duc/client.config';
|
||||||
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UsersService implements OnModuleInit {
|
export class UsersService implements OnModuleInit {
|
||||||
@@ -31,6 +35,7 @@ export class UsersService implements OnModuleInit {
|
|||||||
language: LanguageEnum = LanguageEnum.ptbr;
|
language: LanguageEnum = LanguageEnum.ptbr;
|
||||||
|
|
||||||
private usersClientService: UsersProtoService;
|
private usersClientService: UsersProtoService;
|
||||||
|
private customersClientService: CustomersProtoService;
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(DadosferaLogger)
|
@Inject(DadosferaLogger)
|
||||||
dadosferaLogger: DadosferaLogger,
|
dadosferaLogger: DadosferaLogger,
|
||||||
@@ -41,9 +46,12 @@ export class UsersService implements OnModuleInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onModuleInit() {
|
onModuleInit() {
|
||||||
this.usersClientService = this.grpcClient.getService<UsersProtoService>(
|
this.usersClientService = this.grpcClient.getService(
|
||||||
ProtoServices.UsersProtoService,
|
ProtoServices.UsersProtoService,
|
||||||
);
|
);
|
||||||
|
this.customersClientService = this.grpcClient.getService(
|
||||||
|
ProtoServices.CustomersProtoService,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
setLanguage(l: LanguageEnum = LanguageEnum.ptbr) {
|
setLanguage(l: LanguageEnum = LanguageEnum.ptbr) {
|
||||||
@@ -76,24 +84,27 @@ export class UsersService implements OnModuleInit {
|
|||||||
return { user: this.adjustUsersPayload([user])[0] };
|
return { user: this.adjustUsersPayload([user])[0] };
|
||||||
}
|
}
|
||||||
|
|
||||||
async createUser(req: CreateUserReq) {
|
async createUser(req: CreateUserReq, meta?: Metadata) {
|
||||||
const { email, department, hierarchy, jobTitle, name, roleNames } = req;
|
const { email, department, hierarchy, jobTitle, name, roleNames } = req;
|
||||||
const { user } = await lastValueFrom(
|
const { user } = await lastValueFrom(
|
||||||
this.usersClientService.UserCreate({
|
this.usersClientService.UserCreate(
|
||||||
email,
|
{
|
||||||
hierarchy,
|
email,
|
||||||
name,
|
hierarchy,
|
||||||
roleIds: [],
|
name,
|
||||||
department,
|
roleIds: [],
|
||||||
jobTitle,
|
department,
|
||||||
roleNames,
|
jobTitle,
|
||||||
}),
|
roleNames,
|
||||||
|
},
|
||||||
|
meta,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
return { user: this.adjustUsersPayload([user])[0] };
|
return { user: this.adjustUsersPayload([user])[0] };
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateUser(req: UpdateUserReq, id: string, customerId: string) {
|
async updateUser(req: UpdateUserReq, id: string, customerId: string) {
|
||||||
const { department, hierarchy, jobTitle, name, roleNames } = req;
|
const { department, hierarchy, jobTitle, name, roleNames, email } = req;
|
||||||
if (roleNames) {
|
if (roleNames) {
|
||||||
await this.setRoles({ roleNames, userId: id }, customerId);
|
await this.setRoles({ roleNames, userId: id }, customerId);
|
||||||
}
|
}
|
||||||
@@ -105,6 +116,7 @@ export class UsersService implements OnModuleInit {
|
|||||||
department,
|
department,
|
||||||
hierarchy,
|
hierarchy,
|
||||||
jobTitle,
|
jobTitle,
|
||||||
|
email,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
return { user: this.adjustUsersPayload([user])[0] };
|
return { user: this.adjustUsersPayload([user])[0] };
|
||||||
@@ -126,7 +138,8 @@ export class UsersService implements OnModuleInit {
|
|||||||
return { user: this.adjustUsersPayload([user])[0] };
|
return { user: this.adjustUsersPayload([user])[0] };
|
||||||
}
|
}
|
||||||
|
|
||||||
async batchCreateUser({ users }: BatchCreateUserReq) {
|
async batchCreateUser(req: BatchCreateUserReq, meta?: Metadata) {
|
||||||
|
const { users } = req;
|
||||||
const usersToCreate: UserCreateRequest[] = users.map(
|
const usersToCreate: UserCreateRequest[] = users.map(
|
||||||
({ roleNames, email, department, hierarchy, jobTitle, name }) => ({
|
({ roleNames, email, department, hierarchy, jobTitle, name }) => ({
|
||||||
roleNames,
|
roleNames,
|
||||||
@@ -139,14 +152,16 @@ export class UsersService implements OnModuleInit {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
const { errorUsers, usersCreated } = await lastValueFrom(
|
const { errorUsers, usersCreated } = await lastValueFrom(
|
||||||
this.usersClientService.UserBatchCreate({
|
this.usersClientService.UserBatchCreate(
|
||||||
users: usersToCreate,
|
{
|
||||||
}),
|
users: usersToCreate,
|
||||||
|
},
|
||||||
|
meta,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
usersCreated: this.adjustUsersPayload(usersCreated),
|
usersCreated: this.adjustUsersPayload(usersCreated),
|
||||||
// mapping error code to message
|
|
||||||
errorUsers: errorUsers.map(({ user, error }) => ({
|
errorUsers: errorUsers.map(({ user, error }) => ({
|
||||||
user,
|
user,
|
||||||
error: EnrichErrorCode(error).message,
|
error: EnrichErrorCode(error).message,
|
||||||
@@ -200,4 +215,14 @@ export class UsersService implements OnModuleInit {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findAllCustomers() {
|
||||||
|
return await lastValueFrom(this.customersClientService.CustomerFindAll({}));
|
||||||
|
}
|
||||||
|
|
||||||
|
async synchronizeUser(userId: string) {
|
||||||
|
return await lastValueFrom(
|
||||||
|
this.usersClientService.INTERNAL_UserSynchronize({ userId }),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ interface IMetadata {
|
|||||||
user_id?: string;
|
user_id?: string;
|
||||||
language?: string;
|
language?: string;
|
||||||
details?: string;
|
details?: string;
|
||||||
|
roles?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PackTheMetadata(info: IMetadata): Metadata {
|
export function PackTheMetadata(info: IMetadata): Metadata {
|
||||||
|
|||||||
@@ -185,6 +185,14 @@ export function EnrichErrorCode(code: string) {
|
|||||||
code,
|
code,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
case ErrorCodes.USER.NOT_CREATED:
|
||||||
|
return {
|
||||||
|
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
error: 'Ocorreu um erro ao criar seu usúario',
|
||||||
|
message: 'Tente novamente ou entre em contato com o suporte',
|
||||||
|
code,
|
||||||
|
};
|
||||||
|
|
||||||
case ErrorCodes.USER.NOT_FOUND:
|
case ErrorCodes.USER.NOT_FOUND:
|
||||||
return {
|
return {
|
||||||
statusCode: HttpStatus.NOT_FOUND,
|
statusCode: HttpStatus.NOT_FOUND,
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export const USER = {
|
|||||||
ALREADY_EXISTS: 'USER.ALREADY_EXISTS',
|
ALREADY_EXISTS: 'USER.ALREADY_EXISTS',
|
||||||
ROLE_ALREADY_ASSIGNED: 'USER.ROLE_ALREADY_ASSIGNED',
|
ROLE_ALREADY_ASSIGNED: 'USER.ROLE_ALREADY_ASSIGNED',
|
||||||
ROLE_NOT_ASSIGNED: 'USER.ROLE_NOT_ASSIGNED',
|
ROLE_NOT_ASSIGNED: 'USER.ROLE_NOT_ASSIGNED',
|
||||||
|
NOT_CREATED: 'USER.NOT_CREATED',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CUSTOMER = {
|
export const CUSTOMER = {
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user