Compare commits

...
7 changed files with 87 additions and 36 deletions
+5 -1
View File
@@ -13,4 +13,8 @@ charts:
- name: maestro.in_factory_url
value: in-factory.dadosfera.ai
- name: maestro.tr_factory_url
value: in-factory.dadosfera.ai
value: in-factory.dadosfera.ai
- name: maestro.open_customer_id
value: f239718a-a271-4ef9-ae7e-02a2f0f3aa6e
- name: maestro.open_group_id
value: 401573bb-334f-44b2-b30e-88d4cea31ae9
+10 -5
View File
@@ -5,12 +5,17 @@ charts:
- ../maestro/values.yaml
set:
- name: maestro.duc_url
value: duc-temp.dadosfera.ai
value: duc.stg.dadosfera.ai
- name: hostname
value: maestro-temp.dadosfera.ai
value: maestro.stg.dadosfera.ai
- name: maestro.pi_factory_url
value: pi-factory-temp.dadosfera.ai
value: pi-factory.stg.dadosfera.ai
- name: maestro.in_factory_url
value: in-factory-temp.dadosfera.ai
value: in-factory.stg.dadosfera.ai
- name: maestro.tr_factory_url
value: in-factory-temp.dadosfera.ai
value: in-factory.stg.dadosfera.ai
- name: maestro.open_customer_id
value: bb4e9b26-d465-40ff-9345-e768ca69a55e
- name: maestro.open_group_id
value: 4d621501-5ea4-444b-b46e-1a009f3132ff
+2 -1
View File
@@ -40,7 +40,8 @@ maestro:
sm_oauth_path: prd/root/oauth_applications
tr_factory_url: in-factory.dadosfera.ai
upload_file_agent_connection: cbc2f881-58c4-4d60-8003-0979b0b5b911
open_customer_id: f239718a-a271-4ef9-ae7e-02a2f0f3aa6e
open_group_id: 401573bb-334f-44b2-b30e-88d4cea31ae9
autoscaling:
enabled: false
minReplicas: 1
+32
View File
@@ -0,0 +1,32 @@
import { Injectable, CanActivate, ExecutionContext, ForbiddenException } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { SetMetadata } from '@nestjs/common';
export const SetOrigin = (origin: string) => SetMetadata('allowedOrigin', origin);
@Injectable()
export class CORSGuard implements CanActivate {
constructor(private reflector: Reflector) {}
canActivate(context: ExecutionContext): boolean {
const response = context.switchToHttp().getResponse();
const request = context.switchToHttp().getRequest();
const origin = request.headers.origin;
// Obter a origem permitida através do decorador
const allowedOrigin = this.reflector.get<string>('allowedOrigin', context.getHandler());
if (process.env.ENV === "local") {
return true;
}
// Verifica se a origem da requisição é permitida
if (allowedOrigin && origin !== allowedOrigin) {
throw new ForbiddenException('Acesso não permitido pela política CORS');
}
response.setHeader('Access-Control-Allow-Origin', allowedOrigin);
return true;
}
}
+14 -2
View File
@@ -59,9 +59,21 @@ export class CustomersController {
this.logger.info('saveCustomertheme', JSON.stringify({
id, theme: data
}));
const theme = await this.customersService.createThemeByCustomer(id, data);
return theme;
try {
// const theme = await this.customersService.createThemeByCustomer(id, data);
this.logger.info('saveCustomertheme', JSON.stringify(data));
return { theme: null };
} catch (err) {
if (err.details === ErrorCodes.CUSTOMER.NOT_FOUND) {
this.logger.error('Error - saveCustomertheme - Expect CUSTOMER.NOT_FOUND');
throw new HttpException(err.details, HttpStatus.NOT_FOUND);
} else {
this.logger.error('Error - saveCustomertheme Unknown Error:' + err?.message);
return { theme: null };
};
}
}
@Get(':id/theme')
+10 -19
View File
@@ -96,32 +96,23 @@ export class CustomersService implements OnModuleInit {
throw new HttpException(null, HttpStatus.BAD_REQUEST);
}
try {
const result = await firstValueFrom(
this.customerService.CustomerCreateTheme({
customerId: id,
theme
}),
);
return { theme: result };
} catch (err) {
if (err.details === ErrorCodes.CUSTOMER.NOT_FOUND) {
this.logger.error('Error - saveCustomertheme - Expect CUSTOMER.NOT_FOUND');
throw new HttpException(err.details, HttpStatus.NOT_FOUND);
} else {
this.logger.error('Error - saveCustomertheme Unknown Error:' + err?.message);
throw err
};
}
const result = await firstValueFrom(
this.customerService.CustomerCreateTheme({
customerId: id,
theme
}),
);
return { theme: result };
}
async getThemeByCustomer(id: string): Promise<CustomerThemeResponse> {
async getThemeByCustomer(id: string): Promise<CustomerThemeResponse> {
if (!id) {
this.logger.error('Error - getCustomerTheme - not found id:' + id);
throw new HttpException(null, HttpStatus.BAD_REQUEST);
}
const result = await firstValueFrom(
const result = await firstValueFrom(
this.customerService.CustomerGetTheme({
id
}),
+14 -8
View File
@@ -1,6 +1,6 @@
import DadosferaLogger from '@dadosfera/dadosfera-logs';
import { Body, Controller, Inject, Post, UseFilters } from '@nestjs/common';
import { ApiCreatedResponse, ApiHeaders, ApiTags } from '@nestjs/swagger';
import { Body, Controller, Inject, Post, UseFilters, UseGuards } from '@nestjs/common';
import { ApiCreatedResponse, ApiHeaders, ApiOkResponse, ApiTags } from '@nestjs/swagger';
import { ApiInternalOnlyController } from 'src/decorators/swagger.decorator';
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
import { LanguageEnum } from 'src/utils/languages.enum';
@@ -8,6 +8,7 @@ import { UsersService } from '../users/users.service';
import { Language } from 'src/decorators/language.decorator';
import { OpenDataService } from './open-data.service';
import { CreateUserOpenDataDTO, WordpressForm } from './dto/wordpres-form';
import { CORSGuard, SetOrigin } from 'src/decorators/set-origin.decorator';
@Controller('open-data')
@ApiInternalOnlyController()
@@ -26,7 +27,9 @@ export class OpenDataController {
}
@Post("/sharing-ocean-data")
@ApiCreatedResponse()
@SetOrigin('https://devsbm.dadosfera.io/')
@UseGuards(CORSGuard)
@ApiOkResponse()
async createUser(
@Body()
body: WordpressForm
@@ -34,10 +37,12 @@ export class OpenDataController {
this.logger.info('createUser for open data' + JSON.stringify({ body }));
// "401573bb-334f-44b2-b30e-88d4cea31ae9"
const OPENDATA_PUBLIC_USERS_GROUP_ID = process.env.OPEN_GROUP_ID;
// const OPENDATA_PUBLIC_USERS_GROUP_ID = process.env.OPEN_GROUP_ID;
// ""f239718a-a271-4ef9-ae7e-02a2f0f3aa6e""
const OPENDATA_CUSTOMER_ID = process.env.OPEN_CUSTOMER_ID;
const roles = [OPENDATA_PUBLIC_USERS_GROUP_ID];
// const OPENDATA_CUSTOMER_ID = process.env.OPEN_CUSTOMER_ID;
const OPENDATA_CUSTOMER_ID = "bb4e9b26-d465-40ff-9345-e768ca69a55e";
const roles = ["4d621501-5ea4-444b-b46e-1a009f3132ff"];
const data = {}
@@ -60,10 +65,11 @@ export class OpenDataController {
lastName: data["last_name"],
organization: data["organization"]
}
this.logger.info('user data' + JSON.stringify({ user }));
this.logger.info('user request' + JSON.stringify({ user, roles, customer: OPENDATA_CUSTOMER_ID }));
try {
await this.openDataService.createUser(OPENDATA_CUSTOMER_ID, user, roles);
const response = await this.openDataService.createUser(OPENDATA_CUSTOMER_ID, user, roles);
this.logger.info('user created with sucessfull data' + JSON.stringify(response));
return "success"
} catch (e) {
this.logger.error('user data' + e.message);