Skip to content

Commit 6f0d828

Browse files
committed
support defaultserviceversion
1 parent f4e7e60 commit 6f0d828

13 files changed

+566
-43
lines changed

src/Storage/Azure.Storage.psd1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ CmdletsToExport = 'Get-AzureStorageTable', 'New-AzureStorageTableSASToken',
115115
'Set-AzureStorageContainerStoredAccessPolicy',
116116
'Start-AzureStorageBlobCopy',
117117
'Start-AzureStorageBlobIncrementalCopy',
118-
'Stop-AzureStorageBlobCopy'
118+
'Stop-AzureStorageBlobCopy',
119+
'Set-AzureStorageServiceProperty',
120+
'Get-AzureStorageServiceProperty'
119121

120122
# Variables to export from this module
121123
# VariablesToExport = @()

src/Storage/ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Add cmdlets to get and set Storage service properties
22+
- Get-AzureStorageServiceProperty
23+
- Set-AzureStorageServiceProperty
2124

2225
## Version 4.0.2
2326
* Upgrade to Azure Storage Client Library 8.6.0 and Azure Storage DataMovement Library 0.6.5

src/Storage/Commands.Storage/Commands.Storage.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,14 @@
120120
<Compile Include="Common\BlobToFileSystemNameResolver.cs" />
121121
<Compile Include="Blob\Cmdlet\StartAzureStorageBlobCopy.cs" />
122122
<Compile Include="Blob\Cmdlet\StopAzureStorageBlobCopy.cs" />
123+
<Compile Include="Common\Cmdlet\GetAzureStorageServiceProperties.cs" />
123124
<Compile Include="Common\Cmdlet\NewAzureStorageAccountSasToken.cs" />
124125
<Compile Include="Common\Cmdlet\SetAzureStorageCORSRule.cs" />
125126
<Compile Include="Common\Cmdlet\GetAzureStorageCORSRule.cs" />
126127
<Compile Include="Common\Cmdlet\GetAzureStorageServiceLogging.cs" />
127128
<Compile Include="Common\Cmdlet\GetAzureStorageServiceMetrics.cs" />
128129
<Compile Include="Common\Cmdlet\RemoveAzureStorageCORSRule.cs" />
130+
<Compile Include="Common\Cmdlet\SetAzureStorageServiceProperties.cs" />
129131
<Compile Include="Common\Cmdlet\SetAzureStorageServiceLogging.cs" />
130132
<Compile Include="Common\Cmdlet\SetAzureStorageServiceMetrics.cs" />
131133
<Compile Include="Common\ConfirmTaskCompletionSource.cs" />
@@ -184,6 +186,7 @@
184186
<Compile Include="Model\Contract\StorageQueueManagement.cs" />
185187
<Compile Include="Model\Contract\StorageTableManagement.cs" />
186188
<Compile Include="Model\ResourceModel\PSCorsRule.cs" />
189+
<Compile Include="Model\ResourceModel\PSSeriviceProperties.cs" />
187190
<Compile Include="Properties\AssemblyInfo.cs" />
188191
<Compile Include="Model\Contract\IStorageBlobManagement.cs" />
189192
<Compile Include="Model\Contract\StorageBlobManagement.cs" />

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

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -44,47 +44,8 @@ public GetAzureStorageCORSRuleCommand()
4444
public override void ExecuteCmdlet()
4545
{
4646
ServiceProperties currentServiceProperties = Channel.GetStorageServiceProperties(ServiceType, GetRequestOptions(ServiceType), OperationContext);
47-
List<PSCorsRule> ruleList = new List<PSCorsRule>();
48-
49-
foreach (var corsRule in currentServiceProperties.Cors.CorsRules)
50-
{
51-
PSCorsRule psCorsRule = new PSCorsRule();
52-
psCorsRule.AllowedOrigins = this.ListToArray(corsRule.AllowedOrigins);
53-
psCorsRule.AllowedHeaders = this.ListToArray(corsRule.AllowedHeaders);
54-
psCorsRule.ExposedHeaders = this.ListToArray(corsRule.ExposedHeaders);
55-
psCorsRule.AllowedMethods = this.ConvertCorsHttpMethodToString(corsRule.AllowedMethods);
56-
psCorsRule.MaxAgeInSeconds = corsRule.MaxAgeInSeconds;
57-
ruleList.Add(psCorsRule);
58-
}
59-
60-
WriteObject(ruleList.ToArray());
61-
}
62-
63-
private string[] ConvertCorsHttpMethodToString(CorsHttpMethods methods)
64-
{
65-
List<string> methodList = new List<string>();
66-
67-
foreach (CorsHttpMethods methodValue in Enum.GetValues(typeof(CorsHttpMethods)).Cast<CorsHttpMethods>())
68-
{
69-
if (methodValue != CorsHttpMethods.None && (methods & methodValue) != 0)
70-
{
71-
methodList.Add(methodValue.ToString());
72-
}
73-
}
74-
75-
return methodList.ToArray();
76-
}
77-
78-
private string[] ListToArray(IList<string> stringList)
79-
{
80-
if (null == stringList)
81-
{
82-
return null;
83-
}
84-
85-
string[] stringArray = new string[stringList.Count];
86-
stringList.CopyTo(stringArray, 0);
87-
return stringArray;
47+
48+
WriteObject(PSCorsRule.ParseCorsRules(currentServiceProperties.Cors));
8849
}
8950
}
9051
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.WindowsAzure.Commands.Storage.Common.Cmdlet
16+
{
17+
using Microsoft.WindowsAzure.Storage.Shared.Protocol;
18+
using System.Management.Automation;
19+
using System.Security.Permissions;
20+
using Microsoft.WindowsAzure.Commands.Storage.Model.ResourceModel;
21+
22+
/// <summary>
23+
/// Show Azure Storage service properties
24+
/// </summary>
25+
[Cmdlet(VerbsCommon.Get, StorageNouns.StorageServiceProperty),
26+
OutputType(typeof(PSSeriviceProperties))]
27+
public class GetAzureStorageServicePropertyCommand : StorageCloudBlobCmdletBase
28+
{
29+
[Parameter(Mandatory = true, Position = 0, HelpMessage = GetAzureStorageServiceLoggingCommand.ServiceTypeHelpMessage)]
30+
public StorageServiceType ServiceType { get; set; }
31+
32+
// Overwrite the useless parameter
33+
public override int? ServerTimeoutPerRequest { get; set; }
34+
public override int? ClientTimeoutPerRequest { get; set; }
35+
public override int? ConcurrentTaskCount { get; set; }
36+
37+
public GetAzureStorageServicePropertyCommand()
38+
{
39+
EnableMultiThread = false;
40+
}
41+
42+
/// <summary>
43+
/// Execute command
44+
/// </summary>
45+
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
46+
public override void ExecuteCmdlet()
47+
{
48+
ServiceProperties serviceProperties = Channel.GetStorageServiceProperties(ServiceType, GetRequestOptions(ServiceType), OperationContext);
49+
WriteObject(new PSSeriviceProperties(serviceProperties));
50+
}
51+
}
52+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.WindowsAzure.Commands.Storage.Common.Cmdlet
16+
{
17+
using System;
18+
using System.Management.Automation;
19+
using System.Security.Permissions;
20+
using StorageClient = WindowsAzure.Storage.Shared.Protocol;
21+
using Microsoft.WindowsAzure.Commands.Storage.Model.ResourceModel;
22+
23+
/// <summary>
24+
/// Modify Azure Storage service properties
25+
/// </summary>
26+
[Cmdlet(VerbsCommon.Set, StorageNouns.StorageServiceProperty, SupportsShouldProcess = true), OutputType(typeof(PSSeriviceProperties))]
27+
public class SetAzureStorageServicePropertyCommand : StorageCloudBlobCmdletBase
28+
{
29+
[Parameter(Mandatory = true, Position = 0, HelpMessage = GetAzureStorageServiceLoggingCommand.ServiceTypeHelpMessage)]
30+
public StorageServiceType ServiceType { get; set; }
31+
32+
[Parameter(Mandatory = false, HelpMessage = "Default Service Version to Set")]
33+
[ValidateNotNullOrEmpty]
34+
public string DefaultServiceVersion { get; set; }
35+
36+
[Parameter(Mandatory = false, HelpMessage = "Display ServiceProperties")]
37+
public SwitchParameter PassThru { get; set; }
38+
39+
// Overwrite the useless parameter
40+
public override int? ServerTimeoutPerRequest { get; set; }
41+
public override int? ClientTimeoutPerRequest { get; set; }
42+
public override int? ConcurrentTaskCount { get; set; }
43+
44+
public SetAzureStorageServicePropertyCommand()
45+
{
46+
EnableMultiThread = false;
47+
}
48+
49+
/// <summary>
50+
/// Execute command
51+
/// </summary>
52+
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
53+
public override void ExecuteCmdlet()
54+
{
55+
if (ShouldProcess("ServiceProperties", VerbsCommon.Set))
56+
{
57+
StorageClient.ServiceProperties serviceProperties = Channel.GetStorageServiceProperties(ServiceType, GetRequestOptions(ServiceType), OperationContext);
58+
59+
serviceProperties.DefaultServiceVersion = this.DefaultServiceVersion;
60+
61+
Channel.SetStorageServiceProperties(ServiceType, serviceProperties,
62+
GetRequestOptions(ServiceType), OperationContext);
63+
64+
if (PassThru)
65+
{
66+
WriteObject(new PSSeriviceProperties(serviceProperties));
67+
}
68+
}
69+
}
70+
}
71+
}

src/Storage/Commands.Storage/Common/StorageNouns.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ public static class StorageNouns
104104
/// </summary>
105105
public const string StorageServiceLogging = "AzureStorageServiceLoggingProperty";
106106

107+
/// <summary>
108+
/// Azure storage service Property
109+
/// </summary>
110+
public const string StorageServiceProperty = "AzureStorageServiceProperty";
111+
107112
/// <summary>
108113
/// Azure storage CORS rule
109114
/// </summary>

src/Storage/Commands.Storage/Microsoft.WindowsAzure.Commands.Storage.format.ps1xml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,64 @@
584584
</ListEntries>
585585
</ListControl>
586586
</View>
587+
<View>
588+
<Name>Microsoft.WindowsAzure.Commands.Storage.Model.ResourceModel.PSSeriviceProperties</Name>
589+
<ViewSelectedBy>
590+
<TypeName>Microsoft.WindowsAzure.Commands.Storage.Model.ResourceModel.PSSeriviceProperties</TypeName>
591+
</ViewSelectedBy>
592+
<ListControl>
593+
<ListEntries>
594+
<ListEntry>
595+
<ListItems>
596+
<ListItem>
597+
<Label>Logging.Version</Label>
598+
<ScriptBlock>$_.Logging.Version</ScriptBlock>
599+
</ListItem>
600+
<ListItem>
601+
<Label>Logging.LoggingOperations</Label>
602+
<ScriptBlock>$_.Logging.LoggingOperations</ScriptBlock>
603+
</ListItem>
604+
<ListItem>
605+
<Label>Logging.RetentionDays</Label>
606+
<ScriptBlock>$_.Logging.RetentionDays</ScriptBlock>
607+
</ListItem>
608+
<ListItem>
609+
<Label>HourMetrics.Version</Label>
610+
<ScriptBlock>$_.HourMetrics.Version</ScriptBlock>
611+
</ListItem>
612+
<ListItem>
613+
<Label>HourMetrics.MetricsLevel</Label>
614+
<ScriptBlock>$_.HourMetrics.MetricsLevel</ScriptBlock>
615+
</ListItem>
616+
<ListItem>
617+
<Label>HourMetrics.RetentionDays</Label>
618+
<ScriptBlock>$_.HourMetrics.RetentionDays</ScriptBlock>
619+
</ListItem>
620+
<ListItem>
621+
<Label>MinuteMetrics.Version</Label>
622+
<ScriptBlock>$_.MinuteMetrics.Version</ScriptBlock>
623+
</ListItem>
624+
<ListItem>
625+
<Label>MinuteMetrics.MetricsLevel</Label>
626+
<ScriptBlock>$_.MinuteMetrics.MetricsLevel</ScriptBlock>
627+
</ListItem>
628+
<ListItem>
629+
<Label>MinuteMetrics.RetentionDays</Label>
630+
<ScriptBlock>$_.MinuteMetrics.RetentionDays</ScriptBlock>
631+
</ListItem>
632+
<ListItem>
633+
<Label>Cors</Label>
634+
<ScriptBlock>$_.Cors</ScriptBlock>
635+
</ListItem>
636+
<ListItem>
637+
<Label>DefaultServiceVersion</Label>
638+
<PropertyName>DefaultServiceVersion</PropertyName>
639+
</ListItem>
640+
</ListItems>
641+
</ListEntry>
642+
</ListEntries>
643+
</ListControl>
644+
</View>
587645
<View>
588646
<Name>Microsoft.WindowsAzure.Storage.Shared.Protocol.LoggingProperties</Name>
589647
<ViewSelectedBy>

src/Storage/Commands.Storage/Model/ResourceModel/PSCorsRule.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.WindowsAzure.Storage.Shared.Protocol;
16+
using System.Collections.Generic;
17+
using System;
18+
using System.Linq;
19+
1520
namespace Microsoft.WindowsAzure.Commands.Storage.Model.ResourceModel
1621
{
1722
public class PSCorsRule
@@ -25,5 +30,68 @@ public class PSCorsRule
2530
public string[] AllowedMethods { get; set; }
2631

2732
public int MaxAgeInSeconds { get; set; }
33+
34+
/// <summary>
35+
/// Parse Cors Rules from XSCL to PSCorsRule Array
36+
/// </summary>
37+
/// <param name="corsProperties">Cors Rules from XSCL</param>
38+
/// <returns>PSCorsRule Array</returns>
39+
public static PSCorsRule[] ParseCorsRules(CorsProperties corsProperties)
40+
{
41+
List<PSCorsRule> ruleList = new List<PSCorsRule>();
42+
43+
if (corsProperties != null && corsProperties.CorsRules != null)
44+
{
45+
foreach (var corsRule in corsProperties.CorsRules)
46+
{
47+
PSCorsRule psCorsRule = new PSCorsRule();
48+
psCorsRule.AllowedOrigins = ListToArray(corsRule.AllowedOrigins);
49+
psCorsRule.AllowedHeaders = ListToArray(corsRule.AllowedHeaders);
50+
psCorsRule.ExposedHeaders = ListToArray(corsRule.ExposedHeaders);
51+
psCorsRule.AllowedMethods = ConvertCorsHttpMethodToString(corsRule.AllowedMethods);
52+
psCorsRule.MaxAgeInSeconds = corsRule.MaxAgeInSeconds;
53+
ruleList.Add(psCorsRule);
54+
}
55+
}
56+
57+
return ruleList.ToArray();
58+
}
59+
60+
/// <summary>
61+
/// Parse CorsHttpMethods from XSCL to String Array
62+
/// </summary>
63+
/// <param name="methods">CorsHttpMethods from XSCL</param>
64+
/// <returns>String Array</returns>
65+
private static string[] ConvertCorsHttpMethodToString(CorsHttpMethods methods)
66+
{
67+
List<string> methodList = new List<string>();
68+
69+
foreach (CorsHttpMethods methodValue in Enum.GetValues(typeof(CorsHttpMethods)).Cast<CorsHttpMethods>())
70+
{
71+
if (methodValue != CorsHttpMethods.None && (methods & methodValue) != 0)
72+
{
73+
methodList.Add(methodValue.ToString());
74+
}
75+
}
76+
77+
return methodList.ToArray();
78+
}
79+
80+
/// <summary>
81+
/// Parse String list to String Array for parse CorsRule
82+
/// </summary>
83+
/// <param name="stringList">String list</param>
84+
/// <returns>String Array</returns>
85+
private static string[] ListToArray(IList<string> stringList)
86+
{
87+
if (null == stringList)
88+
{
89+
return null;
90+
}
91+
92+
string[] stringArray = new string[stringList.Count];
93+
stringList.CopyTo(stringArray, 0);
94+
return stringArray;
95+
}
2896
}
2997
}

0 commit comments

Comments
 (0)