Skip to content

Commit 34d24a4

Browse files
committed
Merge branch 'accountsas' of https://github.com/wastoresh/azure-powershell-pr into dev
2 parents 9ea5cb2 + 2b2f318 commit 34d24a4

File tree

8 files changed

+67
-25
lines changed

8 files changed

+67
-25
lines changed

src/Common/Storage/Commands.Storage/Blob/Cmdlet/NewAzureStorageBlobSasToken.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet
2020
using Microsoft.WindowsAzure.Commands.Storage.Common;
2121
using Microsoft.WindowsAzure.Commands.Storage.Model.Contract;
2222
using Microsoft.WindowsAzure.Storage.Blob;
23+
using Microsoft.WindowsAzure.Storage;
2324

2425
[Cmdlet(VerbsCommon.New, StorageNouns.BlobSas, DefaultParameterSetName = BlobNamePipelineParmeterSetWithPermission), OutputType(typeof(String))]
2526
public class NewAzureStorageBlobSasTokenCommand : StorageCloudBlobCmdletBase
@@ -80,6 +81,12 @@ public string Policy
8081
ParameterSetName = BlobPipelineParameterSetWithPermision)]
8182
public string Permission { get; set; }
8283

84+
[Parameter(Mandatory = false, HelpMessage = "Protocol can be used in the request with this SAS token.")]
85+
public SharedAccessProtocol Protocol { get; set; }
86+
87+
[Parameter(Mandatory = false, HelpMessage = "IP, or IP range ACL (access control list) that the request would be accepted from by Azure Storage.")]
88+
public string IPAddressOrRange { get; set; }
89+
8390
[Parameter(HelpMessage = "Start Time")]
8491
public DateTime? StartTime { get; set; }
8592

@@ -133,7 +140,7 @@ public override void ExecuteCmdlet()
133140
SharedAccessBlobPolicy accessPolicy = new SharedAccessBlobPolicy();
134141
bool shouldSetExpiryTime = SasTokenHelper.ValidateContainerAccessPolicy(Channel, blob.Container.Name, accessPolicy, accessPolicyIdentifier);
135142
SetupAccessPolicy(accessPolicy, shouldSetExpiryTime);
136-
string sasToken = GetBlobSharedAccessSignature(blob, accessPolicy, accessPolicyIdentifier);
143+
string sasToken = GetBlobSharedAccessSignature(blob, accessPolicy, accessPolicyIdentifier, Protocol, Util.SetupIPAddressOrRangeForSAS(IPAddressOrRange));
137144

138145
if (FullUri)
139146
{
@@ -154,10 +161,10 @@ public override void ExecuteCmdlet()
154161
/// <param name="accessPolicy">SharedAccessBlobPolicy object</param>
155162
/// <param name="policyIdentifier">The existing policy identifier.</param>
156163
/// <returns></returns>
157-
private string GetBlobSharedAccessSignature(CloudBlob blob, SharedAccessBlobPolicy accessPolicy, string policyIdentifier)
164+
private string GetBlobSharedAccessSignature(CloudBlob blob, SharedAccessBlobPolicy accessPolicy, string policyIdentifier, SharedAccessProtocol protocol, IPAddressOrRange iPAddressOrRange)
158165
{
159166
CloudBlobContainer container = blob.Container;
160-
return blob.GetSharedAccessSignature(accessPolicy, policyIdentifier);
167+
return blob.GetSharedAccessSignature(accessPolicy, null, policyIdentifier, protocol, iPAddressOrRange);
161168
}
162169

163170
/// <summary>

src/Common/Storage/Commands.Storage/Blob/Cmdlet/NewAzureStorageContainerSasToken.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet
2020
using Microsoft.WindowsAzure.Commands.Storage.Common;
2121
using Microsoft.WindowsAzure.Commands.Storage.Model.Contract;
2222
using Microsoft.WindowsAzure.Storage.Blob;
23+
using Microsoft.WindowsAzure.Storage;
2324

2425
[Cmdlet(VerbsCommon.New, StorageNouns.ContainerSas), OutputType(typeof(String))]
2526
public class NewAzureStorageContainerSasTokenCommand : StorageCloudBlobCmdletBase
@@ -54,6 +55,12 @@ public string Policy
5455
ParameterSetName = SasPermissionParameterSet)]
5556
public string Permission { get; set; }
5657

58+
[Parameter(Mandatory = false, HelpMessage = "Protocol can be used in the request with this SAS token.")]
59+
public SharedAccessProtocol Protocol { get; set; }
60+
61+
[Parameter(Mandatory = false, HelpMessage = "IP, or IP range ACL (access control list) that the request would be accepted from by Azure Storage.")]
62+
public string IPAddressOrRange { get; set; }
63+
5764
[Parameter(HelpMessage = "Start Time")]
5865
public DateTime? StartTime { get; set; }
5966

@@ -98,7 +105,7 @@ public override void ExecuteCmdlet()
98105
SharedAccessBlobPolicy accessPolicy = new SharedAccessBlobPolicy();
99106
bool shouldSetExpiryTime = SasTokenHelper.ValidateContainerAccessPolicy(Channel, container.Name, accessPolicy, accessPolicyIdentifier);
100107
SetupAccessPolicy(accessPolicy, shouldSetExpiryTime);
101-
string sasToken = container.GetSharedAccessSignature(accessPolicy, accessPolicyIdentifier);
108+
string sasToken = container.GetSharedAccessSignature(accessPolicy, accessPolicyIdentifier, Protocol, Util.SetupIPAddressOrRangeForSAS(IPAddressOrRange));
102109

103110
if (FullUri)
104111
{

src/Common/Storage/Commands.Storage/Common/Cmdlet/NewAzureStorageAccountSasToken.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public override void ExecuteCmdlet()
7474
Services = Service,
7575
ResourceTypes = ResourceType,
7676
Protocols = Protocol,
77-
IPAddressOrRange = SetupIPAddressOrRange(this.IPAddressOrRange)
77+
IPAddressOrRange = Util.SetupIPAddressOrRangeForSAS(this.IPAddressOrRange)
7878
};
7979

8080
DateTimeOffset? accessStartTime;
@@ -134,21 +134,5 @@ internal SharedAccessAccountPermissions SetupAccessPolicyPermission(string permi
134134

135135
return accountPermission;
136136
}
137-
138-
internal IPAddressOrRange SetupIPAddressOrRange(string inputIPACL)
139-
{
140-
if (string.IsNullOrEmpty(inputIPACL)) return null;
141-
142-
int separator = inputIPACL.IndexOf('-');
143-
144-
if (-1 == separator)
145-
{
146-
return new IPAddressOrRange(inputIPACL);
147-
}
148-
else
149-
{
150-
return new IPAddressOrRange(inputIPACL.Substring(0, separator), inputIPACL.Substring(separator + 1));
151-
}
152-
}
153137
}
154138
}

src/Common/Storage/Commands.Storage/Common/Util.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,21 @@ public static CloudBlob GetBlobReference(Uri blobUri, StorageCredentials storage
161161
blobUri));
162162
}
163163
}
164+
165+
public static IPAddressOrRange SetupIPAddressOrRangeForSAS(string inputIPACL)
166+
{
167+
if (string.IsNullOrEmpty(inputIPACL)) return null;
168+
169+
int separator = inputIPACL.IndexOf('-');
170+
171+
if (-1 == separator)
172+
{
173+
return new IPAddressOrRange(inputIPACL);
174+
}
175+
else
176+
{
177+
return new IPAddressOrRange(inputIPACL.Substring(0, separator), inputIPACL.Substring(separator + 1));
178+
}
179+
}
164180
}
165181
}

src/Common/Storage/Commands.Storage/File/Cmdlet/NewAzureStorageFileSasToken.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using Microsoft.WindowsAzure.Commands.Storage.Common;
2525
using Microsoft.WindowsAzure.Commands.Storage.Model.Contract;
2626
using Microsoft.WindowsAzure.Storage.File;
27+
using Microsoft.WindowsAzure.Storage;
2728

2829
namespace Microsoft.WindowsAzure.Commands.Storage.File.Cmdlet
2930
{
@@ -104,6 +105,12 @@ public string Policy
104105
ParameterSetName = CloudFileSasPermissionParameterSet)]
105106
public string Permission { get; set; }
106107

108+
[Parameter(Mandatory = false, HelpMessage = "Protocol can be used in the request with this SAS token.")]
109+
public SharedAccessProtocol Protocol { get; set; }
110+
111+
[Parameter(Mandatory = false, HelpMessage = "IP, or IP range ACL (access control list) that the request would be accepted from by Azure Storage.")]
112+
public string IPAddressOrRange { get; set; }
113+
107114
[Parameter(HelpMessage = "Start Time")]
108115
public DateTime? StartTime { get; set; }
109116

@@ -158,7 +165,7 @@ public override void ExecuteCmdlet()
158165

159166
SetupAccessPolicy(accessPolicy, shouldSetExpiryTime);
160167

161-
string sasToken = file.GetSharedAccessSignature(accessPolicy, accessPolicyIdentifier);
168+
string sasToken = file.GetSharedAccessSignature(accessPolicy, null, accessPolicyIdentifier, Protocol, Util.SetupIPAddressOrRangeForSAS(IPAddressOrRange));
162169

163170
if (FullUri)
164171
{

src/Common/Storage/Commands.Storage/File/Cmdlet/NewAzureStorageShareSasToken.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace Microsoft.WindowsAzure.Commands.Storage.File.Cmdlet
2222
using Microsoft.WindowsAzure.Commands.Storage.Common;
2323
using Microsoft.WindowsAzure.Commands.Storage.Model.Contract;
2424
using Microsoft.WindowsAzure.Storage.File;
25+
using Microsoft.WindowsAzure.Storage;
2526

2627
[Cmdlet(VerbsCommon.New, StorageNouns.ShareSas), OutputType(typeof(String))]
2728
public class NewAzureStorageShareSasToken : AzureStorageFileCmdletBase
@@ -56,6 +57,12 @@ public string Policy
5657
ParameterSetName = SasPermissionParameterSet)]
5758
public string Permission { get; set; }
5859

60+
[Parameter(Mandatory = false, HelpMessage = "Protocol can be used in the request with this SAS token.")]
61+
public SharedAccessProtocol Protocol { get; set; }
62+
63+
[Parameter(Mandatory = false, HelpMessage = "IP, or IP range ACL (access control list) that the request would be accepted from by Azure Storage.")]
64+
public string IPAddressOrRange { get; set; }
65+
5966
[Parameter(HelpMessage = "Start Time")]
6067
public DateTime? StartTime { get; set; }
6168

@@ -95,7 +102,7 @@ public override void ExecuteCmdlet()
95102
this.ExpiryTime.HasValue);
96103

97104
SetupAccessPolicy(accessPolicy, shouldSetExpiryTime);
98-
string sasToken = fileShare.GetSharedAccessSignature(accessPolicy, accessPolicyIdentifier);
105+
string sasToken = fileShare.GetSharedAccessSignature(accessPolicy, accessPolicyIdentifier, Protocol, Util.SetupIPAddressOrRangeForSAS(IPAddressOrRange));
99106

100107
if (FullUri)
101108
{

src/Common/Storage/Commands.Storage/Queue/Cmdlet/NewAzureStorageQueueSasToken.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace Microsoft.WindowsAzure.Commands.Storage.Queue.Cmdlet
2020
using Microsoft.WindowsAzure.Commands.Storage.Common;
2121
using Microsoft.WindowsAzure.Commands.Storage.Model.Contract;
2222
using Microsoft.WindowsAzure.Storage.Queue;
23+
using Microsoft.WindowsAzure.Storage;
2324

2425
[Cmdlet(VerbsCommon.New, StorageNouns.QueueSas), OutputType(typeof(String))]
2526
public class NewAzureStorageQueueSasTokenCommand : StorageQueueBaseCmdlet
@@ -54,6 +55,12 @@ public string Policy
5455
ParameterSetName = SasPermissionParameterSet)]
5556
public string Permission { get; set; }
5657

58+
[Parameter(Mandatory = false, HelpMessage = "Protocol can be used in the request with this SAS token.")]
59+
public SharedAccessProtocol Protocol { get; set; }
60+
61+
[Parameter(Mandatory = false, HelpMessage = "IP, or IP range ACL (access control list) that the request would be accepted from by Azure Storage.")]
62+
public string IPAddressOrRange { get; set; }
63+
5764
[Parameter(HelpMessage = "Start Time")]
5865
public DateTime? StartTime { get; set; }
5966

@@ -96,7 +103,7 @@ public override void ExecuteCmdlet()
96103
SharedAccessQueuePolicy policy = new SharedAccessQueuePolicy();
97104
bool shouldSetExpiryTime = SasTokenHelper.ValidateQueueAccessPolicy(Channel, queue.Name, policy, accessPolicyIdentifier);
98105
SetupAccessPolicy(policy, shouldSetExpiryTime);
99-
string sasToken = queue.GetSharedAccessSignature(policy, accessPolicyIdentifier);
106+
string sasToken = queue.GetSharedAccessSignature(policy, accessPolicyIdentifier, Protocol, Util.SetupIPAddressOrRangeForSAS(IPAddressOrRange));
100107

101108
if (FullUri)
102109
{

src/Common/Storage/Commands.Storage/Table/Cmdlet/NewAzureStorageTableSasToken.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace Microsoft.WindowsAzure.Commands.Storage.Table.Cmdlet
2020
using Microsoft.WindowsAzure.Commands.Storage.Common;
2121
using Microsoft.WindowsAzure.Commands.Storage.Model.Contract;
2222
using Microsoft.WindowsAzure.Storage.Table;
23+
using Microsoft.WindowsAzure.Storage;
2324

2425
[Cmdlet(VerbsCommon.New, StorageNouns.TableSas), OutputType(typeof(String))]
2526
public class NewAzureStorageTableSasTokenCommand : StorageCloudTableCmdletBase
@@ -55,6 +56,12 @@ public string Policy
5556
ParameterSetName = SasPermissionParameterSet)]
5657
public string Permission { get; set; }
5758

59+
[Parameter(Mandatory = false, HelpMessage = "Protocol can be used in the request with this SAS token.")]
60+
public SharedAccessProtocol Protocol { get; set; }
61+
62+
[Parameter(Mandatory = false, HelpMessage = "IP, or IP range ACL (access control list) that the request would be accepted from by Azure Storage.")]
63+
public string IPAddressOrRange { get; set; }
64+
5865
[Parameter(HelpMessage = "Start Time")]
5966
public DateTime? StartTime { get; set; }
6067

@@ -113,7 +120,7 @@ public override void ExecuteCmdlet()
113120
SetupAccessPolicy(policy, shouldSetExpiryTime);
114121
ValidatePkAndRk(StartPartitionKey, StartRowKey, EndPartitionKey, EndRowKey);
115122
string sasToken = table.GetSharedAccessSignature(policy, accessPolicyIdentifier, StartPartitionKey,
116-
StartRowKey, EndPartitionKey, EndRowKey);
123+
StartRowKey, EndPartitionKey, EndRowKey, Protocol, Util.SetupIPAddressOrRangeForSAS(IPAddressOrRange));
117124

118125
if (FullUri)
119126
{

0 commit comments

Comments
 (0)