Skip to content

Commit 972e4b8

Browse files
authored
[Service Bus] Admin Client emulator slug (#47362)
Adding support for the emulator slug to the Service Bus Administration client. While the emulator itself currently does not support the management operations, there is no harm in proactively enabling awareness in the the client for potential future support.
1 parent 7703a0a commit 972e4b8

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/HttpRequestAndResponse.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ internal class HttpRequestAndResponse
2222
private readonly int _port;
2323
private readonly ClientDiagnostics _diagnostics;
2424
private readonly string _versionQuery;
25+
private readonly string _scheme;
2526

2627
/// <summary>
2728
/// Initializes a new <see cref="HttpRequestAndResponse"/> which can be used to send http request and response.
@@ -31,14 +32,16 @@ public HttpRequestAndResponse(
3132
ClientDiagnostics diagnostics,
3233
TokenCredential tokenCredential,
3334
string fullyQualifiedNamespace,
34-
ServiceBusAdministrationClientOptions.ServiceVersion version)
35+
ServiceBusAdministrationClientOptions.ServiceVersion version,
36+
bool useTls)
3537
{
3638
_pipeline = pipeline;
3739
_diagnostics = diagnostics;
3840
_versionQuery = $"api-version={version.ToVersionString()}";
3941
_tokenCredential = tokenCredential;
4042
_fullyQualifiedNamespace = fullyQualifiedNamespace;
4143
_port = GetPort(_fullyQualifiedNamespace);
44+
_scheme = useTls ? Uri.UriSchemeHttps : Uri.UriSchemeHttp;
4245
}
4346

4447
internal void ThrowIfRequestFailed(Request request, Response response)
@@ -171,7 +174,7 @@ public async Task<Response> GetEntityAsync(
171174
Uri uri = new UriBuilder(_fullyQualifiedNamespace)
172175
{
173176
Path = entityPath,
174-
Scheme = Uri.UriSchemeHttps,
177+
Scheme = _scheme,
175178
Port = _port,
176179
Query = queryString
177180
}.Uri;
@@ -199,7 +202,7 @@ public async Task<Response> PutEntityAsync(
199202
{
200203
Path = entityPath,
201204
Port = _port,
202-
Scheme = Uri.UriSchemeHttps,
205+
Scheme = _scheme,
203206
Query = _versionQuery
204207
}.Uri;
205208
var requestUriBuilder = new RequestUriBuilder();
@@ -245,7 +248,7 @@ public async Task<Response> DeleteEntityAsync(
245248
Uri uri = new UriBuilder(_fullyQualifiedNamespace)
246249
{
247250
Path = entityPath,
248-
Scheme = Uri.UriSchemeHttps,
251+
Scheme = _scheme,
249252
Port = _port,
250253
Query = _versionQuery
251254
}.Uri;

sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/ServiceBusAdministrationClient.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,16 @@ public ServiceBusAdministrationClient(
105105
});
106106
_clientDiagnostics = new ClientDiagnostics(options);
107107

108+
// The Service Bus emulator does not support TLS.
109+
var useTls = (!connectionStringProperties.UseDevelopmentEmulator);
110+
108111
_httpRequestAndResponse = new HttpRequestAndResponse(
109112
pipeline,
110113
_clientDiagnostics,
111114
tokenCredential,
112115
_fullyQualifiedNamespace,
113-
options.Version);
116+
options.Version,
117+
useTls);
114118
}
115119

116120
/// <summary>
@@ -211,7 +215,8 @@ private ServiceBusAdministrationClient(
211215
_clientDiagnostics,
212216
credential,
213217
_fullyQualifiedNamespace,
214-
options.Version);
218+
options.Version,
219+
true);
215220
}
216221

217222
/// <summary>

sdk/servicebus/Azure.Messaging.ServiceBus/tests/Administration/RequestResponseTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public RequestResponseTests()
2020
{
2121
var options = new ServiceBusAdministrationClientOptions();
2222
var pipeline = HttpPipelineBuilder.Build(options);
23-
_requestResponse = new HttpRequestAndResponse(pipeline, new ClientDiagnostics(options), null, "fakeNamespace", ServiceBusAdministrationClientOptions.ServiceVersion.V2017_04);
23+
_requestResponse = new HttpRequestAndResponse(pipeline, new ClientDiagnostics(options), null, "fakeNamespace", ServiceBusAdministrationClientOptions.ServiceVersion.V2017_04, true);
2424
}
2525

2626
[Test]

sdk/servicebus/Azure.Messaging.ServiceBus/tests/Administration/ServiceBusManagementClientLiveTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using Azure.Core.TestFramework.Models;
1212
using Azure.Messaging.ServiceBus.Administration;
1313
using Azure.Messaging.ServiceBus.Authorization;
14-
using Azure.Messaging.ServiceBus.Tests.Infrastructure;
1514
using NUnit.Framework;
1615

1716
namespace Azure.Messaging.ServiceBus.Tests.Management

0 commit comments

Comments
 (0)