import { AccountSASPermissions , AccountSASResourceTypes , AccountSASServices } from "@azure/storage-blob" ; import Operation from "../generated/artifacts/operation" ; import { AccountSASPermission } from "./AccountSASPermissions" ; import { AccountSASResourceType } from "./AccountSASResourceTypes" ; import { AccountSASService } from "./AccountSASServices" ; export class OperationAccountSASPermission { constructor ( public readonly service , public readonly resourceType , public readonly permission ) { } public validate ( services , resourceTypes , permissions ) { return ( this . validateServices ( services ) && this . validateResourceTypes ( resourceTypes ) && this . validatePermissions ( permissions ) ) ; } public validateServices ( services ) { return services . toString ( ) . includes ( this . service ) ; } public validateResourceTypes ( resourceTypes ) { for ( const p of this . resourceType ) { if ( resourceTypes . toString ( ) . includes ( p ) ) { return true ; } } return false ; } public validatePermissions ( permissions ) { for ( const p of this . permission ) { if ( permissions . toString ( ) . includes ( p ) ) { return true ; } } return false ; } } const OPERATION_ACCOUNT_SAS_PERMISSIONS = new Map < Operation , OperationAccountSASPermission > ( ) ; OPERATION_ACCOUNT_SAS_PERMISSIONS . set ( Operation . Service_GetProperties , new OperationAccountSASPermission ( AccountSASService . Queue , AccountSASResourceType . Service , AccountSASPermission . Read ) ) ; OPERATION_ACCOUNT_SAS_PERMISSIONS . set ( Operation . Service_SetProperties , new OperationAccountSASPermission ( AccountSASService . Queue , AccountSASResourceType . Service , AccountSASPermission . Write ) ) ; OPERATION_ACCOUNT_SAS_PERMISSIONS . set ( Operation . Service_ListQueuesSegment , new OperationAccountSASPermission ( AccountSASService . Queue , AccountSASResourceType . Service , AccountSASPermission . List ) ) ; OPERATION_ACCOUNT_SAS_PERMISSIONS . set ( Operation . Service_GetStatistics , new OperationAccountSASPermission ( AccountSASService . Queue , AccountSASResourceType . Service , AccountSASPermission . Read ) ) ; OPERATION_ACCOUNT_SAS_PERMISSIONS . set ( Operation . Queue_Create , new OperationAccountSASPermission ( AccountSASService . Queue , AccountSASResourceType . Container , AccountSASPermission . Create + AccountSASPermission . Write ) ) ; OPERATION_ACCOUNT_SAS_PERMISSIONS . set ( Operation . Queue_Delete , new OperationAccountSASPermission ( AccountSASService . Queue , AccountSASResourceType . Container , AccountSASPermission . Delete ) ) ; OPERATION_ACCOUNT_SAS_PERMISSIONS . set ( Operation . Queue_GetProperties , new OperationAccountSASPermission ( AccountSASService . Queue , AccountSASResourceType . Container , AccountSASPermission . Read ) ) ; OPERATION_ACCOUNT_SAS_PERMISSIONS . set ( Operation . Queue_GetPropertiesWithHead , new OperationAccountSASPermission ( AccountSASService . Queue , AccountSASResourceType . Container , AccountSASPermission . Read ) ) ; OPERATION_ACCOUNT_SAS_PERMISSIONS . set ( Operation . Queue_SetMetadata , new OperationAccountSASPermission ( AccountSASService . Queue , AccountSASResourceType . Container , AccountSASPermission . Write ) ) ; OPERATION_ACCOUNT_SAS_PERMISSIONS . set ( Operation . Queue_GetAccessPolicy , new OperationAccountSASPermission ( AccountSASService . Queue , AccountSASResourceType . Container , "" ) ) ; OPERATION_ACCOUNT_SAS_PERMISSIONS . set ( Operation . Queue_GetAccessPolicyWithHead , new OperationAccountSASPermission ( AccountSASService . Queue , AccountSASResourceType . Container , "" ) ) ; OPERATION_ACCOUNT_SAS_PERMISSIONS . set ( Operation . Queue_SetAccessPolicy , new OperationAccountSASPermission ( AccountSASService . Queue , AccountSASResourceType . Container , "" ) ) ; OPERATION_ACCOUNT_SAS_PERMISSIONS . set ( Operation . Messages_Enqueue , new OperationAccountSASPermission ( AccountSASService . Queue , AccountSASResourceType . Object , AccountSASPermission . Add ) ) ; OPERATION_ACCOUNT_SAS_PERMISSIONS . set ( Operation . Messages_Dequeue , new OperationAccountSASPermission ( AccountSASService . Queue , AccountSASResourceType . Object , AccountSASPermission . Process ) ) ; OPERATION_ACCOUNT_SAS_PERMISSIONS . set ( Operation . Messages_Peek , new OperationAccountSASPermission ( AccountSASService . Queue , AccountSASResourceType . Object , AccountSASPermission . Read ) ) ; OPERATION_ACCOUNT_SAS_PERMISSIONS . set ( Operation . MessageId_Delete , new OperationAccountSASPermission ( AccountSASService . Queue , AccountSASResourceType . Container , AccountSASPermission . Process ) ) ; OPERATION_ACCOUNT_SAS_PERMISSIONS . set ( Operation . Messages_Clear , new OperationAccountSASPermission ( AccountSASService . Queue , AccountSASResourceType . Container , AccountSASPermission . Delete ) ) ; OPERATION_ACCOUNT_SAS_PERMISSIONS . set ( Operation . MessageId_Update , new OperationAccountSASPermission ( AccountSASService . Queue , AccountSASResourceType . Container , AccountSASPermission . Update ) ) ; export default OPERATION_ACCOUNT_SAS_PERMISSIONS ;