-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathBlobSasPolicy.cs
43 lines (37 loc) · 1.2 KB
/
BlobSasPolicy.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Collections.Generic;
using System.Text;
using Azure.Storage;
using Azure.Storage.Sas;
namespace FluentStorage.Azure.Blobs {
/// <summary>
/// Defines a SAS policy for a blob
/// </summary>
public class BlobSasPolicy : OffsetSasPolicy {
/// <summary>
///
/// </summary>
/// <param name="startTime"></param>
/// <param name="duration"></param>
public BlobSasPolicy(DateTimeOffset startTime, TimeSpan duration) : base(startTime, duration) {
}
/// <summary>
/// Permissions for this sas policy
/// </summary>
public BlobSasPermission Permissions { get; set; } = BlobSasPermission.Read;
internal string ToSasQuery(StorageSharedKeyCredential sasSigningCredentials, string containerName, string blobName) {
if (sasSigningCredentials is null)
throw new ArgumentNullException(nameof(sasSigningCredentials));
var sas = new BlobSasBuilder {
BlobContainerName = containerName,
BlobName = blobName,
Protocol = SasProtocol.Https,
StartsOn = StartTime,
ExpiresOn = ExpiryTime
};
sas.SetPermissions((BlobSasPermissions)(int)Permissions);
string query = sas.ToSasQueryParameters(sasSigningCredentials).ToString();
return query;
}
}
}