Skip to content

Commit

Permalink
Blueprint: Unregister API delegating handler (#14200)
Browse files Browse the repository at this point in the history
* Update blueprint client to unregister api handler

* Update change log

* Use initial client design where we create seperate clients based on whether delegating handler is used. This works better with piping scenarios

* New and set artifact cmdlets don't require bp client with $expand handler

* Clean white space

* Clean up more white space
  • Loading branch information
filizt authored Feb 17, 2021
1 parent 1decdb5 commit fcaddf8
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/Blueprint/Blueprint.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2042
Expand Down Expand Up @@ -45,6 +44,10 @@ Global
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Release|Any CPU.Build.0 = Release|Any CPU
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Release|Any CPU.Build.0 = Release|Any CPU
{FF81DC73-B8EC-4082-8841-4FBF2B16E7CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF81DC73-B8EC-4082-8841-4FBF2B16E7CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF81DC73-B8EC-4082-8841-4FBF2B16E7CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
1 change: 1 addition & 0 deletions src/Blueprint/Blueprint/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Added a fix to unregister the API delegating handler from blueprint client

## Version 0.2.13
* Updated Blueprint .NET SDK version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public override void ExecuteCmdlet()
DependsOn = DependsOn
};

WriteObject(BlueprintClientWithVersion.CreateArtifact(scope, Blueprint.Name, Name,
WriteObject(BlueprintClient.CreateArtifact(scope, Blueprint.Name, Name,
templateArtifact));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public override void ExecuteCmdlet()
DependsOn = DependsOn
};

WriteObject(BlueprintClientWithVersion.CreateArtifact(scope, Blueprint.Name, Name,
WriteObject(BlueprintClient.CreateArtifact(scope, Blueprint.Name, Name,
templateArtifact));
}

Expand Down
23 changes: 23 additions & 0 deletions src/Blueprint/Blueprint/Cmdlets/BlueprintCmdletBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Provider = Microsoft.Azure.Management.Internal.ResourceManager.Version2018_05_01.Models.Provider;
using System.Linq;
using System.Net.Http;

namespace Microsoft.Azure.Commands.Blueprint.Cmdlets
{
Expand Down Expand Up @@ -208,5 +209,27 @@ protected string GetValidatedFolderPathForArtifacts(string path)

return artifactsFolderName == null ? null : Path.Combine(path, artifactsFolderName);
}

/// <summary>
/// Unregisters delegating handler if registered.
/// </summary>
protected void UnregisterDelegatingHandlerIfRegistered()
{
var apiExpandHandler = GetExpandHandler();

if (apiExpandHandler != null)
{
AzureSession.Instance.ClientFactory.RemoveHandler(apiExpandHandler.GetType());
}
}

/// <summary>
/// Returns expand handler, if exists.
/// </summary>
private DelegatingHandler GetExpandHandler()
{
return AzureSession.Instance.ClientFactory.GetCustomHandlers()?
.Where(handler => handler.GetType().Equals(typeof(ApiExpandHandler))).FirstOrDefault();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public override void ExecuteCmdlet()
{
WriteExceptionError(ex);
}
finally
{
UnregisterDelegatingHandlerIfRegistered();
}
}
#endregion Cmdlet Overrides

Expand Down
2 changes: 1 addition & 1 deletion src/Blueprint/Blueprint/Common/BlueprintClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public BlueprintClient(IAzureContext context)
var customHandlers = AzureSession.Instance.ClientFactory.GetCustomHandlers();
var apiExpandHandler = customHandlers?.Where(handler => handler.GetType().Equals(typeof(ApiExpandHandler))).FirstOrDefault();

if (apiExpandHandler != null )
if (apiExpandHandler != null)
{
AzureSession.Instance.ClientFactory.RemoveHandler(apiExpandHandler.GetType());
}
Expand Down

0 comments on commit fcaddf8

Please sign in to comment.