Fix null ref in generated cmdlets when context is not set

This commit is contained in:
Erich(Renyong) Wang 2019-12-03 14:31:02 +08:00
Родитель 04be7e4dfc
Коммит 7f401e70ec
4 изменённых файлов: 18 добавлений и 0 удалений

Просмотреть файл

@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Display user friendly error message when context is null in Az 4.0
## Version 1.6.4
* Add a deprecation message for `Resolve-Error` alias.

Просмотреть файл

@ -170,6 +170,11 @@ namespace Microsoft.Azure.Commands.Common
/// <returns></returns>
internal async Task AuthorizeRequest(IAzureContext context, string resourceId, HttpRequestMessage request, CancellationToken outerToken)
{
if (context == null || context.Account == null || context.Environment == null)
{
throw new InvalidOperationException(Resources.InvalidAzureContext);
}
await Task.Run(() =>
{
resourceId = context?.Environment?.GetAudienceFromRequestUri(request.RequestUri) ?? resourceId;

Просмотреть файл

@ -483,6 +483,15 @@ namespace Microsoft.Azure.Commands.Profile.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to The context is invalid. Please login using Connect-AzAccount..
/// </summary>
internal static string InvalidAzureContext {
get {
return ResourceManager.GetString("InvalidAzureContext", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Endpoint provided is invalid. Please check the value and retry again with the correct value..
/// </summary>

Просмотреть файл

@ -465,4 +465,7 @@
<data name="SovereignProfileDescription" xml:space="preserve">
<value>A snapshot of the service API versiosn available in Azure Sovereign Clouds and the Azure Global Cloud.</value>
</data>
<data name="InvalidAzureContext" xml:space="preserve">
<value>The context is invalid. Please login using Connect-AzAccount.</value>
</data>
</root>