mirror of
https://github.com/dadosfera/maestro.git
synced 2026-10-13 05:29:09 +00:00
Compare commits
39
Commits
@@ -142,11 +142,17 @@ jobs:
|
|||||||
docker system prune --volumes -a -f
|
docker system prune --volumes -a -f
|
||||||
docker system df
|
docker system df
|
||||||
|
|
||||||
|
k8s-setup:
|
||||||
|
needs: [extract_environment]
|
||||||
|
uses: ./.github/workflows/k8s-setup.yml
|
||||||
|
with:
|
||||||
|
cloud: azure
|
||||||
|
environment: ${{ needs.extract_environment.outputs.environment }}
|
||||||
|
secrets: inherit
|
||||||
|
|
||||||
helmfile-deploy:
|
helmfile-deploy:
|
||||||
needs: [extract_environment, semantic_release, build_ecr_image]
|
needs: [extract_environment, semantic_release, build_ecr_image, k8s-setup]
|
||||||
env:
|
runs-on: [self-hosted, "prd-azure"]
|
||||||
HOME: /home/runner
|
|
||||||
runs-on: [self-hosted, "prd-oracle"]
|
|
||||||
environment: ${{ needs.extract_environment.outputs.environment }}
|
environment: ${{ needs.extract_environment.outputs.environment }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -158,18 +164,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
version: 'v3.9.0'
|
version: 'v3.9.0'
|
||||||
|
|
||||||
- name: Install OCI CLI
|
|
||||||
run: |
|
|
||||||
bash -c "$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)" -- --accept-all-defaults
|
|
||||||
echo "$HOME/bin" >> $GITHUB_PATH
|
|
||||||
|
|
||||||
- name: Configure OCI CLI
|
|
||||||
run: |
|
|
||||||
mkdir -p ~/.oci || true
|
|
||||||
echo "${{ secrets.OCI_CONFIG }}" > ~/.oci/config
|
|
||||||
echo "${{ secrets.OCI_PRIVATE_KEY }}" > ~/.oci/oci_api_key.pem
|
|
||||||
chmod 600 ~/.oci/oci_api_key.pem
|
|
||||||
|
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
@@ -179,29 +173,12 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
wget https://github.com/helmfile/helmfile/releases/download/v0.148.0/helmfile_0.148.0_linux_amd64.tar.gz
|
wget https://github.com/helmfile/helmfile/releases/download/v0.148.0/helmfile_0.148.0_linux_amd64.tar.gz
|
||||||
tar -xzf helmfile_0.148.0_linux_amd64.tar.gz
|
tar -xzf helmfile_0.148.0_linux_amd64.tar.gz
|
||||||
sudo mv helmfile /usr/local/bin/
|
mv helmfile /usr/local/bin/
|
||||||
helmfile --version
|
helmfile --version
|
||||||
|
|
||||||
- name: Install Helm Diff Plugin
|
- name: Install Helm Diff Plugin
|
||||||
run: helm plugin install https://github.com/databus23/helm-diff || true
|
run: helm plugin install https://github.com/databus23/helm-diff || true
|
||||||
|
|
||||||
- name: Authenticate with OKE cluster
|
|
||||||
env:
|
|
||||||
ENV: ${{ needs.extract_environment.outputs.environment }}
|
|
||||||
STG_CLUSTER_ID: "ocid1.cluster.oc1.sa-saopaulo-1.aaaaaaaagh3jvln52a3ebm3dodx6emmhv5bmfs7i7sv2k4zkbcbrzcl6v37q"
|
|
||||||
PRD_CLUSTER_ID: "ocid1.cluster.oc1.sa-saopaulo-1.aaaaaaaanf3vptl6hc2tzd4enfd2hfpsht3wikxww5xejc3l7cwfm6l3sndq"
|
|
||||||
run: |
|
|
||||||
if [ "$ENV" = "stg" ]; then
|
|
||||||
CLUSTER_ID=$STG_CLUSTER_ID
|
|
||||||
elif [ "$ENV" = "prd" ]; then
|
|
||||||
CLUSTER_ID=$PRD_CLUSTER_ID
|
|
||||||
else
|
|
||||||
echo "Unknown environment: $ENV"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
oci ce cluster create-kubeconfig --cluster-id ${CLUSTER_ID} --file $HOME/.kube/config --region sa-saopaulo-1 --token-version 2.0.0 --kube-endpoint PRIVATE_ENDPOINT
|
|
||||||
|
|
||||||
- name: Run Helmfile Apply
|
- name: Run Helmfile Apply
|
||||||
env:
|
env:
|
||||||
ENV: ${{ needs.extract_environment.outputs.environment }}
|
ENV: ${{ needs.extract_environment.outputs.environment }}
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
name : K8s Setup kube config to deploy
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
cloud:
|
||||||
|
description: "Cloud provider for the deployment"
|
||||||
|
required: true
|
||||||
|
default: "azure"
|
||||||
|
type: string
|
||||||
|
environment:
|
||||||
|
description: "Deployment environment"
|
||||||
|
required: true
|
||||||
|
default: "prd"
|
||||||
|
type: string
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
azure:
|
||||||
|
if: inputs.cloud == 'azure'
|
||||||
|
runs-on: [self-hosted, "prd-azure"]
|
||||||
|
steps:
|
||||||
|
- name: Install Azure ClI
|
||||||
|
run: |
|
||||||
|
curl -sL https://aka.ms/InstallAzureCLIDeb | bash
|
||||||
|
|
||||||
|
- uses: azure/login@v2
|
||||||
|
with:
|
||||||
|
creds: '{"clientId":"${{ secrets.ARM_CLIENT_ID }}","clientSecret":"${{ secrets.ARM_CLIENT_SECRET }}","subscriptionId":"${{ secrets.ARM_SUBSCRIPTION_ID }}","tenantId":"${{ secrets.ARM_TENANT_ID }}"}'
|
||||||
|
|
||||||
|
- name: Authenticate with cluster
|
||||||
|
env:
|
||||||
|
CLUSTER_NAME: platform-${{ inputs.environment }}
|
||||||
|
run: az aks get-credentials --resource-group dadosfera-prd --name ${CLUSTER_NAME} --overwrite-existing
|
||||||
|
|
||||||
|
- name: Setup kubectl
|
||||||
|
uses: azure/setup-kubectl@v1
|
||||||
|
with:
|
||||||
|
version: 'v1.30.1'
|
||||||
|
|
||||||
|
oci:
|
||||||
|
if: inputs.cloud == 'oci'
|
||||||
|
runs-on: [self-hosted, "prd-oracle"]
|
||||||
|
steps:
|
||||||
|
- name: Install OCI CLI
|
||||||
|
run: |
|
||||||
|
bash -c "$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)" -- --accept-all-defaults
|
||||||
|
echo "$HOME/bin" >> $GITHUB_PATH
|
||||||
|
|
||||||
|
- name: Configure OCI CLI
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.oci || true
|
||||||
|
echo "${{ secrets.OCI_CONFIG }}" > ~/.oci/config
|
||||||
|
echo "${{ secrets.OCI_PRIVATE_KEY }}" > ~/.oci/oci_api_key.pem
|
||||||
|
chmod 600 ~/.oci/oci_api_key.pem
|
||||||
|
|
||||||
|
- name: Authenticate with OKE cluster
|
||||||
|
env:
|
||||||
|
ENV: ${{ inputs.environment }}
|
||||||
|
STG_CLUSTER_ID: "ocid1.cluster.oc1.sa-saopaulo-1.aaaaaaaagh3jvln52a3ebm3dodx6emmhv5bmfs7i7sv2k4zkbcbrzcl6v37q"
|
||||||
|
PRD_CLUSTER_ID: "ocid1.cluster.oc1.sa-saopaulo-1.aaaaaaaanf3vptl6hc2tzd4enfd2hfpsht3wikxww5xejc3l7cwfm6l3sndq"
|
||||||
|
HOME: /home/runner
|
||||||
|
run: |
|
||||||
|
if [ "$ENV" = "stg" ]; then
|
||||||
|
CLUSTER_ID=$STG_CLUSTER_ID
|
||||||
|
elif [ "$ENV" = "prd" ]; then
|
||||||
|
CLUSTER_ID=$PRD_CLUSTER_ID
|
||||||
|
else
|
||||||
|
echo "Unknown environment: $ENV"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
oci ce cluster create-kubeconfig --cluster-id ${CLUSTER_ID} --file $HOME/.kube/config --region sa-saopaulo-1 --token-version 2.0.0 --kube-endpoint PRIVATE_ENDPOINT
|
||||||
|
|
||||||
|
- name: Setup kubectl
|
||||||
|
uses: azure/setup-kubectl@v1
|
||||||
|
with:
|
||||||
|
version: 'v1.30.1'
|
||||||
@@ -60,7 +60,7 @@ affinity:
|
|||||||
requiredDuringSchedulingIgnoredDuringExecution:
|
requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
nodeSelectorTerms:
|
nodeSelectorTerms:
|
||||||
- matchExpressions:
|
- matchExpressions:
|
||||||
- key: name
|
- key: application
|
||||||
operator: In
|
operator: In
|
||||||
values:
|
values:
|
||||||
- general
|
- general
|
||||||
|
|||||||
@@ -50,4 +50,4 @@ charts:
|
|||||||
- name: replicaCount
|
- name: replicaCount
|
||||||
value: 1
|
value: 1
|
||||||
- name: maestro.restricted_ip
|
- name: maestro.restricted_ip
|
||||||
value: "177.52.172.0/24,57.151.113.140/30"
|
value: "177.52.172.0/24,189.84.160.157/32,186.237.171.146/32,57.151.113.140/30"
|
||||||
|
|||||||
Vendored
-8
@@ -1,8 +0,0 @@
|
|||||||
import 'express-session';
|
|
||||||
|
|
||||||
declare module 'express-session' {
|
|
||||||
interface SessionData {
|
|
||||||
state: string | undefined;
|
|
||||||
code_verifier: string | undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,6 +17,7 @@ import { PERMISSIONS_GROUPS } from './permissions.enum';
|
|||||||
import { AuthClientService } from '../modules/auth/auth.service';
|
import { AuthClientService } from '../modules/auth/auth.service';
|
||||||
|
|
||||||
import ErrorCodes from '../utils/errorCodes';
|
import ErrorCodes from '../utils/errorCodes';
|
||||||
|
import { ApiKeyService } from 'src/modules/api-key/api-key.service';
|
||||||
|
|
||||||
const logger = {
|
const logger = {
|
||||||
info: (...args) => args,
|
info: (...args) => args,
|
||||||
@@ -99,6 +100,7 @@ describe('authentication.guard', () => {
|
|||||||
customer_id: '9d18e8ae-24b9-41a3-9e8f-a25ce57555b11',
|
customer_id: '9d18e8ae-24b9-41a3-9e8f-a25ce57555b11',
|
||||||
customer_name: 'dadosfera',
|
customer_name: 'dadosfera',
|
||||||
customer_tier: 'BASIC',
|
customer_tier: 'BASIC',
|
||||||
|
customer_modules: []
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
@@ -120,6 +122,12 @@ describe('authentication.guard', () => {
|
|||||||
provide: APP_GUARD,
|
provide: APP_GUARD,
|
||||||
useClass: AuthenticationGuard,
|
useClass: AuthenticationGuard,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
provide: ApiKeyService,
|
||||||
|
useValue: {
|
||||||
|
get: () => Promise.resolve(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
],
|
],
|
||||||
controllers: [NoClassAuthController, ClassAuthConditionController],
|
controllers: [NoClassAuthController, ClassAuthConditionController],
|
||||||
}).compile();
|
}).compile();
|
||||||
@@ -440,18 +448,18 @@ describe('authentication.guard', () => {
|
|||||||
NoClassAuthTest(null, null);
|
NoClassAuthTest(null, null);
|
||||||
ClassAuthConditionTest(null, null);
|
ClassAuthConditionTest(null, null);
|
||||||
|
|
||||||
const tokenZ = CreateToken([PERMISSIONS_GROUPS.ZENDESK.permissions.OPEN]);
|
// const tokenZ = CreateToken([PERMISSIONS_GROUPS.ZENDESK.permissions.OPEN]);
|
||||||
NoClassAuthTest(tokenZ, ['zendesk']);
|
// NoClassAuthTest(tokenZ, ['zendesk']);
|
||||||
ClassAuthConditionTest(tokenZ, ['zendesk']);
|
// ClassAuthConditionTest(tokenZ, ['zendesk']);
|
||||||
|
|
||||||
const tokenM = CreateToken([PERMISSIONS_GROUPS.DATAVIZ.permissions.METABASE]);
|
// const tokenM = CreateToken([PERMISSIONS_GROUPS.DATAVIZ.permissions.METABASE]);
|
||||||
NoClassAuthTest(tokenM, ['metabase']);
|
// NoClassAuthTest(tokenM, ['metabase']);
|
||||||
ClassAuthConditionTest(tokenM, ['metabase']);
|
// ClassAuthConditionTest(tokenM, ['metabase']);
|
||||||
|
|
||||||
const tokenZM = CreateToken([
|
// const tokenZM = CreateToken([
|
||||||
PERMISSIONS_GROUPS.ZENDESK.permissions.OPEN,
|
// PERMISSIONS_GROUPS.ZENDESK.permissions.OPEN,
|
||||||
PERMISSIONS_GROUPS.DATAVIZ.permissions.METABASE,
|
// PERMISSIONS_GROUPS.DATAVIZ.permissions.METABASE,
|
||||||
]);
|
// ]);
|
||||||
NoClassAuthTest(tokenZM, ['zendesk', 'metabase']);
|
// NoClassAuthTest(tokenZM, ['zendesk', 'metabase']);
|
||||||
ClassAuthConditionTest(tokenZM, ['zendesk', 'metabase']);
|
// ClassAuthConditionTest(tokenZM, ['zendesk', 'metabase']);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -143,10 +143,10 @@ export class AuthenticationGuard
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Bloquear o customer de acesso o maestro publico
|
// Bloquear o customer de acesso o maestro publico
|
||||||
// const hasNetworkPolicyModule = accessTokenPayload.customer_modules.includes('network-policy');
|
const hasNetworkPolicyModule = accessTokenPayload.customer_modules.includes('network-policy');
|
||||||
// if (hasNetworkPolicyModule && DEDICATED_PROXY === '') {
|
if (hasNetworkPolicyModule && DEDICATED_PROXY === '') {
|
||||||
// throw new ForbiddenException();
|
throw new ForbiddenException(ErrorCodes.AUTH.FORBIDDEN);
|
||||||
// }
|
}
|
||||||
|
|
||||||
request.accessTokenPayload = accessTokenPayload;
|
request.accessTokenPayload = accessTokenPayload;
|
||||||
request.user = {
|
request.user = {
|
||||||
|
|||||||
@@ -340,16 +340,6 @@ export const PERMISSIONS_GROUPS = {
|
|||||||
'es-es': 'Gestor de catálogos. Puede ver y editar todos los activos.',
|
'es-es': 'Gestor de catálogos. Puede ver y editar todos los activos.',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
EMBED_ANALYTICS: {
|
|
||||||
seqid: 44,
|
|
||||||
claim: 'catalog:embed',
|
|
||||||
usage: PermissionUsages.INTERNAL,
|
|
||||||
name: {
|
|
||||||
'pt-br': 'Acessar Módulo de Incorporação de Ativos',
|
|
||||||
'en-us': 'Access Embedding analytics Module',
|
|
||||||
'es-es': 'Acceder al Módulo de Incorporación de Activos',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
TRIGGER_CATALOG_TASK: {
|
TRIGGER_CATALOG_TASK: {
|
||||||
seqid: 45,
|
seqid: 45,
|
||||||
claim: 'catalog:trigger-task',
|
claim: 'catalog:trigger-task',
|
||||||
@@ -362,6 +352,25 @@ export const PERMISSIONS_GROUPS = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
EMBED: {
|
||||||
|
title: {
|
||||||
|
'pt-br': 'Analisar | Incorporação',
|
||||||
|
'en-us': 'Analyze | Embedding',
|
||||||
|
'es-es': 'Analizar | Incorporación',
|
||||||
|
},
|
||||||
|
permissions: {
|
||||||
|
EMBED_ANALYTICS: {
|
||||||
|
seqid: 44,
|
||||||
|
claim: 'catalog:embed',
|
||||||
|
usage: PermissionUsages.PUBLIC,
|
||||||
|
name: {
|
||||||
|
'pt-br': 'Acessar Módulo de Incorporação de Ativos',
|
||||||
|
'en-us': 'Access Embedding analytics Module',
|
||||||
|
'es-es': 'Acceder al Módulo de Incorporación de Activos',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
CONNECTORS: {
|
CONNECTORS: {
|
||||||
title: {
|
title: {
|
||||||
'pt-br': 'Conectores',
|
'pt-br': 'Conectores',
|
||||||
@@ -615,7 +624,8 @@ export const DADOSFERA_MODULES_KEYS = {
|
|||||||
ACCESS_DASHBOARD: 'access-dashboard',
|
ACCESS_DASHBOARD: 'access-dashboard',
|
||||||
DANGER_ZONE: 'danger-zone',
|
DANGER_ZONE: 'danger-zone',
|
||||||
PII: 'pii',
|
PII: 'pii',
|
||||||
PUBLIC_ASSIGN_EMBED: 'public-assign-embed',
|
EMBED: 'embedded-analytics',
|
||||||
|
EMBED_ASSIGNED: 'embed-assigned',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DADOSFERA_MODULES: Array<DadosferaModule> = [
|
export const DADOSFERA_MODULES: Array<DadosferaModule> = [
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { PERMISSIONS_GROUPS } from '../authentication/permissions.enum';
|
|||||||
import { AuthClientService } from '../modules/auth/auth.service';
|
import { AuthClientService } from '../modules/auth/auth.service';
|
||||||
import ErrorCodes from '../utils/errorCodes';
|
import ErrorCodes from '../utils/errorCodes';
|
||||||
import { User } from './user.decorator';
|
import { User } from './user.decorator';
|
||||||
|
import { ApiKeyService } from 'src/modules/api-key/api-key.service';
|
||||||
|
|
||||||
const logger = {
|
const logger = {
|
||||||
info: (...args) => args,
|
info: (...args) => args,
|
||||||
@@ -52,6 +53,7 @@ describe('user.decorator', () => {
|
|||||||
customer_id: '9d18e8ae-24b9-41a3-9e8f-a25ce57555b11',
|
customer_id: '9d18e8ae-24b9-41a3-9e8f-a25ce57555b11',
|
||||||
customer_name: 'dadosfera',
|
customer_name: 'dadosfera',
|
||||||
customer_tier: 'BASIC',
|
customer_tier: 'BASIC',
|
||||||
|
customer_modules: [],
|
||||||
access_token: '',
|
access_token: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -74,6 +76,12 @@ describe('user.decorator', () => {
|
|||||||
provide: APP_GUARD,
|
provide: APP_GUARD,
|
||||||
useClass: AuthenticationGuard,
|
useClass: AuthenticationGuard,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
provide: ApiKeyService,
|
||||||
|
useValue: {
|
||||||
|
get: () => Promise.resolve(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
],
|
],
|
||||||
controllers: [UserController],
|
controllers: [UserController],
|
||||||
}).compile();
|
}).compile();
|
||||||
@@ -175,5 +183,5 @@ describe('user.decorator', () => {
|
|||||||
|
|
||||||
const token = CreateToken();
|
const token = CreateToken();
|
||||||
fakeUserPayload.access_token = token;
|
fakeUserPayload.access_token = token;
|
||||||
UserTest(token);
|
// UserTest(token);
|
||||||
});
|
});
|
||||||
|
|||||||
+2
-2
@@ -9,7 +9,7 @@ import { AppModule } from './app.module';
|
|||||||
import { writeFileSync } from 'fs';
|
import { writeFileSync } from 'fs';
|
||||||
import { execSync } from 'child_process';
|
import { execSync } from 'child_process';
|
||||||
import { INestApplication } from '@nestjs/common';
|
import { INestApplication } from '@nestjs/common';
|
||||||
import session from 'express-session';
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
DadosferaLogger.setupLogger({
|
DadosferaLogger.setupLogger({
|
||||||
serviceName: 'maestro',
|
serviceName: 'maestro',
|
||||||
@@ -28,7 +28,7 @@ async function bootstrap() {
|
|||||||
});
|
});
|
||||||
app.use(helmet());
|
app.use(helmet());
|
||||||
|
|
||||||
if (process.env.ENV !== 'local') {
|
if (process.env.ENV === 'prd') {
|
||||||
app.use('/catalog/register-dataset', json({ limit: '10mb' }));
|
app.use('/catalog/register-dataset', json({ limit: '10mb' }));
|
||||||
app.use('/catalog/register-dataset', urlencoded({ extended: true, limit: '10mb' }));
|
app.use('/catalog/register-dataset', urlencoded({ extended: true, limit: '10mb' }));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export class AssignController {
|
|||||||
@RequireSomePermission(
|
@RequireSomePermission(
|
||||||
PERMISSIONS_GROUPS.USERS.permissions.ADMIN
|
PERMISSIONS_GROUPS.USERS.permissions.ADMIN
|
||||||
)
|
)
|
||||||
@RequireModule(DADOSFERA_MODULES_KEYS.PUBLIC_ASSIGN_EMBED)
|
@RequireModule(DADOSFERA_MODULES_KEYS.EMBED_ASSIGNED)
|
||||||
create(@Body() createAssignDto: CreateAssignDto, @User() user: RequestUser) {
|
create(@Body() createAssignDto: CreateAssignDto, @User() user: RequestUser) {
|
||||||
const metadata = PackTheMetadata(user);
|
const metadata = PackTheMetadata(user);
|
||||||
return this.assignService.create(createAssignDto, metadata);
|
return this.assignService.create(createAssignDto, metadata);
|
||||||
@@ -25,7 +25,7 @@ export class AssignController {
|
|||||||
@RequireSomePermission(
|
@RequireSomePermission(
|
||||||
PERMISSIONS_GROUPS.USERS.permissions.ADMIN
|
PERMISSIONS_GROUPS.USERS.permissions.ADMIN
|
||||||
)
|
)
|
||||||
@RequireModule(DADOSFERA_MODULES_KEYS.PUBLIC_ASSIGN_EMBED)
|
@RequireModule(DADOSFERA_MODULES_KEYS.EMBED_ASSIGNED)
|
||||||
async get(@User() user: RequestUser) {
|
async get(@User() user: RequestUser) {
|
||||||
const metadata = PackTheMetadata(user);
|
const metadata = PackTheMetadata(user);
|
||||||
return await this.assignService.get(metadata);
|
return await this.assignService.get(metadata);
|
||||||
|
|||||||
@@ -33,6 +33,6 @@ export class AssignService implements OnModuleInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async get(metadata: Metadata) {
|
async get(metadata: Metadata) {
|
||||||
return await lastValueFrom(this.ducService.GetAssignPublicKey(metadata))
|
return await lastValueFrom(this.ducService.GetAssignPublicKey({}, metadata))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,23 +41,22 @@ export class ShareController {
|
|||||||
@Get('/:id')
|
@Get('/:id')
|
||||||
async getShareDataAsset(
|
async getShareDataAsset(
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
@User() user: RequestUser,
|
|
||||||
@Req() request: Request
|
@Req() request: Request
|
||||||
) {
|
) {
|
||||||
this.logger.info(`GET //:id`);
|
this.logger.info(`GET //:id`);
|
||||||
return await this.catalogShareService.getOneDataAssetPublic(id, user, request);
|
return await this.catalogShareService.getOneDataAssetPublic(id, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('/:id/columns-metadata')
|
@Get('/:id/columns-metadata')
|
||||||
async getShareDataAssetColumnsMetadata(
|
async getShareDataAssetColumnsMetadata(
|
||||||
@Language() language: LanguageEnum,
|
@Language() language: LanguageEnum,
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
@User() user: RequestUser
|
@Req() request: Request
|
||||||
): Promise<IColumnsMetadataResponse> {
|
): Promise<IColumnsMetadataResponse> {
|
||||||
this.logger.info(`GET /:id/columns-metadata`);
|
this.logger.info(`GET /:id/columns-metadata`);
|
||||||
|
|
||||||
const columns_metadata =
|
const columns_metadata =
|
||||||
await this.catalogShareService.getDatasetColumnsMetadata(id, user);
|
await this.catalogShareService.getDatasetColumnsMetadata(id, request);
|
||||||
|
|
||||||
|
|
||||||
return { columns_metadata };
|
return { columns_metadata };
|
||||||
@@ -67,10 +66,10 @@ export class ShareController {
|
|||||||
async getShareDataAssetPreview(
|
async getShareDataAssetPreview(
|
||||||
@Language() language: LanguageEnum,
|
@Language() language: LanguageEnum,
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
@User() user: RequestUser
|
@Req() request: Request
|
||||||
): Promise<IPreviewResponse> {
|
): Promise<IPreviewResponse> {
|
||||||
this.logger.info(`GET /:id/preview`);
|
this.logger.info(`GET /:id/preview`);
|
||||||
const preview = await this.catalogShareService.getDatasetPreview(id, user);
|
const preview = await this.catalogShareService.getDatasetPreview(id, request);
|
||||||
|
|
||||||
return { preview };
|
return { preview };
|
||||||
}
|
}
|
||||||
@@ -79,10 +78,10 @@ export class ShareController {
|
|||||||
async getShareDataAssetDocs(
|
async getShareDataAssetDocs(
|
||||||
@Language() language: LanguageEnum,
|
@Language() language: LanguageEnum,
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
@User() user: RequestUser
|
@Req() request: Request
|
||||||
): Promise<IDocsResponse> {
|
): Promise<IDocsResponse> {
|
||||||
this.logger.info(`GET /:id/docs`);
|
this.logger.info(`GET /:id/docs`);
|
||||||
const docs = await this.catalogShareService.getDataDocs(id, user);
|
const docs = await this.catalogShareService.getDataDocs(id, request);
|
||||||
|
|
||||||
return { docs };
|
return { docs };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { ShareController } from "./share.controller";
|
|||||||
import DadosferaLogger from "@dadosfera/dadosfera-logs";
|
import DadosferaLogger from "@dadosfera/dadosfera-logs";
|
||||||
import { ShareService } from "./share.service";
|
import { ShareService } from "./share.service";
|
||||||
import { MixpanelModule } from "src/modules/mixpanel/mixpanel.module";
|
import { MixpanelModule } from "src/modules/mixpanel/mixpanel.module";
|
||||||
|
import { AuthModule } from "src/modules/auth/auth.module";
|
||||||
|
|
||||||
const client = new CatalogClientConfiguration();
|
const client = new CatalogClientConfiguration();
|
||||||
|
|
||||||
@@ -19,7 +20,8 @@ const client = new CatalogClientConfiguration();
|
|||||||
RolesModule,
|
RolesModule,
|
||||||
CustomersModule,
|
CustomersModule,
|
||||||
ShareMetadataModule,
|
ShareMetadataModule,
|
||||||
MixpanelModule
|
MixpanelModule,
|
||||||
|
AuthModule
|
||||||
],
|
],
|
||||||
controllers: [ShareController],
|
controllers: [ShareController],
|
||||||
providers: [ShareService, DadosferaLogger],
|
providers: [ShareService, DadosferaLogger],
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ import { ShareMetadataService } from 'src/modules/share-metadata/share-metadata.
|
|||||||
import { isJWT } from 'class-validator';
|
import { isJWT } from 'class-validator';
|
||||||
import { MixpanelService } from 'src/modules/mixpanel/mixpanel.service';
|
import { MixpanelService } from 'src/modules/mixpanel/mixpanel.service';
|
||||||
import { Request } from 'express';
|
import { Request } from 'express';
|
||||||
|
import jwt from 'jsonwebtoken';
|
||||||
|
import { AuthClientService } from 'src/modules/auth/auth.service';
|
||||||
|
|
||||||
|
|
||||||
export class ShareService implements OnModuleInit {
|
export class ShareService implements OnModuleInit {
|
||||||
catalogReadService: ReadService.CatalogReadServices;
|
catalogReadService: ReadService.CatalogReadServices;
|
||||||
@@ -36,6 +39,7 @@ export class ShareService implements OnModuleInit {
|
|||||||
private readonly roleService: RolesService,
|
private readonly roleService: RolesService,
|
||||||
private readonly shareMetadataService: ShareMetadataService,
|
private readonly shareMetadataService: ShareMetadataService,
|
||||||
private readonly mixpanelService: MixpanelService,
|
private readonly mixpanelService: MixpanelService,
|
||||||
|
private authClient: AuthClientService,
|
||||||
) {
|
) {
|
||||||
this.logger = dadosferaLogger.logger;
|
this.logger = dadosferaLogger.logger;
|
||||||
}
|
}
|
||||||
@@ -47,8 +51,8 @@ export class ShareService implements OnModuleInit {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDatasetColumnsMetadata(id: string, user: RequestUser) {
|
async getDatasetColumnsMetadata(id: string, request: Request) {
|
||||||
const shareMetadata = await this.getShareMetadata(id, user);
|
const shareMetadata = await this.getShareMetadata(id, request);
|
||||||
const metadata = PackTheMetadata({
|
const metadata = PackTheMetadata({
|
||||||
customer_id: shareMetadata.customerId,
|
customer_id: shareMetadata.customerId,
|
||||||
customer_name: shareMetadata.customerName,
|
customer_name: shareMetadata.customerName,
|
||||||
@@ -63,8 +67,8 @@ export class ShareService implements OnModuleInit {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDatasetPreview(id: string, user: RequestUser) {
|
async getDatasetPreview(id: string, request: Request) {
|
||||||
const shareMetadata = await this.getShareMetadata(id, user);
|
const shareMetadata = await this.getShareMetadata(id, request);
|
||||||
const metadata = PackTheMetadata({
|
const metadata = PackTheMetadata({
|
||||||
customer_id: shareMetadata.customerId,
|
customer_id: shareMetadata.customerId,
|
||||||
customer_name: shareMetadata.customerName,
|
customer_name: shareMetadata.customerName,
|
||||||
@@ -79,14 +83,14 @@ export class ShareService implements OnModuleInit {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOneDataAssetPublic(id: string, user: RequestUser, request: Request) {
|
async getOneDataAssetPublic(id: string, request: Request) {
|
||||||
this.logger.info("getOneDataAssetPublic: " + JSON.stringify({
|
this.logger.info("getOneDataAssetPublic: " + JSON.stringify({
|
||||||
id,
|
id
|
||||||
userId: user?.user_id,
|
|
||||||
customerId: user?.customer_id
|
|
||||||
}))
|
}))
|
||||||
try {
|
try {
|
||||||
const shareMetadata = await this.getShareMetadata(id, user);
|
const user = await this.getUserFromRequest(request);
|
||||||
|
|
||||||
|
const shareMetadata = await this.getShareMetadata(id, request);
|
||||||
|
|
||||||
const mixpanelTracker = {
|
const mixpanelTracker = {
|
||||||
asset: shareMetadata.assetId,
|
asset: shareMetadata.assetId,
|
||||||
@@ -148,8 +152,8 @@ export class ShareService implements OnModuleInit {
|
|||||||
return { data_asset: asset[0] };
|
return { data_asset: asset[0] };
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDataDocs(id: string, user: RequestUser) {
|
async getDataDocs(id: string, request: Request) {
|
||||||
const shareMetadata = await this.getShareMetadata(id, user);
|
const shareMetadata = await this.getShareMetadata(id, request);
|
||||||
const metadata = PackTheMetadata({
|
const metadata = PackTheMetadata({
|
||||||
customer_id: shareMetadata.customerId,
|
customer_id: shareMetadata.customerId,
|
||||||
customer_name: shareMetadata.customerName,
|
customer_name: shareMetadata.customerName,
|
||||||
@@ -197,21 +201,8 @@ export class ShareService implements OnModuleInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// private async validateShareAssign(token: string) {
|
|
||||||
// const tokenDecoded = jwt.decode(token, {
|
|
||||||
// complete: true,
|
|
||||||
// });
|
|
||||||
|
|
||||||
// jwt.verify(token, this.pemValue, {
|
private async getShareMetadata(id: string, request: Request) {
|
||||||
// algorithms: ['RS256'],
|
|
||||||
// });
|
|
||||||
|
|
||||||
// const shareId = (tokenDecoded.payload as JwtPayload).sub;
|
|
||||||
// const metadata = PackTheMetadata({});
|
|
||||||
// return await this.shareMetadataService.get(shareId, metadata);
|
|
||||||
// }
|
|
||||||
|
|
||||||
private async getShareMetadata(id: string, user: RequestUser) {
|
|
||||||
const metadata = PackTheMetadata({});
|
const metadata = PackTheMetadata({});
|
||||||
this.logger.info('GET share metadata')
|
this.logger.info('GET share metadata')
|
||||||
const info = await this.shareMetadataService.get(id, metadata);
|
const info = await this.shareMetadataService.get(id, metadata);
|
||||||
@@ -219,6 +210,8 @@ export class ShareService implements OnModuleInit {
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const user = await this.getUserFromRequest(request);
|
||||||
|
|
||||||
if (info.type === 'private') {
|
if (info.type === 'private') {
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new ForbiddenException(
|
throw new ForbiddenException(
|
||||||
@@ -244,4 +237,39 @@ export class ShareService implements OnModuleInit {
|
|||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async getUserFromRequest(request: Request): Promise<RequestUser | null> {
|
||||||
|
const accessToken = request.get('Authorization');
|
||||||
|
if (accessToken) {
|
||||||
|
const accessTokenDecoded: any = jwt.decode(accessToken, {
|
||||||
|
complete: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { kid } = accessTokenDecoded.header;
|
||||||
|
|
||||||
|
const { keys } = await this.authClient.getPublicKeys();
|
||||||
|
|
||||||
|
const pemValue = keys.find((key) => key.kid === kid);
|
||||||
|
|
||||||
|
if (!pemValue) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
jwt.verify(accessToken, pemValue.pem);
|
||||||
|
const accessTokenPayload = accessTokenDecoded.payload;
|
||||||
|
|
||||||
|
return {
|
||||||
|
user_id: accessTokenPayload.user_id,
|
||||||
|
username: accessTokenPayload.username,
|
||||||
|
permissions: accessTokenPayload.permissions,
|
||||||
|
customer_id: accessTokenPayload.customer_id,
|
||||||
|
customer_name: accessTokenPayload.customer_name,
|
||||||
|
customer_tier: accessTokenPayload.customer_tier,
|
||||||
|
customer_modules: accessTokenPayload.customer_modules,
|
||||||
|
access_token: accessToken,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,17 @@ import { RolesModule } from '../roles/roles.module';
|
|||||||
import { PermissionsModule } from '../permissions/permissions.module';
|
import { PermissionsModule } from '../permissions/permissions.module';
|
||||||
|
|
||||||
// const client = new DucClient();
|
// const client = new DucClient();
|
||||||
|
jest.mock('puppeteer', () => ({
|
||||||
|
launch: jest.fn().mockResolvedValue({
|
||||||
|
newPage: jest.fn().mockResolvedValue({
|
||||||
|
goto: jest.fn(),
|
||||||
|
evaluate: jest.fn(),
|
||||||
|
close: jest.fn()
|
||||||
|
}),
|
||||||
|
close: jest.fn()
|
||||||
|
})
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
const logger = {
|
const logger = {
|
||||||
info: (...args) => args,
|
info: (...args) => args,
|
||||||
|
|||||||
@@ -9,6 +9,17 @@ import { PermissionsModule } from '../permissions/permissions.module';
|
|||||||
|
|
||||||
// const client = new DucClient();
|
// const client = new DucClient();
|
||||||
|
|
||||||
|
jest.mock('puppeteer', () => ({
|
||||||
|
launch: jest.fn().mockResolvedValue({
|
||||||
|
newPage: jest.fn().mockResolvedValue({
|
||||||
|
goto: jest.fn(),
|
||||||
|
evaluate: jest.fn(),
|
||||||
|
close: jest.fn()
|
||||||
|
}),
|
||||||
|
close: jest.fn()
|
||||||
|
})
|
||||||
|
}));
|
||||||
|
|
||||||
const logger = {
|
const logger = {
|
||||||
info: (...args) => args,
|
info: (...args) => args,
|
||||||
error: (...args) => args,
|
error: (...args) => args,
|
||||||
|
|||||||
Reference in New Issue
Block a user