Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Service Bus] ConnectionString parsing cleanup #10664

Merged
merged 6 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions sdk/servicebus/Azure.Messaging.ServiceBus/src/Core/Argument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,26 @@ public static void AssertNotClosed(bool wasClosed, string targetName)
targetName);
}
}

/// <summary>
/// Ensures that an argument's value is a well-formed Event Hubs fully qualified namespace value,
/// throwing a <see cref="ArgumentException" /> if that invariant is not met.
/// </summary>
///
/// <param name="argumentValue">The argument value.</param>
/// <param name="argumentName">Name of the argument.</param>
///
///
/// <exception cref="ArgumentException"><paramref name="argumentValue"/> is not a well-formed Service Bus fully qualified namespace.</exception>
///
public static void AssertWellFormedServiceBusNamespace(string argumentValue, string argumentName)
{
argumentValue ??= string.Empty;

if (Uri.CheckHostName(argumentValue) == UriHostNameType.Unknown)
{
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources1.InvalidFullyQualifiedNamespace, argumentValue), argumentName);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public static ConnectionStringProperties Parse(string connectionString)
{
parsedValues.EndpointToken = new UriBuilder(value)
{
Scheme = ServiceBusEndpointScheme
Scheme = ServiceBusEndpointScheme,
Port = -1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, how is this used?

Copy link
Member Author

@ShivangiReja ShivangiReja Mar 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I parse the below connection string without setting Port = -1

ConnectionStringParser.Parse("Endpoint=ns1.servicebus.windows.net/;SharedAccessKeyName=FakeKeyName;SharedAccessKey=FakeKey;")

It returns Endpoint - "sb://ns1.servicebus.windows.net:80/"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, do we know why this wasn't needed in the EH version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we parse this connection string without setting Port = -1 "Endpoint=sb://ns1.servicebus.windows.net/;SharedAccessKeyName=DummyKeyName;SharedAccessKey=DummyKey"

It returns the Endpoint as expected. Meaning if we pass the connection string endpoint starting with sb:// or pb:// or anything; It doesn't append the port and returns the Endpoint as expected.

I don't know about EH. I need to ask @jsquire.

};
}
else if (string.Compare(EntityName, token, StringComparison.OrdinalIgnoreCase) == 0)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions sdk/servicebus/Azure.Messaging.ServiceBus/src/Resources1.resx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
<data name="MissingConnectionInformation" xml:space="preserve">
<value>The connection string used for an Service Bus entity client must specify the Service Bus namespace host, and a Shared Access Signature (both the name and value) to be valid. The path to an Service Bus entity must be included in the connection string or specified separately.</value>
</data>
<data name="OnlyOneEventHubNameMayBeSpecified" xml:space="preserve">
<data name="OnlyOneEntityNameMayBeSpecified" xml:space="preserve">
<value>The path to an Service Bus entity may be specified as part of the connection string or as a separate value, but not both.</value>
</data>
<data name="UnknownConnectionType" xml:space="preserve">
Expand Down Expand Up @@ -225,7 +225,7 @@
<data name="CannotStartEventProcessorWithoutHandler" xml:space="preserve">
<value>Cannot begin processing without {0} handler set.</value>
</data>
<data name="RunningMessageProcessor" xml:space="preserve">
<data name="RunningMessageProcessorCannotPerformOperation" xml:space="preserve">
<value>The message processor is already running and needs to be stopped in order to perform this operation.</value>
</data>
<data name="ClientNeededForThisInformation" xml:space="preserve">
Expand Down Expand Up @@ -270,4 +270,7 @@
<data name="MaxPermittedLength" xml:space="preserve">
<value>Maximum permitted length is {0}</value>
</data>
</root>
<data name="InvalidFullyQualifiedNamespace" xml:space="preserve">
<value>The value '{0}' is not a well-formed Event Hubs fully qualified The value '{0}' is not a well-formed Event Hubs fully qualified namespace.</value>
</data>
</root>
Loading