Skip to content

Commit

Permalink
Update Resources SDK 2024-07-01 (#26507)
Browse files Browse the repository at this point in the history
* Update Resources SDK to 2024-07

* Add update to changelog

* Update SDKGeneratedCodeVerify to 2024-07

* Update whitespace

* Add UXMetadataIssues.csv to Az.Resources Exceptions

---------

Co-authored-by: Tate Smalligan <[email protected]>
Co-authored-by: Vincent Dai <[email protected]>
  • Loading branch information
3 people authored Nov 7, 2024
1 parent 1653719 commit 751c4a8
Show file tree
Hide file tree
Showing 37 changed files with 999 additions and 277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ private Deployment CreateBasicDeployment(PSDeploymentCmdletParameters parameters
: null;
// NOTE(jcotillo): Adding FromJson<> to parameters as well
deployment.Properties.Parameters = !string.IsNullOrEmpty(parametersContent)
? parametersContent.FromJson<JObject>()
? parametersContent.FromJson<Dictionary<string, DeploymentParameter>>()
: null;
}

Expand All @@ -488,17 +488,24 @@ private TemplateValidationInfo GetTemplateValidationResult(PSDeploymentCmdletPar
try
{
var validationResult = this.ValidateDeployment(parameters, deployment);

return new TemplateValidationInfo(validationResult);
switch (validationResult)
{
case DeploymentExtended deploymentExtended:
return new TemplateValidationInfo(deploymentExtended.Properties?.Providers?.ToList() ?? new List<Provider>(), new List<ErrorDetail>());
case DeploymentValidationError deploymentValidationError:
return new TemplateValidationInfo(new List<Provider>(), new List<ErrorDetail>(deploymentValidationError.Error.AsArray()));
default:
throw new InvalidOperationException($"Received unexpected type {validationResult.GetType()}");
}
}
catch (Exception ex)
{
var error = HandleError(ex).FirstOrDefault();
return new TemplateValidationInfo(new DeploymentValidateResult(error));
return new TemplateValidationInfo(new List<Provider>(), error.AsArray().ToList());
}
}

private DeploymentValidateResult ValidateDeployment(PSDeploymentCmdletParameters parameters, Deployment deployment)
private object ValidateDeployment(PSDeploymentCmdletParameters parameters, Deployment deployment)
{
var scopedDeployment = new ScopedDeployment { Properties = deployment.Properties, Location = deployment.Location };

Expand Down Expand Up @@ -527,26 +534,26 @@ private DeploymentValidateResult ValidateDeployment(PSDeploymentCmdletParameters
}
}

private List<ErrorResponse> HandleError(Exception ex)
private List<ErrorDetail> HandleError(Exception ex)
{
if (ex == null)
{
return null;
}

ErrorResponse error = null;
ErrorDetail error = null;
var innerException = HandleError(ex.InnerException);
if (ex is CloudException)
{
var cloudEx = ex as CloudException;
error = new ErrorResponse(cloudEx.Body?.Code, cloudEx.Body?.Message, cloudEx.Body?.Target, innerException);
error = new ErrorDetail(cloudEx.Body?.Code, cloudEx.Body?.Message, cloudEx.Body?.Target, innerException);
}
else
{
error = new ErrorResponse(null, ex.Message, null, innerException);
error = new ErrorDetail(null, ex.Message, null, innerException);
}

return new List<ErrorResponse> { error };
return new List<ErrorDetail> { error };

}

Expand Down Expand Up @@ -1509,7 +1516,7 @@ private DeploymentExtended ExecuteDeploymentInternal(PSDeploymentCmdletParameter
return ProvisionDeploymentStatus(parameters, deployment);
}

private void DisplayInnerDetailErrorMessage(ErrorResponse error)
private void DisplayInnerDetailErrorMessage(ErrorDetail error)
{
WriteError(string.Format(ErrorFormat, error.Code, error.Message));
if (error.Details != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,25 @@ public static PSResourceManagerError ToPSResourceManagerError(this ErrorResponse
return rmError;
}

public static PSResourceManagerError ToPSResourceManagerError(this ErrorDetail error)
{
PSResourceManagerError rmError = new PSResourceManagerError
{
Code = error.Code,
Message = error.Message,
Target = string.IsNullOrEmpty(error.Target) ? null : error.Target
};

if (error.Details != null)
{
List<PSResourceManagerError> innerRMError = new List<PSResourceManagerError>();
error.Details.ForEach(detail => innerRMError.Add(detail.ToPSResourceManagerError()));
rmError.Details = innerRMError;
}

return rmError;
}

public static string ToFormattedString(this ErrorResponse error, int level = 0)
{
if (error.Details == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,22 +261,12 @@ internal static Dictionary<string, PSDeploymentStackParameter> ConvertParameterD
PSDeploymentStackParameter parameter;
if (parameters[key].Reference != null)
{
parameter = new PSDeploymentStackParameter { KeyVaultReference = parameters[key].Reference };

if (parameters[key].Type != null)
{
parameter.Type = parameters[key].Type;
}
else
{
// If type does not exist, secret value is unknown and the type cannot be inferred:
parameter.Type = "unknown";
}
parameter = new PSDeploymentStackParameter { KeyVaultReference = parameters[key].Reference, Type = ExtractDeploymentStackParameterValueType(parameters[key].Value) };
}
else
{
// If the type is not present, attempt to infer:
parameter = new PSDeploymentStackParameter { Value = parameters[key].Value, Type = parameters[key].Type != null ? parameters[key].Type : ExtractDeploymentStackParameterValueType(parameters[key].Value) };
parameter = new PSDeploymentStackParameter { Value = parameters[key].Value, Type = ExtractDeploymentStackParameterValueType(parameters[key].Value) };
if (parameter.Value != null && "Array".Equals(parameter.Type))
{
parameter.Value = JsonConvert.DeserializeObject<object[]>(parameter.Value.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using Commands.Common.Authentication.Abstractions;
using Management.Resources.Models;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Json;
using Microsoft.WindowsAzure.Commands.Common;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -129,7 +130,7 @@ public DeploymentWhatIf ToDeploymentWhatIf()
? PSJsonSerializer.Serialize(parametersDictionary)
: null;
properties.Parameters = !string.IsNullOrEmpty(parametersContent)
? JObject.Parse(parametersContent)
? parametersContent.FromJson<Dictionary<string, DeploymentParameter>>()
: null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,13 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels
{
internal class TemplateValidationInfo
{
public TemplateValidationInfo(DeploymentValidateResult validationResult)
public TemplateValidationInfo(List<Provider> requiredProviders, List<ErrorDetail> errors)
{
Errors = new List<ErrorResponse>();
RequiredProviders = new List<Provider>();

if (validationResult.Error != null)
{
Errors.Add(validationResult.Error);
}

if (validationResult.Properties != null &&
validationResult.Properties.Providers != null)
{
RequiredProviders.AddRange(validationResult.Properties.Providers);
}
Errors = errors;
RequiredProviders = requiredProviders;
}

public List<ErrorResponse> Errors { get; set; }
public List<ErrorDetail> Errors { get; set; }

public List<Provider> RequiredProviders { get; set; }
}
Expand Down
Loading

0 comments on commit 751c4a8

Please sign in to comment.