Skip to content

Commit 393bfe6

Browse files
author
unknown
committed
Merge branch 'dev' of https://github.com/AzureRT/azure-powershell into dev
2 parents 5a62841 + 6df9a7d commit 393bfe6

File tree

152 files changed

+2893
-321
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+2893
-321
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@
5656
<SpecificVersion>False</SpecificVersion>
5757
<HintPath>..\..\packages\Microsoft.Azure.Common.2.0.2\lib\net45\Microsoft.Azure.Common.dll</HintPath>
5858
</Reference>
59-
<Reference Include="Microsoft.Azure.Common.Authentication">
59+
<Reference Include="Microsoft.Azure.Common.Authentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6060
<SpecificVersion>False</SpecificVersion>
61-
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.0.8-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
61+
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.0.13-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
6262
</Reference>
6363
<Reference Include="Microsoft.Azure.Common.NetFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6464
<SpecificVersion>False</SpecificVersion>

src/Common/Commands.Common.Storage/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<packages>
33
<package id="Hyak.Common" version="1.0.2" targetFramework="net45" />
44
<package id="Microsoft.Azure.Common" version="2.0.2" targetFramework="net45" />
5+
<package id="Microsoft.Azure.Common.Authentication" version="1.0.13-preview" targetFramework="net45" />
56
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
6-
<package id="Microsoft.Azure.Common.Authentication" version="1.0.8-preview" targetFramework="net45" />
77
<package id="Microsoft.Azure.Management.Resources" version="2.12.0-preview" targetFramework="net45" />
88
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
99
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />

src/Common/Commands.Common.Test/Commands.Common.Test.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
<Reference Include="Microsoft.Azure.Common">
5555
<HintPath>..\..\packages\Microsoft.Azure.Common.2.0.3\lib\net45\Microsoft.Azure.Common.dll</HintPath>
5656
</Reference>
57-
<Reference Include="Microsoft.Azure.Common.Authentication">
57+
<Reference Include="Microsoft.Azure.Common.Authentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
5858
<SpecificVersion>False</SpecificVersion>
59-
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.0.8-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
59+
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.0.13-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
6060
</Reference>
6161
<Reference Include="Microsoft.Azure.Common.NetFramework">
6262
<HintPath>..\..\packages\Microsoft.Azure.Common.2.0.3\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
@@ -155,7 +155,7 @@
155155
</ItemGroup>
156156
<ItemGroup>
157157
<Compile Include="Common\AuthenticationFactoryTests.cs" />
158-
<Compile Include="Common\ProfileCmdltsTests.cs" />
158+
<Compile Include="Common\MockSubsciptionFactory.cs" />
159159
<Compile Include="Common\ServicePrincipalStoreTests.cs" />
160160
<Compile Include="Common\GeneralUtilitiesTests.cs" />
161161
<Compile Include="Common\Data.cs" />
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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 System;
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using System.Text;
19+
using System.Threading.Tasks;
20+
using Microsoft.Azure.Common.Authentication;
21+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
22+
23+
namespace Microsoft.WindowsAzure.Commands.Common.Test.Common
24+
{
25+
public class MockSubsciptionFactory : IClientFactory
26+
{
27+
public void AddAction(Azure.Common.Authentication.Models.IClientAction action)
28+
{
29+
throw new NotImplementedException();
30+
}
31+
32+
public TClient CreateClient<TClient>(Azure.Common.Authentication.Models.AzureProfile profile, Azure.Common.Authentication.Models.AzureSubscription subscription, Azure.Common.Authentication.Models.AzureEnvironment.Endpoint endpoint) where TClient : Hyak.Common.ServiceClient<TClient>
33+
{
34+
throw new NotImplementedException();
35+
}
36+
37+
public TClient CreateClient<TClient>(Azure.Common.Authentication.Models.AzureProfile profile, Azure.Common.Authentication.Models.AzureEnvironment.Endpoint endpoint) where TClient : Hyak.Common.ServiceClient<TClient>
38+
{
39+
throw new NotImplementedException();
40+
}
41+
42+
public TClient CreateClient<TClient>(Azure.Common.Authentication.Models.AzureContext context, Azure.Common.Authentication.Models.AzureEnvironment.Endpoint endpoint) where TClient : Hyak.Common.ServiceClient<TClient>
43+
{
44+
throw new NotImplementedException();
45+
}
46+
47+
public TClient CreateCustomClient<TClient>(params object[] parameters) where TClient : Hyak.Common.ServiceClient<TClient>
48+
{
49+
throw new NotImplementedException();
50+
}
51+
52+
public System.Net.Http.HttpClient CreateHttpClient(string endpoint, System.Net.Http.HttpMessageHandler effectiveHandler)
53+
{
54+
throw new NotImplementedException();
55+
}
56+
57+
public System.Net.Http.HttpClient CreateHttpClient(string endpoint, System.Net.ICredentials credentials)
58+
{
59+
throw new NotImplementedException();
60+
}
61+
62+
public void RemoveAction(Type actionType)
63+
{
64+
throw new NotImplementedException();
65+
}
66+
67+
public List<System.Net.Http.Headers.ProductInfoHeaderValue> UserAgents
68+
{
69+
get
70+
{
71+
throw new NotImplementedException();
72+
}
73+
set
74+
{
75+
throw new NotImplementedException();
76+
}
77+
}
78+
}
79+
}

src/Common/Commands.Common.Test/Mocks/MockTokenAuthenticationFactory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public MockTokenAuthenticationFactory(string userId, string accessToken)
5151
LoginType = LoginType.OrgId,
5252
AccessToken = accessToken
5353
};
54+
55+
TokenProvider = ((account, environment, tenant) => Token);
5456
}
5557

5658
public IAccessToken Authenticate(AzureAccount account, AzureEnvironment environment, string tenant, SecureString password, ShowDialog promptBehavior,

src/Common/Commands.Common.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<packages>
33
<package id="Hyak.Common" version="1.0.2" targetFramework="net45" />
44
<package id="Microsoft.Azure.Common" version="2.0.3" targetFramework="net45" />
5+
<package id="Microsoft.Azure.Common.Authentication" version="1.0.13-preview" targetFramework="net45" />
56
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
6-
<package id="Microsoft.Azure.Common.Authentication" version="1.0.8-preview" targetFramework="net45" />
77
<package id="Microsoft.Azure.Management.Resources" version="2.12.0-preview" targetFramework="net45" />
88
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.0.5513.27084-prerelease" targetFramework="net45" />
99
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />

src/Common/Commands.Common/AzurePSCmdlet.cs

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using Microsoft.Azure.Common.Authentication;
1616
using Microsoft.Azure.Common.Authentication.Models;
17+
using Microsoft.IdentityModel.Clients.ActiveDirectory;
1718
using Microsoft.WindowsAzure.Commands.Common;
1819
using Microsoft.WindowsAzure.Commands.Common.Properties;
1920
using System;
@@ -30,6 +31,14 @@ public abstract class AzurePSCmdlet : PSCmdlet
3031
[Parameter(Mandatory = false, HelpMessage = "In-memory profile.")]
3132
public AzureProfile Profile { get; set; }
3233

34+
public static AzureProfile CurrentProfile { get; set; }
35+
36+
protected static TokenCache DefaultDiskTokenCache { get; set; }
37+
38+
protected static TokenCache DefaultMemoryTokenCache { get; set; }
39+
40+
protected static AzureProfile DefaultProfile { get; set; }
41+
3342
static AzurePSCmdlet()
3443
{
3544
if (!TestMockSupport.RunningMocked)
@@ -38,6 +47,66 @@ static AzurePSCmdlet()
3847
}
3948

4049
AzureSession.ClientFactory.UserAgents.Add(AzurePowerShell.UserAgentValue);
50+
if (!TestMockSupport.RunningMocked)
51+
{
52+
InitializeTokenCaches();
53+
DefaultProfile = InitializeDefaultProfile();
54+
CurrentProfile = DefaultProfile;
55+
UpdateSessionStateForProfile(CurrentProfile);
56+
AzureSession.DataStore = new DiskDataStore();
57+
}
58+
}
59+
60+
/// <summary>
61+
/// Create the default profile, based on the default profile path
62+
/// </summary>
63+
/// <returns>The default prpofile, serialized from the default location on disk</returns>
64+
protected static AzureProfile InitializeDefaultProfile()
65+
{
66+
if (!string.IsNullOrEmpty(AzureSession.ProfileDirectory) && !string.IsNullOrEmpty(AzureSession.ProfileFile))
67+
{
68+
try
69+
{
70+
return new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
71+
}
72+
catch
73+
{
74+
// swallow exceptions in creating the profile from disk
75+
}
76+
}
77+
78+
return new AzureProfile();
79+
}
80+
81+
protected static void InitializeTokenCaches()
82+
{
83+
DefaultMemoryTokenCache = new TokenCache();
84+
if (!string.IsNullOrWhiteSpace(AzureSession.ProfileDirectory) &&
85+
!string.IsNullOrWhiteSpace(AzureSession.TokenCacheFile))
86+
{
87+
DefaultDiskTokenCache = new ProtectedFileTokenCache(Path.Combine(AzureSession.ProfileDirectory, AzureSession.TokenCacheFile));
88+
}
89+
else
90+
{
91+
DefaultDiskTokenCache = DefaultMemoryTokenCache;
92+
}
93+
}
94+
95+
/// <summary>
96+
/// Update the token cache when setting the profile
97+
/// </summary>
98+
/// <param name="profile"></param>
99+
protected static void UpdateSessionStateForProfile(AzureProfile profile)
100+
{
101+
var defaultProfilePath = Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile);
102+
if (string.Equals(profile.ProfilePath, defaultProfilePath, StringComparison.OrdinalIgnoreCase))
103+
{
104+
AzureSession.TokenCache = DefaultDiskTokenCache;
105+
}
106+
else
107+
{
108+
AzureSession.TokenCache = DefaultMemoryTokenCache;
109+
}
41110
}
42111

43112
/// <summary>
@@ -46,7 +115,6 @@ static AzurePSCmdlet()
46115
protected override void BeginProcessing()
47116
{
48117
InitializeProfile();
49-
50118
if (string.IsNullOrEmpty(ParameterSetName))
51119
{
52120
WriteDebugWithTimestamp(string.Format(Resources.BeginProcessingWithoutParameterSetLog, this.GetType().Name));
@@ -66,15 +134,17 @@ protected override void BeginProcessing()
66134
base.BeginProcessing();
67135
}
68136

137+
/// <summary>
138+
/// Ensure that there is a profile for the command
139+
/// </summary>
69140
private void InitializeProfile()
70141
{
71-
// Load profile from disk
72-
var profileFromDisk = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
73-
if (Profile == null ||
74-
Profile.ProfilePath == profileFromDisk.ProfilePath)
142+
if (Profile == null)
75143
{
76-
Profile = profileFromDisk;
144+
Profile = AzurePSCmdlet.CurrentProfile;
77145
}
146+
147+
UpdateSessionStateForProfile(Profile);
78148
}
79149

80150
/// <summary>

src/Common/Commands.Common/Commands.Common.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
<SpecificVersion>False</SpecificVersion>
5959
<HintPath>..\..\packages\Microsoft.Azure.Common.2.0.2\lib\net45\Microsoft.Azure.Common.dll</HintPath>
6060
</Reference>
61-
<Reference Include="Microsoft.Azure.Common.Authentication">
61+
<Reference Include="Microsoft.Azure.Common.Authentication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6262
<SpecificVersion>False</SpecificVersion>
63-
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.0.8-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
63+
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.0.13-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
6464
</Reference>
6565
<Reference Include="Microsoft.Azure.Common.NetFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6666
<SpecificVersion>False</SpecificVersion>

src/Common/Commands.Common/Properties/Resources.Designer.cs

Lines changed: 46 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Common/Commands.Common/Properties/Resources.resx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,4 +1355,19 @@ use and privacy statement at &lt;url&gt; and (c) agree to sharing my contact inf
13551355
<data name="InvalidDefaultSubscription" xml:space="preserve">
13561356
<value>No default subscription has been designated. Use Select-AzureSubscription -Default &lt;subscriptionName&gt; to set the default subscription.</value>
13571357
</data>
1358+
<data name="InvalidNewProfilePath" xml:space="preserve">
1359+
<value>Path must specify a valid path to an Azure profile.</value>
1360+
</data>
1361+
<data name="InvalidProfileProperties" xml:space="preserve">
1362+
<value>Property bag Hashtable must contain one of the following sets of properties: {SubscriptionId, Certificate}, {SubscriptionId, Username, Password}, {SubscriptionId, ServicePrincipal, Password, Tenant}, {SubscriptionId, AccountId, Token}</value>
1363+
</data>
1364+
<data name="MissingCertificateInProfileProperties" xml:space="preserve">
1365+
<value>Property bag Hashtable must contain a 'Certificate' of type 'X509Certificate2'.</value>
1366+
</data>
1367+
<data name="MissingPasswordInProfileProperties" xml:space="preserve">
1368+
<value>Property bag Hashtable must contain a 'Password' with an associated 'Username' or 'ServicePrincipal'.</value>
1369+
</data>
1370+
<data name="MissingSubscriptionInProfileProperties" xml:space="preserve">
1371+
<value>Property bag Hashtable must contain a 'SubscriptionId'.</value>
1372+
</data>
13581373
</root>

src/Common/Commands.Common/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<package id="Hyak.Common" version="1.0.2" targetFramework="net45" />
44
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.2" targetFramework="net45" />
55
<package id="Microsoft.Azure.Common" version="2.0.2" targetFramework="net45" />
6+
<package id="Microsoft.Azure.Common.Authentication" version="1.0.13-preview" targetFramework="net45" />
67
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
7-
<package id="Microsoft.Azure.Common.Authentication" version="1.0.8-preview" targetFramework="net45" />
88
<package id="Microsoft.Azure.Management.Resources" version="2.12.0-preview" targetFramework="net45" />
99
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
1010
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />

0 commit comments

Comments
 (0)