feat: appove and go
This commit is contained in:
@@ -33,6 +33,14 @@ function roleFromClaim(raw: string | undefined): string {
|
||||
return 'viewer';
|
||||
}
|
||||
|
||||
function projectFromClaims(raw: string | undefined): string | undefined {
|
||||
if (!raw) return undefined;
|
||||
const prefix = 'casan-project:';
|
||||
const projectClaim = raw.split(/[\s,]+/).find((claim) => claim.startsWith(prefix));
|
||||
const project = projectClaim?.slice(prefix.length);
|
||||
return project && /^[A-Za-z0-9._-]+$/.test(project) ? project : undefined;
|
||||
}
|
||||
|
||||
export function actorFromHeaders(headers: Record<string, string | string[] | undefined>): SettingsActor {
|
||||
const actor = firstHeader(headers['x-casan-actor'])
|
||||
|| firstHeader(headers['x-auth-request-user'])
|
||||
@@ -45,7 +53,7 @@ export function actorFromHeaders(headers: Record<string, string | string[] | und
|
||||
return {
|
||||
actor,
|
||||
role: roleFromClaim(roleClaim),
|
||||
project: firstHeader(headers['x-casan-project']) || 'default',
|
||||
project: firstHeader(headers['x-casan-project']) || projectFromClaims(roleClaim) || 'default',
|
||||
tenant: firstHeader(headers['x-casan-tenant']) || 'default',
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user