Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
66 changes: 66 additions & 0 deletions src/Aspire.Hosting/ResourceBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,72 @@ public static IResourceBuilder<T> WithHttpsEndpoint<T>(this IResourceBuilder<T>
return builder.WithEndpoint(targetPort: targetPort, port: port, scheme: "https", name: name, env: env, isProxied: isProxied);
}

/// <summary>
/// Configures the host port for the default HTTP endpoint on a resource.
/// </summary>
/// <typeparam name="T">The resource type.</typeparam>
/// <param name="builder">The resource builder.</param>
/// <param name="port">The host port to bind for the <c>"http"</c> endpoint. If <see langword="null"/>, a random port will be assigned.</param>
/// <returns>The <see cref="IResourceBuilder{T}"/> for chaining.</returns>
/// <remarks>
/// <para>
/// This is a convenience method for setting the host port on the endpoint named <c>"http"</c>.
/// The endpoint must already exist on the resource, for example by calling
/// <see cref="WithHttpEndpoint{T}(IResourceBuilder{T}, int?, int?, string?, string?, bool)"/>,
/// or by using a resource type that creates it automatically (such as <c>AddViteApp</c> or <c>AddNextJsApp</c>).
/// </para>
/// </remarks>
/// <example>
/// Set the host port for a Vite application:
/// <code>
/// var frontend = builder.AddViteApp("frontend", "./frontend")
/// .WithHttpPort(3000);
/// </code>
/// </example>
[AspireExport(Description = "Sets the host port for the HTTP endpoint")]
public static IResourceBuilder<T> WithHttpPort<T>(this IResourceBuilder<T> builder, int? port) where T : IResourceWithEndpoints
{
ArgumentNullException.ThrowIfNull(builder);

return builder.WithEndpoint("http", endpoint =>
{
endpoint.Port = port;
}, createIfNotExists: false);
}

/// <summary>
/// Configures the host port for the default HTTPS endpoint on a resource.
/// </summary>
/// <typeparam name="T">The resource type.</typeparam>
/// <param name="builder">The resource builder.</param>
/// <param name="port">The host port to bind for the <c>"https"</c> endpoint. If <see langword="null"/>, a random port will be assigned.</param>
/// <returns>The <see cref="IResourceBuilder{T}"/> for chaining.</returns>
/// <remarks>
/// <para>
/// This is a convenience method for setting the host port on the endpoint named <c>"https"</c>.
/// The endpoint must already exist on the resource, for example by calling
/// <see cref="WithHttpsEndpoint{T}(IResourceBuilder{T}, int?, int?, string?, string?, bool)"/>.
/// </para>
/// </remarks>
/// <example>
/// Pin the HTTPS port on a container with an HTTPS endpoint:
/// <code>
/// var api = builder.AddContainer("api", "myimage")
/// .WithHttpsEndpoint()
/// .WithHttpsPort(8443);
/// </code>
/// </example>
[AspireExport(Description = "Sets the host port for the HTTPS endpoint")]
public static IResourceBuilder<T> WithHttpsPort<T>(this IResourceBuilder<T> builder, int? port) where T : IResourceWithEndpoints
{
ArgumentNullException.ThrowIfNull(builder);

return builder.WithEndpoint("https", endpoint =>
{
endpoint.Port = port;
}, createIfNotExists: false);
}

/// <summary>
/// Marks existing http or https endpoints on a resource as external.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,32 @@ func (s *CSharpAppResource) WithHttpsEndpoint(port *float64, targetPort *float64
return result.(*IResourceWithEndpoints), nil
}

// WithHttpPort sets the host port for the HTTP endpoint
func (s *CSharpAppResource) WithHttpPort(port float64) (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
"builder": SerializeValue(s.Handle()),
}
reqArgs["port"] = SerializeValue(port)
result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpPort", reqArgs)
if err != nil {
return nil, err
}
return result.(*IResourceWithEndpoints), nil
}

// WithHttpsPort sets the host port for the HTTPS endpoint
func (s *CSharpAppResource) WithHttpsPort(port float64) (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
"builder": SerializeValue(s.Handle()),
}
reqArgs["port"] = SerializeValue(port)
result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpsPort", reqArgs)
if err != nil {
return nil, err
}
return result.(*IResourceWithEndpoints), nil
}

// WithExternalHttpEndpoints makes HTTP endpoints externally accessible
func (s *CSharpAppResource) WithExternalHttpEndpoints() (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
Expand Down Expand Up @@ -4008,6 +4034,32 @@ func (s *ContainerResource) WithHttpsEndpoint(port *float64, targetPort *float64
return result.(*IResourceWithEndpoints), nil
}

// WithHttpPort sets the host port for the HTTP endpoint
func (s *ContainerResource) WithHttpPort(port float64) (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
"builder": SerializeValue(s.Handle()),
}
reqArgs["port"] = SerializeValue(port)
result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpPort", reqArgs)
if err != nil {
return nil, err
}
return result.(*IResourceWithEndpoints), nil
}

// WithHttpsPort sets the host port for the HTTPS endpoint
func (s *ContainerResource) WithHttpsPort(port float64) (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
"builder": SerializeValue(s.Handle()),
}
reqArgs["port"] = SerializeValue(port)
result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpsPort", reqArgs)
if err != nil {
return nil, err
}
return result.(*IResourceWithEndpoints), nil
}

// WithExternalHttpEndpoints makes HTTP endpoints externally accessible
func (s *ContainerResource) WithExternalHttpEndpoints() (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
Expand Down Expand Up @@ -5614,6 +5666,32 @@ func (s *DotnetToolResource) WithHttpsEndpoint(port *float64, targetPort *float6
return result.(*IResourceWithEndpoints), nil
}

// WithHttpPort sets the host port for the HTTP endpoint
func (s *DotnetToolResource) WithHttpPort(port float64) (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
"builder": SerializeValue(s.Handle()),
}
reqArgs["port"] = SerializeValue(port)
result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpPort", reqArgs)
if err != nil {
return nil, err
}
return result.(*IResourceWithEndpoints), nil
}

// WithHttpsPort sets the host port for the HTTPS endpoint
func (s *DotnetToolResource) WithHttpsPort(port float64) (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
"builder": SerializeValue(s.Handle()),
}
reqArgs["port"] = SerializeValue(port)
result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpsPort", reqArgs)
if err != nil {
return nil, err
}
return result.(*IResourceWithEndpoints), nil
}

// WithExternalHttpEndpoints makes HTTP endpoints externally accessible
func (s *DotnetToolResource) WithExternalHttpEndpoints() (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
Expand Down Expand Up @@ -7296,6 +7374,32 @@ func (s *ExecutableResource) WithHttpsEndpoint(port *float64, targetPort *float6
return result.(*IResourceWithEndpoints), nil
}

// WithHttpPort sets the host port for the HTTP endpoint
func (s *ExecutableResource) WithHttpPort(port float64) (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
"builder": SerializeValue(s.Handle()),
}
reqArgs["port"] = SerializeValue(port)
result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpPort", reqArgs)
if err != nil {
return nil, err
}
return result.(*IResourceWithEndpoints), nil
}

// WithHttpsPort sets the host port for the HTTPS endpoint
func (s *ExecutableResource) WithHttpsPort(port float64) (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
"builder": SerializeValue(s.Handle()),
}
reqArgs["port"] = SerializeValue(port)
result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpsPort", reqArgs)
if err != nil {
return nil, err
}
return result.(*IResourceWithEndpoints), nil
}

// WithExternalHttpEndpoints makes HTTP endpoints externally accessible
func (s *ExecutableResource) WithExternalHttpEndpoints() (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
Expand Down Expand Up @@ -12011,6 +12115,32 @@ func (s *ProjectResource) WithHttpsEndpoint(port *float64, targetPort *float64,
return result.(*IResourceWithEndpoints), nil
}

// WithHttpPort sets the host port for the HTTP endpoint
func (s *ProjectResource) WithHttpPort(port float64) (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
"builder": SerializeValue(s.Handle()),
}
reqArgs["port"] = SerializeValue(port)
result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpPort", reqArgs)
if err != nil {
return nil, err
}
return result.(*IResourceWithEndpoints), nil
}

// WithHttpsPort sets the host port for the HTTPS endpoint
func (s *ProjectResource) WithHttpsPort(port float64) (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
"builder": SerializeValue(s.Handle()),
}
reqArgs["port"] = SerializeValue(port)
result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpsPort", reqArgs)
if err != nil {
return nil, err
}
return result.(*IResourceWithEndpoints), nil
}

// WithExternalHttpEndpoints makes HTTP endpoints externally accessible
func (s *ProjectResource) WithExternalHttpEndpoints() (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
Expand Down Expand Up @@ -14127,6 +14257,32 @@ func (s *TestDatabaseResource) WithHttpsEndpoint(port *float64, targetPort *floa
return result.(*IResourceWithEndpoints), nil
}

// WithHttpPort sets the host port for the HTTP endpoint
func (s *TestDatabaseResource) WithHttpPort(port float64) (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
"builder": SerializeValue(s.Handle()),
}
reqArgs["port"] = SerializeValue(port)
result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpPort", reqArgs)
if err != nil {
return nil, err
}
return result.(*IResourceWithEndpoints), nil
}

// WithHttpsPort sets the host port for the HTTPS endpoint
func (s *TestDatabaseResource) WithHttpsPort(port float64) (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
"builder": SerializeValue(s.Handle()),
}
reqArgs["port"] = SerializeValue(port)
result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpsPort", reqArgs)
if err != nil {
return nil, err
}
return result.(*IResourceWithEndpoints), nil
}

// WithExternalHttpEndpoints makes HTTP endpoints externally accessible
func (s *TestDatabaseResource) WithExternalHttpEndpoints() (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
Expand Down Expand Up @@ -15787,6 +15943,32 @@ func (s *TestRedisResource) WithHttpsEndpoint(port *float64, targetPort *float64
return result.(*IResourceWithEndpoints), nil
}

// WithHttpPort sets the host port for the HTTP endpoint
func (s *TestRedisResource) WithHttpPort(port float64) (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
"builder": SerializeValue(s.Handle()),
}
reqArgs["port"] = SerializeValue(port)
result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpPort", reqArgs)
if err != nil {
return nil, err
}
return result.(*IResourceWithEndpoints), nil
}

// WithHttpsPort sets the host port for the HTTPS endpoint
func (s *TestRedisResource) WithHttpsPort(port float64) (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
"builder": SerializeValue(s.Handle()),
}
reqArgs["port"] = SerializeValue(port)
result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpsPort", reqArgs)
if err != nil {
return nil, err
}
return result.(*IResourceWithEndpoints), nil
}

// WithExternalHttpEndpoints makes HTTP endpoints externally accessible
func (s *TestRedisResource) WithExternalHttpEndpoints() (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
Expand Down Expand Up @@ -17590,6 +17772,32 @@ func (s *TestVaultResource) WithHttpsEndpoint(port *float64, targetPort *float64
return result.(*IResourceWithEndpoints), nil
}

// WithHttpPort sets the host port for the HTTP endpoint
func (s *TestVaultResource) WithHttpPort(port float64) (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
"builder": SerializeValue(s.Handle()),
}
reqArgs["port"] = SerializeValue(port)
result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpPort", reqArgs)
if err != nil {
return nil, err
}
return result.(*IResourceWithEndpoints), nil
}

// WithHttpsPort sets the host port for the HTTPS endpoint
func (s *TestVaultResource) WithHttpsPort(port float64) (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
"builder": SerializeValue(s.Handle()),
}
reqArgs["port"] = SerializeValue(port)
result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpsPort", reqArgs)
if err != nil {
return nil, err
}
return result.(*IResourceWithEndpoints), nil
}

// WithExternalHttpEndpoints makes HTTP endpoints externally accessible
func (s *TestVaultResource) WithExternalHttpEndpoints() (*IResourceWithEndpoints, error) {
reqArgs := map[string]any{
Expand Down
Loading
Loading