Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Resources SDK 2024-11-01 #27308

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -489,36 +489,16 @@ private TemplateValidationInfo GetTemplateValidationResult(PSDeploymentCmdletPar
try
{
var validationResult = this.ValidateDeployment(parameters, deployment);
switch (validationResult)
{
case DeploymentExtended deploymentExtended:
return new TemplateValidationInfo(deploymentExtended.Properties?.Providers?.ToList() ?? new List<Provider>(), new List<ErrorDetail>(), deploymentExtended.Properties?.Diagnostics?.ToList() ?? new List<DeploymentDiagnosticsDefinition>());
case DeploymentValidationError deploymentValidationError:
return new TemplateValidationInfo(new List<Provider>(), new List<ErrorDetail>(deploymentValidationError.Error.AsArray()), new List<DeploymentDiagnosticsDefinition>());
case JObject obj:
// 202 Response is not deserialized in DeploymentsOperations so we should attempt to deserialize the object here before failing
// Should attempt to deserialize for success(DeploymentExtended)
try
{
var deploymentDeserialized = SafeJsonConvert.DeserializeObject<DeploymentExtended>(validationResult.ToString(), ResourceManagementClient.DeserializationSettings);
return new TemplateValidationInfo(deploymentDeserialized?.Properties?.Providers?.ToList() ?? new List<Provider>(), new List<ErrorDetail>(), deploymentDeserialized?.Properties?.Diagnostics?.ToList() ?? new List<DeploymentDiagnosticsDefinition>());
}
catch (Newtonsoft.Json.JsonException)
{
throw new InvalidOperationException($"Received unexpected type {validationResult.GetType()}");
}
default:
throw new InvalidOperationException($"Received unexpected type {validationResult.GetType()}");
}
return new TemplateValidationInfo(validationResult);
}
catch (Exception ex)
{
var error = HandleError(ex).FirstOrDefault();
return new TemplateValidationInfo(new List<Provider>(), error.AsArray().ToList(), new List<DeploymentDiagnosticsDefinition>());
return new TemplateValidationInfo(new DeploymentValidateResult(error));
}
}

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

Expand Down Expand Up @@ -547,26 +527,26 @@ private object ValidateDeployment(PSDeploymentCmdletParameters parameters, Deplo
}
}

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

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

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

}

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

private void DisplayInnerDetailErrorMessage(ErrorDetail error)
private void DisplayInnerDetailErrorMessage(ErrorResponse 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 @@ -13,20 +13,38 @@
// ----------------------------------------------------------------------------------

using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Microsoft.Azure.Management.Resources.Models;

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels
{
public class TemplateValidationInfo
{
public TemplateValidationInfo(List<Provider> requiredProviders, List<ErrorDetail> errors, List<DeploymentDiagnosticsDefinition> diagnostics)
public TemplateValidationInfo(DeploymentValidateResult validationResult)
{
Errors = errors;
RequiredProviders = requiredProviders;
Diagnostics = diagnostics;
Errors = new List<ErrorResponse>();
RequiredProviders = new List<Provider>();
Diagnostics = new List<DeploymentDiagnosticsDefinition>();

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

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

if (validationResult.Properties != null &&
validationResult.Properties.Diagnostics != null)
{
Diagnostics.AddRange(validationResult.Properties.Diagnostics);
}
}

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

public List<Provider> RequiredProviders { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public partial class WhatIfChange
/// <param name="delta">The predicted changes to resource
/// properties.</param>
public WhatIfChange(string resourceId, ChangeType changeType, object before = default(object), object after = default(object), IList<WhatIfPropertyChange> delta = default(IList<WhatIfPropertyChange>))
: this(resourceId, changeType, default(string), before, after, delta)
: this(resourceId: resourceId, changeType: changeType, deploymentId: default(string), symbolicName: default(string), identifiers: default(object), unsupportedReason: default(string), before: before, after: after, delta: delta)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ public DeploymentScriptsClient(System.Uri baseUri, Microsoft.Rest.ServiceClientC
/// <param name='rootHandler'>
/// Optional. The http client handler used to handle http transport.
/// </param>
/// <param name='handlers'>
/// Optional. The delegating handlers to add to the http client pipeline.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// Thrown when a required parameter is null
/// </exception>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ public DeploymentStacksClient(System.Uri baseUri, Microsoft.Rest.ServiceClientCr
/// <param name='rootHandler'>
/// Optional. The http client handler used to handle http transport.
/// </param>
/// <param name='handlers'>
/// Optional. The delegating handlers to add to the http client pipeline.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// Thrown when a required parameter is null
/// </exception>
Expand Down
Loading