Skip to content

Commit 98b57b2

Browse files
author
Maddie Clayton
authored
Merge pull request #7221 from deathly809/preview
[Azure Stack] Handle DNS Double Async Headers
2 parents 25f2a12 + 951bf30 commit 98b57b2

File tree

3 files changed

+64
-6
lines changed

3 files changed

+64
-6
lines changed

src/StackAdmin/Dns/Commands.Dns/Commands.Dns.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
</PropertyGroup>
5454
<ItemGroup>
5555
<Compile Include="Models\DnsClient.cs" />
56+
<Compile Include="Models\DoubleFetchHandler.cs" />
5657
<Compile Include="Models\DnsBaseCmdlet.cs" />
5758
<Compile Include="Models\DnsRecordSet.cs" />
5859
<Compile Include="Models\DnsZone.cs" />
@@ -108,4 +109,4 @@
108109
</ItemGroup>
109110
<Copy SourceFiles="@(MarkdownFiles)" DestinationFolder="$(OutputPath)\help\" ContinueOnError="false" />
110111
</Target>
111-
</Project>
112+
</Project>

src/StackAdmin/Dns/Commands.Dns/Models/DnsClient.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using System.Linq;
2424
using ProjectResources = Microsoft.Azure.Commands.Dns.Properties.Resources;
2525
using Sdk = Microsoft.Azure.Management.Dns.Models;
26+
using System.Net.Http;
2627

2728
namespace Microsoft.Azure.Commands.Dns.Models
2829
{
@@ -51,8 +52,21 @@ public class DnsClient
5152
};
5253

5354
public DnsClient(IAzureContext context)
54-
: this(AzureSession.Instance.ClientFactory.CreateArmClient<DnsManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager))
5555
{
56+
// Factories
57+
var authFactory = AzureSession.Instance.AuthenticationFactory;
58+
var clientFactory = AzureSession.Instance.ClientFactory;
59+
60+
var endpoint = AzureEnvironment.Endpoint.ResourceManager;
61+
62+
// Get parameters
63+
var handler = new DelegatingHandler[] { new DoubleFetchHandler() };
64+
var creds = authFactory.GetServiceClientCredentials(context, endpoint);
65+
var baseUri = context.Environment.GetEndpointAsUri(endpoint);
66+
67+
// Construct client
68+
this.DnsManagementClient = clientFactory.CreateCustomArmClient<DnsManagementClient>(baseUri, creds, handler);
69+
this.DnsManagementClient.SubscriptionId = context.Subscription.Id.ToString();
5670
}
5771

5872
public DnsClient(IDnsManagementClient managementClient)
@@ -127,9 +141,9 @@ public List<DnsZone> ListDnsZonesInResourceGroup(string resourceGroupName)
127141
}
128142
else
129143
{
130-
getResponse = this.DnsManagementClient.Zones.ListInResourceGroup(resourceGroupName);
144+
getResponse = this.DnsManagementClient.Zones.ListInResourceGroup(resourceGroupName);
131145
}
132-
146+
133147
results.AddRange(getResponse.Select(ToDnsZone));
134148
} while (getResponse != null && getResponse.NextPageLink != null);
135149

@@ -204,7 +218,7 @@ private RecordSet ConstructRecordSetPropeties(string recordSetName, RecordType r
204218
}
205219
else
206220
{
207-
FillEmptyRecordsForType( properties, recordType);
221+
FillEmptyRecordsForType( properties, recordType);
208222
}
209223
return properties;
210224
}
@@ -354,7 +368,7 @@ public List<DnsRecordSet> ListRecordSets(string zoneName, string resourceGroupNa
354368
}
355369

356370
results.AddRange(listResponse.Select(recordSet => GetPowerShellRecordSet(zoneName, resourceGroupName, recordSet)));
357-
371+
358372
} while (listResponse != null && listResponse.NextPageLink != null);
359373

360374
return results;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Net.Http;
17+
using System.Threading;
18+
using System.Threading.Tasks;
19+
20+
namespace Microsoft.Azure.Commands.Dns.Models
21+
{
22+
public class DoubleFetchHandler : DelegatingHandler, ICloneable
23+
{
24+
public object Clone() {
25+
return new DoubleFetchHandler();
26+
}
27+
28+
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) {
29+
30+
return base.SendAsync(request, cancellationToken).ContinueWith<HttpResponseMessage>(response =>
31+
{
32+
var result = response.Result;
33+
if (result.Headers.Contains("Location") && result.Headers.Contains("Azure-AsyncOperation"))
34+
{
35+
result.Headers.Remove("Location");
36+
}
37+
38+
return result;
39+
});
40+
}
41+
42+
}
43+
}

0 commit comments

Comments
 (0)