mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-01 20:28:17 +00:00
Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f46b1b62db | ||
|
|
8b6cd8a88e | ||
|
|
0c333b476a | ||
|
|
c416a2cb97 | ||
|
|
d03021fc9d | ||
|
|
574cf48726 | ||
|
|
7cef404acf | ||
|
|
3c32c3c7d4 | ||
|
|
d44531b963 | ||
|
|
36c80b480e | ||
|
|
eeef97679c |
+1
-1
@@ -8,7 +8,7 @@ module.exports = {
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:prettier/recommended',
|
||||
'prettier',
|
||||
],
|
||||
root: true,
|
||||
env: {
|
||||
|
||||
@@ -168,7 +168,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Extract Docs BlockId and PageId
|
||||
env:
|
||||
|
||||
Vendored
+1
-1
@@ -20,4 +20,4 @@
|
||||
"console": "integratedTerminal"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
+40
-1
@@ -490,6 +490,45 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/pipelinesV2/monitoring-dashboard": {
|
||||
"get": {
|
||||
"operationId": "PipelinesController_getMonitoringDashboard",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "dadosfera-lang",
|
||||
"in": "header",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"enum": [
|
||||
"pt-br",
|
||||
"en-us"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
"PipelinesV2"
|
||||
],
|
||||
"security": [
|
||||
{
|
||||
"access-token": []
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/pipelinesV2": {
|
||||
"post": {
|
||||
"operationId": "PipelinesController_create",
|
||||
@@ -1752,7 +1791,7 @@
|
||||
}
|
||||
},
|
||||
"info": {
|
||||
"title": "Maestro - feat/generate-token",
|
||||
"title": "Maestro - feat/new-customer-monitoring",
|
||||
"description": "This is the Maestro API",
|
||||
"version": "1.0.0",
|
||||
"contact": {}
|
||||
|
||||
+64
-75
@@ -542,67 +542,6 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/auth/oauth/magalu-id": {
|
||||
"get": {
|
||||
"operationId": "AuthController_magaluIdOauth",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "dadosfera-lang",
|
||||
"in": "header",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"enum": [
|
||||
"pt-br",
|
||||
"en-us"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
"Auth"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/auth/oauth/magalu-id/callback": {
|
||||
"get": {
|
||||
"operationId": "AuthController_magaluIdOauthCallback",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "dadosfera-lang",
|
||||
"in": "header",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"enum": [
|
||||
"pt-br",
|
||||
"en-us"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": ""
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
"Auth"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/connections": {
|
||||
"post": {
|
||||
"operationId": "ConnectionController_createConnection",
|
||||
@@ -2724,6 +2663,45 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/pipelinesV2/monitoring-dashboard": {
|
||||
"get": {
|
||||
"operationId": "PipelinesController_getMonitoringDashboard",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "dadosfera-lang",
|
||||
"in": "header",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"enum": [
|
||||
"pt-br",
|
||||
"en-us"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
"PipelinesV2"
|
||||
],
|
||||
"security": [
|
||||
{
|
||||
"access-token": []
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/pipelinesV2": {
|
||||
"post": {
|
||||
"operationId": "PipelinesController_create",
|
||||
@@ -5010,14 +4988,7 @@
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
"description": ""
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
@@ -5128,6 +5099,28 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/customers/monitoring-dashboard": {
|
||||
"get": {
|
||||
"operationId": "CustomersController_getCustomerMonitoringDashboard",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": ""
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
"Customers"
|
||||
],
|
||||
"security": [
|
||||
{
|
||||
"access-token": []
|
||||
},
|
||||
{
|
||||
"access-token": []
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/health": {
|
||||
"get": {
|
||||
"operationId": "HealthController_check",
|
||||
@@ -5144,7 +5137,7 @@
|
||||
}
|
||||
},
|
||||
"info": {
|
||||
"title": "Maestro - ci/dockerhub",
|
||||
"title": "Maestro - feat/new-customer-monitoring",
|
||||
"description": "This is the Maestro API",
|
||||
"version": "1.0.0",
|
||||
"contact": {}
|
||||
@@ -5368,15 +5361,11 @@
|
||||
},
|
||||
"accessToken": {
|
||||
"type": "string"
|
||||
},
|
||||
"refreshToken": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"permissions",
|
||||
"accessToken",
|
||||
"refreshToken"
|
||||
"accessToken"
|
||||
]
|
||||
},
|
||||
"CreateConnectionDto": {
|
||||
|
||||
Vendored
-1
@@ -4,7 +4,6 @@ declare global {
|
||||
NODE_ENV: 'test';
|
||||
ENV: 'local' | 'stg' | 'prd' | 'test';
|
||||
LOCAL_ENV: 'stg' | 'prd';
|
||||
CLOUD_ENVIRONMENT: 'aws' | 'gcp' | 'mgc';
|
||||
|
||||
DUC_URL: string;
|
||||
INFACTORY_URL: string;
|
||||
|
||||
Generated
+1576
-2200
File diff suppressed because it is too large
Load Diff
+4
-5
@@ -29,7 +29,7 @@
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-secrets-manager": "^3.112.0",
|
||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
||||
"@dadosfera/protospack-v2": "3.32.0-beta.2",
|
||||
"@dadosfera/protospack-v2": "3.33.0",
|
||||
"@grpc/grpc-js": "^1.6.7",
|
||||
"@grpc/proto-loader": "^0.6.13",
|
||||
"@nestjs/cli": "^9.4.2",
|
||||
@@ -43,7 +43,7 @@
|
||||
"@nestjs/schematics": "^9.1.0",
|
||||
"@nestjs/swagger": "^6.3.0",
|
||||
"@nestjs/testing": "^9.4.0",
|
||||
"axios": "^1.6.2",
|
||||
"axios": "^0.27.2",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.0",
|
||||
"cron-parser": "^4.4.0",
|
||||
@@ -80,11 +80,10 @@
|
||||
"@types/passport-google-oauth20": "^2.0.11",
|
||||
"@types/passport-oauth2": "^1.4.11",
|
||||
"@types/supertest": "^2.0.12",
|
||||
"@typescript-eslint/eslint-plugin": "^5.35.0",
|
||||
"@typescript-eslint/parser": "^5.35.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
||||
"@typescript-eslint/parser": "^5.62.0",
|
||||
"eslint": "^8.18.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"jest": "^27.5.1",
|
||||
"nock": "^13.2.7",
|
||||
"prettier": "^2.7.1",
|
||||
|
||||
@@ -79,13 +79,9 @@ export class AuthenticationGuard
|
||||
request,
|
||||
mustBeAuthenticated: boolean,
|
||||
): RequestUser | false {
|
||||
const accessToken: string = request.get('Authorization');
|
||||
const accessToken = request.get('Authorization');
|
||||
let accessTokenPayload: RequestUser;
|
||||
|
||||
this.logger.info(`mustBeAuthenticated: ${mustBeAuthenticated}`);
|
||||
this.logger.info(
|
||||
`accessToken (first 5 chars): ${accessToken?.slice(0, 5)}`,
|
||||
);
|
||||
// If the user isn't authenticated, an error will occurr anywhere here.
|
||||
// Fancy error avoidance isn't performed by purpose, such as avoiding to access null values.
|
||||
try {
|
||||
|
||||
@@ -67,7 +67,6 @@ export const PERMISSIONS_GROUPS = {
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
PIPELINE: {
|
||||
title: {
|
||||
'pt-br': 'Coletar | Pipelines',
|
||||
@@ -117,7 +116,6 @@ export const PERMISSIONS_GROUPS = {
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
CONNECTION: {
|
||||
title: {
|
||||
'pt-br': 'Coletar | Fontes de dados',
|
||||
@@ -157,7 +155,6 @@ export const PERMISSIONS_GROUPS = {
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
NETWORK_CONFIG: {
|
||||
title: {
|
||||
'pt-br': 'Coletar | Redes',
|
||||
@@ -187,7 +184,6 @@ export const PERMISSIONS_GROUPS = {
|
||||
// },
|
||||
},
|
||||
},
|
||||
|
||||
OUTPUT: {
|
||||
title: {
|
||||
'pt-br': 'Output',
|
||||
@@ -237,7 +233,6 @@ export const PERMISSIONS_GROUPS = {
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
TRANSFORMATIONS: {
|
||||
title: {
|
||||
'pt-br': 'Micro-transformações',
|
||||
@@ -287,7 +282,6 @@ export const PERMISSIONS_GROUPS = {
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
CATALOG: {
|
||||
title: {
|
||||
'pt-br': 'Explorar | Catálogo',
|
||||
@@ -368,7 +362,6 @@ export const PERMISSIONS_GROUPS = {
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
CONNECTORS: {
|
||||
title: {
|
||||
'pt-br': 'Conectores',
|
||||
@@ -418,7 +411,6 @@ export const PERMISSIONS_GROUPS = {
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
SNOWFLAKE: {
|
||||
title: {
|
||||
'pt-br': 'Explorar | Consolidar',
|
||||
@@ -438,7 +430,6 @@ export const PERMISSIONS_GROUPS = {
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
ZENDESK: {
|
||||
title: {
|
||||
'pt-br': 'Zendesk',
|
||||
@@ -458,7 +449,6 @@ export const PERMISSIONS_GROUPS = {
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
DATAVIZ: {
|
||||
title: {
|
||||
'pt-br': 'Analisar | Visualização',
|
||||
@@ -497,7 +487,6 @@ export const PERMISSIONS_GROUPS = {
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
MODULES: {
|
||||
title: {
|
||||
'pt-br': 'Módulos da Dadosfera',
|
||||
@@ -594,6 +583,25 @@ export const PERMISSIONS_GROUPS = {
|
||||
},
|
||||
},
|
||||
},
|
||||
CUSTOMER: {
|
||||
title: {
|
||||
'pt-br': 'Organização',
|
||||
'en-us': 'Organization',
|
||||
'es-es': 'Organización',
|
||||
},
|
||||
permissions: {
|
||||
MONITORING_DASHBOARD: {
|
||||
seqid: 47,
|
||||
claim: 'customer:monitoring-dashboard',
|
||||
usage: PermissionUsages.PUBLIC,
|
||||
name: {
|
||||
'pt-br': 'Ver o dashboard de monitoramento',
|
||||
'en-us': 'View the monitoring dashboard',
|
||||
'es-es': 'Ver el dashboard de monitoreo',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
export interface DadosferaModule {
|
||||
name: string;
|
||||
|
||||
@@ -52,7 +52,6 @@ import jwt from 'jsonwebtoken';
|
||||
import { LanguageEnum } from 'src/utils/languages.enum';
|
||||
import { Language } from 'src/decorators/language.decorator';
|
||||
import { ApiInternalOnlyEndpoint } from 'src/decorators/swagger.decorator';
|
||||
import { getFrontendUrl } from 'src/utils/getFrontendBaseUrl';
|
||||
|
||||
@ApiTags('Auth')
|
||||
@ApiHeaders([{ name: 'dadosfera-lang', enum: LanguageEnum, required: false }])
|
||||
@@ -60,7 +59,7 @@ import { getFrontendUrl } from 'src/utils/getFrontendBaseUrl';
|
||||
@Controller('auth')
|
||||
export class AuthController {
|
||||
logger: DadosferaLogger;
|
||||
frontendRedirectUrl: string;
|
||||
redirectUrl: string;
|
||||
|
||||
constructor(
|
||||
@Inject(DadosferaLogger)
|
||||
@@ -68,7 +67,17 @@ export class AuthController {
|
||||
private authClient: AuthClientService,
|
||||
) {
|
||||
this.logger = dadosferaLogger.logger;
|
||||
this.frontendRedirectUrl = getFrontendUrl('/auth/login').href;
|
||||
|
||||
switch (process.env.ENV) {
|
||||
case 'stg':
|
||||
this.redirectUrl = `https://app.${process.env.ENV}.dadosfera.ai/auth/login`;
|
||||
break;
|
||||
case 'prd':
|
||||
this.redirectUrl = `https://app.dadosfera.ai/auth/login`;
|
||||
break;
|
||||
default:
|
||||
this.redirectUrl = `http://localhost:4200/auth/login`;
|
||||
}
|
||||
}
|
||||
|
||||
@Post('sign-in')
|
||||
@@ -96,7 +105,7 @@ export class AuthController {
|
||||
customer_name,
|
||||
language,
|
||||
});
|
||||
this.logger.info(`metadata: ${metadata}`);
|
||||
|
||||
return this.authClient.refreshAccessToken({ refreshToken }, metadata);
|
||||
}
|
||||
|
||||
@@ -260,13 +269,7 @@ export class AuthController {
|
||||
@UseGuards(AuthGuard('google-login'))
|
||||
@Redirect()
|
||||
async googleOauthCallback(@Req() req) {
|
||||
const {
|
||||
url,
|
||||
email,
|
||||
token,
|
||||
refreshToken,
|
||||
language = 'pt-br',
|
||||
} = await this.callback(req);
|
||||
const { url, email, token, language = 'pt-br' } = await this.callback(req);
|
||||
if (url.searchParams.get('error')) {
|
||||
this.logger.error('/oauth/google - ERROR');
|
||||
return { url: url.href };
|
||||
@@ -276,7 +279,6 @@ export class AuthController {
|
||||
.oauthSignIn({
|
||||
username: email,
|
||||
token,
|
||||
refreshToken,
|
||||
})
|
||||
.then(({ session }) => {
|
||||
this.logger.info('/oauth/google - SUCESS');
|
||||
@@ -306,79 +308,18 @@ export class AuthController {
|
||||
return { url: url.href };
|
||||
}
|
||||
|
||||
@ApiInternalOnlyEndpoint()
|
||||
@Get('oauth/magalu-id')
|
||||
@UseGuards(AuthGuard('magalu-id-login'))
|
||||
magaluIdOauth() {
|
||||
this.logger.info('/oauth/magalu-id');
|
||||
return true;
|
||||
}
|
||||
|
||||
@ApiInternalOnlyEndpoint()
|
||||
@Get('oauth/magalu-id/callback')
|
||||
@UseGuards(AuthGuard('magalu-id-login'))
|
||||
@Redirect()
|
||||
async magaluIdOauthCallback(@Req() req) {
|
||||
const {
|
||||
url,
|
||||
email,
|
||||
token,
|
||||
refreshToken,
|
||||
language = 'pt-br',
|
||||
} = await this.callback(req, 'magalu-id');
|
||||
if (url.searchParams.get('error')) {
|
||||
this.logger.error('/oauth/magalu-id/callback - ERROR');
|
||||
this.logger.error(url.searchParams.get('error'));
|
||||
return { url: url.href };
|
||||
}
|
||||
|
||||
await this.authClient
|
||||
.oauthSignIn({
|
||||
username: email,
|
||||
token,
|
||||
refreshToken,
|
||||
})
|
||||
.then(({ session }) => {
|
||||
this.logger.info('/oauth/magalu-id/callback - SUCESS');
|
||||
url.searchParams.set('session', session);
|
||||
})
|
||||
.catch((err) => {
|
||||
this.logger.error('/oauth/magalu-id/callback - LOGIN ERROR');
|
||||
let error = OauthErrors.INVALID_CREDENTIALS[language].error;
|
||||
let error_description =
|
||||
OauthErrors.INVALID_CREDENTIALS[language].error_description;
|
||||
switch (err.details) {
|
||||
case ErrorCodes.USER.NOT_FOUND:
|
||||
error = OauthErrors.USER_NOT_FOUND[language].error;
|
||||
error_description =
|
||||
OauthErrors.USER_NOT_FOUND[language].error_description(email);
|
||||
break;
|
||||
case ErrorCodes.AUTH.UNAUTHORIZED:
|
||||
error = OauthErrors.INVALID_SESSION[language].error;
|
||||
error_description =
|
||||
OauthErrors.INVALID_SESSION[language].error_description;
|
||||
break;
|
||||
}
|
||||
url.searchParams.set('error', error);
|
||||
url.searchParams.set('error_description', error_description);
|
||||
return null;
|
||||
});
|
||||
return { url: url.href };
|
||||
}
|
||||
|
||||
async callback(req: Request, oauth_type?: 'google' | 'magalu-id') {
|
||||
async callback(req: Request) {
|
||||
const { error, state } = req.query;
|
||||
const { authInfo } = req;
|
||||
const url = new URL(this.frontendRedirectUrl);
|
||||
let email, token, refreshToken, error_title, error_description;
|
||||
const language: 'pt-br' | 'en-us' = 'pt-br';
|
||||
// let stateObject;
|
||||
// try {
|
||||
// stateObject = jwt.verify(state as string, process.env.JWT_PRIVATE_KEY);
|
||||
// } catch (error) {
|
||||
// console.log('error', error);
|
||||
// }
|
||||
// if (typeof stateObject != 'string') language = stateObject.language;
|
||||
const url = new URL(this.redirectUrl);
|
||||
let email, token, error_title, error_description;
|
||||
let language: 'pt-br' | 'en-us' = 'pt-br';
|
||||
|
||||
const stateObject = jwt.verify(
|
||||
state as string,
|
||||
process.env.JWT_PRIVATE_KEY,
|
||||
);
|
||||
if (typeof stateObject != 'string') language = stateObject.language;
|
||||
|
||||
if (error || !authInfo) {
|
||||
this.logger.error(error);
|
||||
@@ -389,16 +330,11 @@ export class AuthController {
|
||||
OauthErrors.INVALID_CREDENTIALS[language].error_description;
|
||||
if (error) error_description += ` - [${error}]`;
|
||||
} else {
|
||||
const { accessToken, refreshToken: rt } = authInfo as any;
|
||||
const { _json: userInfo = {} } = req.user as any;
|
||||
const { accessToken } = authInfo as any;
|
||||
const { _json: userInfo } = req.user as any;
|
||||
|
||||
email = userInfo.email;
|
||||
token = accessToken;
|
||||
refreshToken = rt;
|
||||
|
||||
if (oauth_type === 'magalu-id') {
|
||||
const jwtDecoded = jwt.decode(token, { json: true });
|
||||
email = jwtDecoded.email;
|
||||
}
|
||||
}
|
||||
|
||||
if (error_title) {
|
||||
@@ -406,6 +342,6 @@ export class AuthController {
|
||||
url.searchParams.set('error_description', error_description);
|
||||
}
|
||||
|
||||
return { token, refreshToken, email, url, language };
|
||||
return { token, email, url, language };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import { AuthClientService } from './auth.service';
|
||||
import { DucClient } from '../duc/client.config';
|
||||
import { GoogleLoginStrategy } from './passport-strategies/google-strategy';
|
||||
import { getOauthSecrets } from 'src/utils/OauthSecrets';
|
||||
import { MagaluIdStrategy } from './passport-strategies/magalu-id-strategy';
|
||||
const client = new DucClient();
|
||||
|
||||
@Module({
|
||||
@@ -18,7 +17,6 @@ const client = new DucClient();
|
||||
AuthClientService,
|
||||
DadosferaLogger,
|
||||
GoogleLoginStrategy,
|
||||
MagaluIdStrategy,
|
||||
{ provide: 'OAUTH_SECRETS', useValue: getOauthSecrets() },
|
||||
],
|
||||
exports: [AuthClientService],
|
||||
|
||||
@@ -17,7 +17,6 @@ import {
|
||||
AuthResetPasswordRequest,
|
||||
AuthVerifyResetPasswordCodeRequest,
|
||||
AuthConfirmResetPasswordRequest,
|
||||
AuthOauthSignInRequest,
|
||||
} from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
||||
import { DucClient } from '../duc/client.config';
|
||||
import { Metadata } from '@grpc/grpc-js';
|
||||
@@ -163,7 +162,10 @@ export class AuthClientService implements OnModuleInit {
|
||||
return lastValueFrom(this.authService.AuthGetSession({ session }));
|
||||
}
|
||||
|
||||
async oauthSignIn(data: AuthOauthSignInRequest) {
|
||||
return lastValueFrom(this.authService.AuthOauthSignIn(data));
|
||||
async oauthSignIn(data: { username: string; token: string }) {
|
||||
const { username, token } = data;
|
||||
return lastValueFrom(
|
||||
this.authService.AuthOauthSignIn({ token, username, refreshToken: '' }),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,6 +117,4 @@ export class AuthRefreshAccessTokenRes {
|
||||
permissions: string[];
|
||||
@ApiProperty()
|
||||
accessToken: string;
|
||||
@ApiProperty()
|
||||
refreshToken: string;
|
||||
}
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
import {
|
||||
Strategy as Oauth2Strategy,
|
||||
StrategyOptions,
|
||||
VerifyCallback,
|
||||
VerifyFunction,
|
||||
} from 'passport-oauth2';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { OauthSecrets } from 'src/utils/OauthSecrets';
|
||||
import { Request } from 'express';
|
||||
import jwt from 'jsonwebtoken';
|
||||
|
||||
@Injectable()
|
||||
export class MagaluIdStrategy extends PassportStrategy(
|
||||
Oauth2Strategy,
|
||||
'magalu-id-login',
|
||||
) {
|
||||
redirect_uri: string;
|
||||
constructor() {
|
||||
const options: StrategyOptions = {
|
||||
clientID: process.env.MAGALU_ID_CLIENT_ID,
|
||||
clientSecret: process.env.MAGALU_ID_CLIENT_SECRET,
|
||||
callbackURL: process.env.MAGALU_ID_CALLBACK_URL,
|
||||
scope: ['openid'],
|
||||
authorizationURL: 'https://id.magalu.com/login',
|
||||
tokenURL: 'https://id.magalu.com/oauth/token',
|
||||
};
|
||||
const verify: VerifyFunction = (
|
||||
accessToken: string,
|
||||
refreshToken: string,
|
||||
profile: any,
|
||||
verified: VerifyCallback,
|
||||
) => {
|
||||
return verified(null, profile, { accessToken, refreshToken });
|
||||
};
|
||||
|
||||
super(options, verify);
|
||||
}
|
||||
|
||||
// authenticate(req: Request, options: Record<string, any>) {
|
||||
// const language =
|
||||
// req.headers['dadosfera-lang'] || req.query.language || 'pt-br';
|
||||
// // options.state = jwt.sign({ language }, process.env.JWT_PRIVATE_KEY);
|
||||
// super.authenticate(req, options);
|
||||
// console.log('authenticate', JSON.stringify(options));
|
||||
// }
|
||||
}
|
||||
@@ -49,16 +49,10 @@ class CatalogService implements OnModuleInit {
|
||||
_getNimbusUrl(body) {
|
||||
const customer = body.info.customer.toLowerCase();
|
||||
|
||||
const cloud_environment = process.env.CLOUD_ENVIRONMENT || 'aws';
|
||||
|
||||
if (process.env.ENV === 'prd' && cloud_environment === 'aws') {
|
||||
if (process.env.ENV === 'prd') {
|
||||
return `https://nimbus-${customer}.dadosfera.ai`;
|
||||
}
|
||||
|
||||
if (process.env.ENV === 'prd' && cloud_environment === 'mgc') {
|
||||
return `https://nimbus-${customer}.dadosfera.com`;
|
||||
}
|
||||
|
||||
return `https://nimbus-${customer}.${process.env.ENV.replace(
|
||||
'local',
|
||||
'stg',
|
||||
|
||||
@@ -22,6 +22,7 @@ import { CustomersService } from './customers.service';
|
||||
import { CustomerDto, CustomerLinksResponse } from './dtos/customers';
|
||||
import { RequestUser, User } from 'src/decorators/user.decorator';
|
||||
import type { StringValue } from 'ms';
|
||||
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||
|
||||
@ApiInternalOnlyController()
|
||||
@ApiTags('Customers')
|
||||
@@ -71,4 +72,17 @@ export class CustomersController {
|
||||
};
|
||||
return this.customersService.generateToken(exp, data);
|
||||
}
|
||||
|
||||
@Get('monitoring-dashboard')
|
||||
@RequireAllPermissions(
|
||||
PERMISSIONS_GROUPS.CUSTOMER.permissions.MONITORING_DASHBOARD,
|
||||
)
|
||||
async getCustomerMonitoringDashboard(
|
||||
@User() user: RequestUser,
|
||||
): Promise<{ url: string }> {
|
||||
this.logger.info('getCustomerMonitoringDashboard');
|
||||
|
||||
const metadata = PackTheMetadata(user);
|
||||
return this.customersService.getMonitoringDashboardUrl(metadata);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,18 @@ import { ClientsModule } from '@nestjs/microservices';
|
||||
import { DucClient } from '../duc/client.config';
|
||||
import { CustomersController } from './customers.controller';
|
||||
import { CustomersService } from './customers.service';
|
||||
import { PipelinesClientConfiguration } from '../pipelinesV2/pipelines-client';
|
||||
|
||||
const client = new DucClient();
|
||||
const ducClient = new DucClient();
|
||||
const piFactoryClient = new PipelinesClientConfiguration();
|
||||
|
||||
@Module({
|
||||
imports: [ClientsModule.register([client.providerOptions])],
|
||||
imports: [
|
||||
ClientsModule.register([
|
||||
ducClient.providerOptions,
|
||||
piFactoryClient.providerOptions,
|
||||
]),
|
||||
],
|
||||
controllers: [CustomersController],
|
||||
providers: [CustomersService, DadosferaLogger],
|
||||
exports: [CustomersService],
|
||||
|
||||
@@ -22,20 +22,34 @@ import {
|
||||
} from '@aws-sdk/client-secrets-manager';
|
||||
import getEnv from 'src/utils/getEnv';
|
||||
import { logger } from 'elastic-apm-node';
|
||||
import {
|
||||
ReadService,
|
||||
ProtoServices as PipelineProtoServices,
|
||||
} from '@dadosfera/protospack-v2/dist/lib/PipelineV2';
|
||||
import { Metadata } from '@grpc/grpc-js';
|
||||
import { PipelinesClientConfiguration } from '../pipelinesV2/pipelines-client';
|
||||
|
||||
// This function will accept any string, which may result in a bug.
|
||||
@Injectable()
|
||||
export class CustomersService implements OnModuleInit {
|
||||
private customerService: CustomersProtoService;
|
||||
|
||||
private pipelineReadService: ReadService.PipelineV2ReadService;
|
||||
|
||||
constructor(
|
||||
@Inject(DucClient.name) private readonly grpcClient: ClientGrpc,
|
||||
@Inject(PipelinesClientConfiguration.name)
|
||||
private readonly pipelinesGrpcClient: ClientGrpc,
|
||||
) {}
|
||||
|
||||
onModuleInit() {
|
||||
this.customerService = this.grpcClient.getService<CustomersProtoService>(
|
||||
ProtoServices.CustomersProtoService,
|
||||
);
|
||||
this.pipelineReadService =
|
||||
this.pipelinesGrpcClient.getService<ReadService.PipelineV2ReadService>(
|
||||
PipelineProtoServices.PipelineV2ReadService,
|
||||
);
|
||||
}
|
||||
|
||||
async getLinks(customerId: string) {
|
||||
@@ -120,4 +134,21 @@ export class CustomersService implements OnModuleInit {
|
||||
// const decoded = jwt.decode(jwt_token, { complete: true });
|
||||
return jwt_token;
|
||||
}
|
||||
async getMonitoringDashboardUrl(metadata: Metadata) {
|
||||
logger.info('CustomersService - getMonitoringDashboardUrl');
|
||||
|
||||
const res = await lastValueFrom(
|
||||
this.pipelineReadService.PipelineV2GetDashboardUrl(
|
||||
{
|
||||
dashboard_id: '45',
|
||||
exp: '15m',
|
||||
metabase_customer_name: 'dadosferatech',
|
||||
},
|
||||
metadata,
|
||||
),
|
||||
);
|
||||
logger.info('Done');
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@ export class MixpanelController {
|
||||
@Post(':id')
|
||||
async trackEvent(@Param('id') id, @Body() body, @User() user: RequestUser) {
|
||||
delete body.info;
|
||||
//TODO: remove this when mixpanel track is working
|
||||
return true;
|
||||
const mixpanel = init(this.mixpanelToken);
|
||||
|
||||
const separator = user.username.includes('-') ? '-' : '.';
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
Patch,
|
||||
HttpException,
|
||||
BadRequestException,
|
||||
CacheTTL,
|
||||
} from '@nestjs/common';
|
||||
import {
|
||||
ApiCreatedResponse,
|
||||
@@ -86,6 +87,18 @@ export class PipelinesController {
|
||||
this.logger = dadosferaLogger.logger;
|
||||
}
|
||||
|
||||
@Get('monitoring-dashboard')
|
||||
async getMonitoringDashboard(@User() user: RequestUser) {
|
||||
this.logger.info('PipelinesController - getMonitoringDashboard', { user });
|
||||
|
||||
const metadata = PackTheMetadata(user);
|
||||
|
||||
const response =
|
||||
await this.pipelinesClientService.getMonitoringDashboardUrl(metadata);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiCreatedResponse({ type: IPipelineV2 })
|
||||
async create(
|
||||
|
||||
@@ -321,4 +321,22 @@ export class PipelinesService implements OnModuleInit {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async getMonitoringDashboardUrl(metadata: Metadata) {
|
||||
this.logger.info('PipelinesClientService - getMonitoringDashboardUrl');
|
||||
|
||||
const res = await lastValueFrom(
|
||||
this.pipelineReadService.PipelineV2GetDashboardUrl(
|
||||
{
|
||||
dashboard_id: '83',
|
||||
exp: '15m',
|
||||
metabase_customer_name: 'dadosferatech',
|
||||
},
|
||||
metadata,
|
||||
),
|
||||
);
|
||||
this.logger.info('Done');
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,9 +152,7 @@ export class UsersController {
|
||||
});
|
||||
this.logger.info('createUser', { user });
|
||||
this.userService.setLanguage(language);
|
||||
this.logger.info(`user: ${user}`);
|
||||
this.logger.info(`body: ${body}`);
|
||||
this.logger.info(`metadata: ${metadata}`);
|
||||
|
||||
return await this.userService.createUser(body, metadata);
|
||||
}
|
||||
|
||||
@@ -173,9 +171,7 @@ export class UsersController {
|
||||
access_token: user.access_token,
|
||||
language,
|
||||
});
|
||||
this.logger.info(`user: ${user}`);
|
||||
this.logger.info(`body: ${body}`);
|
||||
this.logger.info(`metadata: ${metadata}`);
|
||||
|
||||
return await this.userService.batchCreateUser(body, metadata);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import getEnv from './getEnv';
|
||||
|
||||
export function getFrontendUrl(path?: string): URL {
|
||||
const frontendUrl = new URL('https://app.dadosfera.ai');
|
||||
if (path) frontendUrl.pathname = path;
|
||||
|
||||
const env = getEnv();
|
||||
if (process.env.ENV === 'local') {
|
||||
frontendUrl.protocol = 'http';
|
||||
frontendUrl.host = 'localhost:4200';
|
||||
return frontendUrl;
|
||||
}
|
||||
|
||||
if (process.env.CLOUD_ENVIRONMENT === 'mgc')
|
||||
frontendUrl.host = 'app.dadosfera.com';
|
||||
|
||||
if (env !== 'prd')
|
||||
frontendUrl.host = frontendUrl.host.replace('app.', `app.${env}.`);
|
||||
return frontendUrl;
|
||||
}
|
||||
Reference in New Issue
Block a user