import { PermissionGuardService } from '../../../guards/authorization/services'; export class RedisKeyUtil { public static PATH = { ACCOUNT: 'account', ID: 'id', PROJECT: 'project', PERMISSION: 'permission', ACL: 'acl', COLON: ':', SLASH: '/', ASTERISK: '*', RESOURCE: 'resource', RENEW_TOKEN: 'renew-token', }; public static baseProjectUser(projectShortID: string = null): string { let scope: string = ''; if (projectShortID) { scope = projectShortID; } else { scope = PermissionGuardService.SYSTEM_KEY; } return `${RedisKeyUtil.PATH.PROJECT}${RedisKeyUtil.PATH.COLON}${scope}`; } public static accountProjectPermission(accountId: string, projectShortID: string = null): string { return `${this.baseProjectUser(projectShortID)}${RedisKeyUtil.PATH.COLON}${RedisKeyUtil.PATH.ACCOUNT}${RedisKeyUtil.PATH.COLON}${accountId}${RedisKeyUtil.PATH.COLON}${RedisKeyUtil.PATH.PERMISSION}`; } public static projectPermissionAsterisk(projectShortId: string): string { return `${this.baseProjectUser(projectShortId)}${this.PATH.ASTERISK}`; } public static projectAcl(projectShortID: string, resourceName: string): string { return `${this.baseProjectUser(projectShortID)}${RedisKeyUtil.PATH.COLON}${RedisKeyUtil.PATH.ACL}${RedisKeyUtil.PATH.COLON}${RedisKeyUtil.PATH.RESOURCE}${RedisKeyUtil.PATH.COLON}${resourceName}`; } public static accountProjectAcl(accountId: string, projectShortID: string, resourceName: string): string { return `${this.projectAcl(projectShortID, resourceName)}${RedisKeyUtil.PATH.COLON}${RedisKeyUtil.PATH.ACCOUNT}${RedisKeyUtil.PATH.COLON}${accountId}`; } public static projectAclAsterisk(projectShortID: string, resourceName: string): string { return `${this.projectAcl(projectShortID, resourceName)}${RedisKeyUtil.PATH.ASTERISK}`; } public static userIdAsterisk(userID: string): string { return `${RedisKeyUtil.PATH.ASTERISK}${userID}${RedisKeyUtil.PATH.ASTERISK}`; } public static renewTokenUserId(userID: string): string { return `${RedisKeyUtil.PATH.RENEW_TOKEN}${RedisKeyUtil.PATH.COLON}${userID}`; } }