Fix null ref in generated cmdlets when context is not set
This commit is contained in:
Родитель
04be7e4dfc
Коммит
7f401e70ec
|
@ -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>
|
Загрузка…
Ссылка в новой задаче