Skip to content

Commit

Permalink
[Service Bus] Admin Client emulator slug (#47362)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jsquire authored Nov 28, 2024
1 parent 7703a0a commit 972e4b8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal class HttpRequestAndResponse
private readonly int _port;
private readonly ClientDiagnostics _diagnostics;
private readonly string _versionQuery;
private readonly string _scheme;

/// <summary>
/// Initializes a new <see cref="HttpRequestAndResponse"/> which can be used to send http request and response.
Expand All @@ -31,14 +32,16 @@ public HttpRequestAndResponse(
ClientDiagnostics diagnostics,
TokenCredential tokenCredential,
string fullyQualifiedNamespace,
ServiceBusAdministrationClientOptions.ServiceVersion version)
ServiceBusAdministrationClientOptions.ServiceVersion version,
bool useTls)
{
_pipeline = pipeline;
_diagnostics = diagnostics;
_versionQuery = $"api-version={version.ToVersionString()}";
_tokenCredential = tokenCredential;
_fullyQualifiedNamespace = fullyQualifiedNamespace;
_port = GetPort(_fullyQualifiedNamespace);
_scheme = useTls ? Uri.UriSchemeHttps : Uri.UriSchemeHttp;
}

internal void ThrowIfRequestFailed(Request request, Response response)
Expand Down Expand Up @@ -171,7 +174,7 @@ public async Task<Response> GetEntityAsync(
Uri uri = new UriBuilder(_fullyQualifiedNamespace)
{
Path = entityPath,
Scheme = Uri.UriSchemeHttps,
Scheme = _scheme,
Port = _port,
Query = queryString
}.Uri;
Expand Down Expand Up @@ -199,7 +202,7 @@ public async Task<Response> PutEntityAsync(
{
Path = entityPath,
Port = _port,
Scheme = Uri.UriSchemeHttps,
Scheme = _scheme,
Query = _versionQuery
}.Uri;
var requestUriBuilder = new RequestUriBuilder();
Expand Down Expand Up @@ -245,7 +248,7 @@ public async Task<Response> DeleteEntityAsync(
Uri uri = new UriBuilder(_fullyQualifiedNamespace)
{
Path = entityPath,
Scheme = Uri.UriSchemeHttps,
Scheme = _scheme,
Port = _port,
Query = _versionQuery
}.Uri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,16 @@ public ServiceBusAdministrationClient(
});
_clientDiagnostics = new ClientDiagnostics(options);

// The Service Bus emulator does not support TLS.
var useTls = (!connectionStringProperties.UseDevelopmentEmulator);

_httpRequestAndResponse = new HttpRequestAndResponse(
pipeline,
_clientDiagnostics,
tokenCredential,
_fullyQualifiedNamespace,
options.Version);
options.Version,
useTls);
}

/// <summary>
Expand Down Expand Up @@ -211,7 +215,8 @@ private ServiceBusAdministrationClient(
_clientDiagnostics,
credential,
_fullyQualifiedNamespace,
options.Version);
options.Version,
true);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public RequestResponseTests()
{
var options = new ServiceBusAdministrationClientOptions();
var pipeline = HttpPipelineBuilder.Build(options);
_requestResponse = new HttpRequestAndResponse(pipeline, new ClientDiagnostics(options), null, "fakeNamespace", ServiceBusAdministrationClientOptions.ServiceVersion.V2017_04);
_requestResponse = new HttpRequestAndResponse(pipeline, new ClientDiagnostics(options), null, "fakeNamespace", ServiceBusAdministrationClientOptions.ServiceVersion.V2017_04, true);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Azure.Core.TestFramework.Models;
using Azure.Messaging.ServiceBus.Administration;
using Azure.Messaging.ServiceBus.Authorization;
using Azure.Messaging.ServiceBus.Tests.Infrastructure;
using NUnit.Framework;

namespace Azure.Messaging.ServiceBus.Tests.Management
Expand Down

0 comments on commit 972e4b8

Please sign in to comment.