local-aws/src/iam/iam-policy.entity.ts

55 lines
1.3 KiB
TypeScript

import { IamPolicy as PrismaIamPolicy } from "@prisma/client";
export class IamPolicy implements PrismaIamPolicy {
id: string;
accountId: string;
name: string;
version: number;
isDefault: boolean;
policy: string;
path: string | null;
description: string | null;
isAttachable: boolean;
createdAt: Date;
updatedAt: Date;
constructor(p: PrismaIamPolicy) {
this.id = p.id;
this.accountId = p.accountId;
this.name = p.name;
this.version = p.version;
this.isDefault = p.isDefault;
this.policy = p.policy;
this.path = p.path;
this.description = p.description;
this.isAttachable = p.isAttachable;
this.createdAt = p.createdAt;
this.updatedAt = p.updatedAt;
}
get arn() {
const parts = ['policy'];
if (this.path && this.path !== '/') {
parts.push(this.path);
}
parts.push(this.name);
return `arn:aws:iam::${this.accountId}:${parts.join('/')}`;
}
get metadata() {
return {
Arn: this.arn,
AttachmentCount: 0,
CreateDate: this.createdAt.toISOString(),
DefaultVersionId: `v${this.version}`,
Description: this.description,
IsAttachable: this.isAttachable,
Path: this.path,
PolicyId: this.id,
PolicyName: this.name,
UpdateDate: this.updatedAt.toISOString(),
}
}
}