Skip to content
Merged

Clu #255

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
2 changes: 2 additions & 0 deletions examples/lib/loginService.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
azure account add --spn --appid "$spn" --secret "$secret" -t "$tenant" -s "$subscription"
2 changes: 2 additions & 0 deletions examples/lib/loginUser.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
azure account add -u "$azureUser" -p "$password" -s "$subscription"
8 changes: 4 additions & 4 deletions examples/resource-management/01-ResourceGroups.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ set -e
printf "\n=== Managing Resource Groups in Azure ===\n"

printf "\n1. Creating a new resource group: %s and location: %s.\n" "$groupName" "$location"
azure group create --name "$groupName" --location "$location"
azure group create -n "$groupName" --location "$location"

printf "\n2. Updating the group %s with tags.\n" "$groupName"
azure group set --name "$groupName" --tags "[{\"Value\":\"testval\",\"Name\":\"testtag\"}]"
azure group set -n "$groupName" --tags "[{\"Value\":\"testval\",\"Name\":\"testtag\"}]"

printf "\n3. Get information about resource group : %s.\n" "$groupName"
resourceGroupInfo=`azure group get --name $groupName`
resourceGroupInfo=`azure group get -n $groupName`

printf "\nValidating resource group name is: %s\n" "$groupName"
[ $(echo $resourceGroupInfo | jq '.ResourceGroupName' --raw-output) == "$groupName" ]
Expand All @@ -18,4 +18,4 @@ printf "\n4. Listing all resource groups in the subscription.\n"
azure group get

printf "\n5. Removing resource group: %s.\n" "$groupName"
azure group remove --name "$groupName" --force
azure group remove -n "$groupName" -f
22 changes: 11 additions & 11 deletions src/CLU/CLUCoreCLR.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU", "Microsoft.
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU.Test", "Microsoft.CLU.Test\Microsoft.CLU.Test.xproj", "{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Azure.Commands.Compute", "Microsoft.Azure.Commands.Compute\Microsoft.Azure.Commands.Compute.xproj", "{04F9968A-5662-4508-BEE2-31F56848FCBA}"
ProjectSection(ProjectDependencies) = postProject
{99B1290D-A073-4907-8018-51C714431778} = {99B1290D-A073-4907-8018-51C714431778}
{3910613E-4ED2-49E2-8CCF-966D586665AC} = {3910613E-4ED2-49E2-8CCF-966D586665AC}
{81A48E48-89A7-4B93-8207-4F8FA6DC251B} = {81A48E48-89A7-4B93-8207-4F8FA6DC251B}
{45B05B68-516F-4D74-897F-56D12894946C} = {45B05B68-516F-4D74-897F-56D12894946C}
EndProjectSection
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Commands.Common.ScenarioTest", "Commands.Common.ScenarioTest\Commands.Common.ScenarioTest.xproj", "{B1D3CB1F-C0CA-401F-8146-B2E9C1EF460F}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Azure.Commands.Compute.Test", "Microsoft.Azure.Commands.Compute.Test\Microsoft.Azure.Commands.Compute.Test.xproj", "{13C34370-51A4-4726-81B8-BE0996FC9CFF}"
ProjectSection(ProjectDependencies) = postProject
Expand All @@ -55,6 +49,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Azure.Commands.Co
{04F9968A-5662-4508-BEE2-31F56848FCBA} = {04F9968A-5662-4508-BEE2-31F56848FCBA}
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Azure.Commands.Compute", "Microsoft.Azure.Commands.Compute\Microsoft.Azure.Commands.Compute.xproj", "{04F9968A-5662-4508-BEE2-31F56848FCBA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -133,14 +129,18 @@ Global
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Release|Any CPU.Build.0 = Release|Any CPU
{04F9968A-5662-4508-BEE2-31F56848FCBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{04F9968A-5662-4508-BEE2-31F56848FCBA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{04F9968A-5662-4508-BEE2-31F56848FCBA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{04F9968A-5662-4508-BEE2-31F56848FCBA}.Release|Any CPU.Build.0 = Release|Any CPU
{B1D3CB1F-C0CA-401F-8146-B2E9C1EF460F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B1D3CB1F-C0CA-401F-8146-B2E9C1EF460F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1D3CB1F-C0CA-401F-8146-B2E9C1EF460F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1D3CB1F-C0CA-401F-8146-B2E9C1EF460F}.Release|Any CPU.Build.0 = Release|Any CPU
{13C34370-51A4-4726-81B8-BE0996FC9CFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{13C34370-51A4-4726-81B8-BE0996FC9CFF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13C34370-51A4-4726-81B8-BE0996FC9CFF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13C34370-51A4-4726-81B8-BE0996FC9CFF}.Release|Any CPU.Build.0 = Release|Any CPU
{04F9968A-5662-4508-BEE2-31F56848FCBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{04F9968A-5662-4508-BEE2-31F56848FCBA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{04F9968A-5662-4508-BEE2-31F56848FCBA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{04F9968A-5662-4508-BEE2-31F56848FCBA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>b1d3cb1f-c0ca-401f-8146-b2e9c1ef460f</ProjectGuid>
<RootNamespace>Microsoft.Azure.Commands.Common.ScenarioTest</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
32 changes: 32 additions & 0 deletions src/CLU/Commands.Common.ScenarioTest/EnvironmentConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// ----------------------------------------------------------------------------------
//
// 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.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Microsoft.Azure.Commands.Common.ScenarioTest
{
public static class EnvironmentConstants
{
public const string UsernameKey = "Username";
public const string PasswordKey = "Password";
public const string ServicePrincipalKey = "ServicePrincipal";
public const string TenantKey = "TenantId";
public const string SubscriptionKey = "SubscriptionId";
public const string TestRunDirectory = "TestRunDirectory";
public const string ExampleDirectory = "ExamplesDirectory";
}
}
67 changes: 67 additions & 0 deletions src/CLU/Commands.Common.ScenarioTest/EnvironmentContextFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// ----------------------------------------------------------------------------------
//
// 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.Collections.Generic;
using System.IO;

namespace Microsoft.Azure.Commands.Common.ScenarioTest
{
public class EnvironmentContextFactory
{
ICredentialsProvider _credentials;


public EnvironmentContextFactory(ICredentialsProvider credentials)
{
_credentials = credentials;
}

public TestContext GetTestContext(string scriptDirectoryName)
{
var context = new TestContext();
context.ExecutionDirectory = GetBaseDirectory();
context.TestScriptDirectory =GetExamplesDirectory(context.ExecutionDirectory, scriptDirectoryName);
context.TestExecutableName = "bash.exe";
context.TestScriptSuffix = ".sh";
var helpers = new List<IScriptEnvironmentHelper>();
helpers.Add(_credentials.EnvironmentProvider);
context.EnvironmentHelpers = helpers;
return context;
}

private string GetExamplesDirectory(string executionDirectory, string scriptDirectoryName)
{
string examplesDirectory;
if (!Utilities.TryGetEnvironmentVariable(EnvironmentConstants.ExampleDirectory, out examplesDirectory))
{
examplesDirectory = Path.GetFullPath(Path.Combine(executionDirectory, "..",
"..", "..", "examples"));
}

return Path.Combine(examplesDirectory, scriptDirectoryName);
}
private string GetBaseDirectory()
{
string baseDirectory;
if (!Utilities.TryGetEnvironmentVariable(EnvironmentConstants.TestRunDirectory, out baseDirectory))
{
baseDirectory = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "..", "TestResults"));
}

Utilities.EnsureDirectoryExists(baseDirectory);
return baseDirectory;
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// ----------------------------------------------------------------------------------
//
// 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.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Azure.Commands.Common.ScenarioTest;

namespace Microsoft.Azure.Commands.Common.ScenarioTest
{
public class EnvironmentCredentialsProvider : ICredentialsProvider
{
public const string userScript = "loginUser";
public const string serviceScript = "loginService";

public IScriptEnvironmentHelper EnvironmentProvider { get; protected set; }

public string LoginScriptName { get; protected set; }

public virtual void Initialize(string key)
{
IDictionary<string, string> settings = GetSettings(key);
if (!TryInitializeServiceCredentials(settings) && !TryInitializeUserCredentials(settings))
{
throw new InvalidOperationException($"Unable to create credentials using key {key}. " +
"Please ensure your environment is correctly set up.");
}
}

protected virtual IDictionary<string, string> GetSettings(string key)
{
var environmentValue = Environment.GetEnvironmentVariable(key);
if (string.IsNullOrWhiteSpace(environmentValue))
{
throw new InvalidOperationException($"Unable to create credentials. " +
"Please set environment ${key}");
}
IDictionary<string, string> settings = new Dictionary<string, string>();
foreach (
var setting in
environmentValue.Split(new string[] {$"{Path.PathSeparator}"},
StringSplitOptions.RemoveEmptyEntries)
)
{
string[] pair = setting.Split(new char[] { '='}, 2, StringSplitOptions.RemoveEmptyEntries);
var pairKey = pair[0].Trim();
var pairValue = pair[1].Trim();
settings[pairKey] = pairValue;
}

return settings;
}

protected virtual bool TryInitializeServiceCredentials(IDictionary<string, string> settings )
{
if (settings.ContainsKey(EnvironmentConstants.ServicePrincipalKey) &&
settings.ContainsKey(EnvironmentConstants.PasswordKey) &&
settings.ContainsKey(EnvironmentConstants.TenantKey))
{
LoginScriptName = serviceScript;
EnvironmentProvider = new ServiceAuthenticationHelper(
settings[EnvironmentConstants.ServicePrincipalKey],
settings[EnvironmentConstants.PasswordKey],
settings[EnvironmentConstants.TenantKey],
settings.ContainsKey(EnvironmentConstants.SubscriptionKey) ? settings[EnvironmentConstants.SubscriptionKey] : null);
return true;
}
return false;
}

protected virtual bool TryInitializeUserCredentials(IDictionary<string, string> settings )
{
if (settings.ContainsKey(EnvironmentConstants.UsernameKey) &&
settings.ContainsKey(EnvironmentConstants.PasswordKey))
{
LoginScriptName = userScript;
EnvironmentProvider = new UserAuthenticationHelper(
settings[EnvironmentConstants.UsernameKey],
settings[EnvironmentConstants.PasswordKey],
settings.ContainsKey(EnvironmentConstants.SubscriptionKey) ? settings[EnvironmentConstants.SubscriptionKey] : null);
return true;
}
return false;
}
}
}
Loading