Skip to content

Commit

Permalink
Merge pull request #4 from rdefreitas/master
Browse files Browse the repository at this point in the history
Add ability to set permissions when retrieving SAS-based URL
  • Loading branch information
pofider committed Sep 15, 2015
2 parents a25118e + ce50208 commit 38d312a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
1 change: 1 addition & 0 deletions AzureBlobFileSystem/AzureBlobFileSystem.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<Compile Include="IStorageProvider.cs" />
<Compile Include="PathValidation.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SasPermissionFlags.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
17 changes: 13 additions & 4 deletions AzureBlobFileSystem/AzureBlobStorageProvider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Xml.Linq;
Expand Down Expand Up @@ -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()
Expand All @@ -448,6 +452,11 @@ public Stream CreateFile()

return OpenWrite();
}

private static SharedAccessBlobPermissions GetSharedAccessBlobPermissions(SasPermissionFlags flags)
{
return (SharedAccessBlobPermissions)flags;
}
}

private class AzureBlobFolderStorage : IStorageFolder
Expand Down
2 changes: 1 addition & 1 deletion AzureBlobFileSystem/FileSystemStorageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion AzureBlobFileSystem/IStorageFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/// <summary>
/// Creates a stream for reading from the file.
Expand Down
19 changes: 19 additions & 0 deletions AzureBlobFileSystem/SasPermissionFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using Microsoft.WindowsAzure.Storage.Blob;

namespace AzureBlobFileSystem
{
/// <summary>
/// Specifies the set of possible permissions for a shared access policy.
/// This mirrors the flags available in the Azure Storage Client Library
/// </summary>
[Flags]
public enum SasPermissionFlags
{
None = 0,
Read = 1,
Write = 2,
Delete = 4,
List = 8,
}
}

0 comments on commit 38d312a

Please sign in to comment.