Skip to content

Commit d281a5d

Browse files
authored
Add storage provider and service for storage management sdk 2019-06-01 (#233)
For Azure/azure-powershell#13372
1 parent a03e21a commit d281a5d

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
using Microsoft.Azure.Management.Profiles.Storage.Version2019_06_01;
16+
using Microsoft.WindowsAzure.Commands.Common.Storage;
17+
using Microsoft.Azure.Commands.Compute;
18+
19+
namespace Microsoft.Azure.Commands.Management.Storage.Models
20+
{
21+
public class ARMStorageProvider : IStorageServiceProvider
22+
{
23+
IStorageManagementClient _client;
24+
25+
public ARMStorageProvider(IStorageManagementClient client)
26+
{
27+
_client = client;
28+
}
29+
public IStorageService GetStorageService(string name, string resourceGroupName)
30+
{
31+
var account = _client.StorageAccounts.GetProperties(resourceGroupName, name);
32+
var keys = _client.StorageAccounts.ListKeys(resourceGroupName, name);
33+
return new ARMStorageService(account, keys.GetKey1(), keys.GetKey2());
34+
}
35+
}
36+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
using Microsoft.WindowsAzure.Commands.Common.Storage;
16+
using System;
17+
using System.Collections.Generic;
18+
19+
namespace Microsoft.Azure.Commands.Management.Storage.Models
20+
{
21+
public class ARMStorageService : IStorageService
22+
{
23+
Azure.Management.Profiles.Storage.Version2019_06_01.Models.StorageAccount _account;
24+
List<string> _authenticationKeys = new List<string>();
25+
public ARMStorageService(Azure.Management.Profiles.Storage.Version2019_06_01.Models.StorageAccount account,
26+
params string[] authenticationKeys)
27+
{
28+
_account = account;
29+
foreach (var key in authenticationKeys)
30+
{
31+
_authenticationKeys.Add(key);
32+
}
33+
}
34+
35+
public Uri BlobEndpoint
36+
{
37+
get { return new Uri(_account.PrimaryEndpoints.Blob); }
38+
}
39+
40+
public Uri FileEndpoint
41+
{
42+
get { return new Uri(_account.PrimaryEndpoints.File); }
43+
}
44+
45+
public Uri QueueEndpoint
46+
{
47+
get { return new Uri(_account.PrimaryEndpoints.Queue); }
48+
}
49+
50+
public Uri TableEndpoint
51+
{
52+
get { return new Uri(_account.PrimaryEndpoints.Table); }
53+
}
54+
55+
public string Name
56+
{
57+
get { return _account.Name; }
58+
}
59+
60+
public List<string> AuthenticationKeys
61+
{
62+
get { return _authenticationKeys; }
63+
}
64+
65+
/// <summary>
66+
/// Get the resource group name from a storage account resource Id
67+
/// </summary>
68+
/// <param name="resourceId">The resource Id for the storage account</param>
69+
/// <returns>The resource group containing the storage account</returns>
70+
public static string ParseResourceGroupFromId(string resourceId)
71+
{
72+
if (!string.IsNullOrEmpty(resourceId))
73+
{
74+
string[] tokens = resourceId.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
75+
if (tokens == null || tokens.Length < 4)
76+
{
77+
throw new ArgumentOutOfRangeException("resourceId");
78+
}
79+
80+
return tokens[3];
81+
}
82+
83+
return null;
84+
}
85+
86+
}
87+
}

0 commit comments

Comments
 (0)