Skip to content

Commit

Permalink
feat: add authup policy aggregator
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Jul 5, 2024
1 parent c41942c commit adb2235
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

export * from './permission';
export * from './policy';
export * from './realm';
export * from './robot';
export * from './user';
23 changes: 23 additions & 0 deletions packages/server-core/src/aggregators/authup/entities/policy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2023-2024.
* Author Peter Placzek (tada5hi)
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/
import type { PolicyEventContext } from '@authup/core-kit';
import { useDataSource } from 'typeorm-extension';
import { AnalysisPermissionEntity } from '../../../domains';

export async function handleAuthupPolicyEvent(context: PolicyEventContext) {
if (context.event !== 'deleted') {
return;
}

const dataSource = await useDataSource();
const repository = dataSource.getRepository(AnalysisPermissionEntity);
await repository.update({
policy_id: context.data.id,
}, {
policy_id: null,
});
}
7 changes: 6 additions & 1 deletion packages/server-core/src/aggregators/authup/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { isRedisClientUsable, useLogger, useRedisSubscribeClient } from '@privat
import type { Aggregator } from '@privateaim/server-kit';
import { EnvironmentName, useEnv } from '../../config';
import {
handleAuthupPermissionEvent,
handleAuthupPermissionEvent, handleAuthupPolicyEvent,
handleAuthupRealmEvent, handleAuthupRobotEvent,
handleAuthupUserEvent,
} from './entities';
Expand All @@ -30,6 +30,7 @@ export function createAuthupAggregator() : Aggregator {

redisSub.subscribe(
'permission',
'policy',
'realm',
'user',
'robot',
Expand All @@ -40,6 +41,10 @@ export function createAuthupAggregator() : Aggregator {
const event = JSON.parse(message);

switch (event.type) {
case DomainType.POLICY: {
await handleAuthupPolicyEvent(event);
break;
}
case DomainType.PERMISSION: {
await handleAuthupPermissionEvent(event);
break;
Expand Down

0 comments on commit adb2235

Please sign in to comment.