Skip to content

Commit ba4dfcf

Browse files
afscromedavidfowl
andauthored
Add EndpointProperty.HostAndPort (#7629)
* Add `EndpointProperty.HostAndPort` - Add `EndpointProperty.HostAndPort` - Update existing places that can now use `HostAndPort` instead of concatenating Host and Port themselves. * PR Feedback * Update src/Aspire.Hosting/ApplicationModel/ExpressionResolver.cs * Update src/Aspire.Hosting/ApplicationModel/ExpressionResolver.cs * Add additional tests. --------- Co-authored-by: David Fowler <davidfowl@gmail.com>
1 parent 02381d6 commit ba4dfcf

File tree

16 files changed

+36
-30
lines changed

16 files changed

+36
-30
lines changed

src/Aspire.Hosting.Azure.EventHubs/AzureEventHubsResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ internal ReferenceExpression GetConnectionString(string? eventHub = null, string
5252

5353
if (IsEmulator)
5454
{
55-
builder.Append($"Endpoint=sb://{EmulatorEndpoint.Property(EndpointProperty.Host)}:{EmulatorEndpoint.Property(EndpointProperty.Port)};SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true");
55+
builder.Append($"Endpoint=sb://{EmulatorEndpoint.Property(EndpointProperty.HostAndPort)};SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true");
5656
}
5757
else
5858
{

src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class AzureServiceBusResource(string name, Action<AzureResourceInfrastruc
3333
/// </summary>
3434
public ReferenceExpression ConnectionStringExpression =>
3535
IsEmulator
36-
? ReferenceExpression.Create($"Endpoint=sb://{EmulatorEndpoint.Property(EndpointProperty.Host)}:{EmulatorEndpoint.Property(EndpointProperty.Port)};SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true;")
36+
? ReferenceExpression.Create($"Endpoint=sb://{EmulatorEndpoint.Property(EndpointProperty.HostAndPort)};SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true;")
3737
: ReferenceExpression.Create($"{ServiceBusEndpoint}");
3838

3939
void IResourceWithAzureFunctionsConfig.ApplyAzureFunctionsConfiguration(IDictionary<string, object> target, string connectionName)

src/Aspire.Hosting.Elasticsearch/ElasticsearchResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ public ElasticsearchResource(string name, ParameterResource password) : base(nam
5252
/// Gets the connection string expression for the Elasticsearch
5353
/// </summary>
5454
public ReferenceExpression ConnectionStringExpression =>
55-
ReferenceExpression.Create($"http://{UserName}:{PasswordParameter}@{PrimaryEndpoint.Property(EndpointProperty.Host)}:{PrimaryEndpoint.Property(EndpointProperty.Port)}");
55+
ReferenceExpression.Create($"http://{UserName}:{PasswordParameter}@{PrimaryEndpoint.Property(EndpointProperty.HostAndPort)}");
5656
}
5757

src/Aspire.Hosting.Garnet/GarnetResource.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ public class GarnetResource(string name) : ContainerResource(ThrowIfNull(name)),
2424
/// <summary>
2525
/// Gets the connection string expression for the Garnet server.
2626
/// </summary>
27-
public ReferenceExpression ConnectionStringExpression =>
28-
ReferenceExpression.Create(
29-
$"{PrimaryEndpoint.Property(EndpointProperty.Host)}:{PrimaryEndpoint.Property(EndpointProperty.Port)}");
27+
public ReferenceExpression ConnectionStringExpression =>
28+
ReferenceExpression.Create($"{PrimaryEndpoint.Property(EndpointProperty.HostAndPort)}");
3029

3130
private static string ThrowIfNull([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
3231
=> argument ?? throw new ArgumentNullException(paramName);

src/Aspire.Hosting.Kafka/KafkaBuilderExtensions.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static void ConfigureKafkaUIContainer(EnvironmentCallbackContext context, Endpoi
140140
// In run mode, Kafka UI assumes Kafka is being accessed over a default Aspire container network and hardcodes the host as the Kafka resource name
141141
// This will need to be refactored once updated service discovery APIs are available
142142
? ReferenceExpression.Create($"{endpoint.Resource.Name}:{endpoint.Property(EndpointProperty.TargetPort)}")
143-
: ReferenceExpression.Create($"{endpoint.Property(EndpointProperty.Host)}:{endpoint.Property(EndpointProperty.Port)}");
143+
: ReferenceExpression.Create($"{endpoint.Property(EndpointProperty.HostAndPort)}");
144144

145145
context.EnvironmentVariables.Add($"KAFKA_CLUSTERS_{index}_NAME", endpoint.Resource.Name);
146146
context.EnvironmentVariables.Add($"KAFKA_CLUSTERS_{index}_BOOTSTRAPSERVERS", bootstrapServers);
@@ -218,8 +218,7 @@ private static void ConfigureKafkaContainer(EnvironmentCallbackContext context,
218218
// In run mode, PLAINTEXT_INTERNAL assumes kafka is being accessed over a default Aspire container network and hardcodes the resource address
219219
// This will need to be refactored once updated service discovery APIs are available
220220
? ReferenceExpression.Create($"PLAINTEXT://localhost:29092,PLAINTEXT_HOST://localhost:{primaryEndpoint.Property(EndpointProperty.Port)},PLAINTEXT_INTERNAL://{resource.Name}:{internalEndpoint.Property(EndpointProperty.TargetPort)}")
221-
: ReferenceExpression.Create(
222-
$"PLAINTEXT://{primaryEndpoint.Property(EndpointProperty.Host)}:29092,PLAINTEXT_HOST://{primaryEndpoint.Property(EndpointProperty.Host)}:{primaryEndpoint.Property(EndpointProperty.Port)},PLAINTEXT_INTERNAL://{internalEndpoint.Property(EndpointProperty.Host)}:{internalEndpoint.Property(EndpointProperty.Port)}");
221+
: ReferenceExpression.Create($"PLAINTEXT://{primaryEndpoint.Property(EndpointProperty.Host)}:29092,PLAINTEXT_HOST://{primaryEndpoint.Property(EndpointProperty.HostAndPort)},PLAINTEXT_INTERNAL://{internalEndpoint.Property(EndpointProperty.HostAndPort)}");
223222

224223
context.EnvironmentVariables["KAFKA_ADVERTISED_LISTENERS"] = advertisedListeners;
225224
}

src/Aspire.Hosting.Kafka/KafkaServerResource.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,5 @@ public class KafkaServerResource(string name) : ContainerResource(name), IResour
3535
/// Gets the connection string expression for the Kafka broker.
3636
/// </summary>
3737
public ReferenceExpression ConnectionStringExpression =>
38-
ReferenceExpression.Create(
39-
$"{PrimaryEndpoint.Property(EndpointProperty.Host)}:{PrimaryEndpoint.Property(EndpointProperty.Port)}");
38+
ReferenceExpression.Create($"{PrimaryEndpoint.Property(EndpointProperty.HostAndPort)}");
4039
}

src/Aspire.Hosting.MongoDB/MongoDBServerResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ internal ReferenceExpression BuildConnectionString(string? databaseName = null)
6363
builder.Append($"{UserNameReference}:{PasswordParameter}@");
6464
}
6565

66-
builder.Append($"{PrimaryEndpoint.Property(EndpointProperty.Host)}:{PrimaryEndpoint.Property(EndpointProperty.Port)}");
66+
builder.Append($"{PrimaryEndpoint.Property(EndpointProperty.HostAndPort)}");
6767

6868
if (databaseName is not null)
6969
{

src/Aspire.Hosting.Nats/NatsServerResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ internal ReferenceExpression BuildConnectionString()
6565
builder.Append($"{UserNameReference}:{PasswordParameter}@");
6666
}
6767

68-
builder.Append($"{PrimaryEndpoint.Property(EndpointProperty.Host)}:{PrimaryEndpoint.Property(EndpointProperty.Port)}");
68+
builder.Append($"{PrimaryEndpoint.Property(EndpointProperty.HostAndPort)}");
6969

7070
return builder.Build();
7171
}

src/Aspire.Hosting.Oracle/OracleDatabaseServerResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public OracleDatabaseServerResource(string name, ParameterResource password) : b
3838
/// </summary>
3939
public ReferenceExpression ConnectionStringExpression =>
4040
ReferenceExpression.Create(
41-
$"user id=system;password={PasswordParameter};data source={PrimaryEndpoint.Property(EndpointProperty.Host)}:{PrimaryEndpoint.Property(EndpointProperty.Port)}");
41+
$"user id=system;password={PasswordParameter};data source={PrimaryEndpoint.Property(EndpointProperty.HostAndPort)}");
4242

4343
private readonly Dictionary<string, string> _databases = new(StringComparers.ResourceName);
4444

src/Aspire.Hosting.RabbitMQ/RabbitMQServerResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ UserNameParameter is not null ?
5252
/// </summary>
5353
public ReferenceExpression ConnectionStringExpression =>
5454
ReferenceExpression.Create(
55-
$"amqp://{UserNameReference}:{PasswordParameter}@{PrimaryEndpoint.Property(EndpointProperty.Host)}:{PrimaryEndpoint.Property(EndpointProperty.Port)}");
55+
$"amqp://{UserNameReference}:{PasswordParameter}@{PrimaryEndpoint.Property(EndpointProperty.HostAndPort)}");
5656
}

0 commit comments

Comments
 (0)