diff --git a/AzureBlobFileSystem/AzureBlobFileSystem.csproj b/AzureBlobFileSystem/AzureBlobFileSystem.csproj index d8f1137..a19bfab 100644 --- a/AzureBlobFileSystem/AzureBlobFileSystem.csproj +++ b/AzureBlobFileSystem/AzureBlobFileSystem.csproj @@ -79,6 +79,7 @@ + diff --git a/AzureBlobFileSystem/AzureBlobStorageProvider.cs b/AzureBlobFileSystem/AzureBlobStorageProvider.cs index 4a27743..379a16b 100644 --- a/AzureBlobFileSystem/AzureBlobStorageProvider.cs +++ b/AzureBlobFileSystem/AzureBlobStorageProvider.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Xml.Linq; @@ -420,12 +421,15 @@ public string GetFileType() return Path.GetExtension(GetPath()); } - public string GetSharedAccessPath(DateTimeOffset? expiration = null) + public string GetSharedAccessPath(DateTimeOffset? expiration = null, SasPermissionFlags permissions = SasPermissionFlags.Read) { - return _blob.Uri.AbsoluteUri + _blob.GetSharedAccessSignature(new SharedAccessBlobPolicy() + var sasToken = _blob.GetSharedAccessSignature(new SharedAccessBlobPolicy() { - SharedAccessExpiryTime = expiration ?? _azureFileSystem.DefaultSharedAccessExpiration - }, "default"); + SharedAccessExpiryTime = expiration ?? _azureFileSystem.DefaultSharedAccessExpiration, + Permissions = GetSharedAccessBlobPermissions(permissions) + }); + + return string.Format(CultureInfo.InvariantCulture, "{0}{1}", _blob.Uri, sasToken); } public Stream OpenRead() @@ -448,6 +452,11 @@ public Stream CreateFile() return OpenWrite(); } + + private static SharedAccessBlobPermissions GetSharedAccessBlobPermissions(SasPermissionFlags flags) + { + return (SharedAccessBlobPermissions)flags; + } } private class AzureBlobFolderStorage : IStorageFolder diff --git a/AzureBlobFileSystem/FileSystemStorageProvider.cs b/AzureBlobFileSystem/FileSystemStorageProvider.cs index ad6cac8..4f5997d 100644 --- a/AzureBlobFileSystem/FileSystemStorageProvider.cs +++ b/AzureBlobFileSystem/FileSystemStorageProvider.cs @@ -361,7 +361,7 @@ public string GetFileType() return _fileInfo.Extension; } - public string GetSharedAccessPath(DateTimeOffset? expiration = null) + public string GetSharedAccessPath(DateTimeOffset? expiration = null, SasPermissionFlags permissions = SasPermissionFlags.Read) { return _path; } diff --git a/AzureBlobFileSystem/IStorageFile.cs b/AzureBlobFileSystem/IStorageFile.cs index 157202c..8ba0518 100644 --- a/AzureBlobFileSystem/IStorageFile.cs +++ b/AzureBlobFileSystem/IStorageFile.cs @@ -10,7 +10,7 @@ public interface IStorageFile long GetSize(); DateTime GetLastUpdated(); string GetFileType(); - string GetSharedAccessPath(DateTimeOffset? expiration = null); + string GetSharedAccessPath(DateTimeOffset? expiration = null, SasPermissionFlags permissions = SasPermissionFlags.Read); /// /// Creates a stream for reading from the file. diff --git a/AzureBlobFileSystem/SasPermissionFlags.cs b/AzureBlobFileSystem/SasPermissionFlags.cs new file mode 100644 index 0000000..fb314a8 --- /dev/null +++ b/AzureBlobFileSystem/SasPermissionFlags.cs @@ -0,0 +1,19 @@ +using System; +using Microsoft.WindowsAzure.Storage.Blob; + +namespace AzureBlobFileSystem +{ + /// + /// Specifies the set of possible permissions for a shared access policy. + /// This mirrors the flags available in the Azure Storage Client Library + /// + [Flags] + public enum SasPermissionFlags + { + None = 0, + Read = 1, + Write = 2, + Delete = 4, + List = 8, + } +} \ No newline at end of file