import { SasIPRange as IIPRange } from "@azure/storage-blob" ; import { computeHMACSHA256 , truncatedISO8061Date } from "../../common/utils/utils" ; import AccountSASPermissions from "./AccountSASPermissions" ; import AccountSASResourceTypes from "./AccountSASResourceTypes" ; import AccountSASServices from "./AccountSASServices" ; import { ipRangeToString } from "./IIPRange" ; export enum { number } export enum SASProtocol { /**
     * Protocol that allows HTTPS only
     */ HTTPS = "https" , /**
     * Protocol that allows both HTTPS and HTTP
     */ HTTPSandHTTP = "https,http" } see https see https export class export interface IAccountSASSignatureValues { type { string } memberof version : string ; type { SASProtocol | string } memberof protocol ? : SASProtocol | string ; type { Date | string } memberof startTime ? : Date | string ; type { Date | string } memberof expiryTime : Date | string ; /**
     * Specifies which operations the SAS user may perform. Please refer to  AccountSASPermissions for help
     * constructing the permissions string.
     *
     *  type { AccountSASPermissions | string } memberof permissions : AccountSASPermissions | string ; type { IIPRange | string } memberof ipRange ? : IIPRange | string ; /**
     * The values that indicate the services accessible with this SAS. Please refer to  AccountSASServices to
     * construct this value.
     *
     *  type { AccountSASServices | string } memberof services : AccountSASServices | string ; /**
     * The values that indicate the resource types accessible with this SAS. Please refer
     * to  AccountSASResourceTypes to construct this value.
     *
     *  type { AccountSASResourceType | string } memberof resourceTypes : AccountSASResourceTypes | string ; } see https param { SharedKeyCredential } sharedKeyCredential param { string } accountName param { Buffer } sharedKey returns { [ string , string ] } memberof export function generateAccountSASSignature ( accountSASSignatureValues , accountName , sharedKey ) { const parsedPermissions = accountSASSignatureValues . permissions . toString ( ) ; const parsedServices = accountSASSignatureValues . services . toString ( ) ; const parsedResourceTypes = accountSASSignatureValues . resourceTypes . toString ( ) ; const parsedStartTime = accountSASSignatureValues . startTime === undefined ? "" : typeof accountSASSignatureValues . startTime === "string" ? accountSASSignatureValues . startTime : truncatedISO8061Date ( accountSASSignatureValues . startTime , false ) ; const parsedExpiryTime = typeof accountSASSignatureValues . expiryTime === "string" ? accountSASSignatureValues . expiryTime : truncatedISO8061Date ( accountSASSignatureValues . expiryTime , false ) ; const parsedIPRange = accountSASSignatureValues . ipRange === undefined ? "" : typeof accountSASSignatureValues . ipRange === "string" ? accountSASSignatureValues . ipRange : ipRangeToString ( accountSASSignatureValues . ipRange ) ; const parsedProtocol = accountSASSignatureValues . protocol === undefined ? "" : accountSASSignatureValues . protocol ; const version = accountSASSignatureValues . version ; const stringToSign = [ accountName , parsedPermissions , parsedServices , parsedResourceTypes , parsedStartTime , parsedExpiryTime , parsedIPRange , parsedProtocol , version , "" ] . join ( "\n" ) ; const signature = computeHMACSHA256 ( stringToSign , sharedKey ) ; return [ signature , stringToSign ] ; }