Skip to content

[Azure.Storage] Support defaultserviceversion #5219

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

Merged
merged 3 commits into from
Jan 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Storage/Azure.Storage.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ CmdletsToExport = 'Get-AzureStorageTable', 'New-AzureStorageTableSASToken',
'Set-AzureStorageContainerStoredAccessPolicy',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the changelog with these changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change log is added

'Start-AzureStorageBlobCopy',
'Start-AzureStorageBlobIncrementalCopy',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests for your new cmdlets.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the Storage Client library request can't be record in Unit test framework, generally we don't add unit test in PowerShell solution for data plan cmdelts. We will add functional test for the new cmdelts in storage team regression test. Let me know if you would like to review the CR for the our team regression test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to review the regression tests before this change goes into our repo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Maddie,

Following is the CR link for the test cases. I have sent you another mail for the CR and attached the test log. You can see the powershell cmdelts tested and result validation of the test cases in the test log.

codeflow://open/?server=https%3A%2F%2Fmsazure.visualstudio.com%2F&review=One.664474&host=vso&alert=true

Copy link
Member Author

@blueww blueww Jan 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maddieclayton , @cormacpayne

I have added the Unit test for the service properties parse function as we discussed into the PR.
Please help to review.

'Stop-AzureStorageBlobCopy'
'Stop-AzureStorageBlobCopy',
'Update-AzureStorageServiceProperty',
'Get-AzureStorageServiceProperty'

# Variables to export from this module
# VariablesToExport = @()
Expand Down
3 changes: 3 additions & 0 deletions src/Storage/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
- Additional information about change #1
-->
## Current Release
* Add cmdlets to get and set Storage service properties
- Get-AzureStorageServiceProperty
- Update-AzureStorageServiceProperty

## Version 4.0.2
* Upgrade to Azure Storage Client Library 8.6.0 and Azure Storage DataMovement Library 0.6.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
<Compile Include="Common\ResourceNotFoundExceptionTest.cs" />
<Compile Include="Common\AccessPolicyHelperTest.cs" />
<Compile Include="Common\SasTokenHelperTest.cs" />
<Compile Include="Common\PSServicePropertiesTest.cs" />
<Compile Include="Common\StorageCloudCmdletBaseTest.cs" />
<Compile Include="Common\StorageExceptionUtilTest.cs" />
<Compile Include="File\Cmdlet\GetAzureStorageFileContentTest.cs" />
Expand Down
243 changes: 243 additions & 0 deletions src/Storage/Commands.Storage.Test/Common/PSServicePropertiesTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
// ----------------------------------------------------------------------------------
//
// Copyright 2012 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.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.WindowsAzure.Commands.Storage.Common;
using Microsoft.WindowsAzure.Commands.Storage.Model.ResourceModel;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Table;
using Microsoft.WindowsAzure.Storage.File;
using Microsoft.WindowsAzure.Storage.Queue;
using Microsoft.WindowsAzure.Storage.Shared.Protocol;

namespace Microsoft.WindowsAzure.Commands.Storage.Test.Common
{
/// <summary>
/// Unit test for Access Policy helper
/// </summary>
[TestClass]
public class PSServicePropertiesTest : StorageTestBase
{
/// <summary>
/// unit test for ParseCorsRules() functional
/// </summary>
[TestMethod]
public void ValidateParseCorsRulesTest()
{
CorsProperties coresproperties = PrepareCoresproperties();
PSCorsRule[] pscores = PSCorsRule.ParseCorsRules(coresproperties);
CompareCors(pscores, coresproperties);

coresproperties = new CorsProperties();
pscores = PSCorsRule.ParseCorsRules(coresproperties);
CompareCors(pscores, coresproperties);

coresproperties = null;
pscores = PSCorsRule.ParseCorsRules(coresproperties);
CompareCors(pscores, coresproperties);
}

/// <summary>
/// unit test for new PSSeriviceProperties() functional
/// </summary>
[TestMethod]
public void ValidateParseServicePropertiesTest()
{
ServiceProperties serviceProperties = new ServiceProperties();
serviceProperties.Cors = PrepareCoresproperties();
serviceProperties.HourMetrics = new MetricsProperties("1.0");
serviceProperties.HourMetrics.MetricsLevel = MetricsLevel.ServiceAndApi;
serviceProperties.HourMetrics.RetentionDays = 1;
serviceProperties.MinuteMetrics = new MetricsProperties("1.0");
serviceProperties.MinuteMetrics.MetricsLevel = MetricsLevel.Service;
serviceProperties.MinuteMetrics.RetentionDays = 3;
serviceProperties.Logging = new LoggingProperties("1.0");
serviceProperties.Logging.LoggingOperations = LoggingOperations.All;
serviceProperties.Logging.RetentionDays = 5;
serviceProperties.DefaultServiceVersion = "2017-04-17";
PSSeriviceProperties pSSeriviceProperties = new PSSeriviceProperties(serviceProperties);
CompareServiceProperties(pSSeriviceProperties, serviceProperties);

serviceProperties = new ServiceProperties();
pSSeriviceProperties = new PSSeriviceProperties(serviceProperties);
CompareServiceProperties(pSSeriviceProperties, serviceProperties);

serviceProperties = null;
pSSeriviceProperties = new PSSeriviceProperties(serviceProperties);
CompareServiceProperties(pSSeriviceProperties, serviceProperties);
}

/// <summary>
/// Comapare PSServiceProperties and ServiceProperties, to make sure they are same content
/// </summary>
static private void CompareServiceProperties(PSSeriviceProperties pSSeriviceProperties, ServiceProperties serviceProperties)
{
if ((pSSeriviceProperties != null && pSSeriviceProperties.HourMetrics != null) || (serviceProperties != null && serviceProperties.HourMetrics != null))
{
Assert.AreEqual(serviceProperties.HourMetrics.Version, pSSeriviceProperties.HourMetrics.Version);
Assert.AreEqual(serviceProperties.HourMetrics.MetricsLevel, pSSeriviceProperties.HourMetrics.MetricsLevel);
Assert.AreEqual(serviceProperties.HourMetrics.RetentionDays, pSSeriviceProperties.HourMetrics.RetentionDays);
}
if ((pSSeriviceProperties != null && pSSeriviceProperties.MinuteMetrics != null) || (serviceProperties != null && serviceProperties.MinuteMetrics != null))
{
Assert.AreEqual(serviceProperties.MinuteMetrics.Version, pSSeriviceProperties.MinuteMetrics.Version);
Assert.AreEqual(serviceProperties.MinuteMetrics.MetricsLevel, pSSeriviceProperties.MinuteMetrics.MetricsLevel);
Assert.AreEqual(serviceProperties.MinuteMetrics.RetentionDays, pSSeriviceProperties.MinuteMetrics.RetentionDays);
}
if ((pSSeriviceProperties != null && pSSeriviceProperties.Logging != null) || (serviceProperties != null && serviceProperties.Logging != null))
{
Assert.AreEqual(serviceProperties.Logging.Version, pSSeriviceProperties.Logging.Version);
Assert.AreEqual(serviceProperties.Logging.LoggingOperations, pSSeriviceProperties.Logging.LoggingOperations);
Assert.AreEqual(serviceProperties.Logging.RetentionDays, pSSeriviceProperties.Logging.RetentionDays);
}
if ((pSSeriviceProperties != null && pSSeriviceProperties.Cors != null) || (serviceProperties != null && serviceProperties.Cors != null))
{
CompareCors(pSSeriviceProperties.Cors, serviceProperties.Cors);
}
if ((pSSeriviceProperties != null && pSSeriviceProperties.DefaultServiceVersion != null) || (serviceProperties != null && serviceProperties.DefaultServiceVersion != null))
{
Assert.AreEqual(serviceProperties.DefaultServiceVersion, pSSeriviceProperties.DefaultServiceVersion);
}
}

/// <summary>
/// Comapare PSCorsRule and CorsProperties, to make sure they are same content
/// </summary>
static private void CompareCors(PSCorsRule[] psCorsRules, CorsProperties corsProperties)
{
if ((psCorsRules == null || psCorsRules.Length == 0)
&& (corsProperties == null || corsProperties.CorsRules == null || corsProperties.CorsRules.Count == 0))
{
return;
}
Assert.AreEqual(psCorsRules.Length, corsProperties.CorsRules.Count);
int i = 0;
foreach (CorsRule CorsRule in corsProperties.CorsRules)
{
PSCorsRule psCorsRule = psCorsRules[i];
i++;
CompareStrings(psCorsRule.AllowedHeaders, CorsRule.AllowedHeaders);
CompareStrings(psCorsRule.ExposedHeaders, CorsRule.ExposedHeaders);
CompareStrings(psCorsRule.AllowedOrigins, CorsRule.AllowedOrigins);
Assert.AreEqual(psCorsRule.MaxAgeInSeconds, CorsRule.MaxAgeInSeconds);

CorsHttpMethods psAllowedMethods = CorsHttpMethods.None;
foreach (string method in psCorsRule.AllowedMethods)
{
CorsHttpMethods allowedCorsMethod = CorsHttpMethods.None;
if (Enum.TryParse<CorsHttpMethods>(method, true, out allowedCorsMethod))
{
psAllowedMethods |= allowedCorsMethod;
}
else
{
throw new InvalidOperationException(string.Format("Can't parse {0} to CorsHttpMethods.", method));
}
}

Assert.AreEqual(psAllowedMethods, CorsRule.AllowedMethods);
}
}

/// <summary>
/// Comapare String Array and String List, to make sure they are same content
/// </summary>
static private void CompareStrings(string[] stringArray, IList<String> stringList)
{
if ((stringArray == null || stringArray.Length == 0) && (stringList == null || stringList.Count == 0))
{
return;
}
string[] stringArray2 = new string[stringList.Count];
stringList.CopyTo(stringArray2, 0);
Assert.AreEqual(stringArray.Length, stringArray2.Length);

for(int i=0; i< stringArray.Length; i++)
{
Assert.AreEqual(stringArray[i], stringArray2[i]);
}
}

/// <summary>
/// Create a set of CorsRule that containers different parameters combination
/// </summary>
static private CorsProperties PrepareCoresproperties()
{
CorsProperties coresproperties = new CorsProperties();
coresproperties.CorsRules.Add(
new CorsRule()
{
AllowedHeaders = new List<string>
{
"x-ms-meta-data*",
"x -ms-meta-target*",
"x -ms-meta-abc"
},
AllowedMethods = CorsHttpMethods.Connect | CorsHttpMethods.Delete | CorsHttpMethods.Get | CorsHttpMethods.Head | CorsHttpMethods.Merge,
AllowedOrigins = new List<string>
{
"http://www.contoso.com",
"http://www.fabrikam.com"
},
ExposedHeaders = new List<string>
{
"x-ms-meta-*"
},
MaxAgeInSeconds = 100
});
coresproperties.CorsRules.Add(
new CorsRule()
{
AllowedHeaders = new List<string>
{
"x -ms-meta-12345675754564*"
},
AllowedMethods = CorsHttpMethods.None,
AllowedOrigins = new List<string>
{
"http://www.abc23.com",
"https://www.fabrikam.com/*"
},
ExposedHeaders = new List<string>
{
"x-ms-meta-data*",
"x -ms-meta-target*",
"x -ms-meta-abc"
},
MaxAgeInSeconds = 2000
});
coresproperties.CorsRules.Add(
new CorsRule()
{
AllowedHeaders = new List<string>
{
"*"
},
AllowedMethods = CorsHttpMethods.Options | CorsHttpMethods.Post | CorsHttpMethods.Put | CorsHttpMethods.Trace,
AllowedOrigins = new List<string>
{
"*"
},
ExposedHeaders = new List<string>
{
"*",
},
MaxAgeInSeconds = 0
});
return coresproperties;
}
}
}
3 changes: 3 additions & 0 deletions src/Storage/Commands.Storage/Commands.Storage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,14 @@
<Compile Include="Common\BlobToFileSystemNameResolver.cs" />
<Compile Include="Blob\Cmdlet\StartAzureStorageBlobCopy.cs" />
<Compile Include="Blob\Cmdlet\StopAzureStorageBlobCopy.cs" />
<Compile Include="Common\Cmdlet\GetAzureStorageServiceProperties.cs" />
<Compile Include="Common\Cmdlet\NewAzureStorageAccountSasToken.cs" />
<Compile Include="Common\Cmdlet\SetAzureStorageCORSRule.cs" />
<Compile Include="Common\Cmdlet\GetAzureStorageCORSRule.cs" />
<Compile Include="Common\Cmdlet\GetAzureStorageServiceLogging.cs" />
<Compile Include="Common\Cmdlet\GetAzureStorageServiceMetrics.cs" />
<Compile Include="Common\Cmdlet\RemoveAzureStorageCORSRule.cs" />
<Compile Include="Common\Cmdlet\SetAzureStorageServiceProperties.cs" />
<Compile Include="Common\Cmdlet\SetAzureStorageServiceLogging.cs" />
<Compile Include="Common\Cmdlet\SetAzureStorageServiceMetrics.cs" />
<Compile Include="Common\ConfirmTaskCompletionSource.cs" />
Expand Down Expand Up @@ -184,6 +186,7 @@
<Compile Include="Model\Contract\StorageQueueManagement.cs" />
<Compile Include="Model\Contract\StorageTableManagement.cs" />
<Compile Include="Model\ResourceModel\PSCorsRule.cs" />
<Compile Include="Model\ResourceModel\PSSeriviceProperties.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Model\Contract\IStorageBlobManagement.cs" />
<Compile Include="Model\Contract\StorageBlobManagement.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,47 +44,8 @@ public GetAzureStorageCORSRuleCommand()
public override void ExecuteCmdlet()
{
ServiceProperties currentServiceProperties = Channel.GetStorageServiceProperties(ServiceType, GetRequestOptions(ServiceType), OperationContext);
List<PSCorsRule> ruleList = new List<PSCorsRule>();

foreach (var corsRule in currentServiceProperties.Cors.CorsRules)
{
PSCorsRule psCorsRule = new PSCorsRule();
psCorsRule.AllowedOrigins = this.ListToArray(corsRule.AllowedOrigins);
psCorsRule.AllowedHeaders = this.ListToArray(corsRule.AllowedHeaders);
psCorsRule.ExposedHeaders = this.ListToArray(corsRule.ExposedHeaders);
psCorsRule.AllowedMethods = this.ConvertCorsHttpMethodToString(corsRule.AllowedMethods);
psCorsRule.MaxAgeInSeconds = corsRule.MaxAgeInSeconds;
ruleList.Add(psCorsRule);
}

WriteObject(ruleList.ToArray());
}

private string[] ConvertCorsHttpMethodToString(CorsHttpMethods methods)
{
List<string> methodList = new List<string>();

foreach (CorsHttpMethods methodValue in Enum.GetValues(typeof(CorsHttpMethods)).Cast<CorsHttpMethods>())
{
if (methodValue != CorsHttpMethods.None && (methods & methodValue) != 0)
{
methodList.Add(methodValue.ToString());
}
}

return methodList.ToArray();
}

private string[] ListToArray(IList<string> stringList)
{
if (null == stringList)
{
return null;
}

string[] stringArray = new string[stringList.Count];
stringList.CopyTo(stringArray, 0);
return stringArray;

WriteObject(PSCorsRule.ParseCorsRules(currentServiceProperties.Cors));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// ----------------------------------------------------------------------------------
//
// 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 Microsoft.WindowsAzure.Storage.Shared.Protocol;
using System.Management.Automation;
using System.Security.Permissions;
using Microsoft.WindowsAzure.Commands.Storage.Model.ResourceModel;

/// <summary>
/// Show Azure Storage service properties
/// </summary>
[Cmdlet(VerbsCommon.Get, StorageNouns.StorageServiceProperty),
OutputType(typeof(PSSeriviceProperties))]
public class GetAzureStorageServicePropertyCommand : StorageCloudBlobCmdletBase
{
[Parameter(Mandatory = true, Position = 0, HelpMessage = GetAzureStorageServiceLoggingCommand.ServiceTypeHelpMessage)]
public StorageServiceType ServiceType { get; set; }

// Overwrite the useless parameter
public override int? ServerTimeoutPerRequest { get; set; }
public override int? ClientTimeoutPerRequest { get; set; }
public override int? ConcurrentTaskCount { get; set; }

public GetAzureStorageServicePropertyCommand()
{
EnableMultiThread = false;
}

/// <summary>
/// Execute command
/// </summary>
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public override void ExecuteCmdlet()
{
ServiceProperties serviceProperties = Channel.GetStorageServiceProperties(ServiceType, GetRequestOptions(ServiceType), OperationContext);
WriteObject(new PSSeriviceProperties(serviceProperties));
}
}
}
Loading