mirror of
https://github.com/whyour/qinglong.git
synced 2026-09-20 16:07:11 +08:00
24 lines
872 B
TypeScript
24 lines
872 B
TypeScript
import type { ArtifactReadAuthorizer } from '../../ports/artifactReadAuthorizer';
|
|
import type { ArtifactReadAuthorizationEffect } from '../../ports/artifactReadAuthorizer';
|
|
import type { ProjectPolicyEngine } from '../../application/projectPolicyEngine';
|
|
|
|
export class ProjectPolicyArtifactReadAuthorizer
|
|
implements ArtifactReadAuthorizer
|
|
{
|
|
constructor(private readonly policy: Pick<ProjectPolicyEngine, 'decide'>) {}
|
|
|
|
async authorize(
|
|
request: Parameters<ArtifactReadAuthorizer['authorize']>[0],
|
|
): Promise<ArtifactReadAuthorizationEffect> {
|
|
if (request.action !== 'artifact.read') {
|
|
throw new TypeError('Artifact read authorization action is invalid');
|
|
}
|
|
const result = await this.policy.decide({
|
|
subject: request.subject,
|
|
projectId: request.projectId,
|
|
permission: 'artifact.read',
|
|
});
|
|
return result.effect;
|
|
}
|
|
}
|