-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Add new Account SAS Token cmdlet, and add IPacl/Protocal support to B/T/Q/F new SAS cmdlets #1828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
96b6c77
369ba96
e886fab
11a8813
2ee5fa5
430d30a
7a2ccb0
2b2f318
9ea5cb2
34d24a4
8fbed7b
1da2298
0957564
83fce2c
ba626a2
e4a3b55
4ee7514
83f197f
bfeebb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ namespace Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet | |
| using Microsoft.WindowsAzure.Commands.Storage.Common; | ||
| using Microsoft.WindowsAzure.Commands.Storage.Model.Contract; | ||
| using Microsoft.WindowsAzure.Storage.Blob; | ||
| using Microsoft.WindowsAzure.Storage; | ||
|
|
||
| [Cmdlet(VerbsCommon.New, StorageNouns.ContainerSas), OutputType(typeof(String))] | ||
| public class NewAzureStorageContainerSasTokenCommand : StorageCloudBlobCmdletBase | ||
|
|
@@ -51,9 +52,15 @@ public string Policy | |
| private string accessPolicyIdentifier; | ||
|
|
||
| [Parameter(HelpMessage = "Permissions for a container. Permissions can be any not-empty subset of \"rwdl\".", | ||
| ParameterSetName = SasPermissionParameterSet)] | ||
| ParameterSetName = SasPermissionParameterSet)] | ||
| public string Permission { get; set; } | ||
|
|
||
| [Parameter(Mandatory = false, HelpMessage = "Protocol can be used in the request with this SAS token.")] | ||
| public SharedAccessProtocol Protocol { get; set; } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment. How do I create a SharedAccessProtocol
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SharedAccessProtocol is an Enum, and Powershell support Enum well. Use can just tab to get the enum value, don't need to create by themselves. |
||
|
|
||
| [Parameter(Mandatory = false, HelpMessage = "IP, or IP range ACL (access control list) that the request would be accepted from by Azure Storage.")] | ||
| public string IPAddressOrRange { get; set; } | ||
|
|
||
| [Parameter(HelpMessage = "Start Time")] | ||
| public DateTime? StartTime { get; set; } | ||
|
|
||
|
|
@@ -98,7 +105,7 @@ public override void ExecuteCmdlet() | |
| SharedAccessBlobPolicy accessPolicy = new SharedAccessBlobPolicy(); | ||
| bool shouldSetExpiryTime = SasTokenHelper.ValidateContainerAccessPolicy(Channel, container.Name, accessPolicy, accessPolicyIdentifier); | ||
| SetupAccessPolicy(accessPolicy, shouldSetExpiryTime); | ||
| string sasToken = container.GetSharedAccessSignature(accessPolicy, accessPolicyIdentifier); | ||
| string sasToken = container.GetSharedAccessSignature(accessPolicy, accessPolicyIdentifier, Protocol, Util.SetupIPAddressOrRangeForSAS(IPAddressOrRange)); | ||
|
|
||
| if (FullUri) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| // ---------------------------------------------------------------------------------- | ||
| // | ||
| // Copyright Microsoft Corporation | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // ---------------------------------------------------------------------------------- | ||
|
|
||
| namespace Microsoft.WindowsAzure.Commands.Storage.Common.Cmdlet | ||
| { | ||
| using System; | ||
| using System.Management.Automation; | ||
| using System.Security.Permissions; | ||
| using Microsoft.WindowsAzure.Commands.Storage.Model.Contract; | ||
| using Microsoft.WindowsAzure.Storage; | ||
|
|
||
| [Cmdlet(VerbsCommon.New, StorageNouns.AccountSas), OutputType(typeof(String))] | ||
| public class NewAzureStorageAccountSasTokenCommand : StorageCloudBlobCmdletBase | ||
| { | ||
| [Parameter(Mandatory = true, HelpMessage = "Service type that this SAS token applies to.")] | ||
| public SharedAccessAccountServices Service { get; set; } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do I create this type?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SharedAccessAccountServices , SharedAccessAccountResourceTypes , SharedAccessProtocol is an Enum, and Powershell support Enum well. Use can just tab to get the enum value, don't need to create by themselves. |
||
|
|
||
| [Parameter(Mandatory = true, HelpMessage = "Resource type that this SAS token applies to.")] | ||
| public SharedAccessAccountResourceTypes ResourceType { get; set; } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do I create this type?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SharedAccessAccountServices , SharedAccessAccountResourceTypes , SharedAccessProtocol is an Enum, and Powershell support Enum well. Use can just tab to get the enum value, don't need to create by themselves. |
||
|
|
||
| [Parameter(Mandatory = true, HelpMessage = "Permissions.")] | ||
| public string Permission { get; set; } | ||
|
|
||
| [Parameter(Mandatory = false, HelpMessage = "Protocol can be used in the request with this SAS token.")] | ||
| public SharedAccessProtocol Protocol { get; set; } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SharedAccessAccountServices , SharedAccessAccountResourceTypes , SharedAccessProtocol is an Enum, and Powershell support Enum well. Use can just tab to get the enum value, don't need to create by themselves. |
||
|
|
||
| [Parameter(Mandatory = false, HelpMessage = "IP, or IP range ACL (access control list) that the request would be accepted from by Azure Storage.")] | ||
| public string IPAddressOrRange { get; set; } | ||
|
|
||
| [Parameter(Mandatory = false, HelpMessage = "Start Time")] | ||
| public DateTime? StartTime { get; set; } | ||
|
|
||
| [Parameter(Mandatory = false, HelpMessage = "Expiry Time")] | ||
| public DateTime? ExpiryTime { get; set; } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ExpirationTime
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "ExpiryTime" is standard name in azure rest API, and consistent with other new SAS token cmdlets which already exist for a long time. So we don't suggest to change that. |
||
|
|
||
| // Overwrite the useless parameter | ||
| public override int? ServerTimeoutPerRequest { get; set; } | ||
| public override int? ClientTimeoutPerRequest { get; set; } | ||
| public override int? ConcurrentTaskCount { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the NewAzureStorageAccountSasTokenCommand class. | ||
| /// </summary> | ||
| public NewAzureStorageAccountSasTokenCommand() | ||
| : this(null) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the NewAzureStorageAccountSasTokenCommand class. | ||
| /// </summary> | ||
| /// <param name="channel">IStorageBlobManagement channel</param> | ||
| public NewAzureStorageAccountSasTokenCommand(IStorageBlobManagement channel) | ||
| { | ||
| Channel = channel; | ||
| EnableMultiThread = false; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Execute command | ||
| /// </summary> | ||
| [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] | ||
| public override void ExecuteCmdlet() | ||
| { | ||
| var sharedAccessPolicy = new SharedAccessAccountPolicy() | ||
| { | ||
| Permissions = SetupAccessPolicyPermission(this.Permission), | ||
| Services = Service, | ||
| ResourceTypes = ResourceType, | ||
| Protocols = Protocol, | ||
| IPAddressOrRange = Util.SetupIPAddressOrRangeForSAS(this.IPAddressOrRange) | ||
| }; | ||
|
|
||
| DateTimeOffset? accessStartTime; | ||
| DateTimeOffset? accessEndTime; | ||
| SasTokenHelper.SetupAccessPolicyLifeTime(StartTime, ExpiryTime, | ||
| out accessStartTime, out accessEndTime, true); | ||
| sharedAccessPolicy.SharedAccessStartTime = accessStartTime; | ||
| sharedAccessPolicy.SharedAccessExpiryTime = accessEndTime; | ||
|
|
||
| this.WriteObject(Channel.GetStorageAccountSASToken(sharedAccessPolicy)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Set up access policy permission | ||
| /// </summary> | ||
| /// <param name="policy">SharedAccessBlobPolicy object</param> | ||
| /// <param name="permission">Permisson</param> | ||
| internal SharedAccessAccountPermissions SetupAccessPolicyPermission(string permission) | ||
| { | ||
| if (string.IsNullOrEmpty(permission)) return SharedAccessAccountPermissions.None; | ||
|
|
||
| SharedAccessAccountPermissions accountPermission = SharedAccessAccountPermissions.None; | ||
| permission = permission.ToLower(); | ||
| foreach (char op in permission) | ||
| { | ||
| switch (op) | ||
| { | ||
| case StorageNouns.Permission.Read: | ||
| case StorageNouns.Permission.Query: | ||
| accountPermission |= SharedAccessAccountPermissions.Read; | ||
| break; | ||
| case StorageNouns.Permission.Process: | ||
| accountPermission |= SharedAccessAccountPermissions.ProcessMessages; | ||
| break; | ||
| case StorageNouns.Permission.Write: | ||
| accountPermission |= SharedAccessAccountPermissions.Write; | ||
| break; | ||
| case StorageNouns.Permission.Add: | ||
| accountPermission |= SharedAccessAccountPermissions.Add; | ||
| break; | ||
| case StorageNouns.Permission.Create: | ||
| accountPermission |= SharedAccessAccountPermissions.Create; | ||
| break; | ||
| case StorageNouns.Permission.Update: | ||
| accountPermission |= SharedAccessAccountPermissions.Update; | ||
| break; | ||
| case StorageNouns.Permission.Delete: | ||
| accountPermission |= SharedAccessAccountPermissions.Delete; | ||
| break; | ||
| case StorageNouns.Permission.List: | ||
| accountPermission |= SharedAccessAccountPermissions.List; | ||
| break; | ||
| default: | ||
| throw new ArgumentException(string.Format(Resources.InvalidAccessPermission, op)); | ||
| } | ||
| } | ||
|
|
||
| return accountPermission; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| using Microsoft.WindowsAzure.Commands.Storage.Common; | ||
| using Microsoft.WindowsAzure.Commands.Storage.Model.Contract; | ||
| using Microsoft.WindowsAzure.Storage.File; | ||
| using Microsoft.WindowsAzure.Storage; | ||
|
|
||
| namespace Microsoft.WindowsAzure.Commands.Storage.File.Cmdlet | ||
| { | ||
|
|
@@ -104,6 +105,12 @@ public string Policy | |
| ParameterSetName = CloudFileSasPermissionParameterSet)] | ||
| public string Permission { get; set; } | ||
|
|
||
| [Parameter(Mandatory = false, HelpMessage = "Protocol can be used in the request with this SAS token.")] | ||
| public SharedAccessProtocol Protocol { get; set; } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SharedAccessAccountServices , SharedAccessAccountResourceTypes , SharedAccessProtocol is an Enum, and Powershell support Enum well. Use can just tab to get the enum value, don't need to create by themselves. |
||
|
|
||
| [Parameter(Mandatory = false, HelpMessage = "IP, or IP range ACL (access control list) that the request would be accepted from by Azure Storage.")] | ||
| public string IPAddressOrRange { get; set; } | ||
|
|
||
| [Parameter(HelpMessage = "Start Time")] | ||
| public DateTime? StartTime { get; set; } | ||
|
|
||
|
|
@@ -123,6 +130,11 @@ public string Policy | |
| ParameterSetName = NameSasPolicyParmeterSet)] | ||
| public override AzureStorageContext Context { get; set; } | ||
|
|
||
| // Overwrite the useless parameter | ||
| public override int? ServerTimeoutPerRequest { get; set; } | ||
| public override int? ClientTimeoutPerRequest { get; set; } | ||
| public override int? ConcurrentTaskCount { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Execute command | ||
| /// </summary> | ||
|
|
@@ -158,7 +170,7 @@ public override void ExecuteCmdlet() | |
|
|
||
| SetupAccessPolicy(accessPolicy, shouldSetExpiryTime); | ||
|
|
||
| string sasToken = file.GetSharedAccessSignature(accessPolicy, accessPolicyIdentifier); | ||
| string sasToken = file.GetSharedAccessSignature(accessPolicy, null, accessPolicyIdentifier, Protocol, Util.SetupIPAddressOrRangeForSAS(IPAddressOrRange)); | ||
|
|
||
| if (FullUri) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ namespace Microsoft.WindowsAzure.Commands.Storage.File.Cmdlet | |
| using Microsoft.WindowsAzure.Commands.Storage.Common; | ||
| using Microsoft.WindowsAzure.Commands.Storage.Model.Contract; | ||
| using Microsoft.WindowsAzure.Storage.File; | ||
| using Microsoft.WindowsAzure.Storage; | ||
|
|
||
| [Cmdlet(VerbsCommon.New, StorageNouns.ShareSas), OutputType(typeof(String))] | ||
| public class NewAzureStorageShareSasToken : AzureStorageFileCmdletBase | ||
|
|
@@ -56,6 +57,12 @@ public string Policy | |
| ParameterSetName = SasPermissionParameterSet)] | ||
| public string Permission { get; set; } | ||
|
|
||
| [Parameter(Mandatory = false, HelpMessage = "Protocol can be used in the request with this SAS token.")] | ||
| public SharedAccessProtocol Protocol { get; set; } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SharedAccessAccountServices , SharedAccessAccountResourceTypes , SharedAccessProtocol is an Enum, and Powershell support Enum well. Use can just tab to get the enum value, don't need to create by themselves. |
||
|
|
||
| [Parameter(Mandatory = false, HelpMessage = "IP, or IP range ACL (access control list) that the request would be accepted from by Azure Storage.")] | ||
| public string IPAddressOrRange { get; set; } | ||
|
|
||
| [Parameter(HelpMessage = "Start Time")] | ||
| public DateTime? StartTime { get; set; } | ||
|
|
||
|
|
@@ -95,7 +102,7 @@ public override void ExecuteCmdlet() | |
| this.ExpiryTime.HasValue); | ||
|
|
||
| SetupAccessPolicy(accessPolicy, shouldSetExpiryTime); | ||
| string sasToken = fileShare.GetSharedAccessSignature(accessPolicy, accessPolicyIdentifier); | ||
| string sasToken = fileShare.GetSharedAccessSignature(accessPolicy, accessPolicyIdentifier, Protocol, Util.SetupIPAddressOrRangeForSAS(IPAddressOrRange)); | ||
|
|
||
| if (FullUri) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not an appropriate parameter type - as a user, it is unclear to me how to create this type. This needs to be a simple type, or a type that can be easily created from another cmdlet. Preferrably a simple type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SharedAccessProtocol is an Enum, and Powershell support Enum well. Use can just tab to get the enum value, don't need to create by themselves.