Skip to content

Commit fcaddf8

Browse files
authored
Blueprint: Unregister API delegating handler (#14200)
* 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
1 parent 1decdb5 commit fcaddf8

File tree

7 files changed

+35
-4
lines changed

7 files changed

+35
-4
lines changed

src/Blueprint/Blueprint.sln

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
Microsoft Visual Studio Solution File, Format Version 12.00
32
# Visual Studio 15
43
VisualStudioVersion = 15.0.27703.2042
@@ -45,6 +44,10 @@ Global
4544
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
4645
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
4746
{142D7B0B-388A-4CEB-A228-7F6D423C5C2E}.Release|Any CPU.Build.0 = Release|Any CPU
47+
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
48+
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Debug|Any CPU.Build.0 = Debug|Any CPU
49+
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Release|Any CPU.ActiveCfg = Release|Any CPU
50+
{6BD6B80A-06AF-4B5B-9230-69CCFC6C8D64}.Release|Any CPU.Build.0 = Release|Any CPU
4851
{FF81DC73-B8EC-4082-8841-4FBF2B16E7CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4952
{FF81DC73-B8EC-4082-8841-4FBF2B16E7CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
5053
{FF81DC73-B8EC-4082-8841-4FBF2B16E7CE}.Release|Any CPU.ActiveCfg = Release|Any CPU

src/Blueprint/Blueprint/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Added a fix to unregister the API delegating handler from blueprint client
2122

2223
## Version 0.2.13
2324
* Updated Blueprint .NET SDK version

src/Blueprint/Blueprint/Cmdlets/BlueprintArtifacts/NewAzureRMBlueprintArtifact.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public override void ExecuteCmdlet()
185185
DependsOn = DependsOn
186186
};
187187

188-
WriteObject(BlueprintClientWithVersion.CreateArtifact(scope, Blueprint.Name, Name,
188+
WriteObject(BlueprintClient.CreateArtifact(scope, Blueprint.Name, Name,
189189
templateArtifact));
190190
}
191191

src/Blueprint/Blueprint/Cmdlets/BlueprintArtifacts/SetAzureRMBlueprintArtifact.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public override void ExecuteCmdlet()
185185
DependsOn = DependsOn
186186
};
187187

188-
WriteObject(BlueprintClientWithVersion.CreateArtifact(scope, Blueprint.Name, Name,
188+
WriteObject(BlueprintClient.CreateArtifact(scope, Blueprint.Name, Name,
189189
templateArtifact));
190190
}
191191

src/Blueprint/Blueprint/Cmdlets/BlueprintCmdletBase.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2626
using Provider = Microsoft.Azure.Management.Internal.ResourceManager.Version2018_05_01.Models.Provider;
2727
using System.Linq;
28+
using System.Net.Http;
2829

2930
namespace Microsoft.Azure.Commands.Blueprint.Cmdlets
3031
{
@@ -208,5 +209,27 @@ protected string GetValidatedFolderPathForArtifacts(string path)
208209

209210
return artifactsFolderName == null ? null : Path.Combine(path, artifactsFolderName);
210211
}
212+
213+
/// <summary>
214+
/// Unregisters delegating handler if registered.
215+
/// </summary>
216+
protected void UnregisterDelegatingHandlerIfRegistered()
217+
{
218+
var apiExpandHandler = GetExpandHandler();
219+
220+
if (apiExpandHandler != null)
221+
{
222+
AzureSession.Instance.ClientFactory.RemoveHandler(apiExpandHandler.GetType());
223+
}
224+
}
225+
226+
/// <summary>
227+
/// Returns expand handler, if exists.
228+
/// </summary>
229+
private DelegatingHandler GetExpandHandler()
230+
{
231+
return AzureSession.Instance.ClientFactory.GetCustomHandlers()?
232+
.Where(handler => handler.GetType().Equals(typeof(ApiExpandHandler))).FirstOrDefault();
233+
}
211234
}
212235
}

src/Blueprint/Blueprint/Cmdlets/BlueprintDefinition/GetAzureRMBlueprint.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ public override void ExecuteCmdlet()
107107
{
108108
WriteExceptionError(ex);
109109
}
110+
finally
111+
{
112+
UnregisterDelegatingHandlerIfRegistered();
113+
}
110114
}
111115
#endregion Cmdlet Overrides
112116

src/Blueprint/Blueprint/Common/BlueprintClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public BlueprintClient(IAzureContext context)
4242
var customHandlers = AzureSession.Instance.ClientFactory.GetCustomHandlers();
4343
var apiExpandHandler = customHandlers?.Where(handler => handler.GetType().Equals(typeof(ApiExpandHandler))).FirstOrDefault();
4444

45-
if (apiExpandHandler != null )
45+
if (apiExpandHandler != null)
4646
{
4747
AzureSession.Instance.ClientFactory.RemoveHandler(apiExpandHandler.GetType());
4848
}

0 commit comments

Comments
 (0)