mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-21 17:39:07 +00:00
feat(orchest-identity): permission-mapping helpers
Co-Authored-By: WOZCODE <contact@withwoz.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
Reference in New Issue
Block a user