Skip to content

Commit d7ac7f6

Browse files
committed
Merge branch 'main' of https://github.com/Azure/azure-powershell-common into bez/cmdletpreview
2 parents 106a6c2 + dfe6dba commit d7ac7f6

17 files changed

+570
-50
lines changed

src/Authentication.Abstractions.Test/AzureEnvironmentTests.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@ public void TestArmCloudMetadata20220901Init()
6262
Assert.Equal(3, armEnvironments.Count);
6363
foreach (var env in armEnvironments.Values)
6464
{
65-
if (env.Name == "AzureCloud")
65+
if (env.Name == EnvironmentName.AzureCloud)
6666
{
6767
Assert.Equal(AzureEnvironment.TypeDiscovered, env.Type);
68+
Assert.Null(env.GalleryUrl);
6869
}
6970
else
7071
{
7172
Assert.Equal(AzureEnvironment.TypeBuiltIn, env.Type);
73+
Assert.NotEmpty(env.GalleryUrl);
7274
}
7375
Assert.EndsWith("/", env.ServiceManagementUrl);
7476
Assert.StartsWith(".", env.SqlDatabaseDnsSuffix);
@@ -127,5 +129,20 @@ public void TestDisableArmCloudMetadataInit()
127129
Assert.Equal(AzureEnvironment.TypeBuiltIn, env.Type);
128130
}
129131
}
132+
133+
[Fact]
134+
public void TestArmResponseWithEmptyGalleryEndpoint()
135+
{
136+
Environment.SetEnvironmentVariable(ArmMetadataEnvVariable, @"TestData\ArmResponseWithEmptyGallery.json");
137+
var armEnvironments = AzureEnvironment.InitializeBuiltInEnvironments(null, httpOperations: TestOperationsFactory.Create().GetHttpOperations());
138+
139+
Assert.Equal(3, armEnvironments.Count);
140+
Assert.Equal(AzureEnvironment.TypeDiscovered, armEnvironments[EnvironmentName.AzureCloud].Type);
141+
Assert.Equal(AzureEnvironment.TypeDiscovered, armEnvironments[EnvironmentName.AzureChinaCloud].Type);
142+
Assert.Equal(AzureEnvironment.TypeDiscovered, armEnvironments[EnvironmentName.AzureUSGovernment].Type);
143+
Assert.Null(armEnvironments[EnvironmentName.AzureCloud].GalleryUrl);
144+
Assert.Empty(armEnvironments[EnvironmentName.AzureChinaCloud].GalleryUrl);
145+
Assert.Empty(armEnvironments[EnvironmentName.AzureUSGovernment].GalleryUrl);
146+
}
130147
}
131148
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
[
2+
{
3+
"portal": "https://portal.azure.com",
4+
"authentication": {
5+
"loginEndpoint": "https://login.microsoftonline.com/",
6+
"audiences": [
7+
"https://management.core.windows.net/",
8+
"https://management.azure.com/"
9+
],
10+
"tenant": "common",
11+
"identityProvider": "AAD"
12+
},
13+
"media": "https://rest.media.azure.net",
14+
"graphAudience": "https://graph.windows.net/",
15+
"graph": "https://graph.windows.net/",
16+
"name": "AzureCloud",
17+
"suffixes": {
18+
"azureDataLakeStoreFileSystem": "azuredatalakestore.net",
19+
"acrLoginServer": "azurecr.io",
20+
"sqlServerHostname": "database.windows.net",
21+
"azureDataLakeAnalyticsCatalogAndJob": "azuredatalakeanalytics.net",
22+
"keyVaultDns": "vault.azure.net",
23+
"storage": "core.windows.net",
24+
"azureFrontDoorEndpointSuffix": "azurefd.net"
25+
},
26+
"batch": "https://batch.core.windows.net/",
27+
"resourceManager": "https://management.azure.com/",
28+
"vmImageAliasDoc": "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/arm-compute/quickstart-templates/aliases.json",
29+
"activeDirectoryDataLake": "https://datalake.azure.net/",
30+
"sqlManagement": "https://management.core.windows.net:8443/"
31+
},
32+
{
33+
"portal": "https://portal.azure.cn",
34+
"authentication": {
35+
"loginEndpoint": "https://login.chinacloudapi.cn",
36+
"audiences": [
37+
"https://management.core.chinacloudapi.cn",
38+
"https://management.chinacloudapi.cn"
39+
],
40+
"tenant": "common",
41+
"identityProvider": "AAD"
42+
},
43+
"media": "https://rest.media.chinacloudapi.cn",
44+
"graphAudience": "https://graph.chinacloudapi.cn",
45+
"graph": "https://graph.chinacloudapi.cn",
46+
"name": "AzureChinaCloud",
47+
"suffixes": {
48+
"acrLoginServer": "azurecr.cn",
49+
"sqlServerHostname": "database.chinacloudapi.cn",
50+
"keyVaultDns": "vault.azure.cn",
51+
"storage": "core.chinacloudapi.cn",
52+
"azureFrontDoorEndpointSuffix": ""
53+
},
54+
"batch": "https://batch.chinacloudapi.cn",
55+
"resourceManager": "https://management.chinacloudapi.cn",
56+
"vmImageAliasDoc": "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/arm-compute/quickstart-templates/aliases.json",
57+
"sqlManagement": "https://management.core.chinacloudapi.cn:8443",
58+
"gallery": ""
59+
},
60+
{
61+
"portal": "https://portal.azure.us",
62+
"authentication": {
63+
"loginEndpoint": "https://login.microsoftonline.us",
64+
"audiences": [
65+
"https://management.core.usgovcloudapi.net",
66+
"https://management.usgovcloudapi.net"
67+
],
68+
"tenant": "common",
69+
"identityProvider": "AAD"
70+
},
71+
"media": "https://rest.media.usgovcloudapi.net",
72+
"graphAudience": "https://graph.windows.net",
73+
"graph": "https://graph.windows.net",
74+
"name": "AzureUSGovernment",
75+
"suffixes": {
76+
"acrLoginServer": "azurecr.us",
77+
"sqlServerHostname": "database.usgovcloudapi.net",
78+
"keyVaultDns": "vault.usgovcloudapi.net",
79+
"storage": "core.usgovcloudapi.net",
80+
"azureFrontDoorEndpointSuffix": ""
81+
},
82+
"batch": "https://batch.core.usgovcloudapi.net",
83+
"resourceManager": "https://management.usgovcloudapi.net",
84+
"vmImageAliasDoc": "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/arm-compute/quickstart-templates/aliases.json",
85+
"sqlManagement": "https://management.core.usgovcloudapi.net:8443",
86+
"gallery": ""
87+
}
88+
]

src/Authentication.Abstractions/AzureEnvironment.BuiltIn.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private static AzureEnvironment GetBuiltInUSGovernmentCloud()
139139
{ ExtendedEndpoint.MicrosoftGraphEndpointResourceId, AzureEnvironmentConstants.USGovernmentMicrosoftGraphEndpointResourceId },
140140
{ ExtendedEndpoint.MicrosoftGraphUrl, AzureEnvironmentConstants.USGovernmentMicrosoftGraphUrl },
141141
{ ExtendedEndpoint.AzureSynapseAnalyticsEndpointSuffix, AzureEnvironmentConstants.USGovernmentSynapseAnalyticsEndpointSuffix },
142-
{ ExtendedEndpoint.AzureSynapseAnalyticsEndpointResourceId, AzureEnvironmentConstants.USGovernmentAnalysisServicesEndpointResourceId }
142+
{ ExtendedEndpoint.AzureSynapseAnalyticsEndpointResourceId, AzureEnvironmentConstants.USGovernmentSynapseAnalyticsEndpointResourceId }
143143
}
144144
};
145145
}

src/Authentication.Abstractions/AzureEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ public AzureEnvironment(IAzureEnvironment other)
467467
/// <summary>
468468
/// Additional environment-specific metadata
469469
/// </summary>
470-
public IDictionary<string, string> ExtendedProperties { get; } = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
470+
public IDictionary<string, string> ExtendedProperties { get; } = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
471471

472472
public bool Equals(AzureEnvironment other)
473473
{

src/Common/AzurePSCmdlet.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,17 +467,11 @@ protected void WriteSurvey()
467467
Message = ansiCodePrefix + "https://go.microsoft.com/fwlink/?linkid=2202892"+ ansiCodeSuffix,
468468
NoNewLine = true,
469469
};
470-
HostInformationMessage dot = new HostInformationMessage()
471-
{
472-
Message = ansiCodePrefix + "."+ ansiCodeSuffix,
473-
NoNewLine = true,
474-
};
475470
WriteInformation(newLine, new string[] { "PSHOST" });
476471
WriteInformation(howWas, new string[] { "PSHOST" });
477472
WriteInformation(link, new string[] { "PSHOST" });
478473
WriteInformation(action, new string[] { "PSHOST" });
479474
WriteInformation(website, new string[] { "PSHOST" });
480-
WriteInformation(dot, new string[] { "PSHOST" });
481475
WriteInformation(newLine, new string[] { "PSHOST" });
482476

483477

src/Common/CustomAttributes/BreakingChangeAttributeHelper.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ Please leave this section at the top of the breaking change documentation.
7979
* */
8080
public static void ProcessCustomAttributesAtRuntime(Type type, InvocationInfo invocationInfo, Action<string> writeOutput)
8181
{
82-
List<GenericBreakingChangeAttribute> attributes = new List<GenericBreakingChangeAttribute>(GetAllBreakingChangeAttributesInType(type, invocationInfo));
82+
List<GenericBreakingChangeWithVersionAttribute> attributes = new List<GenericBreakingChangeWithVersionAttribute>(GetAllBreakingChangeAttributesInType(type, invocationInfo));
8383
StringBuilder sb = new StringBuilder();
8484
Action<string> appendBreakingChangeInfo = (string s) => sb.Append(s);
8585

8686
if (attributes != null && attributes.Count > 0)
8787
{
8888
appendBreakingChangeInfo(string.Format(Resources.BreakingChangesAttributesHeaderMessage, Utilities.GetNameFromCmdletType(type)));
8989

90-
foreach (GenericBreakingChangeAttribute attribute in attributes)
90+
foreach (GenericBreakingChangeWithVersionAttribute attribute in attributes)
9191
{
9292
attribute.PrintCustomAttributeInfo(type, false, appendBreakingChangeInfo);
9393
}
@@ -109,7 +109,7 @@ public static List<string> GetBreakingChangeMessagesForType(Type type)
109109

110110
//This is used as a migration guide, we need to process all properties/fields, moreover at this point of time we do not have a list of all the
111111
//bound params anyways
112-
foreach (GenericBreakingChangeAttribute attribute in GetAllBreakingChangeAttributesInType(type, null))
112+
foreach (GenericBreakingChangeWithVersionAttribute attribute in GetAllBreakingChangeAttributesInType(type, null))
113113
{
114114
messages.Add(attribute.GetBreakingChangeTextFromAttribute(type, true));
115115
}
@@ -124,25 +124,25 @@ public static List<string> GetBreakingChangeMessagesForType(Type type)
124124
* the boundParameterNames is a list of parameters bound to the cmdlet at runtime,
125125
* We only process the Parameter beaking change attributes attached only params listed in this list (if present)
126126
**/
127-
public static IEnumerable<GenericBreakingChangeAttribute> GetAllBreakingChangeAttributesInType(Type type, InvocationInfo invocationInfo)
127+
public static IEnumerable<GenericBreakingChangeWithVersionAttribute> GetAllBreakingChangeAttributesInType(Type type, InvocationInfo invocationInfo)
128128
{
129-
List<GenericBreakingChangeAttribute> attributeList = new List<GenericBreakingChangeAttribute>();
129+
List<GenericBreakingChangeWithVersionAttribute> attributeList = new List<GenericBreakingChangeWithVersionAttribute>();
130130

131-
attributeList.AddRange(type.GetCustomAttributes(typeof(GenericBreakingChangeAttribute), false).Cast<GenericBreakingChangeAttribute>());
131+
attributeList.AddRange(type.GetCustomAttributes(typeof(GenericBreakingChangeWithVersionAttribute), false).Cast<GenericBreakingChangeWithVersionAttribute>());
132132

133133
foreach (MethodInfo m in type.GetRuntimeMethods())
134134
{
135-
attributeList.AddRange((m.GetCustomAttributes(typeof(GenericBreakingChangeAttribute), false).Cast<GenericBreakingChangeAttribute>()));
135+
attributeList.AddRange((m.GetCustomAttributes(typeof(GenericBreakingChangeWithVersionAttribute), false).Cast<GenericBreakingChangeWithVersionAttribute>()));
136136
}
137137

138138
foreach (FieldInfo f in type.GetRuntimeFields())
139139
{
140-
attributeList.AddRange(f.GetCustomAttributes(typeof(GenericBreakingChangeAttribute), false).Cast<GenericBreakingChangeAttribute>());
140+
attributeList.AddRange(f.GetCustomAttributes(typeof(GenericBreakingChangeWithVersionAttribute), false).Cast<GenericBreakingChangeWithVersionAttribute>());
141141
}
142142

143143
foreach (PropertyInfo p in type.GetRuntimeProperties())
144144
{
145-
attributeList.AddRange(p.GetCustomAttributes(typeof(GenericBreakingChangeAttribute), false).Cast<GenericBreakingChangeAttribute>());
145+
attributeList.AddRange(p.GetCustomAttributes(typeof(GenericBreakingChangeWithVersionAttribute), false).Cast<GenericBreakingChangeWithVersionAttribute>());
146146
}
147147

148148
return invocationInfo == null ? attributeList : attributeList.Where(e => e.IsApplicableToInvocation(invocationInfo));

src/Common/CustomAttributes/CmdletDeprecationAttribute.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,27 @@
1414

1515
using Microsoft.WindowsAzure.Commands.Common.Properties;
1616
using System;
17-
using System.Collections.Generic;
18-
using System.Linq;
19-
using System.Text;
20-
using System.Threading.Tasks;
2117

2218
namespace Microsoft.WindowsAzure.Commands.Common.CustomAttributes
2319
{
2420
[AttributeUsage(
2521
AttributeTargets.Class,
2622
AllowMultiple = true)]
23+
[Obsolete("This attribute is deprecated. Please use CmdletDeprecationWithVersionAttribute instead to provide the deprecate Az version and module version")]
2724
public class CmdletDeprecationAttribute : GenericBreakingChangeAttribute
2825
{
2926
public string ReplacementCmdletName { get; set; }
30-
27+
3128
public CmdletDeprecationAttribute() :
3229
base(string.Empty)
3330
{
3431
}
35-
32+
3633
public CmdletDeprecationAttribute(string deprecateByVersione) :
3734
base(string.Empty, deprecateByVersione)
3835
{
3936
}
40-
37+
4138
public CmdletDeprecationAttribute(string deprecateByVersion, string changeInEfectByDate) :
4239
base(string.Empty, deprecateByVersion, changeInEfectByDate)
4340
{
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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.Properties;
16+
using System;
17+
18+
namespace Microsoft.WindowsAzure.Commands.Common.CustomAttributes
19+
{
20+
/// <summary>
21+
/// This attribute is used to mark cmdlets as deprecated. It provides information about the breaking change, including change description, the version from which the change is deprecated (DeprecateByVersion), the Azure version from which the change is deprecated (DeprecateByAzVersion). This class provides functionality to generate breaking change messages and display information about the breaking changes when needed.
22+
/// </summary>
23+
[AttributeUsage(
24+
AttributeTargets.Class,
25+
AllowMultiple = true)]
26+
public class CmdletDeprecationWithVersionAttribute : GenericBreakingChangeWithVersionAttribute
27+
{
28+
public string ReplacementCmdletName { get; set; }
29+
30+
public CmdletDeprecationWithVersionAttribute(string deprecateByAzVersion, string deprecateByVersion) :
31+
base(string.Empty, deprecateByAzVersion, deprecateByVersion)
32+
{
33+
}
34+
35+
public CmdletDeprecationWithVersionAttribute(string deprecateByAzVersion, string deprecateByVersion, string changeInEffectByDate) :
36+
base(string.Empty, deprecateByAzVersion, deprecateByVersion, changeInEffectByDate)
37+
{
38+
}
39+
40+
protected override string GetAttributeSpecificMessage()
41+
{
42+
if (string.IsNullOrWhiteSpace(ReplacementCmdletName))
43+
{
44+
return Resources.BreakingChangesAttributesCmdLetDeprecationMessageNoReplacement;
45+
}
46+
else
47+
{
48+
return string.Format(Resources.BreakingChangesAttributesCmdLetDeprecationMessageWithReplacement, ReplacementCmdletName);
49+
}
50+
}
51+
}
52+
}

src/Common/CustomAttributes/CmdletOutputBreakingChangeAttribute.cs

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

1515
using Microsoft.WindowsAzure.Commands.Common.Properties;
1616
using System;
17-
using System.Collections.Generic;
18-
using System.Linq;
1917
using System.Text;
20-
using System.Threading.Tasks;
2118

2219
namespace Microsoft.WindowsAzure.Commands.Common.CustomAttributes
2320
{
2421
[AttributeUsage(
2522
AttributeTargets.Class,
2623
AllowMultiple = true)]
24+
[Obsolete("This attribute is deprecated. Please use CmdletOutputBreakingChangeWithVersionAttribute instead to provide the deprecate Az version and module version")]
2725
public class CmdletOutputBreakingChangeAttribute : GenericBreakingChangeAttribute
2826
{
2927
public Type DeprecatedCmdLetOutputType { get; }
@@ -35,19 +33,19 @@ public class CmdletOutputBreakingChangeAttribute : GenericBreakingChangeAttribut
3533
public string[] DeprecatedOutputProperties { get; set; }
3634

3735
public string[] NewOutputProperties { get; set; }
38-
36+
3937
public CmdletOutputBreakingChangeAttribute(Type deprecatedCmdletOutputTypeName) :
4038
base(string.Empty)
4139
{
4240
this.DeprecatedCmdLetOutputType = deprecatedCmdletOutputTypeName;
4341
}
44-
42+
4543
public CmdletOutputBreakingChangeAttribute(Type deprecatedCmdletOutputTypeName, string deprecateByVersion) :
4644
base(string.Empty, deprecateByVersion)
4745
{
4846
this.DeprecatedCmdLetOutputType = deprecatedCmdletOutputTypeName;
4947
}
50-
48+
5149
public CmdletOutputBreakingChangeAttribute(Type deprecatedCmdletOutputTypeName, string deprecateByVersion, string changeInEfectByDate) :
5250
base(string.Empty, deprecateByVersion, changeInEfectByDate)
5351
{

0 commit comments

Comments
 (0)