mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-04 05:34:48 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d89573bc79 | ||
|
|
03ed4d88a0 | ||
|
|
329bbf2e4d | ||
|
|
ae069a0e00 | ||
|
|
d3bcbdc43c |
@@ -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
|
||||
Generated
+1373
-1482
File diff suppressed because it is too large
Load Diff
+3
-2
@@ -33,6 +33,7 @@
|
||||
"@nestjs/swagger": "^5.2.1",
|
||||
"@victorradael/protospack": "2.4.2-1",
|
||||
"axios": "^0.25.0",
|
||||
"cron-parser": "^4.4.0",
|
||||
"dotenv": "^14.2.0",
|
||||
"helmet": "^5.0.2",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
@@ -42,8 +43,8 @@
|
||||
"rxjs": "^7.5.5",
|
||||
"swagger-ui-express": "^4.3.0"
|
||||
},
|
||||
"overrides":{
|
||||
"busboy@<1.6.0":"1.6.0"
|
||||
"overrides": {
|
||||
"multer": "1.4.5-lts.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "^8.2.4",
|
||||
|
||||
@@ -32,9 +32,10 @@ export class LoggerMiddleware implements NestMiddleware {
|
||||
|
||||
const permissions = jwtDecoded.user.permissions;
|
||||
|
||||
const clienId = jwtDecoded.user.customerId;
|
||||
const clientId = jwtDecoded.user.customerId;
|
||||
const customer = jwtDecoded.user.customer;
|
||||
const userId = jwtDecoded.user.id;
|
||||
const customer_tier = jwtDecoded.user.customer_tier;
|
||||
|
||||
await verifyToken(accessToken);
|
||||
|
||||
@@ -55,11 +56,11 @@ export class LoggerMiddleware implements NestMiddleware {
|
||||
|
||||
if (havePermission) {
|
||||
request.body.info = {
|
||||
customer_id: clienId,
|
||||
customer_id: clientId,
|
||||
user_id: userId,
|
||||
customer,
|
||||
customer_tier,
|
||||
};
|
||||
|
||||
next();
|
||||
} else {
|
||||
throw new ForbiddenException();
|
||||
|
||||
@@ -1,16 +1,52 @@
|
||||
import { Body, HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { Timeout } from '@nestjs/schedule';
|
||||
import CronParser, { CronExpression } from 'cron-parser';
|
||||
import { InputsClientService } from 'src/clients/inputs/client.service';
|
||||
import { IIdRequest, Info } from 'src/clients/inputs/interfaces';
|
||||
|
||||
@Injectable()
|
||||
export class InputsService {
|
||||
constructor(private inputClient: InputsClientService) {}
|
||||
secondsInADay = 60 * 60 * 24;
|
||||
secondsInAnHour = 60 * 60;
|
||||
|
||||
adjustInputPayload(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 {
|
||||
interval = CronParser.parseExpression(cron);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
'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);
|
||||
try {
|
||||
if (
|
||||
data.plugin == 'csv' ||
|
||||
@@ -65,6 +101,7 @@ export class InputsService {
|
||||
}
|
||||
|
||||
async update(id: string, data, info: Info) {
|
||||
this.validateCron({ ...data, info });
|
||||
try {
|
||||
const updateInputResponse: any = await this.inputClient.update({
|
||||
id,
|
||||
|
||||
Reference in New Issue
Block a user