Skip to content

Commit 3b6d435

Browse files
committed
Merge remote-tracking branch 'Azure/master' into tiano-deployment-refactor
# Conflicts: # src/Resources/Resources/ChangeLog.md
2 parents 4456190 + ccb14c1 commit 3b6d435

File tree

495 files changed

+839988
-431071
lines changed

Some content is hidden

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

495 files changed

+839988
-431071
lines changed

documentation/development-docs/azure-powershell-developer-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Before submitting a design review, please be sure that you have read the documen
143143

144144
Please submit a design review here: https://github.com/Azure/azure-powershell-cmdlet-review-pr
145145

146-
_Note_: You will need to be part of the `GitHub Azure` org to see this repository. Please go to [this link](aka.ms/azuregithub) to become part of the `Azure` org.
146+
_Note_: You will need to be part of the `GitHub Azure` org to see this repository. Please go to [this link](https://aka.ms/azuregithub) to become part of the `Azure` org.
147147

148148
We recommend using the `platyPS` module to easily generate markdown files that contains the above information and including the files in the design submission.
149149

documentation/development-docs/design-guidelines/parameter-best-practices.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66

77
The following are naming conventions to keep in mind when coming up with a name for your parameters.
88

9-
In addition, a recommended list of parameter names can be found [here](https://docs.microsoft.com/en-us/powershell/developer/cmdlet/standard-cmdlet-parameter-names-and-types).
9+
In addition, a recommended list of parameter names can be found [here](https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/standard-cmdlet-parameter-names-and-types).
1010

1111
#### Standard Parameter Name
1212

13-
From the [_Strongly Encouraged Development Guidelines_](https://docs.microsoft.com/en-us/powershell/developer/cmdlet/strongly-encouraged-development-guidelines#use-standard-parameter-names):
13+
From the [_Strongly Encouraged Development Guidelines_](https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/strongly-encouraged-development-guidelines#use-standard-parameter-names):
1414

1515
> _Your cmdlet should use standard parameter names so that the user can quickly determine what a particular parameter means. If a more specific name is required, use a standard parameter name, and then specify a more specific name as an alias. For example, the `Get-Service` cmdlet has a parameter that has a generic name (**Name**) and a more specific alias (**ServiceName**). Both terms can be used to specify the parameter._
1616
1717
#### Pascal Case
1818

19-
Similar to cmdlets, parameters should follow pascal casing.From the [_Strongly Encouraged Development Guidelines_](https://docs.microsoft.com/en-us/powershell/developer/cmdlet/strongly-encouraged-development-guidelines#use-pascal-case-for-parameter-names):
19+
Similar to cmdlets, parameters should follow pascal casing.From the [_Strongly Encouraged Development Guidelines_](https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/strongly-encouraged-development-guidelines#use-pascal-case-for-parameter-names):
2020

2121
> _Use Pascal case for parameter names. In other words, capitalize the first letter of each word in the parameter name, including the first letter of the name._
2222
2323
#### Singularity
2424

25-
From the [_Strongly Encouraged Development Guidelines_](https://docs.microsoft.com/en-us/powershell/developer/cmdlet/strongly-encouraged-development-guidelines#use-singular-parameter-names):
25+
From the [_Strongly Encouraged Development Guidelines_](https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/strongly-encouraged-development-guidelines#use-singular-parameter-names):
2626

2727
> _Avoid using plural names for parameters whose value is a single element. This includes parameters that take arrays or lists because the user might supply an array or list with only one element._
2828
>
@@ -40,15 +40,15 @@ The type of parameters should always be defined; a parameter should never be of
4040

4141
#### Consistent Parameter Types
4242

43-
From the [_Strongly Encouraged Development Guidelines_](https://docs.microsoft.com/en-us/powershell/developer/cmdlet/strongly-encouraged-development-guidelines#use-consistent-parameter-types):
43+
From the [_Strongly Encouraged Development Guidelines_](https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/strongly-encouraged-development-guidelines#use-consistent-parameter-types):
4444

4545
> _When the same parameter is used by multiple cmdlets, always use the same parameter type. For example, if the **Process** parameter is an **Int16** type for one cmdlet, do not make the **Process** parameter for another cmdlet a **UInt16** type._
4646
4747
#### Array vs. Enumerable Types
4848

4949
For parameters that require a collection of elements to be provided, use an array instead of any other enumerable type to represent this collection.
5050

51-
From the [_Strongly Encouraged Development Guidelines_](https://docs.microsoft.com/en-us/powershell/developer/cmdlet/strongly-encouraged-development-guidelines#support-arrays-for-parameters):
51+
From the [_Strongly Encouraged Development Guidelines_](https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/strongly-encouraged-development-guidelines#support-arrays-for-parameters):
5252

5353
> _Frequently, users must perform the same operation against multiple arguments. For these users, a cmdlet should accept an array as parameter input so that a user can pass the arguments into the parameter as a Windows PowerShell variable. For example, the `Get-Process` cmdlet uses an array for the strings that identify the names of the processes to retrieve._
5454
@@ -126,7 +126,7 @@ The following are naming conventions to keep in mind when coming up with a name
126126

127127
#### Pascal Case
128128

129-
Similar to parameters (mentioned above), parameter set names should follow pascal casing. From the [_Strongly Encouraged Development Guidelines_](https://docs.microsoft.com/en-us/powershell/developer/cmdlet/strongly-encouraged-development-guidelines#use-pascal-case-for-cmdlet-names-sd02):
129+
Similar to parameters (mentioned above), parameter set names should follow pascal casing. From the [_Strongly Encouraged Development Guidelines_](https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/strongly-encouraged-development-guidelines#use-pascal-case-for-cmdlet-names-sd02):
130130

131131
> _Use Pascal case for cmdlet names. In other words, capitalize the first letter of the verb and all terms used in the noun. For example, "Clear-ItemProperty"._
132132
@@ -136,22 +136,22 @@ The following are guidelines that should be followed when working with the attri
136136

137137
#### Mutually Exclusive Parameter Sets
138138

139-
For PowerShell to determine which parameter set a user is intending to use with a set of provided parameters, the parameter sets need to be designed in such a way that they are mutually exclusive. From the remarks section of [_Parameter Attribute Declaration_](https://docs.microsoft.com/en-us/powershell/developer/cmdlet/parameter-attribute-declaration#remarks):
139+
For PowerShell to determine which parameter set a user is intending to use with a set of provided parameters, the parameter sets need to be designed in such a way that they are mutually exclusive. From the remarks section of [_Parameter Attribute Declaration_](https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/parameter-attribute-declaration#remarks):
140140

141141
> _Each parameter set must have at least one unique parameter. Good cmdlet design indicates this unique parameter should also be mandatory if possible. If your cmdlet is designed to be run without parameters, the unique parameter cannot be mandatory._
142142
143143
#### Positional Parameters Limit
144144

145-
It is possible to call a PowerShell cmdlet without providing the parameter names, but just the values you would like to pass through. This is done by specifying the position at which the value of each parameter should be provided by using the `Position` property for a parameter. However, when there are too many positional parameters in a single parameter set, it can be difficult for the user to remember the exact ordering in which the parameter values should be provided. From the remarks section of [_Parameter Attribute Declaration_](https://docs.microsoft.com/en-us/powershell/developer/cmdlet/parameter-attribute-declaration#remarks):
145+
It is possible to call a PowerShell cmdlet without providing the parameter names, but just the values you would like to pass through. This is done by specifying the position at which the value of each parameter should be provided by using the `Position` property for a parameter. However, when there are too many positional parameters in a single parameter set, it can be difficult for the user to remember the exact ordering in which the parameter values should be provided. From the remarks section of [_Parameter Attribute Declaration_](https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/parameter-attribute-declaration#remarks):
146146

147147
> _When you specify positional parameters, limit the number of positional parameters in a parameter set to less than five. And, positional parameters do not have to be contiguous. Positions 5, 100, and 250 work the same as positions 0, 1, and 2._
148148
149-
In addition, there should be no two parameters with the same position in the same parameter set. From the remarks section of [_Parameter Attribute Declaration_](https://docs.microsoft.com/en-us/powershell/developer/cmdlet/parameter-attribute-declaration#remarks):
149+
In addition, there should be no two parameters with the same position in the same parameter set. From the remarks section of [_Parameter Attribute Declaration_](https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/parameter-attribute-declaration#remarks):
150150

151151
> _No parameter set should contain more than one positional parameter with the same position._
152152
153153
#### ValueFromPipeline Limit
154154

155-
Allowing the user to pipe an object from one cmdlet to another is a major scenario in PowerShell, but allowing multiple parameters in the same parameter set to accept their value from the pipeline can cause issues. From the remarks section of [_Parameter Attribute Declaration_](https://docs.microsoft.com/en-us/powershell/developer/cmdlet/parameter-attribute-declaration#remarks):
155+
Allowing the user to pipe an object from one cmdlet to another is a major scenario in PowerShell, but allowing multiple parameters in the same parameter set to accept their value from the pipeline can cause issues. From the remarks section of [_Parameter Attribute Declaration_](https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/parameter-attribute-declaration#remarks):
156156

157-
> _Only one parameter in a parameter set should declare ValueFromPipeline = true. Multiple parameters can define ValueFromPipelineByPropertyName = true._
157+
> _Only one parameter in a parameter set should declare ValueFromPipeline = true. Multiple parameters can define ValueFromPipelineByPropertyName = true._
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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.Commands.Common.Authentication;
16+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
17+
using Microsoft.Azure.Commands.Common.Authentication.Core;
18+
using Microsoft.Azure.Commands.Common.Authentication.Models;
19+
using Microsoft.Azure.Commands.Common.Authentication.Properties;
20+
using Microsoft.Azure.Commands.ResourceManager.Common;
21+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
22+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
23+
using Newtonsoft.Json;
24+
using System;
25+
using System.IO;
26+
using Xunit;
27+
using Xunit.Abstractions;
28+
29+
namespace Microsoft.Azure.Commands.Profile.Test
30+
{
31+
public class AutoSaveSettingOnLoadingTests
32+
{
33+
private MemoryDataStore dataStore;
34+
private string profileBasePath;
35+
private string settingsPath;
36+
37+
public AutoSaveSettingOnLoadingTests(ITestOutputHelper output)
38+
{
39+
dataStore = new MemoryDataStore();
40+
profileBasePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
41+
settingsPath = Path.Combine(profileBasePath, Resources.AzureDirectoryName);
42+
settingsPath = Path.Combine(settingsPath, ContextAutosaveSettings.AutoSaveSettingsFile);
43+
}
44+
45+
internal string HookSettingFile(string hook)
46+
{
47+
var result = new ContextAutosaveSettings
48+
{
49+
CacheDirectory = hook,
50+
ContextDirectory = hook,
51+
Mode = ContextSaveMode.CurrentUser,
52+
CacheFile = "TokenCache.dat",
53+
ContextFile = "AzureRmContext.json"
54+
};
55+
56+
var backupPath = String.Empty;
57+
if (!dataStore.FileExists(settingsPath))
58+
{
59+
string directoryPath = Path.GetDirectoryName(settingsPath);
60+
if (!dataStore.DirectoryExists(directoryPath))
61+
{
62+
dataStore.CreateDirectory(directoryPath);
63+
}
64+
}
65+
else
66+
{
67+
backupPath = BackupSetting();
68+
}
69+
dataStore.WriteFile(settingsPath, JsonConvert.SerializeObject(result));
70+
return backupPath;
71+
}
72+
73+
internal string BackupSetting()
74+
{
75+
var backupPath = settingsPath + ".bak";
76+
dataStore.CopyFile(settingsPath, backupPath);
77+
return backupPath;
78+
}
79+
80+
internal void RestoreSetting(string backupPath)
81+
{
82+
if(dataStore.FileExists(backupPath))
83+
{
84+
dataStore.DeleteFile(settingsPath);
85+
dataStore.CopyFile(backupPath, settingsPath);
86+
dataStore.DeleteFile(backupPath);
87+
}
88+
else
89+
{
90+
dataStore.DeleteFile(settingsPath);
91+
}
92+
}
93+
94+
[Fact]
95+
[Trait(Category.AcceptanceType, Category.CheckIn)]
96+
public void DisableAutoSaveWhenSettingFileBreaks()
97+
{
98+
string faker = Path.Combine(Directory.GetParent(profileBasePath).ToString(), "faker");
99+
faker = Path.Combine(faker,Resources.AzureDirectoryName);
100+
var backupPath = HookSettingFile(faker);
101+
102+
try
103+
{
104+
AzureSessionInitializer.CreateOrReplaceSession(dataStore);
105+
TestMockSupport.RunningMocked = true;
106+
var cmdlet = new ConnectAzureRmAccountCommand();
107+
cmdlet.OnImport();
108+
Assert.Equal(ContextSaveMode.Process, AzureSession.Instance.ARMContextSaveMode);
109+
Assert.Equal(typeof(ResourceManagerProfileProvider), AzureRmProfileProvider.Instance.GetType());
110+
var afterModified = dataStore.ReadFileAsText(settingsPath);
111+
var newSetting = JsonConvert.DeserializeObject<ContextAutosaveSettings>(afterModified) as ContextAutosaveSettings;
112+
Assert.NotNull(newSetting);
113+
Assert.Equal(ContextSaveMode.CurrentUser, newSetting.Mode);
114+
Assert.Equal(typeof(AuthenticationStoreTokenCache), AzureSession.Instance.TokenCache.GetType());
115+
}
116+
finally
117+
{
118+
RestoreSetting(backupPath);
119+
}
120+
}
121+
}
122+
}

src/Accounts/Accounts/Account/ConnectAzureRmAccount.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414

1515
using Microsoft.Azure.Commands.Common.Authentication;
1616
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
17-
using Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core;
17+
using Microsoft.Azure.Commands.Common.Authentication.Core;
1818
using Microsoft.Azure.Commands.Common.Authentication.Models;
19-
using Microsoft.Azure.Commands.Profile.Models;
2019
using Microsoft.Azure.Commands.Profile.Models.Core;
2120
using Microsoft.Azure.Commands.ResourceManager.Common;
2221
using Microsoft.WindowsAzure.Commands.Utilities.Common;
22+
using Newtonsoft.Json;
2323
using System;
2424
using System.Management.Automation;
25+
using System.IO;
2526
using System.Security;
2627
using Microsoft.Azure.Commands.Profile.Properties;
2728
using Microsoft.Azure.Commands.Profile.Common;
@@ -387,7 +388,11 @@ public void OnImport()
387388
autoSaveEnabled = localAutosave;
388389
}
389390

390-
InitializeProfileProvider(autoSaveEnabled);
391+
if(!InitializeProfileProvider(autoSaveEnabled))
392+
{
393+
DisableAutosave(AzureSession.Instance);
394+
}
395+
391396
IServicePrincipalKeyStore keyStore =
392397
// TODO: Remove IfDef
393398
#if NETSTANDARD
@@ -404,5 +409,22 @@ public void OnImport()
404409
}
405410
#endif
406411
}
412+
413+
private void DisableAutosave(IAzureSession session)
414+
{
415+
session.ARMContextSaveMode = ContextSaveMode.Process;
416+
var memoryCache = session.TokenCache as AuthenticationStoreTokenCache;
417+
if (memoryCache == null)
418+
{
419+
var diskCache = session.TokenCache as ProtectedFileTokenCache;
420+
memoryCache = new AuthenticationStoreTokenCache(new AzureTokenCache());
421+
if (diskCache != null && diskCache.Count > 0)
422+
{
423+
memoryCache.Deserialize(diskCache.Serialize());
424+
}
425+
426+
session.TokenCache = memoryCache;
427+
}
428+
}
407429
}
408430
}

src/Accounts/Accounts/AutoSave/DisableAzureRmContextAutosave.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,13 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure.Commands.Common.Authentication;
16-
// TODO: Remove IfDef
17-
#if NETSTANDARD
18-
using Microsoft.Azure.Commands.Common.Authentication.Core;
19-
#endif
2016
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
17+
using Microsoft.Azure.Commands.Common.Authentication.Core;
2118
using Microsoft.Azure.Commands.Profile.Common;
2219
using Microsoft.Azure.Commands.ResourceManager.Common;
23-
using Microsoft.WindowsAzure.Commands.Common;
2420
using Newtonsoft.Json;
25-
using System.IO;
2621
using System.Management.Automation;
22+
using System.IO;
2723

2824
namespace Microsoft.Azure.Commands.Profile.Context
2925
{
@@ -64,7 +60,7 @@ public override void ExecuteCmdlet()
6460
}
6561
}
6662

67-
void DisableAutosave(IAzureSession session, bool writeAutoSaveFile, out ContextAutosaveSettings result)
63+
protected void DisableAutosave(IAzureSession session, bool writeAutoSaveFile, out ContextAutosaveSettings result)
6864
{
6965
var store = session.DataStore;
7066
string tokenPath = Path.Combine(session.TokenCacheDirectory, session.TokenCacheFile);

src/Accounts/Accounts/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Disable context auto saving when AzureRmContext.json not available
22+
* Update the reference to Azure Powershell Common to 1.3.5-preview
2123

2224
## Version 1.7.0
2325
* Updated Add-AzEnvironment and Set-AzEnvironment to accept parameters AzureAttestationServiceEndpointResourceId and AzureAttestationServiceEndpointSuffix

0 commit comments

Comments
 (0)