mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-20 20:39:08 +00:00
Compare commits
52
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e06e7498db | ||
|
|
922a34a393 | ||
|
|
a795f543f6 | ||
|
|
15b5c49fb2 | ||
|
|
1730ec2753 | ||
|
|
dc4609cbc5 | ||
|
|
e1b0e88bd8 | ||
|
|
cef1184908 | ||
|
|
31dda867d1 | ||
|
|
b89909ad66 | ||
|
|
2bb280e8de | ||
|
|
00cbadbb45 | ||
|
|
47ad527d38 | ||
|
|
51044a23b3 | ||
|
|
bb29d126c1 | ||
|
|
9d0f449eeb | ||
|
|
0eafa67e6f | ||
|
|
c3937472ec | ||
|
|
84d64424ca | ||
|
|
f0bfc5c94b | ||
|
|
ad86a6a698 | ||
|
|
af3b11ad54 | ||
|
|
d54f381998 | ||
|
|
3fd586753e | ||
|
|
9b3894f9e4 | ||
|
|
4a5f8f679a | ||
|
|
a444f5e5ec | ||
|
|
0d30c1cf83 | ||
|
|
15860519e1 | ||
|
|
cffda86eab | ||
|
|
a93fbfbbd9 | ||
|
|
e1cfc6e1a8 | ||
|
|
1e63df6536 | ||
|
|
8eb7fd0169 | ||
|
|
f8c6a8b747 | ||
|
|
8a9d6c2f9c | ||
|
|
bcb2a0b7cb | ||
|
|
2e181e70af | ||
|
|
ef615adb8e | ||
|
|
e03900811b | ||
|
|
5bc5fb0977 | ||
|
|
011032e3d4 | ||
|
|
17363e74f4 | ||
|
|
63efff6adf | ||
|
|
b5f569e522 | ||
|
|
5c77577992 | ||
|
|
4b9e113185 | ||
|
|
c70abfc826 | ||
|
|
db2c7d6c02 | ||
|
|
0a99ce1aa4 | ||
|
|
39c66f030a | ||
|
|
1223e21ac4 |
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
FROM node:20-alpine AS base_image
|
FROM node:20-alpine AS base_image
|
||||||
RUN npm install -g npm@latest
|
RUN npm install -g npm@10.8.2
|
||||||
|
|
||||||
FROM base_image AS build_base
|
FROM base_image AS build_base
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|||||||
@@ -111,6 +111,8 @@ spec:
|
|||||||
value: "{{ .Values.maestro.redis_tls }}"
|
value: "{{ .Values.maestro.redis_tls }}"
|
||||||
- name: PLATFORM_API_URL
|
- name: PLATFORM_API_URL
|
||||||
value: {{ .Values.maestro.platform_api_url }}
|
value: {{ .Values.maestro.platform_api_url }}
|
||||||
|
- name: CONNECTIONS_API_URL
|
||||||
|
value: {{ .Values.maestro.connections_api_url | default "" | quote }}
|
||||||
- name: STORAGE_EXPLORER_API_URL
|
- name: STORAGE_EXPLORER_API_URL
|
||||||
value: {{ .Values.maestro.storage_explorer_api_url | quote }}
|
value: {{ .Values.maestro.storage_explorer_api_url | quote }}
|
||||||
- name: FIREBASE_BASE_URL
|
- name: FIREBASE_BASE_URL
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ maestro:
|
|||||||
cookie_secret: "ff7bc13823edb2ae50d248e5780bddc9d4b31c36"
|
cookie_secret: "ff7bc13823edb2ae50d248e5780bddc9d4b31c36"
|
||||||
redis_database: "1"
|
redis_database: "1"
|
||||||
platform_api_url: https://xs2hkhq07k.execute-api.us-east-1.amazonaws.com
|
platform_api_url: https://xs2hkhq07k.execute-api.us-east-1.amazonaws.com
|
||||||
|
connections_api_url: https://iy40eans64.execute-api.us-east-1.amazonaws.com
|
||||||
storage_explorer_api_url: "http://storage-explorer-{customer}.data-apps.svc.cluster.local:8000/api"
|
storage_explorer_api_url: "http://storage-explorer-{customer}.data-apps.svc.cluster.local:8000/api"
|
||||||
firebase_base_url: https://feature-flag-25bf6-default-rtdb.firebaseio.com/stg
|
firebase_base_url: https://feature-flag-25bf6-default-rtdb.firebaseio.com/stg
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,759 @@
|
|||||||
|
# Orchest Module Identity Implementation Plan
|
||||||
|
|
||||||
|
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||||
|
|
||||||
|
**Goal:** Add a Maestro endpoint `GET /auth/module-identity` that translates a Dadosfera session into the `X-Auth-*` identity headers Orchest's RBAC trusts, gating on a module permission and (for service ingresses) authorizing per-project against orchest-api.
|
||||||
|
|
||||||
|
**Architecture:** One route serves two nginx `auth_request` callers, keyed on whether the ingress annotation carries authz query params. Phase 1: authenticate the `ddf-auth` cookie via Maestro's existing JWKS verify, gate on the module permission (seqid 31), emit identity headers, set `X-Auth-Roles: admin` for Super Admin (seqid 34). Phase 2: when the annotation carries `permission`+`project_uuid`, additionally call the calling tenant's orchest-api `/api/authz/check` (host derived from the JWT's `customer_name` + the `orchest-{module}-{customer_name}` namespace convention) and relay allow/deny, fail-closed. A small orchest-side change flips `service_access_auth_url` to build a scoped URL in Maestro mode.
|
||||||
|
|
||||||
|
**Tech Stack:** NestJS (controllers/providers, Jest via `Test.createTestingModule`), Express `Request`/`Response`, `jsonwebtoken`, plain `process.env` config. Orchest side: Python (`lib/python/orchest-internals`).
|
||||||
|
|
||||||
|
**Spec:** `dbt-to-orchest` repo — `docs/superpowers/specs/2026-08-20-maestro-module-identity-design.md` (the Maestro repo does not hold the spec; executors read it there).
|
||||||
|
|
||||||
|
## Global Constraints
|
||||||
|
|
||||||
|
- **Config via `process.env`** — Maestro reads env directly (no ConfigService). Pattern: `const X = process.env.X || '<default>'` (see `authentication.guard.ts:140`).
|
||||||
|
- **Config values (verbatim):** `ORCHEST_MODULE_PERMISSION_SEQID` default `31` (Intelligence/"Orchest Module", `intelligence:open`); `ORCHEST_ADMIN_PERMISSION_SEQIDS` default `34` (Super Admin, `users:admin`), a comma-separated list parsed to numbers; `ORCHEST_NAMESPACE_MODULE` default `intelli` (∈ `intelli`|`process`).
|
||||||
|
- **Token source is the `ddf-auth` COOKIE**, not the `Authorization` header (the nginx `auth_request` subrequest carries the browser cookie). Never read `Authorization` in this route.
|
||||||
|
- **`permission`/`project_uuid` come from `request.query`** (the orchest-api-authored annotation), never from the end-user URL. The end-user URL is `X-Original-URI` and MUST NOT be read for authz.
|
||||||
|
- **Fail-closed:** any error reaching orchest-api, or an unexpected status, → deny (never allow).
|
||||||
|
- **`/auth/me` is not modified.** Other services depend on it.
|
||||||
|
- **No orchest-api code change.** `/api/authz/check`, the `AuthCustom/AuthUrl` ingress path, and RBAC already exist.
|
||||||
|
- **Namespace pattern:** `orchest-{module}-{customer_name}`. `dadosferademo2` is the one exception (being removed) — explicitly unsupported, no special-casing.
|
||||||
|
- Branch: `feat/orchest-module-identity` (off `origin/beta`), already created.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## File Structure
|
||||||
|
|
||||||
|
**Maestro (`feat/orchest-module-identity` off beta):**
|
||||||
|
- Modify `src/modules/auth/auth.service.ts` — make `validateJwtToken` public (or add a public `verifyAccessToken` wrapper); add `authorizeOrchestServiceAccess(...)` helper (Phase 2).
|
||||||
|
- Modify `src/modules/auth/auth.controller.ts` — add the `GET /auth/module-identity` route.
|
||||||
|
- Create `src/modules/auth/orchest-identity.ts` — pure, testable helpers: `parseAdminSeqids(env)`, `isModuleAllowed(perms, gateSeqid)`, `isAdmin(perms, adminSeqids)`, `tenantOrchestApiHost(customerName, module)`, `isAllowedOrchestApiHost(host)`. Keeps set-membership/string logic out of the controller so it unit-tests without HTTP.
|
||||||
|
- Create `src/modules/auth/orchest-identity.spec.ts` — unit tests for the helpers.
|
||||||
|
- Create `src/modules/auth/module-identity.controller.spec.ts` — controller tests (mock `AuthClientService`, fake `Request`/`Response`).
|
||||||
|
|
||||||
|
**dbt-to-orchest repo (Phase 2 orchest-side, separate branch there):**
|
||||||
|
- Modify `lib/python/orchest-internals/_orchest/internals/utils.py:19-51` — `service_access_auth_url` Maestro branch.
|
||||||
|
- Modify `lib/python/orchest-internals/tests/…` (or wherever `utils` is tested) — add the Maestro-mode case.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## PHASE 1 — Identity (webserver ingress)
|
||||||
|
|
||||||
|
### Task 1: Pure helpers for permission mapping
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Create: `src/modules/auth/orchest-identity.ts`
|
||||||
|
- Test: `src/modules/auth/orchest-identity.spec.ts`
|
||||||
|
|
||||||
|
**Interfaces:**
|
||||||
|
- Consumes: nothing.
|
||||||
|
- Produces:
|
||||||
|
- `parseAdminSeqids(raw: string | undefined): number[]` — parse `"34"` / `"34,40"` → `[34]` / `[34,40]`; empty/undefined → `[34]`.
|
||||||
|
- `moduleGateSeqid(raw: string | undefined): number` — parse `ORCHEST_MODULE_PERMISSION_SEQID` → number; default `31`.
|
||||||
|
- `isModuleAllowed(perms: number[], gateSeqid: number): boolean`
|
||||||
|
- `isAdmin(perms: number[], adminSeqids: number[]): boolean`
|
||||||
|
|
||||||
|
- [ ] **Step 1: Write the failing test**
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import {
|
||||||
|
parseAdminSeqids,
|
||||||
|
moduleGateSeqid,
|
||||||
|
isModuleAllowed,
|
||||||
|
isAdmin,
|
||||||
|
} from './orchest-identity';
|
||||||
|
|
||||||
|
describe('orchest-identity mapping', () => {
|
||||||
|
it('parseAdminSeqids: default, single, list, whitespace', () => {
|
||||||
|
expect(parseAdminSeqids(undefined)).toEqual([34]);
|
||||||
|
expect(parseAdminSeqids('')).toEqual([34]);
|
||||||
|
expect(parseAdminSeqids('34')).toEqual([34]);
|
||||||
|
expect(parseAdminSeqids('34,40')).toEqual([34, 40]);
|
||||||
|
expect(parseAdminSeqids(' 34 , 40 ')).toEqual([34, 40]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('moduleGateSeqid: default and override', () => {
|
||||||
|
expect(moduleGateSeqid(undefined)).toBe(31);
|
||||||
|
expect(moduleGateSeqid('43')).toBe(43);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('isModuleAllowed', () => {
|
||||||
|
expect(isModuleAllowed([31, 5], 31)).toBe(true);
|
||||||
|
expect(isModuleAllowed([5, 7], 31)).toBe(false);
|
||||||
|
expect(isModuleAllowed([], 31)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('isAdmin: intersection', () => {
|
||||||
|
expect(isAdmin([31, 34], [34])).toBe(true);
|
||||||
|
expect(isAdmin([31], [34])).toBe(false);
|
||||||
|
expect(isAdmin([99], [34, 99])).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 2: Run test to verify it fails**
|
||||||
|
|
||||||
|
Run: `npx jest src/modules/auth/orchest-identity.spec.ts -t 'orchest-identity mapping'`
|
||||||
|
Expected: FAIL — `Cannot find module './orchest-identity'`.
|
||||||
|
|
||||||
|
- [ ] **Step 3: Write minimal implementation**
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// src/modules/auth/orchest-identity.ts
|
||||||
|
export function parseAdminSeqids(raw: string | undefined): number[] {
|
||||||
|
if (!raw || !raw.trim()) return [34];
|
||||||
|
return raw
|
||||||
|
.split(',')
|
||||||
|
.map((s) => Number(s.trim()))
|
||||||
|
.filter((n) => Number.isInteger(n));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function moduleGateSeqid(raw: string | undefined): number {
|
||||||
|
const n = Number(raw);
|
||||||
|
return Number.isInteger(n) && n > 0 ? n : 31;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isModuleAllowed(perms: number[], gateSeqid: number): boolean {
|
||||||
|
return Array.isArray(perms) && perms.includes(gateSeqid);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isAdmin(perms: number[], adminSeqids: number[]): boolean {
|
||||||
|
return (
|
||||||
|
Array.isArray(perms) && perms.some((p) => adminSeqids.includes(p))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 4: Run test to verify it passes**
|
||||||
|
|
||||||
|
Run: `npx jest src/modules/auth/orchest-identity.spec.ts -t 'orchest-identity mapping'`
|
||||||
|
Expected: PASS.
|
||||||
|
|
||||||
|
- [ ] **Step 5: Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add src/modules/auth/orchest-identity.ts src/modules/auth/orchest-identity.spec.ts
|
||||||
|
git commit -m "feat(orchest-identity): permission-mapping helpers"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 2: Expose JWKS verify on AuthClientService
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `src/modules/auth/auth.service.ts:413-425`
|
||||||
|
|
||||||
|
**Interfaces:**
|
||||||
|
- Consumes: existing `getPublicKeys()`.
|
||||||
|
- Produces: `public async verifyAccessToken(token: string): Promise<any>` — verifies the JWT against JWKS and returns its payload; throws on missing/invalid token or unknown `kid`. (Rename of the existing private `validateJwtToken`, kept callable by `validateUserSession`.)
|
||||||
|
|
||||||
|
- [ ] **Step 1: Make the method public and rename**
|
||||||
|
|
||||||
|
The method already does exactly the needed decode+verify. Rename `validateJwtToken` → `verifyAccessToken`, change `private` → `public`, and update its one caller.
|
||||||
|
|
||||||
|
In `src/modules/auth/auth.service.ts`, change line 413:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
public async verifyAccessToken(token: string) {
|
||||||
|
const decoded: any = token && jwt.decode(token, { complete: true });
|
||||||
|
if (!decoded) throw new Error('Invalid token');
|
||||||
|
|
||||||
|
const { kid } = decoded.header;
|
||||||
|
const { keys } = await this.getPublicKeys();
|
||||||
|
const pemValue = keys.find((k) => k.kid === kid)?.pem;
|
||||||
|
if (!pemValue) throw new Error('Public key not found');
|
||||||
|
jwt.verify(token, pemValue);
|
||||||
|
|
||||||
|
return decoded.payload;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
And update the caller in `validateUserSession` (was line 310):
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const payload = await this.verifyAccessToken(accessToken);
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 2: Verify existing suite still compiles/passes for auth.service**
|
||||||
|
|
||||||
|
Run: `npx jest src/modules/auth`
|
||||||
|
Expected: PASS (no behavior change; `/auth/me` path unaffected). If there is no existing auth.service spec, run `npx tsc --noEmit` to confirm the rename compiles.
|
||||||
|
|
||||||
|
- [ ] **Step 3: Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add src/modules/auth/auth.service.ts
|
||||||
|
git commit -m "refactor(auth): expose verifyAccessToken (was private validateJwtToken)"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 3: `GET /auth/module-identity` — identity + module gate
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `src/modules/auth/auth.controller.ts` (add route beside `getMe`, ~after line 533)
|
||||||
|
- Test: `src/modules/auth/module-identity.controller.spec.ts`
|
||||||
|
|
||||||
|
**Interfaces:**
|
||||||
|
- Consumes: `AuthClientService.verifyAccessToken` (Task 2); `parseAdminSeqids`/`moduleGateSeqid`/`isModuleAllowed`/`isAdmin` (Task 1).
|
||||||
|
- Produces: route `GET /auth/module-identity`. On 200 sets response headers `X-Auth-User`, `X-Auth-Username`, and (admin only) `X-Auth-Roles: admin`; empty body. 401 (no/invalid cookie), 403 (lacks module gate).
|
||||||
|
|
||||||
|
- [ ] **Step 1: Write the failing test**
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { Test } from '@nestjs/testing';
|
||||||
|
import { AuthController } from './auth.controller';
|
||||||
|
import { AuthClientService } from './auth.service';
|
||||||
|
|
||||||
|
function res() {
|
||||||
|
const headers: Record<string, string> = {};
|
||||||
|
const r: any = {
|
||||||
|
_status: 0,
|
||||||
|
_sent: undefined,
|
||||||
|
set: (k: string, v: string) => { headers[k] = v; return r; },
|
||||||
|
status: (c: number) => { r._status = c; return r; },
|
||||||
|
send: (b?: any) => { r._sent = b ?? ''; return r; },
|
||||||
|
json: (b?: any) => { r._sent = b; return r; },
|
||||||
|
_headers: headers,
|
||||||
|
};
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
function req(cookie?: string, query: Record<string, string> = {}) {
|
||||||
|
return { cookies: cookie ? { 'ddf-auth': cookie } : {}, query } as any;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('GET /auth/module-identity — identity', () => {
|
||||||
|
let controller: AuthController;
|
||||||
|
const auth = { verifyAccessToken: jest.fn() } as unknown as AuthClientService;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
jest.resetAllMocks();
|
||||||
|
process.env.ORCHEST_MODULE_PERMISSION_SEQID = '31';
|
||||||
|
process.env.ORCHEST_ADMIN_PERMISSION_SEQIDS = '34';
|
||||||
|
const mod = await Test.createTestingModule({
|
||||||
|
controllers: [AuthController],
|
||||||
|
providers: [{ provide: AuthClientService, useValue: auth }],
|
||||||
|
})
|
||||||
|
// Any other providers AuthController injects must be stubbed here the
|
||||||
|
// same way (ApiKeyService, DadosferaLogger, etc.). Add them as the
|
||||||
|
// compile step reports missing providers.
|
||||||
|
.compile();
|
||||||
|
controller = mod.get(AuthController);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('no cookie → 401', async () => {
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req(undefined), r);
|
||||||
|
expect(r._status).toBe(401);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('valid + module + admin → 200 with X-Auth-Roles: admin', async () => {
|
||||||
|
(auth.verifyAccessToken as jest.Mock).mockResolvedValue({
|
||||||
|
user_id: 'u-1', username: 'alice', permissions: [31, 34],
|
||||||
|
});
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok'), r);
|
||||||
|
expect(r._status).toBe(200);
|
||||||
|
expect(r._headers['X-Auth-User']).toBe('u-1');
|
||||||
|
expect(r._headers['X-Auth-Username']).toBe('alice');
|
||||||
|
expect(r._headers['X-Auth-Roles']).toBe('admin');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('valid + module, not admin → 200, no X-Auth-Roles', async () => {
|
||||||
|
(auth.verifyAccessToken as jest.Mock).mockResolvedValue({
|
||||||
|
user_id: 'u-2', username: 'bob', permissions: [31],
|
||||||
|
});
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok'), r);
|
||||||
|
expect(r._status).toBe(200);
|
||||||
|
expect(r._headers['X-Auth-Roles']).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('valid, lacks module → 403', async () => {
|
||||||
|
(auth.verifyAccessToken as jest.Mock).mockResolvedValue({
|
||||||
|
user_id: 'u-3', username: 'carol', permissions: [5],
|
||||||
|
});
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok'), r);
|
||||||
|
expect(r._status).toBe(403);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('verify throws (expired/bad) → 401', async () => {
|
||||||
|
(auth.verifyAccessToken as jest.Mock).mockRejectedValue(new Error('bad'));
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok'), r);
|
||||||
|
expect(r._status).toBe(401);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('admin seqids extended by config → 200 admin', async () => {
|
||||||
|
process.env.ORCHEST_ADMIN_PERMISSION_SEQIDS = '34,99';
|
||||||
|
(auth.verifyAccessToken as jest.Mock).mockResolvedValue({
|
||||||
|
user_id: 'u-4', username: 'dana', permissions: [31, 99],
|
||||||
|
});
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok'), r);
|
||||||
|
expect(r._headers['X-Auth-Roles']).toBe('admin');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 2: Run test to verify it fails**
|
||||||
|
|
||||||
|
Run: `npx jest src/modules/auth/module-identity.controller.spec.ts`
|
||||||
|
Expected: FAIL — `controller.moduleIdentity is not a function` (and possibly missing-provider errors, which tell you which providers to stub — add them to the `providers` array per the comment).
|
||||||
|
|
||||||
|
- [ ] **Step 3: Write minimal implementation**
|
||||||
|
|
||||||
|
Add to `auth.controller.ts` (import the helpers at top; `AuthClientService` is already injected as `this.authClient`):
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import {
|
||||||
|
parseAdminSeqids,
|
||||||
|
moduleGateSeqid,
|
||||||
|
isModuleAllowed,
|
||||||
|
isAdmin,
|
||||||
|
} from './orchest-identity';
|
||||||
|
```
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
@Get('module-identity')
|
||||||
|
async moduleIdentity(@Req() req: Request, @Res() res: Response) {
|
||||||
|
const token = req.cookies?.['ddf-auth'];
|
||||||
|
if (!token) {
|
||||||
|
return res.status(401).send();
|
||||||
|
}
|
||||||
|
|
||||||
|
let payload: any;
|
||||||
|
try {
|
||||||
|
payload = await this.authClient.verifyAccessToken(token);
|
||||||
|
} catch (e) {
|
||||||
|
return res.status(401).send();
|
||||||
|
}
|
||||||
|
|
||||||
|
const perms: number[] = payload?.permissions ?? [];
|
||||||
|
const gate = moduleGateSeqid(process.env.ORCHEST_MODULE_PERMISSION_SEQID);
|
||||||
|
if (!isModuleAllowed(perms, gate)) {
|
||||||
|
return res.status(403).send();
|
||||||
|
}
|
||||||
|
|
||||||
|
res.set('X-Auth-User', String(payload.user_id));
|
||||||
|
res.set('X-Auth-Username', String(payload.username ?? ''));
|
||||||
|
if (isAdmin(perms, parseAdminSeqids(process.env.ORCHEST_ADMIN_PERMISSION_SEQIDS))) {
|
||||||
|
res.set('X-Auth-Roles', 'admin');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Phase 2 authz branch is inserted here (Task 5) before the 200.
|
||||||
|
return res.status(200).send();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 4: Run test to verify it passes**
|
||||||
|
|
||||||
|
Run: `npx jest src/modules/auth/module-identity.controller.spec.ts`
|
||||||
|
Expected: PASS (all identity cases).
|
||||||
|
|
||||||
|
- [ ] **Step 5: Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add src/modules/auth/auth.controller.ts src/modules/auth/module-identity.controller.spec.ts
|
||||||
|
git commit -m "feat(auth): GET /auth/module-identity — identity + module gate"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## PHASE 2 — Per-service authz
|
||||||
|
|
||||||
|
### Task 4: Tenant orchest-api host derivation + allowlist
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `src/modules/auth/orchest-identity.ts`
|
||||||
|
- Modify: `src/modules/auth/orchest-identity.spec.ts`
|
||||||
|
|
||||||
|
**Interfaces:**
|
||||||
|
- Consumes: nothing.
|
||||||
|
- Produces:
|
||||||
|
- `tenantOrchestApiHost(customerName: string, module: string): string` — returns `orchest-api.orchest-{module}-{customerName}.svc.cluster.local`.
|
||||||
|
- `isAllowedOrchestApiHost(host: string): boolean` — matches `^orchest-api\.orchest-(intelli|process)-[a-z0-9-]+\.svc\.cluster\.local$`.
|
||||||
|
- `namespaceModule(raw: string | undefined): 'intelli' | 'process'` — parse `ORCHEST_NAMESPACE_MODULE`; default `intelli`; anything not `process` → `intelli`.
|
||||||
|
|
||||||
|
- [ ] **Step 1: Write the failing test (append to orchest-identity.spec.ts)**
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import {
|
||||||
|
tenantOrchestApiHost,
|
||||||
|
isAllowedOrchestApiHost,
|
||||||
|
namespaceModule,
|
||||||
|
} from './orchest-identity';
|
||||||
|
|
||||||
|
describe('orchest-identity tenant routing', () => {
|
||||||
|
it('namespaceModule default and values', () => {
|
||||||
|
expect(namespaceModule(undefined)).toBe('intelli');
|
||||||
|
expect(namespaceModule('process')).toBe('process');
|
||||||
|
expect(namespaceModule('garbage')).toBe('intelli');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('tenantOrchestApiHost builds the namespace pattern', () => {
|
||||||
|
expect(tenantOrchestApiHost('acme', 'intelli')).toBe(
|
||||||
|
'orchest-api.orchest-intelli-acme.svc.cluster.local',
|
||||||
|
);
|
||||||
|
expect(tenantOrchestApiHost('acme', 'process')).toBe(
|
||||||
|
'orchest-api.orchest-process-acme.svc.cluster.local',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('isAllowedOrchestApiHost guards against malformed values', () => {
|
||||||
|
expect(
|
||||||
|
isAllowedOrchestApiHost('orchest-api.orchest-intelli-acme.svc.cluster.local'),
|
||||||
|
).toBe(true);
|
||||||
|
expect(isAllowedOrchestApiHost('evil.example.com')).toBe(false);
|
||||||
|
expect(
|
||||||
|
isAllowedOrchestApiHost('orchest-api.orchest-intelli-.svc.cluster.local'),
|
||||||
|
).toBe(false);
|
||||||
|
expect(
|
||||||
|
isAllowedOrchestApiHost('orchest-api.orchest-other-acme.svc.cluster.local'),
|
||||||
|
).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 2: Run test to verify it fails**
|
||||||
|
|
||||||
|
Run: `npx jest src/modules/auth/orchest-identity.spec.ts -t 'tenant routing'`
|
||||||
|
Expected: FAIL — the three functions are not exported.
|
||||||
|
|
||||||
|
- [ ] **Step 3: Write minimal implementation (append to orchest-identity.ts)**
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
export function namespaceModule(raw: string | undefined): 'intelli' | 'process' {
|
||||||
|
return raw === 'process' ? 'process' : 'intelli';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function tenantOrchestApiHost(
|
||||||
|
customerName: string,
|
||||||
|
module: string,
|
||||||
|
): string {
|
||||||
|
return `orchest-api.orchest-${module}-${customerName}.svc.cluster.local`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ORCHEST_API_HOST_RE =
|
||||||
|
/^orchest-api\.orchest-(intelli|process)-[a-z0-9-]+\.svc\.cluster\.local$/;
|
||||||
|
|
||||||
|
export function isAllowedOrchestApiHost(host: string): boolean {
|
||||||
|
return ORCHEST_API_HOST_RE.test(host);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Slug-normalization note (verify during implementation):** confirm the
|
||||||
|
JWT's `customer_name` is *exactly* the namespace slug (lowercase, kebab, no
|
||||||
|
spaces). If it is not, normalize deterministically inside
|
||||||
|
`tenantOrchestApiHost` (e.g. `customerName.toLowerCase().replace(/[^a-z0-9-]/g, '-')`)
|
||||||
|
and extend the test with the raw→normalized case. Do NOT guess the rule —
|
||||||
|
inspect a real token or ask the team.
|
||||||
|
|
||||||
|
- [ ] **Step 4: Run test to verify it passes**
|
||||||
|
|
||||||
|
Run: `npx jest src/modules/auth/orchest-identity.spec.ts -t 'tenant routing'`
|
||||||
|
Expected: PASS.
|
||||||
|
|
||||||
|
- [ ] **Step 5: Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add src/modules/auth/orchest-identity.ts src/modules/auth/orchest-identity.spec.ts
|
||||||
|
git commit -m "feat(orchest-identity): tenant orchest-api host derivation + allowlist"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 5: authz branch — call `/api/authz/check`, relay, fail-closed
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `src/modules/auth/auth.service.ts` (add `authorizeOrchestServiceAccess`)
|
||||||
|
- Modify: `src/modules/auth/auth.controller.ts` (insert the authz branch in `moduleIdentity`)
|
||||||
|
- Modify: `src/modules/auth/module-identity.controller.spec.ts`
|
||||||
|
|
||||||
|
**Interfaces:**
|
||||||
|
- Consumes: `tenantOrchestApiHost`, `isAllowedOrchestApiHost`, `namespaceModule` (Task 4); an HTTP client. Maestro uses gRPC for its own services but plain HTTP for this cross-service call — use `axios` if already a dependency, else the `@nestjs/axios` `HttpService`; confirm which is present before writing (grep `import axios` / `HttpService`).
|
||||||
|
- Produces: `AuthClientService.authorizeOrchestServiceAccess(args: { host: string; permission: string; projectUuid?: string; headers: Record<string,string> }): Promise<'allow' | 'deny' | 'error'>` — GET `http://{host}/api/authz/check?permission=…[&project_uuid=…]` with the identity headers; 200→`allow`, 403→`deny`, anything else/throw→`error`.
|
||||||
|
|
||||||
|
- [ ] **Step 1: Write the failing test (append to module-identity.controller.spec.ts)**
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
describe('GET /auth/module-identity — per-service authz', () => {
|
||||||
|
let controller: AuthController;
|
||||||
|
const auth = {
|
||||||
|
verifyAccessToken: jest.fn(),
|
||||||
|
authorizeOrchestServiceAccess: jest.fn(),
|
||||||
|
} as unknown as AuthClientService;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
jest.resetAllMocks();
|
||||||
|
process.env.ORCHEST_MODULE_PERMISSION_SEQID = '31';
|
||||||
|
process.env.ORCHEST_ADMIN_PERMISSION_SEQIDS = '34';
|
||||||
|
process.env.ORCHEST_NAMESPACE_MODULE = 'intelli';
|
||||||
|
const mod = await Test.createTestingModule({
|
||||||
|
controllers: [AuthController],
|
||||||
|
providers: [{ provide: AuthClientService, useValue: auth }],
|
||||||
|
}).compile(); // add the same stubbed providers as Task 3
|
||||||
|
controller = mod.get(AuthController);
|
||||||
|
(auth.verifyAccessToken as jest.Mock).mockResolvedValue({
|
||||||
|
user_id: 'u-1', username: 'alice', permissions: [31], customer_name: 'acme',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const q = { permission: 'session.open', project_uuid: 'p-1' };
|
||||||
|
|
||||||
|
it('has grant → 200 and calls the tenant host', async () => {
|
||||||
|
(auth.authorizeOrchestServiceAccess as jest.Mock).mockResolvedValue('allow');
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok', q), r);
|
||||||
|
expect(r._status).toBe(200);
|
||||||
|
expect(auth.authorizeOrchestServiceAccess).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
host: 'orchest-api.orchest-intelli-acme.svc.cluster.local',
|
||||||
|
permission: 'session.open',
|
||||||
|
projectUuid: 'p-1',
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('lacks grant → 403', async () => {
|
||||||
|
(auth.authorizeOrchestServiceAccess as jest.Mock).mockResolvedValue('deny');
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok', q), r);
|
||||||
|
expect(r._status).toBe(403);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('orchest-api error → 502 (fail-closed)', async () => {
|
||||||
|
(auth.authorizeOrchestServiceAccess as jest.Mock).mockResolvedValue('error');
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok', q), r);
|
||||||
|
expect(r._status).toBe(502);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('permission without project_uuid → 403 (all-or-nothing)', async () => {
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok', { permission: 'session.open' }), r);
|
||||||
|
expect(r._status).toBe(403);
|
||||||
|
expect(auth.authorizeOrchestServiceAccess).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('no authz params → 200 identity-only (webserver case)', async () => {
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok', {}), r);
|
||||||
|
expect(r._status).toBe(200);
|
||||||
|
expect(auth.authorizeOrchestServiceAccess).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('malformed customer_name → host fails allowlist → 403, no call', async () => {
|
||||||
|
(auth.verifyAccessToken as jest.Mock).mockResolvedValue({
|
||||||
|
user_id: 'u-1', username: 'alice', permissions: [31], customer_name: 'Bad Name!',
|
||||||
|
});
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok', q), r);
|
||||||
|
expect(r._status).toBe(403);
|
||||||
|
expect(auth.authorizeOrchestServiceAccess).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 2: Run test to verify it fails**
|
||||||
|
|
||||||
|
Run: `npx jest src/modules/auth/module-identity.controller.spec.ts -t 'per-service authz'`
|
||||||
|
Expected: FAIL — `authorizeOrchestServiceAccess` undefined / authz branch absent.
|
||||||
|
|
||||||
|
- [ ] **Step 3a: Implement the service helper**
|
||||||
|
|
||||||
|
In `auth.service.ts` (use the HTTP client confirmed in the Interfaces note; `axios` shown):
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
public async authorizeOrchestServiceAccess(args: {
|
||||||
|
host: string;
|
||||||
|
permission: string;
|
||||||
|
projectUuid?: string;
|
||||||
|
headers: Record<string, string>;
|
||||||
|
}): Promise<'allow' | 'deny' | 'error'> {
|
||||||
|
const params: Record<string, string> = { permission: args.permission };
|
||||||
|
if (args.projectUuid) params.project_uuid = args.projectUuid;
|
||||||
|
try {
|
||||||
|
const resp = await axios.get(`http://${args.host}/api/authz/check`, {
|
||||||
|
params,
|
||||||
|
headers: args.headers,
|
||||||
|
timeout: 5000,
|
||||||
|
validateStatus: () => true, // never throw on 4xx/5xx; we branch below
|
||||||
|
});
|
||||||
|
if (resp.status === 200) return 'allow';
|
||||||
|
if (resp.status === 403) return 'deny';
|
||||||
|
return 'error';
|
||||||
|
} catch (e) {
|
||||||
|
return 'error';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 3b: Insert the authz branch in the controller**
|
||||||
|
|
||||||
|
Replace the `// Phase 2 authz branch is inserted here` marker (Task 3) with:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const permission = req.query?.permission as string | undefined;
|
||||||
|
const projectUuid = req.query?.project_uuid as string | undefined;
|
||||||
|
if (permission) {
|
||||||
|
// Service-ingress caller: authorize per-project. All-or-nothing —
|
||||||
|
// an incomplete annotation must not silently skip the check.
|
||||||
|
if (!projectUuid) {
|
||||||
|
return res.status(403).send();
|
||||||
|
}
|
||||||
|
const module = namespaceModule(process.env.ORCHEST_NAMESPACE_MODULE);
|
||||||
|
const host = tenantOrchestApiHost(String(payload.customer_name ?? ''), module);
|
||||||
|
if (!isAllowedOrchestApiHost(host)) {
|
||||||
|
return res.status(403).send();
|
||||||
|
}
|
||||||
|
const identityHeaders: Record<string, string> = {
|
||||||
|
'X-Auth-User': String(payload.user_id),
|
||||||
|
'X-Auth-Username': String(payload.username ?? ''),
|
||||||
|
};
|
||||||
|
if (isAdmin(perms, parseAdminSeqids(process.env.ORCHEST_ADMIN_PERMISSION_SEQIDS))) {
|
||||||
|
identityHeaders['X-Auth-Roles'] = 'admin';
|
||||||
|
}
|
||||||
|
const decision = await this.authClient.authorizeOrchestServiceAccess({
|
||||||
|
host,
|
||||||
|
permission,
|
||||||
|
projectUuid,
|
||||||
|
headers: identityHeaders,
|
||||||
|
});
|
||||||
|
if (decision === 'deny') return res.status(403).send();
|
||||||
|
if (decision === 'error') return res.status(502).send();
|
||||||
|
// 'allow' falls through to the 200 below (identity headers already set).
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(200).send();
|
||||||
|
```
|
||||||
|
|
||||||
|
Add the imports `tenantOrchestApiHost`, `isAllowedOrchestApiHost`, `namespaceModule` to the existing `./orchest-identity` import line.
|
||||||
|
|
||||||
|
- [ ] **Step 4: Run test to verify it passes**
|
||||||
|
|
||||||
|
Run: `npx jest src/modules/auth/module-identity.controller.spec.ts`
|
||||||
|
Expected: PASS (identity + per-service authz suites).
|
||||||
|
|
||||||
|
- [ ] **Step 5: Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add src/modules/auth/auth.service.ts src/modules/auth/auth.controller.ts src/modules/auth/module-identity.controller.spec.ts
|
||||||
|
git commit -m "feat(auth): per-service authz branch on /auth/module-identity"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 6: orchest-side — scope the Maestro service auth-url (dbt-to-orchest repo)
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `lib/python/orchest-internals/_orchest/internals/utils.py:19-51` (`service_access_auth_url`)
|
||||||
|
- Test: the module's existing test (grep `service_access_auth_url` under `lib/python/…/tests`; if none, create `lib/python/orchest-internals/tests/test_service_access_auth_url.py`)
|
||||||
|
|
||||||
|
**This task is in the `dbt-to-orchest` repo, not Maestro.** Do it on a branch there (e.g. off the current RBAC branch). It has no dependency on Tasks 1-5 compiling, but the annotation it produces is what Task 5 consumes at runtime.
|
||||||
|
|
||||||
|
**Interfaces:**
|
||||||
|
- Consumes: nothing new.
|
||||||
|
- Produces: `service_access_auth_url(base_auth_url, permission, project_uuid, auth_custom)` — in Maestro mode (`auth_custom=True`), returns `f"{base_auth_url}?permission={permission}"` (plus `&project_uuid=…` when set) instead of returning `base_auth_url` unchanged.
|
||||||
|
|
||||||
|
- [ ] **Step 1: Write the failing test**
|
||||||
|
|
||||||
|
```python
|
||||||
|
from _orchest.internals.utils import service_access_auth_url
|
||||||
|
|
||||||
|
def test_maestro_mode_appends_scoped_params():
|
||||||
|
url = service_access_auth_url(
|
||||||
|
"http://maestro/auth/module-identity", "session.open", "p-1",
|
||||||
|
auth_custom=True,
|
||||||
|
)
|
||||||
|
assert url == (
|
||||||
|
"http://maestro/auth/module-identity?permission=session.open&project_uuid=p-1"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_maestro_mode_without_project_uuid():
|
||||||
|
url = service_access_auth_url(
|
||||||
|
"http://maestro/auth/module-identity", "project.view", None,
|
||||||
|
auth_custom=True,
|
||||||
|
)
|
||||||
|
assert url == "http://maestro/auth/module-identity?permission=project.view"
|
||||||
|
|
||||||
|
def test_local_mode_unchanged():
|
||||||
|
url = service_access_auth_url(
|
||||||
|
"http://auth-server/auth", "session.open", "p-1", auth_custom=False,
|
||||||
|
)
|
||||||
|
assert url == (
|
||||||
|
"http://auth-server/auth/service-access?permission=session.open&project_uuid=p-1"
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 2: Run test to verify it fails**
|
||||||
|
|
||||||
|
Run (in the pod or a venv with the lib on path):
|
||||||
|
`python -m pytest lib/python/orchest-internals/tests/test_service_access_auth_url.py -q`
|
||||||
|
Expected: FAIL on the two Maestro cases (current code returns the base URL unchanged).
|
||||||
|
|
||||||
|
- [ ] **Step 3: Write minimal implementation**
|
||||||
|
|
||||||
|
Replace the `if auth_custom:` short-circuit in `utils.py`:
|
||||||
|
|
||||||
|
```python
|
||||||
|
if auth_custom:
|
||||||
|
# Maestro mode: no /auth/service-access sibling route — the unified
|
||||||
|
# /auth/module-identity route authorizes when the annotation carries
|
||||||
|
# the scope. Append the same permission/project_uuid params. (Maestro
|
||||||
|
# derives the tenant orchest-api host from the JWT, not from the URL.)
|
||||||
|
query = f"permission={permission}"
|
||||||
|
if project_uuid:
|
||||||
|
query += f"&project_uuid={project_uuid}"
|
||||||
|
return f"{base_auth_url}?{query}"
|
||||||
|
```
|
||||||
|
|
||||||
|
Update the docstring's "falls back to the plain base_auth_url" paragraph to describe the new scoped behavior.
|
||||||
|
|
||||||
|
- [ ] **Step 4: Run test to verify it passes**
|
||||||
|
|
||||||
|
Run: `python -m pytest lib/python/orchest-internals/tests/test_service_access_auth_url.py -q`
|
||||||
|
Expected: PASS (all three).
|
||||||
|
|
||||||
|
- [ ] **Step 5: Commit (dbt-to-orchest repo)**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add lib/python/orchest-internals/_orchest/internals/utils.py lib/python/orchest-internals/tests/test_service_access_auth_url.py
|
||||||
|
git commit -m "feat(rbac): scope Maestro-mode service auth-url (close direct-URL bypass)"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Deployment & manual verification (after Tasks 1-6)
|
||||||
|
|
||||||
|
Not code steps — run after merging, per the spec §8/§10.
|
||||||
|
|
||||||
|
- [ ] **Maestro env** on the Orchest-serving deployment: `ORCHEST_MODULE_PERMISSION_SEQID=31`, `ORCHEST_ADMIN_PERMISSION_SEQIDS=34`, `ORCHEST_NAMESPACE_MODULE=intelli`.
|
||||||
|
- [ ] **OrchestCluster spec** (webserver ingress): `AuthCustom: true`, `AuthUrl: http://maestro.<maestro-ns>.svc.cluster.local/auth/module-identity`, `AuthSignin: <platform login URL>`.
|
||||||
|
- [ ] **⚠️ celery-worker rebuild (Phase 2 / Task 6):** `service_access_auth_url` runs in the **celery-worker baked image** — rebuild + roll it, and verify the scoped annotation on a **freshly launched** service ingress (`kubectl get ingress …`), never an existing one. (This gotcha cost a debugging cycle last week; see `docs/source/development/building_images_minikube.md`.)
|
||||||
|
- [ ] **Verify path A (spec §10):** curl-drive orchest-api with the `X-Auth-*` headers Maestro would set and watch the RBAC ladder + `external_admin` resolve, before standing up real Maestro.
|
||||||
|
- [ ] **Forgery checks (spec §9.11, §9.12):** a non-admin's forged `X-Auth-Roles: admin` through the ingress must not reach orchest-api as admin; `?permission=…` appended to the app URL must not trigger an authz check.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Self-Review
|
||||||
|
|
||||||
|
**Spec coverage:**
|
||||||
|
- §4.1 cookie auth + JWKS reuse → Task 2 (expose verify) + Task 3 (read cookie).
|
||||||
|
- §4.2 ladder (401/403/200 + authz + all-or-nothing + no refresh) → Task 3 (401/403/200) + Task 5 (authz, 502, all-or-nothing).
|
||||||
|
- §4.3 three headers, no email → Task 3 (sets exactly the three; email never set).
|
||||||
|
- §5 module gate + admin set (config, list) → Task 1 + Task 3.
|
||||||
|
- §5.1 tenant routing (namespace pattern, allowlist, slug note, dadosferademo2) → Task 4 + Task 5.
|
||||||
|
- §6 forgery boundary → deployment verification checklist.
|
||||||
|
- §7 service_access_auth_url scoping → Task 6.
|
||||||
|
- §8 deployment config → deployment checklist.
|
||||||
|
- §9 tests 1-12 → Tasks 1/3 (1-5), Task 5 (6-10), deployment checklist (11-12).
|
||||||
|
- §10 minikube verification → deployment checklist.
|
||||||
|
- §11 phase split → Phase 1 (Tasks 1-3) / Phase 2 (Tasks 4-6).
|
||||||
|
|
||||||
|
**Placeholder scan:** none — every code step has real content; the only deliberately-open items are flagged verify-steps (HTTP client choice in Task 5; `customer_name` slug normalization in Task 4), each with an explicit instruction to inspect rather than guess.
|
||||||
|
|
||||||
|
**Type consistency:** `verifyAccessToken` (Task 2) consumed in Tasks 3/5; `moduleIdentity(req,res)` signature identical across Tasks 3/5; helper names (`parseAdminSeqids`, `moduleGateSeqid`, `isModuleAllowed`, `isAdmin`, `tenantOrchestApiHost`, `isAllowedOrchestApiHost`, `namespaceModule`) defined in Tasks 1/4 and used verbatim in Tasks 3/5; `authorizeOrchestServiceAccess` return union `'allow'|'deny'|'error'` consistent between service (Task 5 3a) and controller (Task 5 3b).
|
||||||
+401
-2
@@ -900,6 +900,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -949,6 +952,9 @@
|
|||||||
"connections"
|
"connections"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -997,6 +1003,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -1033,6 +1042,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -1066,6 +1078,9 @@
|
|||||||
"connections"
|
"connections"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -2403,6 +2418,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -2486,6 +2504,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -2525,6 +2546,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -2564,6 +2588,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -2601,6 +2628,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -2640,6 +2670,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -2681,6 +2714,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -2722,6 +2758,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -3071,6 +3110,9 @@
|
|||||||
"PipelinesV2"
|
"PipelinesV2"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -3120,6 +3162,9 @@
|
|||||||
"PipelinesV2"
|
"PipelinesV2"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -3190,6 +3235,9 @@
|
|||||||
"PipelinesV2"
|
"PipelinesV2"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -3230,6 +3278,9 @@
|
|||||||
"PipelinesV2"
|
"PipelinesV2"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -3270,6 +3321,9 @@
|
|||||||
"PipelinesV2"
|
"PipelinesV2"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -3310,6 +3364,9 @@
|
|||||||
"PipelinesV2"
|
"PipelinesV2"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -3350,6 +3407,9 @@
|
|||||||
"PipelinesV2"
|
"PipelinesV2"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -3397,6 +3457,9 @@
|
|||||||
"PipelinesV2"
|
"PipelinesV2"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -3442,6 +3505,9 @@
|
|||||||
"PipelinesV2"
|
"PipelinesV2"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -3490,6 +3556,9 @@
|
|||||||
"PipelinesV2"
|
"PipelinesV2"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -3528,6 +3597,9 @@
|
|||||||
"PipelinesV2"
|
"PipelinesV2"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -3586,6 +3658,9 @@
|
|||||||
"PipelinesV2"
|
"PipelinesV2"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -3634,6 +3709,9 @@
|
|||||||
"PipelinesV2"
|
"PipelinesV2"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -3674,6 +3752,9 @@
|
|||||||
"PipelinesV2"
|
"PipelinesV2"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -3716,6 +3797,9 @@
|
|||||||
"PipelinesV2"
|
"PipelinesV2"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -3765,6 +3849,9 @@
|
|||||||
"PipelinesV2"
|
"PipelinesV2"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -3814,6 +3901,9 @@
|
|||||||
"PipelinesV2"
|
"PipelinesV2"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -3861,6 +3951,9 @@
|
|||||||
"PipelinesV2"
|
"PipelinesV2"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4031,6 +4124,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4056,6 +4152,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4092,6 +4191,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4126,6 +4228,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4160,6 +4265,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4187,6 +4295,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4214,6 +4325,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4241,6 +4355,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4277,6 +4394,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4313,6 +4433,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4340,6 +4463,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4367,6 +4493,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4404,6 +4533,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4440,6 +4572,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4484,6 +4619,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4520,6 +4658,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4574,6 +4715,7 @@
|
|||||||
"get": {
|
"get": {
|
||||||
"operationId": "PlatformApiController_getPipelineRunJobs",
|
"operationId": "PlatformApiController_getPipelineRunJobs",
|
||||||
"summary": "Get pipeline run jobs",
|
"summary": "Get pipeline run jobs",
|
||||||
|
"description": "Proxies platform-api DB-backed job runs and returns `{ jobs: [...] }`.",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"name": "pipelineId",
|
"name": "pipelineId",
|
||||||
@@ -4594,11 +4736,22 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "",
|
"description": "DB-backed job runs for the selected pipeline run.",
|
||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object"
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"jobs": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"jobs"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4644,6 +4797,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4678,6 +4834,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4714,6 +4873,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4750,6 +4912,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4787,6 +4952,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4814,6 +4982,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -4841,6 +5012,9 @@
|
|||||||
"Platform API"
|
"Platform API"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -5252,6 +5426,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -5295,6 +5472,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -5404,6 +5584,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -5436,6 +5619,9 @@
|
|||||||
"Catalog"
|
"Catalog"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -5478,6 +5664,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -5526,6 +5715,48 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/catalog/custom-properties": {
|
||||||
|
"get": {
|
||||||
|
"operationId": "CatalogController_getCustomPropertyDefinitions",
|
||||||
|
"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": [
|
||||||
|
"Catalog"
|
||||||
|
],
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
"/catalog/data-asset/{id}": {
|
"/catalog/data-asset/{id}": {
|
||||||
"get": {
|
"get": {
|
||||||
"operationId": "CatalogController_getDataAsset",
|
"operationId": "CatalogController_getDataAsset",
|
||||||
@@ -5571,6 +5802,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -5629,6 +5863,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -5677,6 +5914,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -5770,6 +6010,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -5820,6 +6063,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -5878,6 +6124,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -5931,6 +6180,72 @@
|
|||||||
"Catalog"
|
"Catalog"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/catalog/data-asset/{id}/certification-status": {
|
||||||
|
"put": {
|
||||||
|
"operationId": "CatalogController_updateDataAssetCertificationStatus",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "dadosfera-lang",
|
||||||
|
"in": "header",
|
||||||
|
"required": false,
|
||||||
|
"schema": {
|
||||||
|
"enum": [
|
||||||
|
"pt-br",
|
||||||
|
"en-us"
|
||||||
|
],
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"required": true,
|
||||||
|
"in": "path",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/IUpdateCertificationStatusRequest"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/IUpdateCertificationStatusRequest"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"Catalog"
|
||||||
|
],
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
@@ -5974,6 +6289,9 @@
|
|||||||
"Catalog"
|
"Catalog"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -6014,6 +6332,9 @@
|
|||||||
"Catalog"
|
"Catalog"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -6074,6 +6395,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -6132,6 +6456,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -6508,6 +6835,9 @@
|
|||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -6961,6 +7291,9 @@
|
|||||||
"Connection Test"
|
"Connection Test"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -6997,6 +7330,9 @@
|
|||||||
"Connection Test"
|
"Connection Test"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -7033,6 +7369,9 @@
|
|||||||
"Connection Test"
|
"Connection Test"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -7069,6 +7408,9 @@
|
|||||||
"Connection Test"
|
"Connection Test"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -7105,6 +7447,9 @@
|
|||||||
"Connection Test"
|
"Connection Test"
|
||||||
],
|
],
|
||||||
"security": [
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"access-token": []
|
"access-token": []
|
||||||
}
|
}
|
||||||
@@ -10973,6 +11318,37 @@
|
|||||||
"docs"
|
"docs"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"CustomPropertyDto": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"key": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"value": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"text",
|
||||||
|
"number",
|
||||||
|
"date",
|
||||||
|
"boolean"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"color": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"emoji": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"key",
|
||||||
|
"value",
|
||||||
|
"type"
|
||||||
|
]
|
||||||
|
},
|
||||||
"IUpdateDataRequest": {
|
"IUpdateDataRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -11001,6 +11377,12 @@
|
|||||||
},
|
},
|
||||||
"docs": {
|
"docs": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"custom_properties": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/components/schemas/CustomPropertyDto"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
@@ -11020,6 +11402,23 @@
|
|||||||
"data_asset"
|
"data_asset"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"IUpdateCertificationStatusRequest": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"certification_status": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"draft",
|
||||||
|
"in_review",
|
||||||
|
"approved",
|
||||||
|
"deprecated"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"certification_status"
|
||||||
|
]
|
||||||
|
},
|
||||||
"ICreateDataAsset": {
|
"ICreateDataAsset": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ const config: Config.InitialOptions = {
|
|||||||
roots: ['<rootDir>/src/', '<rootDir>/test/'],
|
roots: ['<rootDir>/src/', '<rootDir>/test/'],
|
||||||
testRegex: '.*\\.(test|spec)\\.[jt]s$',
|
testRegex: '.*\\.(test|spec)\\.[jt]s$',
|
||||||
transform: { '\\.[jt]s$': 'ts-jest' },
|
transform: { '\\.[jt]s$': 'ts-jest' },
|
||||||
|
// Dummy values for env vars read at module-import time (see the setup file),
|
||||||
|
// so specs importing those modules don't crash on load.
|
||||||
|
setupFiles: ['<rootDir>/test/jest.setup-env.ts'],
|
||||||
collectCoverageFrom: ['**/*.[jt]s'],
|
collectCoverageFrom: ['**/*.[jt]s'],
|
||||||
coverageDirectory: 'coverage',
|
coverageDirectory: 'coverage',
|
||||||
coveragePathIgnorePatterns: [
|
coveragePathIgnorePatterns: [
|
||||||
|
|||||||
Generated
+4
-5
@@ -16,7 +16,7 @@
|
|||||||
"@aws-sdk/lib-dynamodb": "^3.414.0",
|
"@aws-sdk/lib-dynamodb": "^3.414.0",
|
||||||
"@aws-sdk/signature-v4": "^3.370.0",
|
"@aws-sdk/signature-v4": "^3.370.0",
|
||||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
||||||
"@dadosfera/protospack-v2": "3.40.0-beta.10",
|
"@dadosfera/protospack-v2": "^3.40.0-beta.14",
|
||||||
"@grpc/grpc-js": "^1.9.3",
|
"@grpc/grpc-js": "^1.9.3",
|
||||||
"@grpc/proto-loader": "^0.7.9",
|
"@grpc/proto-loader": "^0.7.9",
|
||||||
"@nestjs/cli": "^9.5.0",
|
"@nestjs/cli": "^9.5.0",
|
||||||
@@ -1735,10 +1735,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@dadosfera/protospack-v2": {
|
"node_modules/@dadosfera/protospack-v2": {
|
||||||
"version": "3.40.0-beta.10",
|
"version": "3.40.0-beta.14",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.40.0-beta.10.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.40.0-beta.14.tgz",
|
||||||
"integrity": "sha512-F45dSEIKG+gwwDMYHayA242bFwhFTJbZm26KesQbGhf4I45ur6hYZD8dK0voNuVQInLMQhtm6+7th6/jJ8xpTQ==",
|
"integrity": "sha512-pv3pxq0x1XcBgf3ajD6QOFRLOduh8iEozKFA3AKlIW4gid+gT4iL0GcU2M+O7h0QFeO4JIzRZe/nEMN82nqk7A==",
|
||||||
"license": "ISC",
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@grpc/grpc-js": "^1.9.3",
|
"@grpc/grpc-js": "^1.9.3",
|
||||||
"rxjs": "^7.5.5"
|
"rxjs": "^7.5.5"
|
||||||
|
|||||||
+1
-1
@@ -34,7 +34,7 @@
|
|||||||
"@aws-sdk/lib-dynamodb": "^3.414.0",
|
"@aws-sdk/lib-dynamodb": "^3.414.0",
|
||||||
"@aws-sdk/signature-v4": "^3.370.0",
|
"@aws-sdk/signature-v4": "^3.370.0",
|
||||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
||||||
"@dadosfera/protospack-v2": "3.40.0-beta.10",
|
"@dadosfera/protospack-v2": "^3.40.0-beta.14",
|
||||||
"@grpc/grpc-js": "^1.9.3",
|
"@grpc/grpc-js": "^1.9.3",
|
||||||
"@grpc/proto-loader": "^0.7.9",
|
"@grpc/proto-loader": "^0.7.9",
|
||||||
"@nestjs/cli": "^9.5.0",
|
"@nestjs/cli": "^9.5.0",
|
||||||
|
|||||||
@@ -357,6 +357,16 @@ export const PERMISSIONS_GROUPS = {
|
|||||||
'es-es': 'Crear y editar atributos en el catálogo',
|
'es-es': 'Crear y editar atributos en el catálogo',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
CERTIFY: {
|
||||||
|
seqid: 53,
|
||||||
|
claim: 'catalog:certify',
|
||||||
|
usage: PermissionUsages.PUBLIC,
|
||||||
|
name: {
|
||||||
|
'pt-br': 'Alterar o status de certificação dos Ativos',
|
||||||
|
'en-us': "Change Assets' certification status",
|
||||||
|
'es-es': 'Cambiar el estado de certificación de los Activos',
|
||||||
|
},
|
||||||
|
},
|
||||||
DELETE: {
|
DELETE: {
|
||||||
seqid: 1,
|
seqid: 1,
|
||||||
claim: 'catalog:delete',
|
claim: 'catalog:delete',
|
||||||
@@ -712,6 +722,8 @@ export const DADOSFERA_MODULES_KEYS = {
|
|||||||
PII: 'pii',
|
PII: 'pii',
|
||||||
EMBED: 'embedded-analytics',
|
EMBED: 'embedded-analytics',
|
||||||
EMBED_ASSIGNED: 'embed-assigned',
|
EMBED_ASSIGNED: 'embed-assigned',
|
||||||
|
CATALOG: 'catalog',
|
||||||
|
COLLECT: 'collect',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DADOSFERA_MODULES: Array<DadosferaModule> = [
|
export const DADOSFERA_MODULES: Array<DadosferaModule> = [
|
||||||
|
|||||||
@@ -32,6 +32,15 @@ import {
|
|||||||
} from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
} from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
||||||
|
|
||||||
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
||||||
|
import {
|
||||||
|
parseAdminSeqids,
|
||||||
|
moduleGateSeqid,
|
||||||
|
isModuleAllowed,
|
||||||
|
isAdmin,
|
||||||
|
tenantOrchestApiHost,
|
||||||
|
isAllowedOrchestApiHost,
|
||||||
|
namespaceModule,
|
||||||
|
} from './orchest-identity';
|
||||||
import {
|
import {
|
||||||
Authenticated,
|
Authenticated,
|
||||||
RequireAllPermissions,
|
RequireAllPermissions,
|
||||||
@@ -531,4 +540,84 @@ export class AuthController {
|
|||||||
return res.status(200).json(user);
|
return res.status(200).json(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ingress auth subrequest for Orchest (see dbt-to-orchest
|
||||||
|
* docs/superpowers/specs/2026-08-20-maestro-module-identity-design.md).
|
||||||
|
*
|
||||||
|
* Authenticates the ddf-auth cookie, gates on the module permission, and
|
||||||
|
* returns the X-Auth-* identity headers orchest-api trusts. Never writes
|
||||||
|
* cookies (an auth_request response cannot). No token refresh: an expired
|
||||||
|
* token is a 401 (the signin flow re-auths).
|
||||||
|
*/
|
||||||
|
@Get('module-identity')
|
||||||
|
async moduleIdentity(@Req() req: Request, @Res() res: Response) {
|
||||||
|
const token = req.cookies?.['ddf-auth'];
|
||||||
|
if (!token) {
|
||||||
|
return res.status(401).send();
|
||||||
|
}
|
||||||
|
|
||||||
|
let payload: any;
|
||||||
|
try {
|
||||||
|
payload = await this.authClient.verifyAccessToken(token);
|
||||||
|
} catch (e) {
|
||||||
|
return res.status(401).send();
|
||||||
|
}
|
||||||
|
|
||||||
|
const perms: number[] = payload?.permissions ?? [];
|
||||||
|
const gate = moduleGateSeqid(process.env.ORCHEST_MODULE_PERMISSION_SEQID);
|
||||||
|
if (!isModuleAllowed(perms, gate)) {
|
||||||
|
return res.status(403).send();
|
||||||
|
}
|
||||||
|
|
||||||
|
const adminUser = isAdmin(
|
||||||
|
perms,
|
||||||
|
parseAdminSeqids(process.env.ORCHEST_ADMIN_PERMISSION_SEQIDS),
|
||||||
|
);
|
||||||
|
|
||||||
|
res.set('X-Auth-User', String(payload.user_id));
|
||||||
|
res.set('X-Auth-Username', String(payload.username ?? ''));
|
||||||
|
if (adminUser) {
|
||||||
|
res.set('X-Auth-Roles', 'admin');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Service-ingress caller: the orchest-api-authored annotation carries the
|
||||||
|
// scope. Authorize per-project against the tenant's orchest-api. A
|
||||||
|
// param-less request is the webserver-ingress case → identity only.
|
||||||
|
const permission = req.query?.permission as string | undefined;
|
||||||
|
const projectUuid = req.query?.project_uuid as string | undefined;
|
||||||
|
if (permission) {
|
||||||
|
// All-or-nothing: an incomplete annotation must not silently skip the
|
||||||
|
// per-project check.
|
||||||
|
if (!projectUuid) {
|
||||||
|
return res.status(403).send();
|
||||||
|
}
|
||||||
|
const module = namespaceModule(process.env.ORCHEST_NAMESPACE_MODULE);
|
||||||
|
const host = tenantOrchestApiHost(
|
||||||
|
String(payload.customer_name ?? ''),
|
||||||
|
module,
|
||||||
|
);
|
||||||
|
if (!isAllowedOrchestApiHost(host)) {
|
||||||
|
return res.status(403).send();
|
||||||
|
}
|
||||||
|
const identityHeaders: Record<string, string> = {
|
||||||
|
'X-Auth-User': String(payload.user_id),
|
||||||
|
'X-Auth-Username': String(payload.username ?? ''),
|
||||||
|
};
|
||||||
|
if (adminUser) {
|
||||||
|
identityHeaders['X-Auth-Roles'] = 'admin';
|
||||||
|
}
|
||||||
|
const decision = await this.authClient.authorizeOrchestServiceAccess({
|
||||||
|
host,
|
||||||
|
permission,
|
||||||
|
projectUuid,
|
||||||
|
headers: identityHeaders,
|
||||||
|
});
|
||||||
|
if (decision === 'deny') return res.status(403).send();
|
||||||
|
if (decision === 'error') return res.status(502).send();
|
||||||
|
// 'allow' falls through to the 200 (identity headers already set).
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(200).send();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
import { ClientGrpc } from '@nestjs/microservices';
|
import { ClientGrpc } from '@nestjs/microservices';
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
import { lastValueFrom } from 'rxjs';
|
import { lastValueFrom } from 'rxjs';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Duc';
|
import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Duc';
|
||||||
import {
|
import {
|
||||||
@@ -307,7 +308,7 @@ export class AuthClientService implements OnModuleInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async validateUserSession(accessToken: any, resourceHost: string) {
|
public async validateUserSession(accessToken: any, resourceHost: string) {
|
||||||
const payload = await this.validateJwtToken(accessToken);
|
const payload = await this.verifyAccessToken(accessToken);
|
||||||
|
|
||||||
const userDto = await this.getUserfromPayload(payload);
|
const userDto = await this.getUserfromPayload(payload);
|
||||||
|
|
||||||
@@ -410,7 +411,12 @@ export class AuthClientService implements OnModuleInit {
|
|||||||
this.logger.info('Clean cookie sessions');
|
this.logger.info('Clean cookie sessions');
|
||||||
}
|
}
|
||||||
|
|
||||||
private async validateJwtToken(token: string) {
|
/**
|
||||||
|
* Verify a DUC access token against the JWKS and return its payload.
|
||||||
|
* Public so the /auth/module-identity route can authenticate the ddf-auth
|
||||||
|
* cookie the same way (was the private validateJwtToken).
|
||||||
|
*/
|
||||||
|
public async verifyAccessToken(token: string) {
|
||||||
const decoded: any = token && jwt.decode(token, { complete: true });
|
const decoded: any = token && jwt.decode(token, { complete: true });
|
||||||
if (!decoded) throw new Error('Invalid token');
|
if (!decoded) throw new Error('Invalid token');
|
||||||
|
|
||||||
@@ -492,4 +498,33 @@ export class AuthClientService implements OnModuleInit {
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ask a tenant's orchest-api whether the acting user holds `permission` on
|
||||||
|
* `projectUuid` (the per-service authz half of /auth/module-identity).
|
||||||
|
* Fail-closed: any error / unexpected status → 'error' (the route denies).
|
||||||
|
*/
|
||||||
|
public async authorizeOrchestServiceAccess(args: {
|
||||||
|
host: string;
|
||||||
|
permission: string;
|
||||||
|
projectUuid?: string;
|
||||||
|
headers: Record<string, string>;
|
||||||
|
}): Promise<'allow' | 'deny' | 'error'> {
|
||||||
|
const params: Record<string, string> = { permission: args.permission };
|
||||||
|
if (args.projectUuid) params.project_uuid = args.projectUuid;
|
||||||
|
try {
|
||||||
|
const resp = await axios.get(`http://${args.host}/api/authz/check`, {
|
||||||
|
params,
|
||||||
|
headers: args.headers,
|
||||||
|
timeout: 5000,
|
||||||
|
// Never throw on 4xx/5xx; branch on the status ourselves.
|
||||||
|
validateStatus: () => true,
|
||||||
|
});
|
||||||
|
if (resp.status === 200) return 'allow';
|
||||||
|
if (resp.status === 403) return 'deny';
|
||||||
|
return 'error';
|
||||||
|
} catch (e) {
|
||||||
|
return 'error';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,206 @@
|
|||||||
|
import { Test } from '@nestjs/testing';
|
||||||
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
|
import { AuthController } from './auth.controller';
|
||||||
|
import { AuthClientService } from './auth.service';
|
||||||
|
import { ApiKeyService } from 'src/modules/api-key/api-key.service';
|
||||||
|
|
||||||
|
function res() {
|
||||||
|
const headers: Record<string, string> = {};
|
||||||
|
const r: any = {
|
||||||
|
_status: 0,
|
||||||
|
_sent: undefined,
|
||||||
|
set: (k: string, v: string) => {
|
||||||
|
headers[k] = v;
|
||||||
|
return r;
|
||||||
|
},
|
||||||
|
status: (c: number) => {
|
||||||
|
r._status = c;
|
||||||
|
return r;
|
||||||
|
},
|
||||||
|
send: (b?: any) => {
|
||||||
|
r._sent = b ?? '';
|
||||||
|
return r;
|
||||||
|
},
|
||||||
|
json: (b?: any) => {
|
||||||
|
r._sent = b;
|
||||||
|
return r;
|
||||||
|
},
|
||||||
|
_headers: headers,
|
||||||
|
};
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
function req(cookie?: string, query: Record<string, string> = {}) {
|
||||||
|
return { cookies: cookie ? { 'ddf-auth': cookie } : {}, query } as any;
|
||||||
|
}
|
||||||
|
|
||||||
|
const loggerStub = {
|
||||||
|
logger: { info: jest.fn(), error: jest.fn(), warn: jest.fn() },
|
||||||
|
} as unknown as DadosferaLogger;
|
||||||
|
|
||||||
|
async function makeController(auth: AuthClientService): Promise<AuthController> {
|
||||||
|
const mod = await Test.createTestingModule({
|
||||||
|
controllers: [AuthController],
|
||||||
|
providers: [
|
||||||
|
{ provide: DadosferaLogger, useValue: loggerStub },
|
||||||
|
{ provide: AuthClientService, useValue: auth },
|
||||||
|
{ provide: ApiKeyService, useValue: {} },
|
||||||
|
],
|
||||||
|
}).compile();
|
||||||
|
return mod.get(AuthController);
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('GET /auth/module-identity — identity', () => {
|
||||||
|
let controller: AuthController;
|
||||||
|
const auth = {
|
||||||
|
verifyAccessToken: jest.fn(),
|
||||||
|
} as unknown as AuthClientService;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
jest.resetAllMocks();
|
||||||
|
process.env.ORCHEST_MODULE_PERMISSION_SEQID = '31';
|
||||||
|
process.env.ORCHEST_ADMIN_PERMISSION_SEQIDS = '34';
|
||||||
|
controller = await makeController(auth);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('no cookie → 401', async () => {
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req(undefined), r);
|
||||||
|
expect(r._status).toBe(401);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('valid + module + admin → 200 with X-Auth-Roles: admin', async () => {
|
||||||
|
(auth.verifyAccessToken as jest.Mock).mockResolvedValue({
|
||||||
|
user_id: 'u-1',
|
||||||
|
username: 'alice',
|
||||||
|
permissions: [31, 34],
|
||||||
|
});
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok'), r);
|
||||||
|
expect(r._status).toBe(200);
|
||||||
|
expect(r._headers['X-Auth-User']).toBe('u-1');
|
||||||
|
expect(r._headers['X-Auth-Username']).toBe('alice');
|
||||||
|
expect(r._headers['X-Auth-Roles']).toBe('admin');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('valid + module, not admin → 200, no X-Auth-Roles', async () => {
|
||||||
|
(auth.verifyAccessToken as jest.Mock).mockResolvedValue({
|
||||||
|
user_id: 'u-2',
|
||||||
|
username: 'bob',
|
||||||
|
permissions: [31],
|
||||||
|
});
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok'), r);
|
||||||
|
expect(r._status).toBe(200);
|
||||||
|
expect(r._headers['X-Auth-Roles']).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('valid, lacks module → 403', async () => {
|
||||||
|
(auth.verifyAccessToken as jest.Mock).mockResolvedValue({
|
||||||
|
user_id: 'u-3',
|
||||||
|
username: 'carol',
|
||||||
|
permissions: [5],
|
||||||
|
});
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok'), r);
|
||||||
|
expect(r._status).toBe(403);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('verify throws (expired/bad) → 401', async () => {
|
||||||
|
(auth.verifyAccessToken as jest.Mock).mockRejectedValue(new Error('bad'));
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok'), r);
|
||||||
|
expect(r._status).toBe(401);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('admin seqids extended by config → 200 admin', async () => {
|
||||||
|
process.env.ORCHEST_ADMIN_PERMISSION_SEQIDS = '34,99';
|
||||||
|
(auth.verifyAccessToken as jest.Mock).mockResolvedValue({
|
||||||
|
user_id: 'u-4',
|
||||||
|
username: 'dana',
|
||||||
|
permissions: [31, 99],
|
||||||
|
});
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok'), r);
|
||||||
|
expect(r._headers['X-Auth-Roles']).toBe('admin');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('GET /auth/module-identity — per-service authz', () => {
|
||||||
|
let controller: AuthController;
|
||||||
|
const auth = {
|
||||||
|
verifyAccessToken: jest.fn(),
|
||||||
|
authorizeOrchestServiceAccess: jest.fn(),
|
||||||
|
} as unknown as AuthClientService;
|
||||||
|
|
||||||
|
const q = { permission: 'session.open', project_uuid: 'p-1' };
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
jest.resetAllMocks();
|
||||||
|
process.env.ORCHEST_MODULE_PERMISSION_SEQID = '31';
|
||||||
|
process.env.ORCHEST_ADMIN_PERMISSION_SEQIDS = '34';
|
||||||
|
process.env.ORCHEST_NAMESPACE_MODULE = 'intelli';
|
||||||
|
controller = await makeController(auth);
|
||||||
|
(auth.verifyAccessToken as jest.Mock).mockResolvedValue({
|
||||||
|
user_id: 'u-1',
|
||||||
|
username: 'alice',
|
||||||
|
permissions: [31],
|
||||||
|
customer_name: 'acme',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('has grant → 200 and calls the tenant host', async () => {
|
||||||
|
(auth.authorizeOrchestServiceAccess as jest.Mock).mockResolvedValue('allow');
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok', q), r);
|
||||||
|
expect(r._status).toBe(200);
|
||||||
|
expect(auth.authorizeOrchestServiceAccess).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
host: 'orchest-api.orchest-intelli-acme.svc.cluster.local',
|
||||||
|
permission: 'session.open',
|
||||||
|
projectUuid: 'p-1',
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('lacks grant → 403', async () => {
|
||||||
|
(auth.authorizeOrchestServiceAccess as jest.Mock).mockResolvedValue('deny');
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok', q), r);
|
||||||
|
expect(r._status).toBe(403);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('orchest-api error → 502 (fail-closed)', async () => {
|
||||||
|
(auth.authorizeOrchestServiceAccess as jest.Mock).mockResolvedValue('error');
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok', q), r);
|
||||||
|
expect(r._status).toBe(502);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('permission without project_uuid → 403 (all-or-nothing)', async () => {
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok', { permission: 'session.open' }), r);
|
||||||
|
expect(r._status).toBe(403);
|
||||||
|
expect(auth.authorizeOrchestServiceAccess).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('no authz params → 200 identity-only (webserver case)', async () => {
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok', {}), r);
|
||||||
|
expect(r._status).toBe(200);
|
||||||
|
expect(auth.authorizeOrchestServiceAccess).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('malformed customer_name → host fails allowlist → 403, no call', async () => {
|
||||||
|
(auth.verifyAccessToken as jest.Mock).mockResolvedValue({
|
||||||
|
user_id: 'u-1',
|
||||||
|
username: 'alice',
|
||||||
|
permissions: [31],
|
||||||
|
customer_name: '',
|
||||||
|
});
|
||||||
|
const r = res();
|
||||||
|
await controller.moduleIdentity(req('tok', q), r);
|
||||||
|
expect(r._status).toBe(403);
|
||||||
|
expect(auth.authorizeOrchestServiceAccess).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
import {
|
||||||
|
parseAdminSeqids,
|
||||||
|
moduleGateSeqid,
|
||||||
|
isModuleAllowed,
|
||||||
|
isAdmin,
|
||||||
|
tenantOrchestApiHost,
|
||||||
|
isAllowedOrchestApiHost,
|
||||||
|
namespaceModule,
|
||||||
|
} from './orchest-identity';
|
||||||
|
|
||||||
|
describe('orchest-identity mapping', () => {
|
||||||
|
it('parseAdminSeqids: default, single, list, whitespace', () => {
|
||||||
|
expect(parseAdminSeqids(undefined)).toEqual([34]);
|
||||||
|
expect(parseAdminSeqids('')).toEqual([34]);
|
||||||
|
expect(parseAdminSeqids('34')).toEqual([34]);
|
||||||
|
expect(parseAdminSeqids('34,40')).toEqual([34, 40]);
|
||||||
|
expect(parseAdminSeqids(' 34 , 40 ')).toEqual([34, 40]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('moduleGateSeqid: default and override', () => {
|
||||||
|
expect(moduleGateSeqid(undefined)).toBe(31);
|
||||||
|
expect(moduleGateSeqid('43')).toBe(43);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('isModuleAllowed', () => {
|
||||||
|
expect(isModuleAllowed([31, 5], 31)).toBe(true);
|
||||||
|
expect(isModuleAllowed([5, 7], 31)).toBe(false);
|
||||||
|
expect(isModuleAllowed([], 31)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('isAdmin: intersection', () => {
|
||||||
|
expect(isAdmin([31, 34], [34])).toBe(true);
|
||||||
|
expect(isAdmin([31], [34])).toBe(false);
|
||||||
|
expect(isAdmin([99], [34, 99])).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('orchest-identity tenant routing', () => {
|
||||||
|
it('namespaceModule default and values', () => {
|
||||||
|
expect(namespaceModule(undefined)).toBe('intelli');
|
||||||
|
expect(namespaceModule('process')).toBe('process');
|
||||||
|
expect(namespaceModule('garbage')).toBe('intelli');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('tenantOrchestApiHost builds the namespace pattern', () => {
|
||||||
|
expect(tenantOrchestApiHost('acme', 'intelli')).toBe(
|
||||||
|
'orchest-api.orchest-intelli-acme.svc.cluster.local',
|
||||||
|
);
|
||||||
|
expect(tenantOrchestApiHost('acme', 'process')).toBe(
|
||||||
|
'orchest-api.orchest-process-acme.svc.cluster.local',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('tenantOrchestApiHost normalizes a non-slug customer_name', () => {
|
||||||
|
expect(tenantOrchestApiHost('Acme Corp', 'intelli')).toBe(
|
||||||
|
'orchest-api.orchest-intelli-acme-corp.svc.cluster.local',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('isAllowedOrchestApiHost guards against malformed values', () => {
|
||||||
|
expect(
|
||||||
|
isAllowedOrchestApiHost(
|
||||||
|
'orchest-api.orchest-intelli-acme.svc.cluster.local',
|
||||||
|
),
|
||||||
|
).toBe(true);
|
||||||
|
expect(isAllowedOrchestApiHost('evil.example.com')).toBe(false);
|
||||||
|
expect(
|
||||||
|
isAllowedOrchestApiHost('orchest-api.orchest-intelli-.svc.cluster.local'),
|
||||||
|
).toBe(false);
|
||||||
|
expect(
|
||||||
|
isAllowedOrchestApiHost(
|
||||||
|
'orchest-api.orchest-other-acme.svc.cluster.local',
|
||||||
|
),
|
||||||
|
).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/**
|
||||||
|
* Pure helpers backing `GET /auth/module-identity` (see
|
||||||
|
* dbt-to-orchest docs/superpowers/specs/2026-08-20-maestro-module-identity-design.md).
|
||||||
|
*
|
||||||
|
* Kept free of HTTP/Nest so the permission mapping and tenant-routing logic
|
||||||
|
* unit-test without a request. Authorization decisions that reach orchest-api
|
||||||
|
* live on AuthClientService; this module only maps Maestro permissions to the
|
||||||
|
* Orchest header contract and derives the tenant orchest-api host.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Parse ORCHEST_ADMIN_PERMISSION_SEQIDS ("34" / "34,40"); default [34]. */
|
||||||
|
export function parseAdminSeqids(raw: string | undefined): number[] {
|
||||||
|
if (!raw || !raw.trim()) return [34];
|
||||||
|
return raw
|
||||||
|
.split(',')
|
||||||
|
.map((s) => Number(s.trim()))
|
||||||
|
.filter((n) => Number.isInteger(n));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Parse ORCHEST_MODULE_PERMISSION_SEQID; default 31 (Intelligence/Orchest). */
|
||||||
|
export function moduleGateSeqid(raw: string | undefined): number {
|
||||||
|
const n = Number(raw);
|
||||||
|
return Number.isInteger(n) && n > 0 ? n : 31;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Whether the user's permissions include the module-access gate seqid. */
|
||||||
|
export function isModuleAllowed(perms: number[], gateSeqid: number): boolean {
|
||||||
|
return Array.isArray(perms) && perms.includes(gateSeqid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Whether the user's permissions intersect the admin seqid set. */
|
||||||
|
export function isAdmin(perms: number[], adminSeqids: number[]): boolean {
|
||||||
|
return Array.isArray(perms) && perms.some((p) => adminSeqids.includes(p));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The `{module}` slug in the tenant namespace pattern; default 'intelli'. */
|
||||||
|
export function namespaceModule(
|
||||||
|
raw: string | undefined,
|
||||||
|
): 'intelli' | 'process' {
|
||||||
|
return raw === 'process' ? 'process' : 'intelli';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The in-cluster DNS of the calling tenant's orchest-api, from the tenant
|
||||||
|
* namespace convention `orchest-{module}-{customer_name}`.
|
||||||
|
*
|
||||||
|
* `customer_name` is normalized to the namespace slug shape (lowercase,
|
||||||
|
* non-[a-z0-9-] → '-') so a display-name value still yields a valid host; a
|
||||||
|
* value that is already a clean slug is unchanged. NOTE: confirm the exact
|
||||||
|
* prod `customer_name` → namespace mapping against a real token before relying
|
||||||
|
* on this in production (the `dadosferademo2` tenant is a known exception and
|
||||||
|
* is unsupported — it is being removed).
|
||||||
|
*/
|
||||||
|
export function tenantOrchestApiHost(
|
||||||
|
customerName: string,
|
||||||
|
module: string,
|
||||||
|
): string {
|
||||||
|
const slug = String(customerName)
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/[^a-z0-9-]/g, '-');
|
||||||
|
return `orchest-api.orchest-${module}-${slug}.svc.cluster.local`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ORCHEST_API_HOST_RE =
|
||||||
|
/^orchest-api\.orchest-(intelli|process)-[a-z0-9-]+\.svc\.cluster\.local$/;
|
||||||
|
|
||||||
|
/** Defense in depth: only call an orchest-api host matching the convention. */
|
||||||
|
export function isAllowedOrchestApiHost(host: string): boolean {
|
||||||
|
return ORCHEST_API_HOST_RE.test(host);
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
HttpStatus,
|
HttpStatus,
|
||||||
Res,
|
Res,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
|
import { ValidationPipe } from '../../pipes/object-validation.pipe';
|
||||||
import {
|
import {
|
||||||
ApiCreatedResponse,
|
ApiCreatedResponse,
|
||||||
ApiHeaders,
|
ApiHeaders,
|
||||||
@@ -46,6 +47,7 @@ import {
|
|||||||
IMakeAComment,
|
IMakeAComment,
|
||||||
IOneDataAsset,
|
IOneDataAsset,
|
||||||
IPreviewResponse,
|
IPreviewResponse,
|
||||||
|
IUpdateCertificationStatusRequest,
|
||||||
IUpdateDataRequest,
|
IUpdateDataRequest,
|
||||||
TriggerCatalogReq,
|
TriggerCatalogReq,
|
||||||
TriggerCatalogRes,
|
TriggerCatalogRes,
|
||||||
@@ -83,6 +85,9 @@ export class CatalogController {
|
|||||||
PERMISSIONS_GROUPS.CATALOG.permissions.GET,
|
PERMISSIONS_GROUPS.CATALOG.permissions.GET,
|
||||||
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
||||||
)
|
)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.CATALOG
|
||||||
|
)
|
||||||
async searchCatalog(
|
async searchCatalog(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Query() query: ICatalogAllRequest,
|
@Query() query: ICatalogAllRequest,
|
||||||
@@ -122,6 +127,9 @@ export class CatalogController {
|
|||||||
PERMISSIONS_GROUPS.CATALOG.permissions.GET,
|
PERMISSIONS_GROUPS.CATALOG.permissions.GET,
|
||||||
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
||||||
)
|
)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.CATALOG
|
||||||
|
)
|
||||||
async dowloadAsserts(
|
async dowloadAsserts(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Query() query: ICatalogAllRequest,
|
@Query() query: ICatalogAllRequest,
|
||||||
@@ -165,6 +173,9 @@ export class CatalogController {
|
|||||||
|
|
||||||
@ApiInternalOnlyEndpoint()
|
@ApiInternalOnlyEndpoint()
|
||||||
@Get('data-asset')
|
@Get('data-asset')
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.CATALOG
|
||||||
|
)
|
||||||
async findByPipelineAndObject(@User() user: RequestUser, @Query() query) {
|
async findByPipelineAndObject(@User() user: RequestUser, @Query() query) {
|
||||||
const { username, user_id, customer_id, customer_name, permissions } = user;
|
const { username, user_id, customer_id, customer_name, permissions } = user;
|
||||||
const { pipeline, object } = query;
|
const { pipeline, object } = query;
|
||||||
@@ -223,6 +234,9 @@ export class CatalogController {
|
|||||||
PERMISSIONS_GROUPS.CATALOG.permissions.GET,
|
PERMISSIONS_GROUPS.CATALOG.permissions.GET,
|
||||||
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
||||||
)
|
)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.CATALOG
|
||||||
|
)
|
||||||
async findAllTags(@Body() body) {
|
async findAllTags(@Body() body) {
|
||||||
this.logger.info(`/catalog - ON FIND ALL TAGS ROUTE`, {
|
this.logger.info(`/catalog - ON FIND ALL TAGS ROUTE`, {
|
||||||
user: body.info.user_id,
|
user: body.info.user_id,
|
||||||
@@ -269,11 +283,31 @@ export class CatalogController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('custom-properties')
|
||||||
|
@RequireSomePermission(
|
||||||
|
PERMISSIONS_GROUPS.CATALOG.permissions.GET,
|
||||||
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
||||||
|
)
|
||||||
|
async getCustomPropertyDefinitions(@User() user: RequestUser) {
|
||||||
|
const { customer_id, customer_name, user_id, username } = user;
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
customer_id,
|
||||||
|
customer_name,
|
||||||
|
user_id,
|
||||||
|
username,
|
||||||
|
});
|
||||||
|
|
||||||
|
return this.catalogService.getCustomPropertyDefinitions(metadata);
|
||||||
|
}
|
||||||
|
|
||||||
@Get('data-asset/:id')
|
@Get('data-asset/:id')
|
||||||
@RequireSomePermission(
|
@RequireSomePermission(
|
||||||
PERMISSIONS_GROUPS.CATALOG.permissions.GET,
|
PERMISSIONS_GROUPS.CATALOG.permissions.GET,
|
||||||
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
||||||
)
|
)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.CATALOG
|
||||||
|
)
|
||||||
async getDataAsset(
|
async getDataAsset(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
@@ -385,6 +419,9 @@ export class CatalogController {
|
|||||||
PERMISSIONS_GROUPS.CATALOG.permissions.GET,
|
PERMISSIONS_GROUPS.CATALOG.permissions.GET,
|
||||||
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
||||||
)
|
)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.CATALOG
|
||||||
|
)
|
||||||
async getDataAssetColumnsMetadata(
|
async getDataAssetColumnsMetadata(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Language() language: LanguageEnum,
|
@Language() language: LanguageEnum,
|
||||||
@@ -416,6 +453,9 @@ export class CatalogController {
|
|||||||
PERMISSIONS_GROUPS.CATALOG.permissions.GET,
|
PERMISSIONS_GROUPS.CATALOG.permissions.GET,
|
||||||
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
||||||
)
|
)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.CATALOG
|
||||||
|
)
|
||||||
async getDataAssetPreview(
|
async getDataAssetPreview(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Language() language: LanguageEnum,
|
@Language() language: LanguageEnum,
|
||||||
@@ -447,6 +487,9 @@ export class CatalogController {
|
|||||||
PERMISSIONS_GROUPS.CATALOG.permissions.GET,
|
PERMISSIONS_GROUPS.CATALOG.permissions.GET,
|
||||||
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
||||||
)
|
)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.CATALOG
|
||||||
|
)
|
||||||
async getDataAssetDocs(
|
async getDataAssetDocs(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Language() language: LanguageEnum,
|
@Language() language: LanguageEnum,
|
||||||
@@ -478,6 +521,9 @@ export class CatalogController {
|
|||||||
PERMISSIONS_GROUPS.CATALOG.permissions.UPDATE,
|
PERMISSIONS_GROUPS.CATALOG.permissions.UPDATE,
|
||||||
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
||||||
)
|
)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.CATALOG
|
||||||
|
)
|
||||||
async updateDataAsset(
|
async updateDataAsset(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Language() language: LanguageEnum,
|
@Language() language: LanguageEnum,
|
||||||
@@ -493,6 +539,8 @@ export class CatalogController {
|
|||||||
language,
|
language,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
delete (body as any).certification_status;
|
||||||
|
|
||||||
const result = await this.catalogService.updateOneDataAsset({
|
const result = await this.catalogService.updateOneDataAsset({
|
||||||
body,
|
body,
|
||||||
data_asset_id,
|
data_asset_id,
|
||||||
@@ -506,11 +554,44 @@ export class CatalogController {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Put('data-asset/:id/certification-status')
|
||||||
|
@RequireSomePermission(
|
||||||
|
PERMISSIONS_GROUPS.CATALOG.permissions.CERTIFY,
|
||||||
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
||||||
|
)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.CATALOG
|
||||||
|
)
|
||||||
|
async updateDataAssetCertificationStatus(
|
||||||
|
@User() user: RequestUser,
|
||||||
|
@Language() language: LanguageEnum,
|
||||||
|
@Param('id') data_asset_id: string,
|
||||||
|
@Body(new ValidationPipe()) body: IUpdateCertificationStatusRequest,
|
||||||
|
): Promise<IUpdateCertificationStatusRequest> {
|
||||||
|
const { customer_id, customer_name, user_id, username } = user;
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
customer_id,
|
||||||
|
customer_name,
|
||||||
|
user_id,
|
||||||
|
username,
|
||||||
|
language,
|
||||||
|
});
|
||||||
|
|
||||||
|
return this.catalogService.updateCertificationStatus({
|
||||||
|
body,
|
||||||
|
data_asset_id,
|
||||||
|
metadata,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Post('data-asset/:id/docs')
|
@Post('data-asset/:id/docs')
|
||||||
@RequireSomePermission(
|
@RequireSomePermission(
|
||||||
PERMISSIONS_GROUPS.CATALOG.permissions.UPDATE,
|
PERMISSIONS_GROUPS.CATALOG.permissions.UPDATE,
|
||||||
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
||||||
)
|
)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.CATALOG
|
||||||
|
)
|
||||||
async manageDataAssetDocs(
|
async manageDataAssetDocs(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Headers() headers,
|
@Headers() headers,
|
||||||
@@ -548,6 +629,9 @@ export class CatalogController {
|
|||||||
|
|
||||||
@ApiInternalOnlyEndpoint()
|
@ApiInternalOnlyEndpoint()
|
||||||
@Put('data-asset/:id/manage-permissions')
|
@Put('data-asset/:id/manage-permissions')
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.CATALOG
|
||||||
|
)
|
||||||
async manageDataAssetPermissions(
|
async manageDataAssetPermissions(
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@@ -570,6 +654,9 @@ export class CatalogController {
|
|||||||
|
|
||||||
@ApiInternalOnlyEndpoint()
|
@ApiInternalOnlyEndpoint()
|
||||||
@Put('data-asset/:id/revoke-permissions')
|
@Put('data-asset/:id/revoke-permissions')
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.CATALOG
|
||||||
|
)
|
||||||
async revokeDataAssetPermissions(
|
async revokeDataAssetPermissions(
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@@ -595,6 +682,9 @@ export class CatalogController {
|
|||||||
PERMISSIONS_GROUPS.CATALOG.permissions.CREATE,
|
PERMISSIONS_GROUPS.CATALOG.permissions.CREATE,
|
||||||
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
||||||
)
|
)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.CATALOG
|
||||||
|
)
|
||||||
async createDataAsset(
|
async createDataAsset(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Body() body: ICreateDataAsset,
|
@Body() body: ICreateDataAsset,
|
||||||
@@ -619,6 +709,9 @@ export class CatalogController {
|
|||||||
PERMISSIONS_GROUPS.CATALOG.permissions.UPDATE,
|
PERMISSIONS_GROUPS.CATALOG.permissions.UPDATE,
|
||||||
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
||||||
)
|
)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.CATALOG
|
||||||
|
)
|
||||||
async commentOnDataAsset(
|
async commentOnDataAsset(
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@@ -645,6 +738,9 @@ export class CatalogController {
|
|||||||
PERMISSIONS_GROUPS.CATALOG.permissions.DELETE,
|
PERMISSIONS_GROUPS.CATALOG.permissions.DELETE,
|
||||||
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
||||||
)
|
)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.CATALOG
|
||||||
|
)
|
||||||
async deleteDataAsset(@Param('id') id: string, @User() user: RequestUser) {
|
async deleteDataAsset(@Param('id') id: string, @User() user: RequestUser) {
|
||||||
const { customer_id, customer_name, user_id, username } = user;
|
const { customer_id, customer_name, user_id, username } = user;
|
||||||
const metadata = PackTheMetadata({
|
const metadata = PackTheMetadata({
|
||||||
@@ -666,6 +762,9 @@ export class CatalogController {
|
|||||||
PERMISSIONS_GROUPS.CATALOG.permissions.UPDATE,
|
PERMISSIONS_GROUPS.CATALOG.permissions.UPDATE,
|
||||||
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER,
|
||||||
)
|
)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.CATALOG
|
||||||
|
)
|
||||||
async deleteComment(
|
async deleteComment(
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@@ -819,6 +918,9 @@ export class CatalogController {
|
|||||||
|
|
||||||
@Get('nimbus-dashboards')
|
@Get('nimbus-dashboards')
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.CATALOG
|
||||||
|
)
|
||||||
async getNimbusDashboards(
|
async getNimbusDashboards(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@Body() body: GetNimbusDashboardsRequest,
|
@Body() body: GetNimbusDashboardsRequest,
|
||||||
@@ -971,4 +1073,4 @@ export class CatalogController {
|
|||||||
this.logger.error(error.message);
|
this.logger.error(error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import {
|
|||||||
AssetReporter,
|
AssetReporter,
|
||||||
BatchRemoveRlsRulesRequest,
|
BatchRemoveRlsRulesRequest,
|
||||||
CreateDataDocsDTO,
|
CreateDataDocsDTO,
|
||||||
|
IUpdateCertificationStatusRequest,
|
||||||
IUpdateDataRequest,
|
IUpdateDataRequest,
|
||||||
TriggerCatalogReq,
|
TriggerCatalogReq,
|
||||||
} from './dtos';
|
} from './dtos';
|
||||||
@@ -119,6 +120,10 @@ class CatalogService implements OnModuleInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getCustomPropertyDefinitions(metadata: Metadata) {
|
||||||
|
return lastValueFrom(this.catalogReadService.GetCustomPropertyDefinitions({}, metadata));
|
||||||
|
}
|
||||||
|
|
||||||
async createDataAsset(data: Messages.CreateDataAssetRequest, metadata) {
|
async createDataAsset(data: Messages.CreateDataAssetRequest, metadata) {
|
||||||
this.logger.info('CatalogService - Manage Data assets permissions');
|
this.logger.info('CatalogService - Manage Data assets permissions');
|
||||||
if (!data.embed) data.embed = undefined;
|
if (!data.embed) data.embed = undefined;
|
||||||
@@ -384,6 +389,28 @@ class CatalogService implements OnModuleInit {
|
|||||||
return { data_asset: asset[0] };
|
return { data_asset: asset[0] };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateCertificationStatus(data: {
|
||||||
|
data_asset_id: string;
|
||||||
|
body: IUpdateCertificationStatusRequest;
|
||||||
|
metadata: Metadata;
|
||||||
|
}) {
|
||||||
|
const { body, data_asset_id, metadata } = data;
|
||||||
|
|
||||||
|
await lastValueFrom(
|
||||||
|
this.catalogWriteService.UpdateDataAsset(
|
||||||
|
{
|
||||||
|
id: data_asset_id,
|
||||||
|
changes: JSON.stringify({
|
||||||
|
certification_status: body.certification_status,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
metadata,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return { certification_status: body.certification_status };
|
||||||
|
}
|
||||||
|
|
||||||
async updateOneDataAsset(data: {
|
async updateOneDataAsset(data: {
|
||||||
data_asset_id: string;
|
data_asset_id: string;
|
||||||
customer_id: string;
|
customer_id: string;
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
import { ApiProperty, ApiPropertyOptional, PickType } from '@nestjs/swagger';
|
import { ApiProperty, ApiPropertyOptional, PickType } from '@nestjs/swagger';
|
||||||
|
import {
|
||||||
|
IsEnum,
|
||||||
|
IsNotEmpty,
|
||||||
|
IsOptional,
|
||||||
|
IsString,
|
||||||
|
} from 'class-validator';
|
||||||
import { CreateDataAssetRequest } from '@dadosfera/protospack-v2/dist/lib/Catalog/interfaces/messages';
|
import { CreateDataAssetRequest } from '@dadosfera/protospack-v2/dist/lib/Catalog/interfaces/messages';
|
||||||
|
|
||||||
export enum DataAssetShareType {
|
export enum DataAssetShareType {
|
||||||
@@ -6,6 +12,12 @@ export enum DataAssetShareType {
|
|||||||
public = 'public',
|
public = 'public',
|
||||||
private = 'private',
|
private = 'private',
|
||||||
}
|
}
|
||||||
|
export enum CertificationStatus {
|
||||||
|
draft = 'draft',
|
||||||
|
in_review = 'in_review',
|
||||||
|
approved = 'approved',
|
||||||
|
deprecated = 'deprecated',
|
||||||
|
}
|
||||||
export enum OrderEnum {
|
export enum OrderEnum {
|
||||||
asc = 'asc',
|
asc = 'asc',
|
||||||
desc = 'desc',
|
desc = 'desc',
|
||||||
@@ -191,6 +203,27 @@ export class IData {
|
|||||||
day_opening: number;
|
day_opening: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export enum CustomPropertyType {
|
||||||
|
TEXT = 'text',
|
||||||
|
NUMBER = 'number',
|
||||||
|
DATE = 'date',
|
||||||
|
BOOLEAN = 'boolean',
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CustomPropertyDto {
|
||||||
|
@ApiProperty()
|
||||||
|
key: string;
|
||||||
|
@ApiProperty()
|
||||||
|
value: string;
|
||||||
|
@ApiProperty({ enum: CustomPropertyType })
|
||||||
|
type: CustomPropertyType;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
color?: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
emoji?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class IUpdateDataRequest {
|
export class IUpdateDataRequest {
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
name: string;
|
name: string;
|
||||||
@@ -204,7 +237,16 @@ export class IUpdateDataRequest {
|
|||||||
share_type?: DataAssetShareType;
|
share_type?: DataAssetShareType;
|
||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
docs?: string;
|
docs?: string;
|
||||||
|
@ApiPropertyOptional({ type: [CustomPropertyDto] })
|
||||||
|
custom_properties?: CustomPropertyDto[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class IUpdateCertificationStatusRequest {
|
||||||
|
@ApiProperty({ enum: CertificationStatus })
|
||||||
|
@IsEnum(CertificationStatus)
|
||||||
|
certification_status: CertificationStatus;
|
||||||
|
}
|
||||||
|
|
||||||
export class ICreateDataAsset implements CreateDataAssetRequest {
|
export class ICreateDataAsset implements CreateDataAssetRequest {
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
display_name: string;
|
display_name: string;
|
||||||
@@ -358,4 +400,4 @@ export type CreateDataDocsDTO = {
|
|||||||
docs: string;
|
docs: string;
|
||||||
asset_type: string;
|
asset_type: string;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,17 +22,24 @@ import {
|
|||||||
ConnectionTestListTablesRes,
|
ConnectionTestListTablesRes,
|
||||||
GetTableMetadataRes,
|
GetTableMetadataRes,
|
||||||
GetTableMetadataReq,
|
GetTableMetadataReq,
|
||||||
|
RefreshCatalogReq,
|
||||||
|
RefreshCatalogRes,
|
||||||
|
RefreshCatalogStatusReq,
|
||||||
} from './dto/connection-test';
|
} from './dto/connection-test';
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
import { Authenticated } from 'src/decorators/authentication.decorator';
|
import { Authenticated, RequireModule } from 'src/decorators/authentication.decorator';
|
||||||
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
||||||
import { ApiInternalOnlyController } from 'src/decorators/swagger.decorator';
|
import { ApiInternalOnlyController } from 'src/decorators/swagger.decorator';
|
||||||
|
import { DADOSFERA_MODULES_KEYS } from 'src/authentication/permissions.enum';
|
||||||
|
|
||||||
@ApiInternalOnlyController()
|
@ApiInternalOnlyController()
|
||||||
@ApiTags('Connection Test')
|
@ApiTags('Connection Test')
|
||||||
@Controller('connection-test')
|
@Controller('connection-test')
|
||||||
@UseFilters(new GrpcToHttpExceptionFilter())
|
@UseFilters(new GrpcToHttpExceptionFilter())
|
||||||
@Authenticated()
|
@Authenticated()
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.COLLECT
|
||||||
|
)
|
||||||
export class ConnectionTestController {
|
export class ConnectionTestController {
|
||||||
logger: any;
|
logger: any;
|
||||||
constructor(
|
constructor(
|
||||||
@@ -84,7 +91,7 @@ export class ConnectionTestController {
|
|||||||
});
|
});
|
||||||
return this.connectionTestService.connectionTestListSchemas(
|
return this.connectionTestService.connectionTestListSchemas(
|
||||||
body,
|
body,
|
||||||
user.customer_name,
|
user,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +108,7 @@ export class ConnectionTestController {
|
|||||||
});
|
});
|
||||||
return this.connectionTestService.connectionTestListTables(
|
return this.connectionTestService.connectionTestListTables(
|
||||||
body,
|
body,
|
||||||
user.customer_name,
|
user,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +125,38 @@ export class ConnectionTestController {
|
|||||||
});
|
});
|
||||||
return this.connectionTestService.getTableMetadata(
|
return this.connectionTestService.getTableMetadata(
|
||||||
body,
|
body,
|
||||||
user.customer_name,
|
user,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post('refresh-catalog')
|
||||||
|
@ApiOkResponse({ type: RefreshCatalogRes })
|
||||||
|
@HttpCode(HttpStatus.ACCEPTED)
|
||||||
|
async refreshCatalog(
|
||||||
|
@User() user: RequestUser,
|
||||||
|
@Body(new ValidationPipe()) body: RefreshCatalogReq,
|
||||||
|
) {
|
||||||
|
this.logger.info('/connection-test/refresh-catalog', {
|
||||||
|
user: user.user_id,
|
||||||
|
customer: user.customer_name,
|
||||||
|
connection: body.connection_id,
|
||||||
|
});
|
||||||
|
return this.connectionTestService.refreshCatalog(body, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('refresh-catalog/status')
|
||||||
|
@ApiOkResponse({ type: RefreshCatalogRes })
|
||||||
|
@HttpCode(HttpStatus.OK)
|
||||||
|
async refreshCatalogStatus(
|
||||||
|
@User() user: RequestUser,
|
||||||
|
@Body(new ValidationPipe()) body: RefreshCatalogStatusReq,
|
||||||
|
) {
|
||||||
|
this.logger.info('/connection-test/refresh-catalog/status', {
|
||||||
|
user: user.user_id,
|
||||||
|
customer: user.customer_name,
|
||||||
|
connection: body.connection_id,
|
||||||
|
session: body.session_id,
|
||||||
|
});
|
||||||
|
return this.connectionTestService.refreshCatalogStatus(body, user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,17 @@ import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
|||||||
import { ClientsModule } from '@nestjs/microservices';
|
import { ClientsModule } from '@nestjs/microservices';
|
||||||
import { ConnectionTestClientConfiguration } from './connection-test-client.config';
|
import { ConnectionTestClientConfiguration } from './connection-test-client.config';
|
||||||
import { ConnectionModule } from '../connection/connection.module';
|
import { ConnectionModule } from '../connection/connection.module';
|
||||||
|
import { ConnectionsApiModule } from '../connections-api/connections-api.module';
|
||||||
|
import { PlatformApiModule } from '../platform-api/platform-api.module';
|
||||||
const client = new ConnectionTestClientConfiguration();
|
const client = new ConnectionTestClientConfiguration();
|
||||||
@Module({
|
@Module({
|
||||||
controllers: [ConnectionTestController],
|
controllers: [ConnectionTestController],
|
||||||
providers: [ConnectionTestService, DadosferaLogger],
|
providers: [ConnectionTestService, DadosferaLogger],
|
||||||
imports: [ClientsModule.register([client.providerOptions]), ConnectionModule],
|
imports: [
|
||||||
|
ClientsModule.register([client.providerOptions]),
|
||||||
|
ConnectionModule,
|
||||||
|
ConnectionsApiModule,
|
||||||
|
PlatformApiModule,
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class ConnectionTestModule {}
|
export class ConnectionTestModule {}
|
||||||
|
|||||||
@@ -0,0 +1,205 @@
|
|||||||
|
import { ConnectionTestService } from './connection-test.service';
|
||||||
|
import { RequestUser } from 'src/decorators/user.decorator';
|
||||||
|
|
||||||
|
describe('ConnectionTestService catalog cache', () => {
|
||||||
|
const user: RequestUser = {
|
||||||
|
user_id: 'user-id',
|
||||||
|
username: 'user@example.com',
|
||||||
|
permissions: [],
|
||||||
|
customer_id: 'customer-id',
|
||||||
|
customer_name: 'customer-name',
|
||||||
|
customer_tier: 'standard',
|
||||||
|
access_token: 'token',
|
||||||
|
customer_modules: [],
|
||||||
|
roles: [],
|
||||||
|
};
|
||||||
|
const grpcClient = { getService: jest.fn().mockReturnValue({}) };
|
||||||
|
const connectionsService = {};
|
||||||
|
const connectionsApiService = { proxy: jest.fn() };
|
||||||
|
const platformApiService = { proxy: jest.fn() };
|
||||||
|
let service: ConnectionTestService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
service = new ConnectionTestService(
|
||||||
|
grpcClient as any,
|
||||||
|
connectionsService as any,
|
||||||
|
connectionsApiService as any,
|
||||||
|
platformApiService as any,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps the existing schemas response contract', async () => {
|
||||||
|
connectionsApiService.proxy.mockResolvedValue({
|
||||||
|
schemas: [{ schema_name: 'analytics' }, { schema_name: 'public' }],
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
service.connectionTestListSchemas(
|
||||||
|
{ connection_id: 'config-id', plugin: 'postgresql' },
|
||||||
|
user,
|
||||||
|
),
|
||||||
|
).resolves.toEqual({
|
||||||
|
operation_result: true,
|
||||||
|
schema_list: ['analytics', 'public'],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps the existing tables response contract', async () => {
|
||||||
|
connectionsApiService.proxy.mockResolvedValue({
|
||||||
|
tables: [{ table_name: 'customers' }, { table_name: 'orders' }],
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
service.connectionTestListTables(
|
||||||
|
{
|
||||||
|
connection_id: 'config-id',
|
||||||
|
plugin: 'postgresql',
|
||||||
|
schema: 'public',
|
||||||
|
},
|
||||||
|
user,
|
||||||
|
),
|
||||||
|
).resolves.toEqual({
|
||||||
|
operation_result: true,
|
||||||
|
table_list: ['customers', 'orders'],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('maps cached columns to the existing table metadata contract', async () => {
|
||||||
|
connectionsApiService.proxy.mockResolvedValue({
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
column_name: 'id',
|
||||||
|
data_type: 'bigint',
|
||||||
|
is_primary_key: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
service.getTableMetadata(
|
||||||
|
{
|
||||||
|
connection_id: 'config-id',
|
||||||
|
plugin: 'postgresql',
|
||||||
|
schema: 'public',
|
||||||
|
table_list: ['customers'],
|
||||||
|
},
|
||||||
|
user,
|
||||||
|
),
|
||||||
|
).resolves.toEqual({
|
||||||
|
operation_result: true,
|
||||||
|
tables_metadata: [
|
||||||
|
{
|
||||||
|
table_name: 'customers',
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
name: 'id',
|
||||||
|
type: 'bigint',
|
||||||
|
is_primary_key: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
references: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
expect(connectionsApiService.proxy).toHaveBeenCalledWith(
|
||||||
|
'GET',
|
||||||
|
'/connection_catalog/config-id/schemas/public/tables/customers/columns',
|
||||||
|
user,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('submits a catalog refresh without holding the request open', async () => {
|
||||||
|
platformApiService.proxy.mockResolvedValue({
|
||||||
|
session_id: 'session-id',
|
||||||
|
date: '20260731',
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
service.refreshCatalog(
|
||||||
|
{ connection_id: 'config-id', plugin: 'postgresql' },
|
||||||
|
user,
|
||||||
|
),
|
||||||
|
).resolves.toEqual({
|
||||||
|
operation_result: true,
|
||||||
|
status: 'PENDING',
|
||||||
|
session_id: 'session-id',
|
||||||
|
date: '20260731',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(platformApiService.proxy).toHaveBeenCalledWith(
|
||||||
|
'POST',
|
||||||
|
'/connection_test',
|
||||||
|
user,
|
||||||
|
{
|
||||||
|
customer_id: user.customer_name,
|
||||||
|
plugin: 'postgresql',
|
||||||
|
task: {
|
||||||
|
task_type: 'refresh_catalog',
|
||||||
|
connection: {
|
||||||
|
provider: 'connection_manager',
|
||||||
|
config_id: 'config-id',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps polling without changing the catalog pointer while pending', async () => {
|
||||||
|
platformApiService.proxy.mockResolvedValue({ status: 'PENDING' });
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
service.refreshCatalogStatus(
|
||||||
|
{
|
||||||
|
connection_id: 'config-id',
|
||||||
|
plugin: 'postgresql',
|
||||||
|
session_id: 'session-id',
|
||||||
|
date: '20260731',
|
||||||
|
},
|
||||||
|
user,
|
||||||
|
),
|
||||||
|
).resolves.toEqual({
|
||||||
|
operation_result: false,
|
||||||
|
status: 'PENDING',
|
||||||
|
session_id: 'session-id',
|
||||||
|
date: '20260731',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(connectionsApiService.proxy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('publishes the catalog pointer after the refresh finishes', async () => {
|
||||||
|
platformApiService.proxy.mockResolvedValue({ status: 'DONE' });
|
||||||
|
connectionsApiService.proxy.mockResolvedValue({
|
||||||
|
last_catalog_refresh_status: 'SUCCESS',
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
service.refreshCatalogStatus(
|
||||||
|
{
|
||||||
|
connection_id: 'config/id',
|
||||||
|
plugin: 'postgresql',
|
||||||
|
session_id: 'session-id',
|
||||||
|
date: '20260731',
|
||||||
|
},
|
||||||
|
user,
|
||||||
|
),
|
||||||
|
).resolves.toEqual({
|
||||||
|
operation_result: true,
|
||||||
|
status: 'DONE',
|
||||||
|
session_id: 'session-id',
|
||||||
|
date: '20260731',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(connectionsApiService.proxy).toHaveBeenCalledWith(
|
||||||
|
'PUT',
|
||||||
|
'/connection_config/config%2Fid/catalog_metadata',
|
||||||
|
user,
|
||||||
|
{
|
||||||
|
last_catalog_refresh_status: 'SUCCESS',
|
||||||
|
last_catalog_connection_test_date: '20260731',
|
||||||
|
last_catalog_connection_test_session_id: 'session-id',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
|
||||||
import { ClientGrpc } from '@nestjs/microservices';
|
import { ClientGrpc } from '@nestjs/microservices';
|
||||||
import { ConnectionTest } from '@dadosfera/protospack-v2';
|
import { ConnectionTest } from '@dadosfera/protospack-v2';
|
||||||
import { lastValueFrom } from 'rxjs';
|
import { lastValueFrom } from 'rxjs';
|
||||||
@@ -13,6 +13,9 @@ import {
|
|||||||
ConnectionTestPingRes,
|
ConnectionTestPingRes,
|
||||||
GetTableMetadataReq,
|
GetTableMetadataReq,
|
||||||
GetTableMetadataRes,
|
GetTableMetadataRes,
|
||||||
|
RefreshCatalogReq,
|
||||||
|
RefreshCatalogRes,
|
||||||
|
RefreshCatalogStatusReq,
|
||||||
} from './dto/connection-test';
|
} from './dto/connection-test';
|
||||||
import { ConnectionClientService } from '../connection/client.service';
|
import { ConnectionClientService } from '../connection/client.service';
|
||||||
import {
|
import {
|
||||||
@@ -21,6 +24,8 @@ import {
|
|||||||
} from '../connection/dtos/connection';
|
} from '../connection/dtos/connection';
|
||||||
import { RequestUser } from 'src/decorators/user.decorator';
|
import { RequestUser } from 'src/decorators/user.decorator';
|
||||||
import { PackTheMetadata } from 'src/utils/PackTheMetadata';
|
import { PackTheMetadata } from 'src/utils/PackTheMetadata';
|
||||||
|
import { ConnectionsApiService } from '../connections-api/connections-api.service';
|
||||||
|
import { PlatformApiService } from '../platform-api/platform-api.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ConnectionTestService {
|
export class ConnectionTestService {
|
||||||
@@ -28,6 +33,8 @@ export class ConnectionTestService {
|
|||||||
constructor(
|
constructor(
|
||||||
@Inject('ConnectionTestGrpcClient') private readonly grpcClient: ClientGrpc,
|
@Inject('ConnectionTestGrpcClient') private readonly grpcClient: ClientGrpc,
|
||||||
private connectionsService: ConnectionClientService,
|
private connectionsService: ConnectionClientService,
|
||||||
|
private connectionsApiService: ConnectionsApiService,
|
||||||
|
private platformApiService: PlatformApiService,
|
||||||
) {
|
) {
|
||||||
this.connectionTestReadClient =
|
this.connectionTestReadClient =
|
||||||
grpcClient.getService<ConnectionTest.ReadService.ConnectionTestReadServices>(
|
grpcClient.getService<ConnectionTest.ReadService.ConnectionTestReadServices>(
|
||||||
@@ -147,45 +154,137 @@ export class ConnectionTestService {
|
|||||||
}
|
}
|
||||||
async connectionTestListSchemas(
|
async connectionTestListSchemas(
|
||||||
body: ConnectionTestListSchemasReq,
|
body: ConnectionTestListSchemasReq,
|
||||||
customer_name: string,
|
user: RequestUser,
|
||||||
): Promise<ConnectionTestListSchemasRes> {
|
): Promise<ConnectionTestListSchemasRes> {
|
||||||
const { connection_id, plugin } = body;
|
const result = await this.connectionsApiService.proxy(
|
||||||
return lastValueFrom(
|
'GET',
|
||||||
this.connectionTestReadClient.ListSchemas({
|
`/connection_catalog/${encodeURIComponent(body.connection_id)}/schemas`,
|
||||||
connection_id,
|
user,
|
||||||
customer_name,
|
|
||||||
plugin,
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
|
return {
|
||||||
|
operation_result: true,
|
||||||
|
schema_list: result.schemas.map((schema) => schema.schema_name),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async connectionTestListTables(
|
async connectionTestListTables(
|
||||||
body: ConnectionTestListTablesReq,
|
body: ConnectionTestListTablesReq,
|
||||||
customer_name: string,
|
user: RequestUser,
|
||||||
): Promise<ConnectionTestListTablesRes> {
|
): Promise<ConnectionTestListTablesRes> {
|
||||||
const { connection_id, plugin, schema } = body;
|
const result = await this.connectionsApiService.proxy(
|
||||||
return lastValueFrom(
|
'GET',
|
||||||
this.connectionTestReadClient.ListTables({
|
`/connection_catalog/${encodeURIComponent(body.connection_id)}` +
|
||||||
connection_id,
|
`/schemas/${encodeURIComponent(body.schema)}/tables`,
|
||||||
customer_name,
|
user,
|
||||||
plugin,
|
|
||||||
schema,
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
|
return {
|
||||||
|
operation_result: true,
|
||||||
|
table_list: result.tables.map((table) => table.table_name),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTableMetadata(
|
async getTableMetadata(
|
||||||
body: GetTableMetadataReq,
|
body: GetTableMetadataReq,
|
||||||
customer_name: string,
|
user: RequestUser,
|
||||||
): Promise<GetTableMetadataRes> {
|
): Promise<GetTableMetadataRes> {
|
||||||
const { schema, plugin, table_list, connection_id } = body;
|
const tables_metadata = await Promise.all(
|
||||||
return lastValueFrom(
|
body.table_list.map(async (table_name) => {
|
||||||
this.connectionTestReadClient.GetTableMetadata({
|
const result = await this.connectionsApiService.proxy(
|
||||||
connection_id,
|
'GET',
|
||||||
customer_name,
|
`/connection_catalog/${encodeURIComponent(body.connection_id)}` +
|
||||||
plugin,
|
`/schemas/${encodeURIComponent(body.schema)}` +
|
||||||
schema,
|
`/tables/${encodeURIComponent(table_name)}/columns`,
|
||||||
table_list,
|
user,
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
table_name,
|
||||||
|
columns: result.columns.map((column) => ({
|
||||||
|
name: column.column_name,
|
||||||
|
type: column.data_type,
|
||||||
|
is_primary_key: column.is_primary_key,
|
||||||
|
})),
|
||||||
|
references: [],
|
||||||
|
};
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
return { operation_result: true, tables_metadata };
|
||||||
|
}
|
||||||
|
|
||||||
|
async refreshCatalog(
|
||||||
|
body: RefreshCatalogReq,
|
||||||
|
user: RequestUser,
|
||||||
|
): Promise<RefreshCatalogRes> {
|
||||||
|
const task = await this.platformApiService.proxy(
|
||||||
|
'POST',
|
||||||
|
'/connection_test',
|
||||||
|
user,
|
||||||
|
{
|
||||||
|
customer_id: user.customer_name,
|
||||||
|
plugin: body.plugin,
|
||||||
|
task: {
|
||||||
|
task_type: 'refresh_catalog',
|
||||||
|
connection: {
|
||||||
|
provider: 'connection_manager',
|
||||||
|
config_id: body.connection_id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!task.session_id || !task.date) {
|
||||||
|
throw new HttpException(
|
||||||
|
'Platform API did not return a catalog refresh task identifier',
|
||||||
|
HttpStatus.BAD_GATEWAY,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
operation_result: true,
|
||||||
|
status: 'PENDING',
|
||||||
|
session_id: task.session_id,
|
||||||
|
date: task.date,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async refreshCatalogStatus(
|
||||||
|
body: RefreshCatalogStatusReq,
|
||||||
|
user: RequestUser,
|
||||||
|
): Promise<RefreshCatalogRes> {
|
||||||
|
const result = await this.platformApiService.proxy(
|
||||||
|
'POST',
|
||||||
|
'/connection_test/status',
|
||||||
|
user,
|
||||||
|
{
|
||||||
|
session_id: body.session_id,
|
||||||
|
date: body.date,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.status === 'DONE') {
|
||||||
|
await this.connectionsApiService.proxy(
|
||||||
|
'PUT',
|
||||||
|
`/connection_config/${encodeURIComponent(
|
||||||
|
body.connection_id,
|
||||||
|
)}/catalog_metadata`,
|
||||||
|
user,
|
||||||
|
{
|
||||||
|
last_catalog_refresh_status: 'SUCCESS',
|
||||||
|
last_catalog_connection_test_date: body.date,
|
||||||
|
last_catalog_connection_test_session_id: body.session_id,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else if (result.status === 'ERROR' || result.status === 'EXPIRED') {
|
||||||
|
throw new HttpException(
|
||||||
|
`Catalog refresh finished with status ${result.status}`,
|
||||||
|
HttpStatus.BAD_GATEWAY,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
operation_result: result.status === 'DONE',
|
||||||
|
status: result.status,
|
||||||
|
session_id: body.session_id,
|
||||||
|
date: body.date,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { ApiProperty, ApiPropertyOptional, OmitType } from '@nestjs/swagger';
|
import { ApiProperty, ApiPropertyOptional, OmitType } from '@nestjs/swagger';
|
||||||
import { IsString, IsOptional } from 'class-validator';
|
import { IsIn, IsString, IsOptional } from 'class-validator';
|
||||||
import { DatabaseConnectionPropertiesDto } from 'src/modules/connection/dtos/connection';
|
import { DatabaseConnectionPropertiesDto } from 'src/modules/connection/dtos/connection';
|
||||||
import { CreateConnectionDto } from 'src/modules/connection/dtos/connection';
|
import { CreateConnectionDto } from 'src/modules/connection/dtos/connection';
|
||||||
export class ColumnDto {
|
export class ColumnDto {
|
||||||
@@ -7,6 +7,8 @@ export class ColumnDto {
|
|||||||
name: string;
|
name: string;
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
type: string;
|
type: string;
|
||||||
|
@ApiProperty()
|
||||||
|
is_primary_key: boolean;
|
||||||
}
|
}
|
||||||
export class TableMetadataDto {
|
export class TableMetadataDto {
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
@@ -131,3 +133,37 @@ export class GetTableMetadataRes {
|
|||||||
@ApiProperty({ type: [TableMetadataDto] })
|
@ApiProperty({ type: [TableMetadataDto] })
|
||||||
tables_metadata: TableMetadataDto[];
|
tables_metadata: TableMetadataDto[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class RefreshCatalogReq {
|
||||||
|
@ApiProperty()
|
||||||
|
@IsString()
|
||||||
|
connection_id: string;
|
||||||
|
|
||||||
|
@ApiProperty({ enum: ['oracle', 'mysql', 'postgresql', 'sqlserver'] })
|
||||||
|
@IsIn(['oracle', 'mysql', 'postgresql', 'sqlserver'])
|
||||||
|
plugin: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class RefreshCatalogStatusReq extends RefreshCatalogReq {
|
||||||
|
@ApiProperty()
|
||||||
|
@IsString()
|
||||||
|
session_id: string;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
@IsString()
|
||||||
|
date: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class RefreshCatalogRes {
|
||||||
|
@ApiProperty()
|
||||||
|
operation_result: boolean;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
status: string;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
session_id: string;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
date: string;
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,8 +16,9 @@ import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
|||||||
import {
|
import {
|
||||||
Authenticated,
|
Authenticated,
|
||||||
RequireAllPermissions,
|
RequireAllPermissions,
|
||||||
|
RequireModule,
|
||||||
} from 'src/decorators/authentication.decorator';
|
} from 'src/decorators/authentication.decorator';
|
||||||
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
import { DADOSFERA_MODULES_KEYS, PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
||||||
import { RequestUser, User } from 'src/decorators/user.decorator';
|
import { RequestUser, User } from 'src/decorators/user.decorator';
|
||||||
import { ValidationPipe } from '../../pipes/object-validation.pipe';
|
import { ValidationPipe } from '../../pipes/object-validation.pipe';
|
||||||
import {
|
import {
|
||||||
@@ -39,6 +40,9 @@ const connectionPermissions = PERMISSIONS_GROUPS.CONNECTION.permissions;
|
|||||||
@ApiTags('connections')
|
@ApiTags('connections')
|
||||||
@Authenticated()
|
@Authenticated()
|
||||||
@Controller('connections')
|
@Controller('connections')
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.COLLECT
|
||||||
|
)
|
||||||
export class ConnectionController {
|
export class ConnectionController {
|
||||||
logger: any;
|
logger: any;
|
||||||
constructor(
|
constructor(
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
export const CONNECTIONS_API_CONFIG = {
|
||||||
|
getUrl: (): string => {
|
||||||
|
const url = process.env.CONNECTIONS_API_URL;
|
||||||
|
if (!url) {
|
||||||
|
throw new Error('CONNECTIONS_API_URL environment variable is not set');
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
},
|
||||||
|
region: process.env.AWS_REGION || 'us-east-1',
|
||||||
|
timeout: parseInt(process.env.CONNECTIONS_API_TIMEOUT || '30000', 10),
|
||||||
|
};
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
|
|
||||||
|
import { ConnectionsApiService } from './connections-api.service';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
providers: [ConnectionsApiService, DadosferaLogger],
|
||||||
|
exports: [ConnectionsApiService],
|
||||||
|
})
|
||||||
|
export class ConnectionsApiModule {}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
import { Injectable, Inject, HttpException } from '@nestjs/common';
|
||||||
|
import { SignatureV4 } from '@aws-sdk/signature-v4';
|
||||||
|
import { Sha256 } from '@aws-crypto/sha256-js';
|
||||||
|
import { defaultProvider } from '@aws-sdk/credential-provider-node';
|
||||||
|
import axios, { AxiosResponse, Method } from 'axios';
|
||||||
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
|
|
||||||
|
import { RequestUser } from '../../decorators/user.decorator';
|
||||||
|
import { CONNECTIONS_API_CONFIG } from './connections-api.config';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ConnectionsApiService {
|
||||||
|
private signer: SignatureV4;
|
||||||
|
private logger: any;
|
||||||
|
|
||||||
|
constructor(@Inject(DadosferaLogger) dadosferaLogger: DadosferaLogger) {
|
||||||
|
this.logger = dadosferaLogger.logger;
|
||||||
|
this.signer = new SignatureV4({
|
||||||
|
service: 'execute-api',
|
||||||
|
region: CONNECTIONS_API_CONFIG.region,
|
||||||
|
credentials: defaultProvider(),
|
||||||
|
sha256: Sha256,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async proxy(
|
||||||
|
method: string,
|
||||||
|
path: string,
|
||||||
|
user: RequestUser,
|
||||||
|
body?: any,
|
||||||
|
query?: Record<string, string>,
|
||||||
|
): Promise<any> {
|
||||||
|
const baseUrl = CONNECTIONS_API_CONFIG.getUrl();
|
||||||
|
const url = new URL(`${baseUrl}${path}`);
|
||||||
|
|
||||||
|
if (query) {
|
||||||
|
Object.entries(query).forEach(([key, value]) => {
|
||||||
|
if (value !== undefined && value !== null) {
|
||||||
|
url.searchParams.set(key, String(value));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const headers: Record<string, string> = {
|
||||||
|
host: url.hostname,
|
||||||
|
'content-type': 'application/json',
|
||||||
|
customer_name: user.customer_name || '',
|
||||||
|
customer_id: user.customer_id || '',
|
||||||
|
'x-user-id': user.user_id || '',
|
||||||
|
'x-username': user.username || '',
|
||||||
|
'x-customer-tier': user.customer_tier || '',
|
||||||
|
'x-customer-id': user.customer_id || '',
|
||||||
|
};
|
||||||
|
const requestToSign = {
|
||||||
|
method: method.toUpperCase(),
|
||||||
|
protocol: url.protocol,
|
||||||
|
hostname: url.hostname,
|
||||||
|
port: url.port ? parseInt(url.port, 10) : undefined,
|
||||||
|
path: url.pathname + url.search,
|
||||||
|
headers,
|
||||||
|
body: body ? JSON.stringify(body) : undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const signedRequest = await this.signer.sign(requestToSign);
|
||||||
|
const response: AxiosResponse = await axios({
|
||||||
|
method: method as Method,
|
||||||
|
url: url.href,
|
||||||
|
headers: signedRequest.headers as Record<string, string>,
|
||||||
|
data: body,
|
||||||
|
timeout: CONNECTIONS_API_CONFIG.timeout,
|
||||||
|
validateStatus: () => true,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.status >= 400) {
|
||||||
|
throw new HttpException(response.data, response.status);
|
||||||
|
}
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error('Connections API proxy error', {
|
||||||
|
error: error.message,
|
||||||
|
path,
|
||||||
|
method: method.toUpperCase(),
|
||||||
|
});
|
||||||
|
if (error instanceof HttpException) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
if (error.response) {
|
||||||
|
throw new HttpException(error.response.data, error.response.status);
|
||||||
|
}
|
||||||
|
if (error.code === 'ECONNREFUSED') {
|
||||||
|
throw new HttpException('Connections API service unavailable', 503);
|
||||||
|
}
|
||||||
|
if (error.code === 'ETIMEDOUT' || error.code === 'ECONNABORTED') {
|
||||||
|
throw new HttpException('Connections API request timeout', 504);
|
||||||
|
}
|
||||||
|
throw new HttpException('Internal server error', 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,9 +25,10 @@ import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
|||||||
import {
|
import {
|
||||||
Authenticated,
|
Authenticated,
|
||||||
RequireAllPermissions,
|
RequireAllPermissions,
|
||||||
|
RequireModule,
|
||||||
RequireSomePermission,
|
RequireSomePermission,
|
||||||
} from 'src/decorators/authentication.decorator';
|
} from 'src/decorators/authentication.decorator';
|
||||||
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
import { DADOSFERA_MODULES_KEYS, PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
||||||
import { Language } from 'src/decorators/language.decorator';
|
import { Language } from 'src/decorators/language.decorator';
|
||||||
import { LanguageEnum } from 'src/utils/languages.enum';
|
import { LanguageEnum } from 'src/utils/languages.enum';
|
||||||
import { ApiInternalOnlyController } from 'src/decorators/swagger.decorator';
|
import { ApiInternalOnlyController } from 'src/decorators/swagger.decorator';
|
||||||
@@ -99,6 +100,9 @@ export class ConnectorController {
|
|||||||
PERMISSIONS_GROUPS.PIPELINE.permissions.UPDATE,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.UPDATE,
|
||||||
PERMISSIONS_GROUPS.PIPELINE.permissions.DELETE,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.DELETE,
|
||||||
)
|
)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.COLLECT
|
||||||
|
)
|
||||||
async getAllConnectors(
|
async getAllConnectors(
|
||||||
@Language() language: LanguageEnum,
|
@Language() language: LanguageEnum,
|
||||||
@Query() queries: GetAllDto,
|
@Query() queries: GetAllDto,
|
||||||
@@ -131,6 +135,9 @@ export class ConnectorController {
|
|||||||
PERMISSIONS_GROUPS.PIPELINE.permissions.UPDATE,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.UPDATE,
|
||||||
PERMISSIONS_GROUPS.PIPELINE.permissions.DELETE,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.DELETE,
|
||||||
)
|
)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.COLLECT
|
||||||
|
)
|
||||||
async getConnectorsTags() {
|
async getConnectorsTags() {
|
||||||
return await this.connectorClientService.getConnectorsTags();
|
return await this.connectorClientService.getConnectorsTags();
|
||||||
}
|
}
|
||||||
@@ -143,6 +150,9 @@ export class ConnectorController {
|
|||||||
PERMISSIONS_GROUPS.PIPELINE.permissions.UPDATE,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.UPDATE,
|
||||||
PERMISSIONS_GROUPS.PIPELINE.permissions.DELETE,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.DELETE,
|
||||||
)
|
)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.COLLECT
|
||||||
|
)
|
||||||
async getConnector(
|
async getConnector(
|
||||||
@Language() language: LanguageEnum,
|
@Language() language: LanguageEnum,
|
||||||
@Param('plugin') plugin: string,
|
@Param('plugin') plugin: string,
|
||||||
@@ -171,6 +181,9 @@ export class ConnectorController {
|
|||||||
PERMISSIONS_GROUPS.PIPELINE.permissions.UPDATE,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.UPDATE,
|
||||||
PERMISSIONS_GROUPS.PIPELINE.permissions.DELETE,
|
PERMISSIONS_GROUPS.PIPELINE.permissions.DELETE,
|
||||||
)
|
)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.COLLECT
|
||||||
|
)
|
||||||
async getConnectorDetails(
|
async getConnectorDetails(
|
||||||
@Language() language: LanguageEnum,
|
@Language() language: LanguageEnum,
|
||||||
@Param('plugin') plugin: string,
|
@Param('plugin') plugin: string,
|
||||||
@@ -193,6 +206,9 @@ export class ConnectorController {
|
|||||||
@Put('/:plugin')
|
@Put('/:plugin')
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.CONNECTORS.permissions.UPDATE)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.CONNECTORS.permissions.UPDATE)
|
||||||
@ApiConsumes('multipart/form-data')
|
@ApiConsumes('multipart/form-data')
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.COLLECT
|
||||||
|
)
|
||||||
async updateConnector(
|
async updateConnector(
|
||||||
@Param('plugin') plugin: string,
|
@Param('plugin') plugin: string,
|
||||||
@Body() body: UpdateDto,
|
@Body() body: UpdateDto,
|
||||||
@@ -214,6 +230,9 @@ export class ConnectorController {
|
|||||||
|
|
||||||
@Put('/:plugin/add-tag')
|
@Put('/:plugin/add-tag')
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.CONNECTORS.permissions.UPDATE)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.CONNECTORS.permissions.UPDATE)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.COLLECT
|
||||||
|
)
|
||||||
async addTagOnConnector(
|
async addTagOnConnector(
|
||||||
@Param('plugin') plugin: string,
|
@Param('plugin') plugin: string,
|
||||||
@Body() body: AddTagDto,
|
@Body() body: AddTagDto,
|
||||||
@@ -241,6 +260,9 @@ export class ConnectorController {
|
|||||||
|
|
||||||
@Put('/:plugin/remove-tag')
|
@Put('/:plugin/remove-tag')
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.CONNECTORS.permissions.UPDATE)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.CONNECTORS.permissions.UPDATE)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.COLLECT
|
||||||
|
)
|
||||||
async removeTagOnConnector(
|
async removeTagOnConnector(
|
||||||
@Param('plugin') plugin: string,
|
@Param('plugin') plugin: string,
|
||||||
@Body() body: RemoveTagDto,
|
@Body() body: RemoveTagDto,
|
||||||
@@ -269,6 +291,9 @@ export class ConnectorController {
|
|||||||
|
|
||||||
@Delete('/:plugin')
|
@Delete('/:plugin')
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.CONNECTORS.permissions.DELETE)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.CONNECTORS.permissions.DELETE)
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.COLLECT
|
||||||
|
)
|
||||||
async deleteConnector(
|
async deleteConnector(
|
||||||
@Param('plugin') plugin: string,
|
@Param('plugin') plugin: string,
|
||||||
@Query('version') version: string,
|
@Query('version') version: string,
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import {
|
|||||||
} from '@dadosfera/protospack-v2/dist/lib/Input/interfaces/messages';
|
} from '@dadosfera/protospack-v2/dist/lib/Input/interfaces/messages';
|
||||||
import { Info } from '@dadosfera/protospack-v2/dist/lib/Input/interfaces/entities';
|
import { Info } from '@dadosfera/protospack-v2/dist/lib/Input/interfaces/entities';
|
||||||
import { CreateInputReq } from './dtos/input.model';
|
import { CreateInputReq } from './dtos/input.model';
|
||||||
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|
||||||
@@ -73,10 +74,10 @@ export class InputsService {
|
|||||||
objectCamelToSnake(createInputResponse);
|
objectCamelToSnake(createInputResponse);
|
||||||
return createInputResponse;
|
return createInputResponse;
|
||||||
},
|
},
|
||||||
update: async (updateInputDTO: UpdateInputRequest): Promise<InputUpdateResponse> => {
|
update: async (updateInputDTO: UpdateInputRequest, metadata: Metadata): Promise<InputUpdateResponse> => {
|
||||||
this.logger.info('InputClientService - Update' + JSON.stringify(updateInputDTO));
|
this.logger.info('InputClientService - Update' + JSON.stringify(updateInputDTO));
|
||||||
const updateInputResponse = await lastValueFrom(
|
const updateInputResponse = await lastValueFrom(
|
||||||
this.inputWriteService.InputUpdate(updateInputDTO),
|
this.inputWriteService.InputUpdate(updateInputDTO, metadata),
|
||||||
);
|
);
|
||||||
|
|
||||||
return updateInputResponse;
|
return updateInputResponse;
|
||||||
@@ -206,7 +207,7 @@ export class InputsService {
|
|||||||
return findOneInputResponse;
|
return findOneInputResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: string, data, info: Info) {
|
async update(id: string, data, info: Info, metadata?: Metadata) {
|
||||||
// this.validateCron({ ...data, info });
|
// this.validateCron({ ...data, info });
|
||||||
try {
|
try {
|
||||||
const {
|
const {
|
||||||
@@ -217,7 +218,7 @@ export class InputsService {
|
|||||||
id,
|
id,
|
||||||
...data,
|
...data,
|
||||||
info,
|
info,
|
||||||
});
|
}, metadata);
|
||||||
|
|
||||||
const updateInputResponse = this.adjustInputPayload(
|
const updateInputResponse = this.adjustInputPayload(
|
||||||
input,
|
input,
|
||||||
|
|||||||
@@ -25,9 +25,10 @@ import {
|
|||||||
} from '@nestjs/swagger';
|
} from '@nestjs/swagger';
|
||||||
import {
|
import {
|
||||||
RequireAllPermissions,
|
RequireAllPermissions,
|
||||||
|
RequireModule,
|
||||||
RequireSomePermission,
|
RequireSomePermission,
|
||||||
} from 'src/decorators/authentication.decorator';
|
} from 'src/decorators/authentication.decorator';
|
||||||
import { PERMISSIONS_GROUPS } from '../../authentication/permissions.enum';
|
import { DADOSFERA_MODULES_KEYS, PERMISSIONS_GROUPS } from '../../authentication/permissions.enum';
|
||||||
import { PipelinesService } from './pipelines.service';
|
import { PipelinesService } from './pipelines.service';
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
import { Messages } from '@dadosfera/protospack-v2/dist/lib/PipelineV2';
|
import { Messages } from '@dadosfera/protospack-v2/dist/lib/PipelineV2';
|
||||||
@@ -57,6 +58,9 @@ type PipelineTablesConfig = { input_id?: string; tables: PipelineTable[] };
|
|||||||
@ApiHeaders([{ name: 'dadosfera-lang', enum: LanguageEnum, required: false }])
|
@ApiHeaders([{ name: 'dadosfera-lang', enum: LanguageEnum, required: false }])
|
||||||
@UseFilters(new GrpcToHttpExceptionFilter())
|
@UseFilters(new GrpcToHttpExceptionFilter())
|
||||||
@Controller('pipelinesV2')
|
@Controller('pipelinesV2')
|
||||||
|
@RequireModule(
|
||||||
|
DADOSFERA_MODULES_KEYS.COLLECT
|
||||||
|
)
|
||||||
export class PipelinesController {
|
export class PipelinesController {
|
||||||
logger: DadosferaLogger;
|
logger: DadosferaLogger;
|
||||||
constructor(
|
constructor(
|
||||||
@@ -317,7 +321,6 @@ export class PipelinesController {
|
|||||||
) {
|
) {
|
||||||
this.logger.info('PipelinesController - update', { user });
|
this.logger.info('PipelinesController - update', { user });
|
||||||
|
|
||||||
const { customer_id, customer_name, user_id, username } = user;
|
|
||||||
const info: Info = {
|
const info: Info = {
|
||||||
user_id: user.user_id,
|
user_id: user.user_id,
|
||||||
customer: user.customer_name,
|
customer: user.customer_name,
|
||||||
@@ -325,13 +328,7 @@ export class PipelinesController {
|
|||||||
pipeline_id: pipelineId
|
pipeline_id: pipelineId
|
||||||
};
|
};
|
||||||
|
|
||||||
const metadata = PackTheMetadata({
|
const metadata = PackTheMetadata(user);
|
||||||
customer_id,
|
|
||||||
customer_name,
|
|
||||||
user_id,
|
|
||||||
username,
|
|
||||||
language,
|
|
||||||
});
|
|
||||||
|
|
||||||
const response = await this.pipelinesClientService.updatePipelineInput(
|
const response = await this.pipelinesClientService.updatePipelineInput(
|
||||||
pipelineId,
|
pipelineId,
|
||||||
|
|||||||
@@ -383,7 +383,8 @@ export class PipelinesService implements OnModuleInit {
|
|||||||
const updateInputResponse = await this.inputsService.update(
|
const updateInputResponse = await this.inputsService.update(
|
||||||
inputId,
|
inputId,
|
||||||
updateInputDTO,
|
updateInputDTO,
|
||||||
info
|
info,
|
||||||
|
metadata
|
||||||
);
|
);
|
||||||
|
|
||||||
const inputRollback = () => {
|
const inputRollback = () => {
|
||||||
@@ -404,34 +405,36 @@ export class PipelinesService implements OnModuleInit {
|
|||||||
|
|
||||||
const nimbusUpdates = updateInputResponse?.tablesUpdate || [];
|
const nimbusUpdates = updateInputResponse?.tablesUpdate || [];
|
||||||
|
|
||||||
nimbusUpdates.forEach(update => {
|
if (user.customer_modules.includes('catalog')) {
|
||||||
const nimbusRollback = () => {
|
nimbusUpdates.forEach(update => {
|
||||||
return this.nimbusService.renameTable(
|
const nimbusRollback = () => {
|
||||||
info.customer,
|
return this.nimbusService.renameTable(
|
||||||
update.database,
|
info.customer,
|
||||||
{
|
update.database,
|
||||||
table_name: update.table_name,
|
{
|
||||||
table_schema: update.table_schema
|
table_name: update.table_name,
|
||||||
},
|
table_schema: update.table_schema
|
||||||
{
|
},
|
||||||
table_name: update.old_table_name,
|
{
|
||||||
table_schema: update.old_table_schema
|
table_name: update.old_table_name,
|
||||||
}
|
table_schema: update.old_table_schema
|
||||||
);
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
rollback.push(nimbusRollback);
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.updateNimbus(info.customer, nimbusUpdates);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(error);
|
||||||
|
if (error instanceof AxiosError) {
|
||||||
|
this.logger.error(JSON.stringify(error.response.data));
|
||||||
|
}
|
||||||
|
await this.executeRenameRollback(rollback);
|
||||||
|
|
||||||
|
throw new Error("Error Nimbus updating tables");
|
||||||
}
|
}
|
||||||
rollback.push(nimbusRollback);
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
await this.updateNimbus(info.customer, nimbusUpdates);
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.error(error);
|
|
||||||
if (error instanceof AxiosError) {
|
|
||||||
this.logger.error(JSON.stringify(error.response.data));
|
|
||||||
}
|
|
||||||
await this.executeRenameRollback(rollback);
|
|
||||||
|
|
||||||
throw new Error("Error Nimbus updating tables");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -14,16 +14,17 @@ import {
|
|||||||
NotFoundException,
|
NotFoundException,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiTags, ApiOperation } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiOkResponse } from '@nestjs/swagger';
|
||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Authenticated,
|
Authenticated,
|
||||||
RequireAllPermissions,
|
RequireAllPermissions,
|
||||||
|
RequireModule,
|
||||||
} from '../../decorators/authentication.decorator';
|
} from '../../decorators/authentication.decorator';
|
||||||
import { User, RequestUser } from '../../decorators/user.decorator';
|
import { User, RequestUser } from '../../decorators/user.decorator';
|
||||||
import { PlatformApiService } from './platform-api.service';
|
import { PlatformApiService } from './platform-api.service';
|
||||||
import { PERMISSIONS_GROUPS } from '../../authentication/permissions.enum';
|
import { DADOSFERA_MODULES_KEYS, PERMISSIONS_GROUPS } from '../../authentication/permissions.enum';
|
||||||
import { ElasticsearchService } from '../../services/elasticsearch';
|
import { ElasticsearchService } from '../../services/elasticsearch';
|
||||||
import { DynamoDBService, ReferenceColumn } from '../../services/dynamodb';
|
import { DynamoDBService, ReferenceColumn } from '../../services/dynamodb';
|
||||||
import { CustomersService } from '../customers/customers.service';
|
import { CustomersService } from '../customers/customers.service';
|
||||||
@@ -49,6 +50,7 @@ type RenameTablesBody = {
|
|||||||
|
|
||||||
@ApiTags('Platform API')
|
@ApiTags('Platform API')
|
||||||
@Controller('platform')
|
@Controller('platform')
|
||||||
|
@RequireModule(DADOSFERA_MODULES_KEYS.COLLECT)
|
||||||
export class PlatformApiController {
|
export class PlatformApiController {
|
||||||
private logger: any;
|
private logger: any;
|
||||||
|
|
||||||
@@ -72,6 +74,10 @@ export class PlatformApiController {
|
|||||||
return id?.replace(/-/g, '_') || '';
|
return id?.replace(/-/g, '_') || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private decodePathParam(value: string): string {
|
||||||
|
return value ? decodeURIComponent(value) : '';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Denormalize ID back to UUID format (replace _ with -).
|
* Denormalize ID back to UUID format (replace _ with -).
|
||||||
* Used when we receive a normalized ID but need the original UUID.
|
* Used when we receive a normalized ID but need the original UUID.
|
||||||
@@ -833,7 +839,23 @@ export class PlatformApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('pipelines/:pipelineId/pipeline_run/:runId/jobs')
|
@Get('pipelines/:pipelineId/pipeline_run/:runId/jobs')
|
||||||
@ApiOperation({ summary: 'Get pipeline run jobs' })
|
@ApiOperation({
|
||||||
|
summary: 'Get pipeline run jobs',
|
||||||
|
description: 'Proxies platform-api DB-backed job runs and returns `{ jobs: [...] }`.',
|
||||||
|
})
|
||||||
|
@ApiOkResponse({
|
||||||
|
description: 'DB-backed job runs for the selected pipeline run.',
|
||||||
|
schema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
jobs: {
|
||||||
|
type: 'array',
|
||||||
|
items: { type: 'object' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ['jobs'],
|
||||||
|
},
|
||||||
|
})
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.PIPELINE.permissions.GET)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.PIPELINE.permissions.GET)
|
||||||
async getPipelineRunJobs(
|
async getPipelineRunJobs(
|
||||||
@Param('pipelineId') pipelineId: string,
|
@Param('pipelineId') pipelineId: string,
|
||||||
@@ -841,11 +863,11 @@ export class PlatformApiController {
|
|||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
) {
|
) {
|
||||||
const normalizedPipelineId = this.normalizePipelineId(pipelineId);
|
const normalizedPipelineId = this.normalizePipelineId(pipelineId);
|
||||||
const normalizedRunId = this.normalizePipelineId(runId);
|
const decodedRunId = this.decodePathParam(runId);
|
||||||
|
|
||||||
return this.platformApiService.proxy(
|
return this.platformApiService.proxy(
|
||||||
'GET',
|
'GET',
|
||||||
`/pipeline/${normalizedPipelineId}/pipeline_run/${normalizedRunId}/jobs`,
|
`/pipeline/${normalizedPipelineId}/pipeline_run/${decodedRunId}/jobs`,
|
||||||
user,
|
user,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ interface IMetadata {
|
|||||||
details?: string;
|
details?: string;
|
||||||
sensitive?: string;
|
sensitive?: string;
|
||||||
roles?: string[];
|
roles?: string[];
|
||||||
|
customer_modules?: string[];
|
||||||
is_data_manager?: boolean;
|
is_data_manager?: boolean;
|
||||||
access_token?: string;
|
access_token?: string;
|
||||||
host?: string;
|
host?: string;
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* Jest setupFiles hook: provide dummy values for env vars that modules read
|
||||||
|
* at *import time* (module-load side effects), so unit specs that transitively
|
||||||
|
* import those modules don't crash before a single test runs.
|
||||||
|
*
|
||||||
|
* These are never exercised by unit tests — the services that use them are
|
||||||
|
* stubbed via DI — but the values must exist because the reads happen at
|
||||||
|
* module evaluation, before any mock is installed.
|
||||||
|
*
|
||||||
|
* DUC_URL: read at load time in src/modules/duc/client.config.ts, reached via
|
||||||
|
* the AuthClientService import chain.
|
||||||
|
*/
|
||||||
|
process.env.DUC_URL = process.env.DUC_URL || 'duc:localhost:0';
|
||||||
Reference in New Issue
Block a user