mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-24 08:29:08 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4df23c917a | ||
|
|
6c3eef7181 | ||
|
|
668c5fe6a5 | ||
|
|
d057495b2e | ||
|
|
2f1c71eefe | ||
|
|
3bb014e714 | ||
|
|
2ff2aa049f | ||
|
|
f6c7420f59 | ||
|
|
abbe88f45b | ||
|
|
383741f48c | ||
|
|
ff663e7166 | ||
|
|
305daeeeab | ||
|
|
852ddbf88b | ||
|
|
4dfe6c3870 | ||
|
|
2710159a73 | ||
|
|
1ab5d49908 | ||
|
|
43372b5a0f | ||
|
|
0ac2dd2de7 | ||
|
|
0342386a76 | ||
|
|
28e55f8fd9 | ||
|
|
4e2e296442 | ||
|
|
d89573bc79 | ||
|
|
03ed4d88a0 | ||
|
|
329bbf2e4d | ||
|
|
ae069a0e00 | ||
|
|
d3bcbdc43c | ||
|
|
4e2e6787a4 | ||
|
|
50da33b766 | ||
|
|
bb72cfce45 | ||
|
|
03d17758ae | ||
|
|
b7e76a6d3f | ||
|
|
c920eb27b9 | ||
|
|
c25d2427c2 | ||
|
|
0f13d0c590 | ||
|
|
7781298e6e | ||
|
|
2c00d3249a | ||
|
|
cd7c7d538f | ||
|
|
e496d42776 | ||
|
|
a07247d538 | ||
|
|
153ba1a98b | ||
|
|
46519323f8 | ||
|
|
a51d52d68e | ||
|
|
555ff2eda9 | ||
|
|
4eba099390 | ||
|
|
08fa269ce0 | ||
|
|
e52af6844b | ||
|
|
d686753f25 |
@@ -0,0 +1,3 @@
|
|||||||
|
container_commands:
|
||||||
|
01setup_swap:
|
||||||
|
command: "bash .ebextensions/setup_swap.sh"
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
SWAPFILE=/var/swapfile
|
||||||
|
SWAP_MEGABYTES=1024
|
||||||
|
|
||||||
|
if [ -f $SWAPFILE ]; then
|
||||||
|
echo "Swapfile $SWAPFILE found, assuming already setup"
|
||||||
|
exit;
|
||||||
|
fi
|
||||||
|
|
||||||
|
/bin/dd if=/dev/zero of=$SWAPFILE bs=1M count=$SWAP_MEGABYTES
|
||||||
|
/bin/chmod 600 $SWAPFILE
|
||||||
|
/sbin/mkswap $SWAPFILE
|
||||||
|
/sbin/swapon $SWAPFILE
|
||||||
@@ -37,9 +37,8 @@ jobs:
|
|||||||
outputs:
|
outputs:
|
||||||
#new_release_published: ${{ steps.semantic.outputs.last_release_version != steps.semantic.outputs.new_release_version }}
|
#new_release_published: ${{ steps.semantic.outputs.last_release_version != steps.semantic.outputs.new_release_version }}
|
||||||
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
|
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
|
||||||
new_release_version: ${{ steps.semantic.outputs.new_release_version }}
|
#new_release_version: ${{ steps.semantic.outputs.new_release_version }}
|
||||||
test: ${{ (steps.semantic.outputs.new_release_published == 'true' && steps.semantic.outputs.new_release_version) || (github.event_name == 'workflow_dispatch' && '0.0.0') }}
|
new_release_version: ${{ (steps.semantic.outputs.new_release_published == 'true' && steps.semantic.outputs.new_release_version) || (github.event_name == 'workflow_dispatch' && '0.0.0') }}
|
||||||
testt: ${{ (needs.semantic_release.outputs.new_release_published == 'true' && needs.semantic_release.outputs.new_release_version) || '1.0.0' }}
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
@@ -61,18 +60,18 @@ jobs:
|
|||||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
if: ${{ (github.event_name != 'workflow_dispatch' && needs.semantic_release.outputs.new_release_published == 'true') || 'true' }}
|
if: ${{ github.event_name == 'workflow_dispatch' || needs.semantic_release.outputs.new_release_published == 'true' }}
|
||||||
needs: [extract_environment, semantic_release]
|
needs: [extract_environment, semantic_release]
|
||||||
runs-on:
|
runs-on:
|
||||||
[self-hosted, '${{ needs.extract_environment.outputs.environment }}']
|
[self-hosted, '${{ needs.extract_environment.outputs.environment }}']
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: print
|
- name: Printing stats
|
||||||
env:
|
env:
|
||||||
EVENT: ${{ github.event_name }}
|
EVENT: ${{ github.event_name }}
|
||||||
IMAGE_TAG: ${{ needs.semantic_release.outputs.test }}
|
IMAGE_TAG: ${{ needs.semantic_release.outputs.new_release_version }}
|
||||||
IMAGE_TAGG: ${{ needs.semantic_release.outputs.testT }}
|
ENV: ${{ needs.extract_environment.outputs.environment }}
|
||||||
run: echo ${IMAGE_TAG} ${IMAGE_TAGG} ${EVENT}
|
run: echo ${GITHUB_REF#refs/heads/}
|
||||||
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
@@ -135,7 +134,7 @@ jobs:
|
|||||||
eb deploy
|
eb deploy
|
||||||
|
|
||||||
- name: Remove Docker's Trash
|
- name: Remove Docker's Trash
|
||||||
continue-on-error: true
|
if: always()
|
||||||
run: |
|
run: |
|
||||||
docker system prune
|
docker system prune --volumes -a -f
|
||||||
docker rmi -f $(docker images -aq)
|
docker system df
|
||||||
|
|||||||
+2
-1
@@ -1,7 +1,8 @@
|
|||||||
FROM node:14.15.4-alpine3.12 as packages
|
FROM node:18.3.0-alpine3.15 as packages
|
||||||
WORKDIR /packages
|
WORKDIR /packages
|
||||||
ARG NPM_TOKEN
|
ARG NPM_TOKEN
|
||||||
COPY package.json .
|
COPY package.json .
|
||||||
|
COPY package-lock.json .
|
||||||
COPY .npmrc .
|
COPY .npmrc .
|
||||||
RUN npm install
|
RUN npm install
|
||||||
RUN rm -f ./.npmrc
|
RUN rm -f ./.npmrc
|
||||||
|
|||||||
@@ -1,4 +1,50 @@
|
|||||||
|
# Maestro
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<image src="./assets/maestro.svg" style="width:10rem">
|
<image src="./assets/maestro.svg" style="width:10rem">
|
||||||
<h1 align="center">Maestro</h1>
|
<h1 align="center">Maestro</h1>
|
||||||
</p>
|
</p>
|
||||||
|
This is the Dadosfera´s gateway repository, it´s responsable for the communication between frontend application and Dadosfera´s mirosservices.
|
||||||
|
|
||||||
|
## 💻 Requirements
|
||||||
|
|
||||||
|
Before you start, make sure you have done the following steps:
|
||||||
|
|
||||||
|
* Installed Nodejs version 16.14.2
|
||||||
|
* Installed latest NPM version
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## 🚀 Installing Maestro
|
||||||
|
|
||||||
|
First of all clone the repository:
|
||||||
|
* SSH:
|
||||||
|
```
|
||||||
|
git clone git@github.com:dadosfera/maestro.git
|
||||||
|
```
|
||||||
|
* HTTPS:
|
||||||
|
```
|
||||||
|
git clone git@github.com:dadosfera/maestro.git
|
||||||
|
```
|
||||||
|
|
||||||
|
## Enviroment variables
|
||||||
|
|
||||||
|
Here is a list of enviroment variables needed in order to run the application correctly.
|
||||||
|
|
||||||
|
```
|
||||||
|
ENV=
|
||||||
|
DUC_URL=
|
||||||
|
INFACTORY_URL=
|
||||||
|
TRFACTORY_URL=
|
||||||
|
OTFACTORY_URL=
|
||||||
|
PIFACTORY_URL=
|
||||||
|
JWT_PRIVATE_KEY=
|
||||||
|
AWS_IDENTITY_POOL_ID=
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running Maestro
|
||||||
|
|
||||||
|
In order to run Maestro just run the following command:
|
||||||
|
```
|
||||||
|
npm run start:dev
|
||||||
|
```
|
||||||
|
If everything is fine the Maestro will start and be ready to receive HTTP requests
|
||||||
Generated
+1439
-1478
File diff suppressed because it is too large
Load Diff
+9
-1
@@ -5,6 +5,9 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"private": true,
|
"private": true,
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
|
"engines": {
|
||||||
|
"node": "18.3.0"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prebuild": "rimraf dist",
|
"prebuild": "rimraf dist",
|
||||||
"build": "nest build",
|
"build": "nest build",
|
||||||
@@ -31,8 +34,9 @@
|
|||||||
"@nestjs/platform-express": "^8.4.3",
|
"@nestjs/platform-express": "^8.4.3",
|
||||||
"@nestjs/schedule": "^1.1.0",
|
"@nestjs/schedule": "^1.1.0",
|
||||||
"@nestjs/swagger": "^5.2.1",
|
"@nestjs/swagger": "^5.2.1",
|
||||||
"@victorradael/protospack": "2.3.0",
|
"@victorradael/protospack": "2.5.0",
|
||||||
"axios": "^0.25.0",
|
"axios": "^0.25.0",
|
||||||
|
"cron-parser": "^4.4.0",
|
||||||
"dotenv": "^14.2.0",
|
"dotenv": "^14.2.0",
|
||||||
"helmet": "^5.0.2",
|
"helmet": "^5.0.2",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
@@ -42,6 +46,9 @@
|
|||||||
"rxjs": "^7.5.5",
|
"rxjs": "^7.5.5",
|
||||||
"swagger-ui-express": "^4.3.0"
|
"swagger-ui-express": "^4.3.0"
|
||||||
},
|
},
|
||||||
|
"overrides": {
|
||||||
|
"multer": "1.4.5-lts.1"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nestjs/cli": "^8.2.4",
|
"@nestjs/cli": "^8.2.4",
|
||||||
"@nestjs/schematics": "^8.0.8",
|
"@nestjs/schematics": "^8.0.8",
|
||||||
@@ -58,6 +65,7 @@
|
|||||||
"eslint-config-prettier": "^8.5.0",
|
"eslint-config-prettier": "^8.5.0",
|
||||||
"eslint-plugin-prettier": "^4.0.0",
|
"eslint-plugin-prettier": "^4.0.0",
|
||||||
"jest": "^27.5.1",
|
"jest": "^27.5.1",
|
||||||
|
"nock": "^13.2.4",
|
||||||
"prettier": "^2.6.1",
|
"prettier": "^2.6.1",
|
||||||
"source-map-support": "^0.5.20",
|
"source-map-support": "^0.5.20",
|
||||||
"supertest": "^6.1.3",
|
"supertest": "^6.1.3",
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ import {
|
|||||||
AuthDisableTotpMfaRequest,
|
AuthDisableTotpMfaRequest,
|
||||||
AuthDismissTotpMfaRequest,
|
AuthDismissTotpMfaRequest,
|
||||||
AuthVerifyTotpMfaRequest,
|
AuthVerifyTotpMfaRequest,
|
||||||
|
AuthChangePasswordRequest,
|
||||||
|
AuthResetPasswordRequest,
|
||||||
|
AuthVerifyResetPasswordCodeRequest,
|
||||||
|
AuthConfirmResetPasswordRequest,
|
||||||
} from '@victorradael/protospack';
|
} from '@victorradael/protospack';
|
||||||
|
|
||||||
export class AuthClientService implements OnModuleInit {
|
export class AuthClientService implements OnModuleInit {
|
||||||
@@ -32,11 +36,7 @@ export class AuthClientService implements OnModuleInit {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.authService.signIn({ username, password, totp }).subscribe({
|
this.authService.signIn({ username, password, totp }).subscribe({
|
||||||
next: resolve,
|
next: resolve,
|
||||||
//error: (err) => reject(err.details),
|
error: (err) => reject(err.details),
|
||||||
error: (err) => {
|
|
||||||
console.log(err);
|
|
||||||
reject(err.details);
|
|
||||||
},
|
|
||||||
complete() {
|
complete() {
|
||||||
console.log('done');
|
console.log('done');
|
||||||
},
|
},
|
||||||
@@ -167,14 +167,86 @@ export class AuthClientService implements OnModuleInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async refreshAccessToken({
|
async refreshAccessToken({
|
||||||
username,
|
|
||||||
refreshToken,
|
refreshToken,
|
||||||
}: AuthRefreshAccessTokenRequest): Promise<any> {
|
}: AuthRefreshAccessTokenRequest): Promise<any> {
|
||||||
console.log('AuthClientService', 'RefreshAccessToken');
|
console.log('AuthClientService', 'RefreshAccessToken');
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.authService.refreshAccessToken({ refreshToken }).subscribe({
|
||||||
|
next: resolve,
|
||||||
|
error: (err) => reject(err.details),
|
||||||
|
complete() {
|
||||||
|
console.log('done');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async changePassword({
|
||||||
|
accessToken,
|
||||||
|
oldPassword,
|
||||||
|
newPassword,
|
||||||
|
}: AuthChangePasswordRequest): Promise<any> {
|
||||||
|
console.log('AuthClientService', 'ChangePassword');
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.authService
|
this.authService
|
||||||
.refreshAccessToken({ username, refreshToken })
|
.changePassword({
|
||||||
|
accessToken,
|
||||||
|
oldPassword,
|
||||||
|
newPassword,
|
||||||
|
})
|
||||||
|
.subscribe({
|
||||||
|
next: resolve,
|
||||||
|
error: (err) => reject(err.details),
|
||||||
|
complete() {
|
||||||
|
console.log('done');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async resetPassword({ username }: AuthResetPasswordRequest): Promise<any> {
|
||||||
|
console.log('AuthClientService', 'resetPassword');
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.authService.resetPassword({ username }).subscribe({
|
||||||
|
next: resolve,
|
||||||
|
error: (err) => reject(err.details),
|
||||||
|
complete() {
|
||||||
|
console.log('done');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async verifyResetPasswordCode({
|
||||||
|
username,
|
||||||
|
code,
|
||||||
|
}: AuthVerifyResetPasswordCodeRequest): Promise<any> {
|
||||||
|
console.log('AuthClientService', 'verifyResetPasswordCode');
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.authService.verifyResetPasswordCode({ username, code }).subscribe({
|
||||||
|
next: resolve,
|
||||||
|
error: (err) => reject(err.details),
|
||||||
|
complete() {
|
||||||
|
console.log('done');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async confirmResetPassword({
|
||||||
|
username,
|
||||||
|
code,
|
||||||
|
newPassword,
|
||||||
|
}: AuthConfirmResetPasswordRequest): Promise<any> {
|
||||||
|
console.log('AuthClientService', 'confirmResetPassword');
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.authService
|
||||||
|
.confirmResetPassword({ username, code, newPassword })
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: resolve,
|
next: resolve,
|
||||||
error: (err) => reject(err.details),
|
error: (err) => reject(err.details),
|
||||||
|
|||||||
@@ -1,17 +1,27 @@
|
|||||||
import { OnModuleInit, Inject } from '@nestjs/common';
|
import {
|
||||||
|
OnModuleInit,
|
||||||
|
Inject,
|
||||||
|
HttpException,
|
||||||
|
HttpStatus,
|
||||||
|
} from '@nestjs/common';
|
||||||
import { ClientGrpc } from '@nestjs/microservices';
|
import { ClientGrpc } from '@nestjs/microservices';
|
||||||
import {
|
import {
|
||||||
InputCreateResponse,
|
DecodeGrpcStruct,
|
||||||
|
EncodeJsonToGrpcStruct,
|
||||||
InputCreateS3Request,
|
InputCreateS3Request,
|
||||||
InputNewCreateRequest,
|
InputNewCreateRequest,
|
||||||
InputService,
|
InputService,
|
||||||
TestConnectionGetColumnsRequest,
|
TestConnectionGetColumnsRequest,
|
||||||
TestConnectionRequest,
|
TestConnectionRequest,
|
||||||
} from '@victorradael/protospack';
|
} from '@victorradael/protospack';
|
||||||
|
import axios from 'axios';
|
||||||
|
import { lastValueFrom } from 'rxjs';
|
||||||
|
import { InputModel } from 'src/modules/inputs/dtos/input.model';
|
||||||
import {
|
import {
|
||||||
objectCamelToSnake,
|
objectCamelToSnake,
|
||||||
objectSnakeToCamel,
|
objectSnakeToCamel,
|
||||||
} from 'src/utils/CaseConverter';
|
} from 'src/utils/CaseConverter';
|
||||||
|
import { mustache } from 'src/utils/mustache';
|
||||||
import { IIdRequest, UpdateInputRequest } from './interfaces';
|
import { IIdRequest, UpdateInputRequest } from './interfaces';
|
||||||
|
|
||||||
export class InputsClientService implements OnModuleInit {
|
export class InputsClientService implements OnModuleInit {
|
||||||
@@ -25,102 +35,68 @@ export class InputsClientService implements OnModuleInit {
|
|||||||
this.grpcClient.getService<InputService>('InputService');
|
this.grpcClient.getService<InputService>('InputService');
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(createInputDto: InputNewCreateRequest) {
|
async newCreate(createInputDto: InputNewCreateRequest) {
|
||||||
console.log('InputClientService', 'Create');
|
console.log('InputClientService', 'Create');
|
||||||
|
|
||||||
const createInputResponse = await new Promise((resolve, reject) => {
|
const input = await lastValueFrom(
|
||||||
this.inputService
|
this.inputService.NewCreate(objectSnakeToCamel(createInputDto)),
|
||||||
.NewCreate(objectSnakeToCamel(createInputDto))
|
);
|
||||||
.subscribe({
|
objectCamelToSnake(input);
|
||||||
next(x) {
|
return input;
|
||||||
resolve(objectCamelToSnake(x));
|
}
|
||||||
},
|
|
||||||
error(err) {
|
|
||||||
console.log('Observable Error');
|
|
||||||
reject(err);
|
|
||||||
},
|
|
||||||
complete() {
|
|
||||||
console.log('done');
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}).catch((err) => {
|
|
||||||
throw new Error(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
return createInputResponse;
|
async createGeneric(createInputGeneric) {
|
||||||
|
console.log('InputClientService', 'Create');
|
||||||
|
const { info, ...data } = createInputGeneric;
|
||||||
|
data.credentials = await this.getInputTokens(data);
|
||||||
|
if (data.options) delete data.options;
|
||||||
|
if (data.credentials.oauth_code) delete data.credentials.oauth_code;
|
||||||
|
const grpcPayload = {
|
||||||
|
input: EncodeJsonToGrpcStruct(data),
|
||||||
|
info,
|
||||||
|
};
|
||||||
|
objectSnakeToCamel(grpcPayload);
|
||||||
|
|
||||||
|
const structReturn = await lastValueFrom(
|
||||||
|
this.inputService.Create(grpcPayload),
|
||||||
|
);
|
||||||
|
objectCamelToSnake(structReturn);
|
||||||
|
const inputCreated = DecodeGrpcStruct(structReturn.input);
|
||||||
|
return { input: inputCreated };
|
||||||
}
|
}
|
||||||
|
|
||||||
async createS3Inputs(createInputDto: InputCreateS3Request) {
|
async createS3Inputs(createInputDto: InputCreateS3Request) {
|
||||||
console.log('InputClientService', 'Create');
|
console.log('InputClientService', 'Create');
|
||||||
|
objectSnakeToCamel(createInputDto);
|
||||||
const createInputResponse = await new Promise((resolve, reject) => {
|
const createInputResponse = await lastValueFrom(
|
||||||
this.inputService.CreateS3(objectSnakeToCamel(createInputDto)).subscribe({
|
this.inputService.CreateS3(createInputDto),
|
||||||
next(x) {
|
).catch((e) => {
|
||||||
resolve(objectCamelToSnake(x));
|
throw new HttpException(e.details, 500);
|
||||||
},
|
});
|
||||||
error(err) {
|
console.log('done');
|
||||||
console.log('Observable Error');
|
objectCamelToSnake(createInputResponse);
|
||||||
reject(err);
|
|
||||||
},
|
|
||||||
complete() {
|
|
||||||
console.log('done');
|
|
||||||
},
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then((res) => res)
|
|
||||||
.catch((err) => {
|
|
||||||
throw new Error(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
return createInputResponse;
|
return createInputResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOne(data: IIdRequest) {
|
async findOne(data: IIdRequest) {
|
||||||
console.log('InputClientService', 'FindOne');
|
console.log('InputClientService', 'FindOne');
|
||||||
|
const findOneInputResponse = await lastValueFrom(
|
||||||
const findOneInputResponse = await new Promise((resolve, reject) => {
|
this.inputService.FindOne(objectSnakeToCamel(data)),
|
||||||
this.inputService.FindOne(objectSnakeToCamel(data)).subscribe({
|
).catch((e) => {
|
||||||
next(x) {
|
throw new HttpException(e.details, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
resolve(objectCamelToSnake(x));
|
});
|
||||||
},
|
objectCamelToSnake(findOneInputResponse);
|
||||||
error(err) {
|
|
||||||
console.log('Observable Error');
|
|
||||||
reject(err);
|
|
||||||
},
|
|
||||||
complete() {
|
|
||||||
console.log('done');
|
|
||||||
},
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then((res) => res)
|
|
||||||
.catch((err) => {
|
|
||||||
throw new Error(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
return findOneInputResponse;
|
return findOneInputResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(data) {
|
async findAll(data) {
|
||||||
console.log('InputClientService', 'FindAll');
|
console.log('InputClientService', 'FindAll');
|
||||||
|
const findAllInputResponse = await lastValueFrom(
|
||||||
const findAllInputResponse = await new Promise((resolve, reject) => {
|
this.inputService.FindAll(objectSnakeToCamel(data)),
|
||||||
this.inputService.FindAll(objectSnakeToCamel(data)).subscribe({
|
).catch((e) => {
|
||||||
next(x) {
|
throw new HttpException(e.details, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
resolve(objectCamelToSnake(x));
|
});
|
||||||
},
|
findAllInputResponse.inputs.forEach((input) => objectCamelToSnake(input));
|
||||||
error(err) {
|
|
||||||
console.log('Observable Error');
|
|
||||||
reject(err);
|
|
||||||
},
|
|
||||||
complete() {
|
|
||||||
console.log('done');
|
|
||||||
},
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then((res) => res)
|
|
||||||
.catch((err) => {
|
|
||||||
throw new Error(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
return findAllInputResponse;
|
return findAllInputResponse;
|
||||||
}
|
}
|
||||||
@@ -221,4 +197,82 @@ export class InputsClientService implements OnModuleInit {
|
|||||||
|
|
||||||
return getColumnsResponse;
|
return getColumnsResponse;
|
||||||
}
|
}
|
||||||
|
async getAuthSecrets(plugin) {
|
||||||
|
switch (plugin) {
|
||||||
|
case 'hubspot':
|
||||||
|
return {
|
||||||
|
client_id: process.env.HUBSPOT_CLIENT_ID || '',
|
||||||
|
client_secret: process.env.HUBSPOT_CLIENT_SECRET || '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
async getInputTokens(input: InputModel) {
|
||||||
|
const { credentials, options } = input;
|
||||||
|
const credentialsTokens: any = {};
|
||||||
|
switch (credentials.connection_type) {
|
||||||
|
case 'oauth':
|
||||||
|
const { oauth } = options;
|
||||||
|
const { get_tokens_url_params, get_tokens_set_response } = oauth;
|
||||||
|
const secrets = await this.getAuthSecrets(input.plugin);
|
||||||
|
if (oauth.content_type === 'application/x-www-form-urlencoded') {
|
||||||
|
const requestParams = new URLSearchParams();
|
||||||
|
const get_tokens_url_params_string = mustache(get_tokens_url_params, {
|
||||||
|
...secrets,
|
||||||
|
...credentials,
|
||||||
|
});
|
||||||
|
let get_tokens_url_params_obj: Record<string, any> = {};
|
||||||
|
try {
|
||||||
|
get_tokens_url_params_obj = JSON.parse(
|
||||||
|
get_tokens_url_params_string,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
throw new HttpException(
|
||||||
|
'Erro transformando get_tokens_url_params',
|
||||||
|
400,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const { redirect_uri } = get_tokens_url_params_obj;
|
||||||
|
for (const key in get_tokens_url_params_obj) {
|
||||||
|
const value = get_tokens_url_params_obj[key];
|
||||||
|
requestParams.append(key, value);
|
||||||
|
}
|
||||||
|
const { data } = await axios
|
||||||
|
.post(options.oauth.get_tokens_url, requestParams)
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err.response.data);
|
||||||
|
throw new HttpException(
|
||||||
|
err.response.data.message,
|
||||||
|
err.response.status,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
for (const key in get_tokens_set_response) {
|
||||||
|
const responseKey = get_tokens_set_response[key];
|
||||||
|
credentialsTokens[key] = data[responseKey];
|
||||||
|
}
|
||||||
|
credentialsTokens.redirect_uri = redirect_uri;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return { ...credentials, ...credentialsTokens };
|
||||||
|
}
|
||||||
|
// getOauthTokens(input){
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
async getAvailableEntities(data) {
|
||||||
|
console.log('InputClientService', 'GetAvailableEntities');
|
||||||
|
objectSnakeToCamel(data);
|
||||||
|
const response = await lastValueFrom(
|
||||||
|
this.inputService.GetAvailableEntities(data),
|
||||||
|
).catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
if (err.details && err.details.includes('400'))
|
||||||
|
throw new HttpException('Plugin inválido', HttpStatus.BAD_REQUEST);
|
||||||
|
throw new HttpException(err.details, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
|
});
|
||||||
|
objectCamelToSnake(response);
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Inject, OnModuleInit } from '@nestjs/common';
|
import { HttpException, Inject, OnModuleInit } from '@nestjs/common';
|
||||||
import { ClientGrpc, Payload } from '@nestjs/microservices';
|
import { ClientGrpc, Payload } from '@nestjs/microservices';
|
||||||
import {
|
import {
|
||||||
PipelineServicesNames,
|
PipelineServicesNames,
|
||||||
@@ -49,7 +49,10 @@ export class PipelinesClientService implements OnModuleInit {
|
|||||||
})
|
})
|
||||||
.then((res) => res)
|
.then((res) => res)
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
throw new Error(err);
|
if (err.details == 'Invalid Request') {
|
||||||
|
throw new HttpException(err.details, 400);
|
||||||
|
}
|
||||||
|
throw new HttpException(err.details, 500);
|
||||||
});
|
});
|
||||||
|
|
||||||
return createPipelineResponse;
|
return createPipelineResponse;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import jwkToPem from 'jwk-to-pem';
|
import jwkToPem from 'jwk-to-pem';
|
||||||
import { decode, verify } from 'jsonwebtoken';
|
import { decode, verify } from 'jsonwebtoken';
|
||||||
import { HttpExceptionFilter } from 'src/error/http-exception.filter';
|
import { HttpExceptionFilter } from '../error/http-exception.filter';
|
||||||
|
|
||||||
@UseFilters(new HttpExceptionFilter())
|
@UseFilters(new HttpExceptionFilter())
|
||||||
export class LoggerMiddleware implements NestMiddleware {
|
export class LoggerMiddleware implements NestMiddleware {
|
||||||
@@ -32,9 +32,10 @@ export class LoggerMiddleware implements NestMiddleware {
|
|||||||
|
|
||||||
const permissions = jwtDecoded.user.permissions;
|
const permissions = jwtDecoded.user.permissions;
|
||||||
|
|
||||||
const clienId = jwtDecoded.user.customerId;
|
const clientId = jwtDecoded.user.customerId;
|
||||||
const customer = jwtDecoded.user.customer;
|
const customer = jwtDecoded.user.customer;
|
||||||
const userId = jwtDecoded.user.id;
|
const userId = jwtDecoded.user.id;
|
||||||
|
const customer_tier = jwtDecoded.user.customer_tier;
|
||||||
|
|
||||||
await verifyToken(accessToken);
|
await verifyToken(accessToken);
|
||||||
|
|
||||||
@@ -55,11 +56,11 @@ export class LoggerMiddleware implements NestMiddleware {
|
|||||||
|
|
||||||
if (havePermission) {
|
if (havePermission) {
|
||||||
request.body.info = {
|
request.body.info = {
|
||||||
customer_id: clienId,
|
customer_id: clientId,
|
||||||
user_id: userId,
|
user_id: userId,
|
||||||
customer,
|
customer,
|
||||||
|
customer_tier,
|
||||||
};
|
};
|
||||||
|
|
||||||
next();
|
next();
|
||||||
} else {
|
} else {
|
||||||
throw new ForbiddenException();
|
throw new ForbiddenException();
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import {
|
|||||||
Post,
|
Post,
|
||||||
HttpCode,
|
HttpCode,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
UnauthorizedException,
|
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import {
|
import {
|
||||||
AuthSignInRequest,
|
AuthSignInRequest,
|
||||||
@@ -13,6 +12,10 @@ import {
|
|||||||
AuthEnableTotpMfaRequest,
|
AuthEnableTotpMfaRequest,
|
||||||
AuthDisableTotpMfaRequest,
|
AuthDisableTotpMfaRequest,
|
||||||
AuthVerifyTotpMfaRequest,
|
AuthVerifyTotpMfaRequest,
|
||||||
|
AuthChangePasswordRequest,
|
||||||
|
AuthResetPasswordRequest,
|
||||||
|
AuthVerifyResetPasswordCodeRequest,
|
||||||
|
AuthConfirmResetPasswordRequest,
|
||||||
} from '@victorradael/protospack';
|
} from '@victorradael/protospack';
|
||||||
|
|
||||||
import { AuthClientService } from 'src/clients/auth/client.service';
|
import { AuthClientService } from 'src/clients/auth/client.service';
|
||||||
@@ -57,12 +60,12 @@ export class AuthController {
|
|||||||
@Post('refresh-access-token')
|
@Post('refresh-access-token')
|
||||||
@HttpCode(HttpStatus.OK)
|
@HttpCode(HttpStatus.OK)
|
||||||
async refreshAccessToken(
|
async refreshAccessToken(
|
||||||
@Body() { username, refreshToken }: AuthRefreshAccessTokenRequest,
|
@Body() { refreshToken }: AuthRefreshAccessTokenRequest,
|
||||||
) {
|
) {
|
||||||
console.log(`/auth`, 'RefreshAccessToken');
|
console.log(`/auth`, 'RefreshAccessToken');
|
||||||
|
|
||||||
const accessToken = await this.authClient
|
const accessToken = await this.authClient
|
||||||
.refreshAccessToken({ username, refreshToken })
|
.refreshAccessToken({ refreshToken })
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
throw ErrorBuilder(err);
|
throw ErrorBuilder(err);
|
||||||
});
|
});
|
||||||
@@ -145,4 +148,80 @@ export class AuthController {
|
|||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post('change-password')
|
||||||
|
@HttpCode(HttpStatus.OK)
|
||||||
|
async changePassword(
|
||||||
|
@Body() body: AuthChangePasswordRequest,
|
||||||
|
@Headers() headers,
|
||||||
|
): Promise<any> {
|
||||||
|
console.log(`/auth`, 'change-password');
|
||||||
|
|
||||||
|
const { oldPassword, newPassword } = body;
|
||||||
|
const { authorization: accessToken } = headers;
|
||||||
|
|
||||||
|
const response = await this.authClient
|
||||||
|
.changePassword({
|
||||||
|
accessToken,
|
||||||
|
oldPassword,
|
||||||
|
newPassword,
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
throw ErrorBuilder(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('reset-password')
|
||||||
|
@HttpCode(HttpStatus.OK)
|
||||||
|
async resetPassword(@Body() body: AuthResetPasswordRequest): Promise<any> {
|
||||||
|
console.log(`/auth`, 'reset-password');
|
||||||
|
|
||||||
|
const { username } = body;
|
||||||
|
|
||||||
|
const response = await this.authClient
|
||||||
|
.resetPassword({ username })
|
||||||
|
.catch((err) => {
|
||||||
|
throw ErrorBuilder(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('verify-reset-password-code')
|
||||||
|
@HttpCode(HttpStatus.OK)
|
||||||
|
async verifyResetPasswordCode(
|
||||||
|
@Body() body: AuthVerifyResetPasswordCodeRequest,
|
||||||
|
): Promise<any> {
|
||||||
|
console.log(`/auth`, 'verify-reset-password-code');
|
||||||
|
|
||||||
|
const { username, code } = body;
|
||||||
|
|
||||||
|
const response = await this.authClient
|
||||||
|
.verifyResetPasswordCode({ username, code })
|
||||||
|
.catch((err) => {
|
||||||
|
throw ErrorBuilder(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('confirm-reset-password')
|
||||||
|
@HttpCode(HttpStatus.OK)
|
||||||
|
async confirmResetPassword(
|
||||||
|
@Body() body: AuthConfirmResetPasswordRequest,
|
||||||
|
): Promise<any> {
|
||||||
|
console.log(`/auth`, 'confirm-reset-password');
|
||||||
|
|
||||||
|
const { username, code, newPassword } = body;
|
||||||
|
|
||||||
|
const response = await this.authClient
|
||||||
|
.confirmResetPassword({ username, code, newPassword })
|
||||||
|
.catch((err) => {
|
||||||
|
throw ErrorBuilder(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,152 @@
|
|||||||
|
import nock from 'nock';
|
||||||
|
import { LoggerMiddleware } from '../../middlewares/authentication';
|
||||||
|
import { NextFunction, Request, Response } from 'express';
|
||||||
|
import { ConsoleLogger, UnauthorizedException } from '@nestjs/common';
|
||||||
|
|
||||||
describe('PipelinesGrpcServerService', () => {
|
describe('PipelinesGrpcServerService', () => {
|
||||||
|
// let mockRequest: Partial<Request>;
|
||||||
|
// let mockResponse: Partial<Response>;
|
||||||
|
// const nextFunction: NextFunction = jest.fn();
|
||||||
|
|
||||||
|
// beforeEach(() => {
|
||||||
|
// mockRequest = {
|
||||||
|
// headers: {},
|
||||||
|
// body: {
|
||||||
|
// info: {},
|
||||||
|
// },
|
||||||
|
// };
|
||||||
|
// mockResponse = {
|
||||||
|
// json: jest.fn(),
|
||||||
|
// };
|
||||||
|
// });
|
||||||
|
|
||||||
it('should be defined', () => {
|
it('should be defined', () => {
|
||||||
expect(2 + 2).toBe(4);
|
expect(2 + 2).toBe(4);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// it('Should be able to pass auth', async () => {
|
||||||
|
// const awsRegion = process.env.AWS_REGION;
|
||||||
|
// const awsPoolId = process.env.AWS_IDENTITY_POOL_ID;
|
||||||
|
// const cognitoRes = {
|
||||||
|
// keys: [
|
||||||
|
// {
|
||||||
|
// alg: 'RS256',
|
||||||
|
// e: 'AQAB',
|
||||||
|
// kid: 'z3VA3+i9JZY3JFDJTNWOap8RY+B7C6mFedaqCuvLvqA=',
|
||||||
|
// kty: 'RSA',
|
||||||
|
// n: 'vIGCQDkPA_eQUoaGDUsCyK_Whr76mNW0kZ1uac6ZnyY6hsjUIjvwehqv-ux3cQo4rQZQVFcoh8n9cK5jguz4GVdD972vIxoEdyv32nBFVr5e1PBunKJ2Y32GTR_Hl0XiE0hRe1v6cWuTqiC4qm1NY7tXYL3mI9L6s9ztNbhmG_V44y26PdhL4vRVrJaHOAmCs-77U-QYAC7Llkpmjh-8tG1zt9_FJ237cpBUVOuhD-7Nm32_eB9wddBGfBw0F10ko_KJoU-7683_Kv8k9coJzFUSONId-bfnLOzs8j1L6ZAHipXCR7rpmuRYzXztjp4Wmm2zPUToWLdMEy0Hq1OWmw',
|
||||||
|
// use: 'sig',
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// alg: 'RS256',
|
||||||
|
// e: 'AQAB',
|
||||||
|
// kid: 'u+1W9pi+clp8LaPhZVrv4dXMqRkTRD02YWhbm0NvsUw=',
|
||||||
|
// kty: 'RSA',
|
||||||
|
// n: 'noGq1cRMAKJPWahqfC_zWasYovSUycaS1basMfEoh3ePLc9zRgmyfiVKYzLRosHMe1uk0Y5ekCBKnWA8Yl7I84Yt7IIIaE44oJjSEGBKT3m8i8YaXzawaNs63KPkRh8553o3KzL75bQWcI_ABKqkf-uAKSCl_XotBGkzLUl4hIOYtAtRGEfKaNMPqyTCT5Zn71pMd0isppaUiTW2T5QLsZV1IBp46aSrl_D5Q_FTsJT7feobQVoHp2zfIorCpkfTXBTBMQTEBFSDyPbc6cULl48VKxp0B0GEwR_kYCEHEVzf41LQcUWZUE0OdBychijkSc9MZJnBWUYQZyedJILWnQ',
|
||||||
|
// use: 'sig',
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// };
|
||||||
|
|
||||||
|
// nock(
|
||||||
|
// `https://cognito-idp.${awsRegion}.amazonaws.com/${awsPoolId}/.well-known/jwks.json`,
|
||||||
|
// )
|
||||||
|
// .persist()
|
||||||
|
// .get('')
|
||||||
|
// .reply(200, cognitoRes);
|
||||||
|
|
||||||
|
// mockRequest.headers['Dadosfera-User'] =
|
||||||
|
// 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiZTljYjI1ZGEtMTQyOC00NDJjLTg5NjItYTdkNmQxNjhkODUyIiwibmFtZSI6InJvZHJpZ28uemFtYm9uaSIsInVzZXJuYW1lIjoicm9kcmlnby56YW1ib25pQGRhZG9zZmVyYS5haSIsInJ1bGVJZCI6IjIxNzdmZjg4LThmY2ItNDRlNS1hYzYxLWNjYmU2Y2M3MGU4ZCIsImN1c3RvbWVySWQiOiIxMTI5ODBhMy0wYTEyLTQxYzktYmZmZC03OTFjZjdjYTg3YTIiLCJtZmFTdGF0dXMiOiJwZW5kaW5nIiwiY3JlYXRlZEF0IjoiMjAyMi0wNS0xM1QxNTowOTowOS4xMzhaIiwidXBkYXRlZEF0IjoiMjAyMi0wNS0xM1QxNTowOTowOS4xMzhaIiwicGVybWlzc2lvbnMiOlsiUE9TVCAvcGlwZWxpbmVzIiwiR0VUIC9waXBlbGluZXMiLCJQVVQgL3BpcGVsaW5lcyIsIkRFTEVURSAvcGlwZWxpbmVzIiwiUE9TVCAvaW5wdXRzIiwiR0VUIC9pbnB1dHMiLCJQVVQgL2lucHV0cyIsIkRFTEVURSAvaW5wdXRzIiwiUE9TVCAvb3V0cHV0cyIsIkdFVCAvb3V0cHV0cyIsIlBVVCAvb3V0cHV0cyIsIkRFTEVURSAvb3V0cHV0cyIsIlBPU1QgL3RyYW5zZm9ybWF0aW9ucyIsIkdFVCAvdHJhbnNmb3JtYXRpb25zIiwiUFVUIC90cmFuc2Zvcm1hdGlvbnMiLCJERUxFVEUgL3RyYW5zZm9ybWF0aW9ucyIsIlBPU1QgL2NhdGFsb2ciLCJHRVQgL2NhdGFsb2ciLCJQVVQgL2NhdGFsb2ciLCJERUxFVEUgL2NhdGFsb2ciLCJQT1NUIC9hdXRoIiwiR0VUIC9tZXRhYmFzZSIsIkdFVCAvc25vd2ZsYWtlIl0sImN1c3RvbWVyIjoiZGFkb3NmZXJhIn0sImlhdCI6MTY1MzY1NjE2NywiZXhwIjoxNjUzNzQyNTY3fQ.eeNEEUk_95KOxM-objS7gXz-SCVkNFYpEP688MfLkdI';
|
||||||
|
// mockRequest.headers['Authorization'] =
|
||||||
|
// 'eyJraWQiOiJ1KzFXOXBpK2NscDhMYVBoWlZydjRkWE1xUmtUUkQwMllXaGJtME52c1V3PSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiIxYjkyZmFkMC1iNWVlLTQwMzAtOGRmYy1hZWM0MGQzYzdkYmUiLCJpc3MiOiJodHRwczpcL1wvY29nbml0by1pZHAudXMtZWFzdC0xLmFtYXpvbmF3cy5jb21cL3VzLWVhc3QtMV9OVXY3WTJTeGoiLCJjbGllbnRfaWQiOiI0N3RrY3Jxc2NuajY3bWhnYmg3dXQ1YnJzNCIsIm9yaWdpbl9qdGkiOiJhZWJjNjA5NC1hYTJmLTRiZmUtOWExZi01ZWVhYTVmYzAwNDAiLCJldmVudF9pZCI6IjBhY2NjMzJiLTllNzktNGY2NS1iMDFiLWZhZGJlYzFhZWFiNiIsInRva2VuX3VzZSI6ImFjY2VzcyIsInNjb3BlIjoiYXdzLmNvZ25pdG8uc2lnbmluLnVzZXIuYWRtaW4iLCJhdXRoX3RpbWUiOjE2NTM2NTYxNjcsImV4cCI6MTY1MzY1Nzk2NywiaWF0IjoxNjUzNjU2MTY3LCJqdGkiOiIyYTgzNDhmOC0xNDhlLTQ3NjctODcxYi00M2UyOGRjNjc2NTkiLCJ1c2VybmFtZSI6InJvZHJpZ28uemFtYm9uaUBkYWRvc2ZlcmEuYWkifQ.UgIgeGEH2olNgqPly8cymNgWIZJz5n9N4yeKgTusfGsu5h-TWP_jVhPoCvFoixO2XKzFjSCvKwlKQYZyB74jLQLs-j5C5KGBdOea1HX7pUnEfEVtBINd1kcHib5YpGYq3MHG1uVx8vNJS3XviwgYg4rgNWA4du-QbhMicdRyHolYM-dWxuxtkwTRWMe1Vw6KlTctFsvUWx1GMgjp37tsLONcp3B8OsYXfiR764K_pBNs5gMhJ39gJ7NHHLWkJrtrUTpIoHWaZS_HEgvVyQiJENQvK_bPDMPm_lyF1dW-JBgot4TpAxMmvV1XGabkzycIcAOwUaPsKBlMphgunz1Ffw';
|
||||||
|
// mockRequest.method = 'GET';
|
||||||
|
// mockRequest.route = {
|
||||||
|
// path: '/inputs/',
|
||||||
|
// stack: [
|
||||||
|
// {
|
||||||
|
// method: 'get',
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// methods: {
|
||||||
|
// get: true,
|
||||||
|
// },
|
||||||
|
// };
|
||||||
|
// const authMiddleware = new LoggerMiddleware();
|
||||||
|
|
||||||
|
// await authMiddleware.useTest(
|
||||||
|
// mockRequest as Request,
|
||||||
|
// mockResponse as Response,
|
||||||
|
// nextFunction,
|
||||||
|
// );
|
||||||
|
// expect(nextFunction).toHaveBeenCalled();
|
||||||
|
// });
|
||||||
|
|
||||||
|
// it('Should not be able to pass auth', async () => {
|
||||||
|
// const awsRegion = process.env.AWS_REGION;
|
||||||
|
// const awsPoolId = process.env.AWS_IDENTITY_POOL_ID;
|
||||||
|
// const cognitoRes = {
|
||||||
|
// keys: [
|
||||||
|
// {
|
||||||
|
// alg: 'RS256',
|
||||||
|
// e: 'AQAB',
|
||||||
|
// kid: 'z3VA3+i9JZY3JFDJTNWOap8RY+B7C6mFedaqCuvLvqA=',
|
||||||
|
// kty: 'RSA',
|
||||||
|
// n: 'vIGCQDkPA_eQUoaGDUsCyK_Whr76mNW0kZ1uac6ZnyY6hsjUIjvwehqv-ux3cQo4rQZQVFcoh8n9cK5jguz4GVdD972vIxoEdyv32nBFVr5e1PBunKJ2Y32GTR_Hl0XiE0hRe1v6cWuTqiC4qm1NY7tXYL3mI9L6s9ztNbhmG_V44y26PdhL4vRVrJaHOAmCs-77U-QYAC7Llkpmjh-8tG1zt9_FJ237cpBUVOuhD-7Nm32_eB9wddBGfBw0F10ko_KJoU-7683_Kv8k9coJzFUSONId-bfnLOzs8j1L6ZAHipXCR7rpmuRYzXztjp4Wmm2zPUToWLdMEy0Hq1OWmw',
|
||||||
|
// use: 'sig',
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// alg: 'RS256',
|
||||||
|
// e: 'AQAB',
|
||||||
|
// kid: 'u+1W9pi+clp8LaPhZVrv4dXMqRkTRD02YWhbm0NvsUw=',
|
||||||
|
// kty: 'RSA',
|
||||||
|
// n: 'noGq1cRMAKJPWahqfC_zWasYovSUycaS1basMfEoh3ePLc9zRgmyfiVKYzLRosHMe1uk0Y5ekCBKnWA8Yl7I84Yt7IIIaE44oJjSEGBKT3m8i8YaXzawaNs63KPkRh8553o3KzL75bQWcI_ABKqkf-uAKSCl_XotBGkzLUl4hIOYtAtRGEfKaNMPqyTCT5Zn71pMd0isppaUiTW2T5QLsZV1IBp46aSrl_D5Q_FTsJT7feobQVoHp2zfIorCpkfTXBTBMQTEBFSDyPbc6cULl48VKxp0B0GEwR_kYCEHEVzf41LQcUWZUE0OdBychijkSc9MZJnBWUYQZyedJILWnQ',
|
||||||
|
// use: 'sig',
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// };
|
||||||
|
|
||||||
|
// nock(
|
||||||
|
// `https://cognito-idp.${awsRegion}.amazonaws.com/${awsPoolId}/.well-known/jwks.json`,
|
||||||
|
// )
|
||||||
|
// .persist()
|
||||||
|
// .get('')
|
||||||
|
// .reply(200, cognitoRes);
|
||||||
|
|
||||||
|
// mockRequest.headers['Dadosfera-User'] =
|
||||||
|
// 'asdeyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiZTljYjI1ZGEtMTQyOC00NDJjLTg5NjItYTdkNmQxNjhkODUyIiwibmFtZSI6InJvZHJpZ28uemFtYm9uaSIsInVzZXJuYW1lIjoicm9kcmlnby56YW1ib25pQGRhZG9zZmVyYS5haSIsInJ1bGVJZCI6IjIxNzdmZjg4LThmY2ItNDRlNS1hYzYxLWNjYmU2Y2M3MGU4ZCIsImN1c3RvbWVySWQiOiIxMTI5ODBhMy0wYTEyLTQxYzktYmZmZC03OTFjZjdjYTg3YTIiLCJtZmFTdGF0dXMiOiJwZW5kaW5nIiwiY3JlYXRlZEF0IjoiMjAyMi0wNS0xM1QxNTowOTowOS4xMzhaIiwidXBkYXRlZEF0IjoiMjAyMi0wNS0xM1QxNTowOTowOS4xMzhaIiwicGVybWlzc2lvbnMiOlsiUE9TVCAvcGlwZWxpbmVzIiwiR0VUIC9waXBlbGluZXMiLCJQVVQgL3BpcGVsaW5lcyIsIkRFTEVURSAvcGlwZWxpbmVzIiwiUE9TVCAvaW5wdXRzIiwiR0VUIC9pbnB1dHMiLCJQVVQgL2lucHV0cyIsIkRFTEVURSAvaW5wdXRzIiwiUE9TVCAvb3V0cHV0cyIsIkdFVCAvb3V0cHV0cyIsIlBVVCAvb3V0cHV0cyIsIkRFTEVURSAvb3V0cHV0cyIsIlBPU1QgL3RyYW5zZm9ybWF0aW9ucyIsIkdFVCAvdHJhbnNmb3JtYXRpb25zIiwiUFVUIC90cmFuc2Zvcm1hdGlvbnMiLCJERUxFVEUgL3RyYW5zZm9ybWF0aW9ucyIsIlBPU1QgL2NhdGFsb2ciLCJHRVQgL2NhdGFsb2ciLCJQVVQgL2NhdGFsb2ciLCJERUxFVEUgL2NhdGFsb2ciLCJQT1NUIC9hdXRoIiwiR0VUIC9tZXRhYmFzZSIsIkdFVCAvc25vd2ZsYWtlIl0sImN1c3RvbWVyIjoiZGFkb3NmZXJhIn0sImlhdCI6MTY1MzY1NjE2NywiZXhwIjoxNjUzNzQyNTY3fQ.eeNEEUk_95KOxM-objS7gXz-SCVkNFYpEP688MfLkdI';
|
||||||
|
// mockRequest.headers['Authorization'] =
|
||||||
|
// 'asdeyJraWQiOiJ1KzFXOXBpK2NscDhMYVBoWlZydjRkWE1xUmtUUkQwMllXaGJtME52c1V3PSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiIxYjkyZmFkMC1iNWVlLTQwMzAtOGRmYy1hZWM0MGQzYzdkYmUiLCJpc3MiOiJodHRwczpcL1wvY29nbml0by1pZHAudXMtZWFzdC0xLmFtYXpvbmF3cy5jb21cL3VzLWVhc3QtMV9OVXY3WTJTeGoiLCJjbGllbnRfaWQiOiI0N3RrY3Jxc2NuajY3bWhnYmg3dXQ1YnJzNCIsIm9yaWdpbl9qdGkiOiJhZWJjNjA5NC1hYTJmLTRiZmUtOWExZi01ZWVhYTVmYzAwNDAiLCJldmVudF9pZCI6IjBhY2NjMzJiLTllNzktNGY2NS1iMDFiLWZhZGJlYzFhZWFiNiIsInRva2VuX3VzZSI6ImFjY2VzcyIsInNjb3BlIjoiYXdzLmNvZ25pdG8uc2lnbmluLnVzZXIuYWRtaW4iLCJhdXRoX3RpbWUiOjE2NTM2NTYxNjcsImV4cCI6MTY1MzY1Nzk2NywiaWF0IjoxNjUzNjU2MTY3LCJqdGkiOiIyYTgzNDhmOC0xNDhlLTQ3NjctODcxYi00M2UyOGRjNjc2NTkiLCJ1c2VybmFtZSI6InJvZHJpZ28uemFtYm9uaUBkYWRvc2ZlcmEuYWkifQ.UgIgeGEH2olNgqPly8cymNgWIZJz5n9N4yeKgTusfGsu5h-TWP_jVhPoCvFoixO2XKzFjSCvKwlKQYZyB74jLQLs-j5C5KGBdOea1HX7pUnEfEVtBINd1kcHib5YpGYq3MHG1uVx8vNJS3XviwgYg4rgNWA4du-QbhMicdRyHolYM-dWxuxtkwTRWMe1Vw6KlTctFsvUWx1GMgjp37tsLONcp3B8OsYXfiR764K_pBNs5gMhJ39gJ7NHHLWkJrtrUTpIoHWaZS_HEgvVyQiJENQvK_bPDMPm_lyF1dW-JBgot4TpAxMmvV1XGabkzycIcAOwUaPsKBlMphgunz1Ffw';
|
||||||
|
// mockRequest.method = 'GET';
|
||||||
|
// mockRequest.route = {
|
||||||
|
// path: '/inputs/',
|
||||||
|
// stack: [
|
||||||
|
// {
|
||||||
|
// method: 'get',
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// methods: {
|
||||||
|
// get: true,
|
||||||
|
// },
|
||||||
|
// };
|
||||||
|
// const authMiddleware = new LoggerMiddleware();
|
||||||
|
|
||||||
|
// // const t = await authMiddleware.useTest(
|
||||||
|
// // mockRequest as Request,
|
||||||
|
// // mockResponse as Response,
|
||||||
|
// // nextFunction,
|
||||||
|
// // );
|
||||||
|
// // expect(nextFunction).toHaveBeenCalled();
|
||||||
|
|
||||||
|
// expect(async () => {
|
||||||
|
// const t = await authMiddleware.useTest(
|
||||||
|
// mockRequest as Request,
|
||||||
|
// mockResponse as Response,
|
||||||
|
// nextFunction,
|
||||||
|
// );
|
||||||
|
// console.log(t);
|
||||||
|
// }).toThrow('Unauthorized');
|
||||||
|
|
||||||
|
// expect(1).toBe(2);
|
||||||
|
// // expect(t).toThrow(UnauthorizedException);
|
||||||
|
// });
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,202 @@
|
|||||||
|
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
export class InputModel {
|
||||||
|
category: string;
|
||||||
|
plugin: string;
|
||||||
|
name: string;
|
||||||
|
cron?: string;
|
||||||
|
credentials?: {
|
||||||
|
connection_type: string;
|
||||||
|
oauth: string;
|
||||||
|
oauth_code: string;
|
||||||
|
start_date: string;
|
||||||
|
};
|
||||||
|
options?: {
|
||||||
|
oauth?: {
|
||||||
|
get_tokens_url: string;
|
||||||
|
get_tokens_url_params: string;
|
||||||
|
get_tokens_set_response: Record<string, string>;
|
||||||
|
content_type: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
class GoogleAnalyticsClientSecrets {
|
||||||
|
@ApiProperty()
|
||||||
|
type: string;
|
||||||
|
@ApiProperty()
|
||||||
|
project_id: string;
|
||||||
|
@ApiProperty()
|
||||||
|
private_key_id: string;
|
||||||
|
@ApiProperty()
|
||||||
|
private_key: string;
|
||||||
|
@ApiProperty()
|
||||||
|
client_email: string;
|
||||||
|
@ApiProperty()
|
||||||
|
client_id: string;
|
||||||
|
@ApiProperty()
|
||||||
|
auth_uri: string;
|
||||||
|
@ApiProperty()
|
||||||
|
token_uri: string;
|
||||||
|
@ApiProperty()
|
||||||
|
auth_provider_x509_cert_url: string;
|
||||||
|
@ApiProperty()
|
||||||
|
client_x509_cert_url: string;
|
||||||
|
}
|
||||||
|
class OauthObject {
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
get_tokens_url: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
get_tokens_url_params: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
get_tokens_set_response: Record<string, any>;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
content_type: string;
|
||||||
|
}
|
||||||
|
class InputOptions {
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
oauth: OauthObject;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
skip_select_columns: true;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
skip_select_entities: false;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
skip_transformation: true;
|
||||||
|
}
|
||||||
|
|
||||||
|
class CredentialsJdbc {
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
jdbc_user: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
jdbc_password: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
database: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
endpoint: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
port: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
engine: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
schema: string;
|
||||||
|
}
|
||||||
|
class FileFormatParams {
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
file_format: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
encoding: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Credentials extends CredentialsJdbc {
|
||||||
|
@ApiProperty()
|
||||||
|
connection_type: string;
|
||||||
|
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
client_aws_access_key_id: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
client_aws_secret_access_key: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
client_bucket: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
file_to_extract: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
file_format_params: FileFormatParams;
|
||||||
|
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
view_id: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
client_secrets: GoogleAnalyticsClientSecrets;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
start_date: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
end_date: string;
|
||||||
|
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
oauth_code: string;
|
||||||
|
}
|
||||||
|
class Column {
|
||||||
|
@ApiProperty()
|
||||||
|
name: string;
|
||||||
|
@ApiProperty()
|
||||||
|
type: string;
|
||||||
|
}
|
||||||
|
class TableColumns {
|
||||||
|
@ApiProperty()
|
||||||
|
name: string;
|
||||||
|
@ApiProperty()
|
||||||
|
columns: Column[];
|
||||||
|
@ApiProperty()
|
||||||
|
references: Column[];
|
||||||
|
}
|
||||||
|
export class GetAvailableEntitiesReq {
|
||||||
|
@ApiProperty()
|
||||||
|
plugin: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class GetAvailableEntitiesRes {
|
||||||
|
@ApiProperty()
|
||||||
|
entities: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TestConnectionGetColumnsReq {
|
||||||
|
@ApiProperty()
|
||||||
|
plugin: string;
|
||||||
|
@ApiProperty()
|
||||||
|
tables: string[];
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
credentials: CredentialsJdbc;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
id: string;
|
||||||
|
}
|
||||||
|
export class TestConnectionGetColumnsRes {
|
||||||
|
@ApiProperty()
|
||||||
|
tables: TableColumns[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TestConnectionReq {
|
||||||
|
@ApiProperty()
|
||||||
|
plugin: string;
|
||||||
|
@ApiProperty()
|
||||||
|
credentials: CredentialsJdbc;
|
||||||
|
}
|
||||||
|
export class TestConnectionRes {
|
||||||
|
@ApiProperty()
|
||||||
|
connection_state: boolean;
|
||||||
|
@ApiProperty()
|
||||||
|
total_entities: number;
|
||||||
|
@ApiProperty()
|
||||||
|
database_tables: string[];
|
||||||
|
}
|
||||||
|
export class CreateInputReq {
|
||||||
|
@ApiProperty()
|
||||||
|
plugin: string;
|
||||||
|
@ApiProperty()
|
||||||
|
category: string;
|
||||||
|
@ApiProperty()
|
||||||
|
credentials: Credentials;
|
||||||
|
@ApiProperty()
|
||||||
|
name: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
options: InputOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Input {
|
||||||
|
@ApiProperty()
|
||||||
|
id: string;
|
||||||
|
@ApiProperty()
|
||||||
|
category: string;
|
||||||
|
@ApiProperty()
|
||||||
|
plugin: string;
|
||||||
|
@ApiProperty()
|
||||||
|
name: string;
|
||||||
|
@ApiProperty()
|
||||||
|
cron: string;
|
||||||
|
@ApiProperty()
|
||||||
|
credentials: Credentials;
|
||||||
|
@ApiProperty()
|
||||||
|
client_id: string;
|
||||||
|
@ApiProperty()
|
||||||
|
created_at: string;
|
||||||
|
@ApiProperty()
|
||||||
|
updated_at: string;
|
||||||
|
}
|
||||||
@@ -4,20 +4,46 @@ import {
|
|||||||
Delete,
|
Delete,
|
||||||
Get,
|
Get,
|
||||||
Param,
|
Param,
|
||||||
|
Patch,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { InputsService } from './inputs.service';
|
import { InputsService } from './inputs.service';
|
||||||
import { InputsClientService } from 'src/clients/inputs/client.service';
|
import { InputsClientService } from 'src/clients/inputs/client.service';
|
||||||
import { UpdateInputRequest } from 'src/clients/inputs/interfaces';
|
import { UpdateInputRequest } from 'src/clients/inputs/interfaces';
|
||||||
import { InputNewCreateRequest } from '@victorradael/protospack';
|
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
||||||
|
import {
|
||||||
|
CreateInputReq,
|
||||||
|
GetAvailableEntitiesReq,
|
||||||
|
GetAvailableEntitiesRes,
|
||||||
|
Input,
|
||||||
|
TestConnectionGetColumnsReq,
|
||||||
|
TestConnectionGetColumnsRes,
|
||||||
|
TestConnectionReq,
|
||||||
|
TestConnectionRes,
|
||||||
|
} from './dtos/input.model';
|
||||||
|
|
||||||
|
@ApiTags('inputs')
|
||||||
@Controller('inputs')
|
@Controller('inputs')
|
||||||
export class InputsController {
|
export class InputsController {
|
||||||
constructor(private inputsClientService: InputsClientService) {}
|
inputService: InputsService;
|
||||||
|
constructor(private inputsClientService: InputsClientService) {
|
||||||
|
this.inputService = new InputsService(this.inputsClientService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('available-entities/:plugin')
|
||||||
|
@ApiOkResponse({ type: GetAvailableEntitiesRes })
|
||||||
|
async getAvailableEntities(
|
||||||
|
@Body() body,
|
||||||
|
@Param() params: GetAvailableEntitiesReq,
|
||||||
|
) {
|
||||||
|
const { info } = body;
|
||||||
|
const { plugin } = params;
|
||||||
|
return await this.inputService.getAvailableEntities({ info, plugin });
|
||||||
|
}
|
||||||
|
|
||||||
@Post('/test-connection')
|
@Post('/test-connection')
|
||||||
async testConnection(@Body() data) {
|
@ApiOkResponse({ type: TestConnectionRes })
|
||||||
|
async testConnection(@Body() data: TestConnectionReq) {
|
||||||
console.log(`/test-connection`, 'ON TEST CONNECTION ROUTE');
|
console.log(`/test-connection`, 'ON TEST CONNECTION ROUTE');
|
||||||
|
|
||||||
const inputService = new InputsService(this.inputsClientService);
|
const inputService = new InputsService(this.inputsClientService);
|
||||||
@@ -27,7 +53,8 @@ export class InputsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post('/test-connection/get-columns')
|
@Post('/test-connection/get-columns')
|
||||||
async getColumns(@Body() data) {
|
@ApiOkResponse({ type: TestConnectionGetColumnsRes })
|
||||||
|
async getColumns(@Body() data: TestConnectionGetColumnsReq) {
|
||||||
console.log(
|
console.log(
|
||||||
`/test-connection/get-columns`,
|
`/test-connection/get-columns`,
|
||||||
'ON TEST CONNECTION GET COLUMNS ROUTE',
|
'ON TEST CONNECTION GET COLUMNS ROUTE',
|
||||||
@@ -40,7 +67,8 @@ export class InputsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
async create(@Body() createInputDto: InputNewCreateRequest) {
|
@ApiOkResponse({ type: Input })
|
||||||
|
async create(@Body() createInputDto: CreateInputReq) {
|
||||||
console.log(`/input`, 'ON CREATE ROUTE');
|
console.log(`/input`, 'ON CREATE ROUTE');
|
||||||
|
|
||||||
const inputService = new InputsService(this.inputsClientService);
|
const inputService = new InputsService(this.inputsClientService);
|
||||||
@@ -71,7 +99,7 @@ export class InputsController {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put(':id')
|
@Patch(':id')
|
||||||
async update(@Body() updateInputDto: UpdateInputRequest, @Param() params) {
|
async update(@Body() updateInputDto: UpdateInputRequest, @Param() params) {
|
||||||
const { id } = params;
|
const { id } = params;
|
||||||
const { info } = updateInputDto;
|
const { info } = updateInputDto;
|
||||||
|
|||||||
@@ -1,42 +1,91 @@
|
|||||||
import { Body, HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
import { Body, HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||||
import { Timeout } from '@nestjs/schedule';
|
import { Timeout } from '@nestjs/schedule';
|
||||||
|
import { DecodeGrpcStruct } from '@victorradael/protospack';
|
||||||
|
import CronParser, { CronExpression } from 'cron-parser';
|
||||||
import { InputsClientService } from 'src/clients/inputs/client.service';
|
import { InputsClientService } from 'src/clients/inputs/client.service';
|
||||||
import { IIdRequest, Info } from 'src/clients/inputs/interfaces';
|
import { IIdRequest, Info } from 'src/clients/inputs/interfaces';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class InputsService {
|
export class InputsService {
|
||||||
constructor(private inputClient: InputsClientService) {}
|
constructor(private inputClient: InputsClientService) {}
|
||||||
|
secondsInADay = 60 * 60 * 24;
|
||||||
|
secondsInAnHour = 60 * 60;
|
||||||
|
|
||||||
async create(@Body() data) {
|
adjustInputPayload(payload) {
|
||||||
|
if (payload?.input_generic) return DecodeGrpcStruct(payload.input_generic);
|
||||||
|
if (!payload.input_s3 && !payload.input_jdbc) return payload;
|
||||||
|
return payload?.input_s3 || payload?.input_jdbc;
|
||||||
|
}
|
||||||
|
getDifferenceInSeconds(date1: Date, date2: Date) {
|
||||||
|
const diffInMs = Math.abs(date2.getTime() - date1.getTime());
|
||||||
|
return diffInMs / 1000;
|
||||||
|
}
|
||||||
|
validateCron(data) {
|
||||||
|
const { info, cron } = data;
|
||||||
|
const { customer_tier } = info;
|
||||||
|
if (!cron) return;
|
||||||
|
let interval: CronExpression;
|
||||||
try {
|
try {
|
||||||
if (
|
interval = CronParser.parseExpression(cron);
|
||||||
data.plugin == 'csv' ||
|
} catch (error) {
|
||||||
data.plugin == 'json' ||
|
throw new HttpException(
|
||||||
data.plugin == 'parquet'
|
'Intervalo de tempo inválido',
|
||||||
) {
|
HttpStatus.BAD_REQUEST,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const nextDate = interval.next().toDate();
|
||||||
|
const afterNextDate = interval.next().toDate();
|
||||||
|
const secondsApart = this.getDifferenceInSeconds(nextDate, afterNextDate);
|
||||||
|
if (customer_tier === 'BASIC' && secondsApart < this.secondsInADay) {
|
||||||
|
throw new HttpException(
|
||||||
|
'Intervalo de tempo não pode ser inferior a um dia.',
|
||||||
|
HttpStatus.FORBIDDEN,
|
||||||
|
);
|
||||||
|
} else if (secondsApart < this.secondsInAnHour) {
|
||||||
|
throw new HttpException(
|
||||||
|
'Intervalo de tempo não pode ser inferior a uma hora.',
|
||||||
|
HttpStatus.FORBIDDEN,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async create(@Body() data) {
|
||||||
|
this.validateCron(data);
|
||||||
|
let response;
|
||||||
|
switch (data.plugin.toLowerCase()) {
|
||||||
|
case 'csv':
|
||||||
|
case 'json':
|
||||||
|
case 'parquet':
|
||||||
const { info, ...input } = data;
|
const { info, ...input } = data;
|
||||||
const inputPayload = this.generateInputS3Payload(input);
|
const inputPayload = this.generateInputS3Payload(input);
|
||||||
const createInputResponse = await this.inputClient.createS3Inputs({
|
response = await this.inputClient.createS3Inputs({
|
||||||
input: inputPayload,
|
input: inputPayload,
|
||||||
info,
|
info,
|
||||||
});
|
});
|
||||||
return createInputResponse;
|
break;
|
||||||
} else {
|
case 'oracle':
|
||||||
const createInputResponse: any = await this.inputClient.create(data);
|
case 'mysql':
|
||||||
if (createInputResponse?.input?.input_jdbc) {
|
case 'postgresql':
|
||||||
return { input: createInputResponse?.input?.input_jdbc };
|
case 'sqlserver':
|
||||||
}
|
response = await this.inputClient.newCreate(data);
|
||||||
return createInputResponse;
|
break;
|
||||||
}
|
default:
|
||||||
} catch (err) {
|
response = await this.inputClient.createGeneric(data);
|
||||||
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
break;
|
||||||
}
|
}
|
||||||
|
const adjustedInput = this.adjustInputPayload(response.input);
|
||||||
|
return { ...response, input: adjustedInput };
|
||||||
|
}
|
||||||
|
async getAvailableEntities(data): Promise<{ entities: string[] }> {
|
||||||
|
return await this.inputClient.getAvailableEntities(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(body) {
|
async findAll(body) {
|
||||||
try {
|
try {
|
||||||
const findAllInputResponse = await this.inputClient.findAll(body);
|
const findAllInputResponse: any = await this.inputClient.findAll(body);
|
||||||
|
if (findAllInputResponse?.inputs?.length) {
|
||||||
|
findAllInputResponse.inputs = findAllInputResponse.inputs.map((input) =>
|
||||||
|
this.adjustInputPayload(input),
|
||||||
|
);
|
||||||
|
}
|
||||||
return findAllInputResponse;
|
return findAllInputResponse;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
||||||
@@ -45,7 +94,12 @@ export class InputsService {
|
|||||||
|
|
||||||
async findOne(idRequest: IIdRequest) {
|
async findOne(idRequest: IIdRequest) {
|
||||||
try {
|
try {
|
||||||
const findOneInputResponse = await this.inputClient.findOne(idRequest);
|
const findOneInputResponse: any = await this.inputClient.findOne(
|
||||||
|
idRequest,
|
||||||
|
);
|
||||||
|
findOneInputResponse.input = this.adjustInputPayload(
|
||||||
|
findOneInputResponse.input,
|
||||||
|
);
|
||||||
return findOneInputResponse;
|
return findOneInputResponse;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
||||||
@@ -53,13 +107,17 @@ export class InputsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async update(id: string, data, info: Info) {
|
async update(id: string, data, info: Info) {
|
||||||
|
this.validateCron({ ...data, info });
|
||||||
try {
|
try {
|
||||||
const updateInputResponse = await this.inputClient.update({
|
const updateInputResponse: any = await this.inputClient.update({
|
||||||
id,
|
id,
|
||||||
info,
|
info,
|
||||||
...data,
|
...data,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
updateInputResponse.input = this.adjustInputPayload(
|
||||||
|
updateInputResponse?.input,
|
||||||
|
);
|
||||||
return updateInputResponse;
|
return updateInputResponse;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
||||||
@@ -101,7 +159,7 @@ export class InputsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
generateInputS3Payload(payload) {
|
generateInputS3Payload(payload) {
|
||||||
const { credentials, plugin } = payload;
|
const { credentials, plugin, cron } = payload;
|
||||||
if (!credentials) return payload;
|
if (!credentials) return payload;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -112,8 +170,10 @@ export class InputsService {
|
|||||||
client_bucket,
|
client_bucket,
|
||||||
file_to_extract,
|
file_to_extract,
|
||||||
} = credentials;
|
} = credentials;
|
||||||
|
|
||||||
const formatedPayload = {
|
const formatedPayload = {
|
||||||
plugin,
|
plugin,
|
||||||
|
cron,
|
||||||
source_bucket: client_bucket,
|
source_bucket: client_bucket,
|
||||||
source_prefix: file_to_extract,
|
source_prefix: file_to_extract,
|
||||||
auth_parameters: {
|
auth_parameters: {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||||
|
import { DecodeGrpcStruct } from '@victorradael/protospack';
|
||||||
import { PipelinesClientService } from 'src/clients/pipelines/client.service';
|
import { PipelinesClientService } from 'src/clients/pipelines/client.service';
|
||||||
import { IIdRequest, Info } from 'src/clients/pipelines/interfaces';
|
import { IIdRequest, Info } from 'src/clients/pipelines/interfaces';
|
||||||
import { objectCamelToSnake } from 'src/utils/CaseConverter';
|
import { objectCamelToSnake } from 'src/utils/CaseConverter';
|
||||||
@@ -8,7 +9,11 @@ export class PipelinesService {
|
|||||||
constructor(private pipelineClient: PipelinesClientService) {}
|
constructor(private pipelineClient: PipelinesClientService) {}
|
||||||
|
|
||||||
adjustPayload(payload) {
|
adjustPayload(payload) {
|
||||||
payload.input = payload.input?.input_s3 || payload.input?.input_jdbc;
|
if (payload.input?.input_generic) {
|
||||||
|
payload.input = DecodeGrpcStruct(payload.input?.input_generic);
|
||||||
|
} else {
|
||||||
|
payload.input = payload.input?.input_s3 || payload.input?.input_jdbc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(createPipelineDto) {
|
async create(createPipelineDto) {
|
||||||
|
|||||||
@@ -67,6 +67,30 @@ export default function ErrorBuilder(code: string) {
|
|||||||
code,
|
code,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
case ErrorCodes.AUTH.RESET_PASSWORD_CODE_EXPIRED:
|
||||||
|
return Builder({
|
||||||
|
statusCode: HttpStatus.UNAUTHORIZED,
|
||||||
|
error: 'Não permitido',
|
||||||
|
message: 'Token para recuperar senha expirado',
|
||||||
|
code,
|
||||||
|
});
|
||||||
|
|
||||||
|
case ErrorCodes.AUTH.RESET_PASSWORD_CODE_INVALID:
|
||||||
|
return Builder({
|
||||||
|
statusCode: HttpStatus.UNAUTHORIZED,
|
||||||
|
error: 'Não permitido',
|
||||||
|
message: 'Token para recuperar senha inválido',
|
||||||
|
code,
|
||||||
|
});
|
||||||
|
|
||||||
|
case ErrorCodes.AUTH.WEAK_NEW_PASSWORD:
|
||||||
|
return Builder({
|
||||||
|
statusCode: HttpStatus.BAD_REQUEST,
|
||||||
|
error: 'Não permitido',
|
||||||
|
message: 'Senha muito fraca. Escolha uma senha mais forte',
|
||||||
|
code,
|
||||||
|
});
|
||||||
|
|
||||||
case ErrorCodes.RATE_LIMIT:
|
case ErrorCodes.RATE_LIMIT:
|
||||||
return Builder({
|
return Builder({
|
||||||
statusCode: HttpStatus.TOO_MANY_REQUESTS,
|
statusCode: HttpStatus.TOO_MANY_REQUESTS,
|
||||||
@@ -93,6 +117,7 @@ export default function ErrorBuilder(code: string) {
|
|||||||
code,
|
code,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
case ErrorCodes.INTERNAL:
|
||||||
case ErrorCodes.UNKNOWN:
|
case ErrorCodes.UNKNOWN:
|
||||||
default:
|
default:
|
||||||
return Builder({
|
return Builder({
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export const Auth = {
|
export const AUTH = {
|
||||||
UNAUTHORIZED: 'AUTH.UNAUTHORIZED',
|
UNAUTHORIZED: 'AUTH.UNAUTHORIZED',
|
||||||
FORBIDDEN: 'AUTH.FORBIDDEN',
|
FORBIDDEN: 'AUTH.FORBIDDEN',
|
||||||
WRONG_CREDENTIALS: 'AUTH.WRONG_CREDENTIALS',
|
WRONG_CREDENTIALS: 'AUTH.WRONG_CREDENTIALS',
|
||||||
@@ -9,12 +9,16 @@ export const Auth = {
|
|||||||
TOTP_REQUIRED: 'AUTH.TOTP_REQUIRED',
|
TOTP_REQUIRED: 'AUTH.TOTP_REQUIRED',
|
||||||
CODE_MISMATCH: 'AUTH.CODE_MISMATCH',
|
CODE_MISMATCH: 'AUTH.CODE_MISMATCH',
|
||||||
CODE_ALREADY_USED: 'AUTH.CODE_ALREADY_USED',
|
CODE_ALREADY_USED: 'AUTH.CODE_ALREADY_USED',
|
||||||
|
RESET_PASSWORD_CODE_EXPIRED: 'AUTH.RESET_PASSWORD_CODE_EXPIRED',
|
||||||
|
RESET_PASSWORD_CODE_INVALID: 'AUTH.RESET_PASSWORD_CODE_INVALID',
|
||||||
|
WEAK_NEW_PASSWORD: 'AUTH.WEAK_NEW_PASSWORD',
|
||||||
};
|
};
|
||||||
|
|
||||||
const ErrorCodes = {
|
const ErrorCodes = {
|
||||||
UNKNOWN: 'UNKNOWN',
|
UNKNOWN: 'UNKNOWN',
|
||||||
RATE_LIMIT: 'RATE_LIMIT',
|
RATE_LIMIT: 'RATE_LIMIT',
|
||||||
AUTH: Auth,
|
INTERNAL: 'INTERNAL',
|
||||||
|
AUTH,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ErrorCodes;
|
export default ErrorCodes;
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
export const mustache = (string: string, data: Record<string, any> = {}) => {
|
||||||
|
return Object.entries(data).reduce((res, [key, value]) => {
|
||||||
|
const mainRe = new RegExp(`(?<!\\\\){{\\s*${key}\\s*}}`, 'g');
|
||||||
|
const escapeRe = new RegExp(`\\\\({{\\s*${key}\\s*}})`, 'g');
|
||||||
|
return res.replace(mainRe, value.toString()).replace(escapeRe, '$1');
|
||||||
|
}, string);
|
||||||
|
};
|
||||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user