Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
83 changes: 83 additions & 0 deletions src/Ssh/Ssh.AlcWrapper/AzureIdUtilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// ----------------------------------------------------------------------------------
//
// 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.
// ----------------------------------------------------------------------------------

using System;
using System.Linq;
using System.Text.RegularExpressions;

namespace Microsoft.Azure.Commands.Ssh
{
public static class AzureIdUtilities
{
private static Regex locationRegex = new Regex("/locations/(?<Location>.*?)/", RegexOptions.Compiled | RegexOptions.IgnoreCase);

private static Regex rgRegex = new Regex("/resourceGroups/(?<RG>.*?)/", RegexOptions.Compiled | RegexOptions.IgnoreCase);

private static Regex subscriptionRegex = new Regex("/subscriptions/(?<subscriptionId>.*?)/", RegexOptions.Compiled | RegexOptions.IgnoreCase);

private static Regex resourceProviderRegex = new Regex("/providers/(?<resourceProvider>.*/*?)/", RegexOptions.Compiled | RegexOptions.IgnoreCase);

public static string GetResourceName(string id)
{
return id.Split('/').Last();
}

public static string GetResourceLocation(string id)
{
var match = locationRegex.Match(id);

if (match.Success != true)
{
throw new ArgumentException("Invalid format of the resource identifier.", "id");
}

return match.Groups["Location"].Value;
}

public static string GetResourceGroup(string id)
{
var match = rgRegex.Match(id);

if (match.Success != true)
{
return null;
}

return match.Groups["RG"].Value;
}

public static string GetResourceSubscription(string id)
{
var match = subscriptionRegex.Match(id);

if (match.Success != true)
{
throw new ArgumentException("Invalid format of the resource identifier.", "id");
}

return match.Groups["subscriptionId"].Value;
}

public static string GetResourceType(string id)
{
var match = resourceProviderRegex.Match(id);
if (match.Success != true)
{
throw new ArgumentException("Invalid format of the resource identifier.", "id");
}

return match.Groups["resourceProvider"].Value;
}
}
}
22 changes: 22 additions & 0 deletions src/Ssh/Ssh.AlcWrapper/Ssh.AlcWrapper.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PsModuleName>Ssh</PsModuleName>
<OmitJsonPackage>true</OmitJsonPackage>
<AssemblyLoadContextEntryPoint>true</AssemblyLoadContextEntryPoint>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)..\..\Az.props" />

<PropertyGroup>
<RootNamespace>$(LegacyAssemblyPrefix)$(PsModuleName)</RootNamespace>
<AssemblyName>$(LegacyAssemblyPrefix)$(PsModuleName).AlcWrapper</AssemblyName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="49.1.0" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="20.6.0" />
<PackageReference Include="Microsoft.Azure.Management.HybridCompute" Version="0.1.0-preview.2" />
</ItemGroup>

</Project>
Loading