diff --git a/src/Aspire.Hosting/ApplicationModel/EndpointUpdateContext.cs b/src/Aspire.Hosting/ApplicationModel/EndpointUpdateContext.cs new file mode 100644 index 00000000000..a5c28ee495e --- /dev/null +++ b/src/Aspire.Hosting/ApplicationModel/EndpointUpdateContext.cs @@ -0,0 +1,110 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Net.Sockets; + +namespace Aspire.Hosting.ApplicationModel; + +/// +/// Provides a mutable callback context for updating an endpoint in polyglot app hosts. +/// +[AspireExport(ExposeProperties = true)] +internal sealed class EndpointUpdateContext(EndpointAnnotation endpointAnnotation) +{ + private readonly EndpointAnnotation _endpointAnnotation = endpointAnnotation ?? throw new ArgumentNullException(nameof(endpointAnnotation)); + + /// + /// Gets the endpoint name. + /// + public string Name => _endpointAnnotation.Name; + + /// + /// Gets or sets the network protocol. + /// + public ProtocolType Protocol + { + get => _endpointAnnotation.Protocol; + set => _endpointAnnotation.Protocol = value; + } + + /// + /// Gets or sets the desired host port. + /// + public int? Port + { + get => _endpointAnnotation.Port; + set => _endpointAnnotation.Port = value; + } + + /// + /// Gets or sets the target port. + /// + public int? TargetPort + { + get => _endpointAnnotation.TargetPort; + set => _endpointAnnotation.TargetPort = value; + } + + /// + /// Gets or sets the URI scheme. + /// + public string UriScheme + { + get => _endpointAnnotation.UriScheme; + set => _endpointAnnotation.UriScheme = value; + } + + /// + /// Gets or sets the target host. + /// + public string TargetHost + { + get => _endpointAnnotation.TargetHost; + set => _endpointAnnotation.TargetHost = value; + } + + /// + /// Gets or sets the transport. + /// + public string Transport + { + get => _endpointAnnotation.Transport; + set => _endpointAnnotation.Transport = value; + } + + /// + /// Gets or sets a value indicating whether the endpoint is external. + /// + public bool IsExternal + { + get => _endpointAnnotation.IsExternal; + set => _endpointAnnotation.IsExternal = value; + } + + /// + /// Gets or sets a value indicating whether the endpoint is proxied. + /// + public bool IsProxied + { + get => _endpointAnnotation.IsProxied; + set => _endpointAnnotation.IsProxied = value; + } + + /// + /// Gets or sets a value indicating whether the endpoint is excluded from the default reference set. + /// + public bool ExcludeReferenceEndpoint + { + get => _endpointAnnotation.ExcludeReferenceEndpoint; + set => _endpointAnnotation.ExcludeReferenceEndpoint = value; + } + + /// + /// Gets or sets a value indicating whether TLS is enabled. + /// + public bool TlsEnabled + { + get => _endpointAnnotation.TlsEnabled; + set => _endpointAnnotation.TlsEnabled = value; + } +} diff --git a/src/Aspire.Hosting/ResourceBuilderExtensions.cs b/src/Aspire.Hosting/ResourceBuilderExtensions.cs index d6d836910e2..e30ae41f0e6 100644 --- a/src/Aspire.Hosting/ResourceBuilderExtensions.cs +++ b/src/Aspire.Hosting/ResourceBuilderExtensions.cs @@ -1210,9 +1210,9 @@ private static void ApplyEndpoints(this IResourceBuilder builder, IResourc /// }); /// /// - /// This method is not available in polyglot app hosts. Use the parameter-based overload instead. + /// This method is not available in polyglot app hosts. Use the callback-based endpoint mutation export instead. /// - [AspireExportIgnore(Reason = "EndpointAnnotation has read-only properties AllocatedEndpointSnapshot and AllAllocatedEndpoints that are not ATS-compatible. Callback-free variant is exported.")] + [AspireExportIgnore(Reason = "Polyglot app hosts use the internal withEndpointCallback export, which exposes EndpointUpdateContext instead of EndpointAnnotation.")] [System.Diagnostics.CodeAnalysis.SuppressMessage("ApiDesign", "RS0026:Do not add multiple public overloads with optional parameters", Justification = "")] public static IResourceBuilder WithEndpoint(this IResourceBuilder builder, [EndpointName] string endpointName, Action callback, bool createIfNotExists = true) where T : IResourceWithEndpoints { @@ -1247,6 +1247,33 @@ public static IResourceBuilder WithEndpoint(this IResourceBuilder build return builder; } + [AspireExport(Description = "Updates a named endpoint via callback")] + internal static IResourceBuilder WithEndpointCallback(this IResourceBuilder builder, [EndpointName] string endpointName, Action callback, bool createIfNotExists = true) where T : IResourceWithEndpoints + { + ArgumentNullException.ThrowIfNull(builder); + ArgumentNullException.ThrowIfNull(endpointName); + ArgumentNullException.ThrowIfNull(callback); + + return builder.WithEndpoint(endpointName, endpoint => callback(new EndpointUpdateContext(endpoint)), createIfNotExists); + } + + [AspireExport(Description = "Updates an HTTP endpoint via callback")] + internal static IResourceBuilder WithHttpEndpointCallback(this IResourceBuilder builder, Action callback, [EndpointName] string? name = null, bool createIfNotExists = true) where T : IResourceWithEndpoints + { + ArgumentNullException.ThrowIfNull(builder); + ArgumentNullException.ThrowIfNull(callback); + + var endpointName = name ?? "http"; + + if (createIfNotExists && + !builder.Resource.Annotations.OfType().Any(endpoint => string.Equals(endpoint.Name, endpointName, StringComparisons.EndpointAnnotationName))) + { + builder.WithHttpEndpoint(name: endpointName); + } + + return builder.WithEndpoint(endpointName, endpoint => callback(new EndpointUpdateContext(endpoint)), createIfNotExists: false); + } + /// /// Exposes an endpoint on a resource. A reference to this endpoint can be retrieved using . /// The endpoint name will be the scheme name if not specified. @@ -1394,7 +1421,6 @@ public static IResourceBuilder WithExternalHttpEndpoints(this IResourceBui return builder; } - /// /// Gets an by name from the resource. These endpoints are declared either using or by launch settings (for project resources). /// The can be used to resolve the address of the endpoint in . diff --git a/tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.go b/tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.go index 7890993632f..e82e2d5c27b 100644 --- a/tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.go +++ b/tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.go @@ -755,6 +755,46 @@ func (s *CSharpAppResource) WithReferenceEndpoint(endpointReference *EndpointRef return result.(*IResourceWithEnvironment), nil } +// WithEndpointCallback updates a named endpoint via callback +func (s *CSharpAppResource) WithEndpointCallback(endpointName string, callback func(...any) any, createIfNotExists *bool) (*IResourceWithEndpoints, error) { + reqArgs := map[string]any{ + "builder": SerializeValue(s.Handle()), + } + reqArgs["endpointName"] = SerializeValue(endpointName) + if callback != nil { + reqArgs["callback"] = RegisterCallback(callback) + } + if createIfNotExists != nil { + reqArgs["createIfNotExists"] = SerializeValue(createIfNotExists) + } + result, err := s.Client().InvokeCapability("Aspire.Hosting/withEndpointCallback", reqArgs) + if err != nil { + return nil, err + } + return result.(*IResourceWithEndpoints), nil +} + +// WithHttpEndpointCallback updates an HTTP endpoint via callback +func (s *CSharpAppResource) WithHttpEndpointCallback(callback func(...any) any, name *string, createIfNotExists *bool) (*IResourceWithEndpoints, error) { + reqArgs := map[string]any{ + "builder": SerializeValue(s.Handle()), + } + if callback != nil { + reqArgs["callback"] = RegisterCallback(callback) + } + if name != nil { + reqArgs["name"] = SerializeValue(name) + } + if createIfNotExists != nil { + reqArgs["createIfNotExists"] = SerializeValue(createIfNotExists) + } + result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpEndpointCallback", reqArgs) + if err != nil { + return nil, err + } + return result.(*IResourceWithEndpoints), nil +} + // WithEndpoint adds a network endpoint func (s *CSharpAppResource) WithEndpoint(port *float64, targetPort *float64, scheme *string, name *string, env *string, isProxied *bool, isExternal *bool, protocol *ProtocolType) (*IResourceWithEndpoints, error) { reqArgs := map[string]any{ @@ -3901,6 +3941,46 @@ func (s *ContainerResource) WithReferenceEndpoint(endpointReference *EndpointRef return result.(*IResourceWithEnvironment), nil } +// WithEndpointCallback updates a named endpoint via callback +func (s *ContainerResource) WithEndpointCallback(endpointName string, callback func(...any) any, createIfNotExists *bool) (*IResourceWithEndpoints, error) { + reqArgs := map[string]any{ + "builder": SerializeValue(s.Handle()), + } + reqArgs["endpointName"] = SerializeValue(endpointName) + if callback != nil { + reqArgs["callback"] = RegisterCallback(callback) + } + if createIfNotExists != nil { + reqArgs["createIfNotExists"] = SerializeValue(createIfNotExists) + } + result, err := s.Client().InvokeCapability("Aspire.Hosting/withEndpointCallback", reqArgs) + if err != nil { + return nil, err + } + return result.(*IResourceWithEndpoints), nil +} + +// WithHttpEndpointCallback updates an HTTP endpoint via callback +func (s *ContainerResource) WithHttpEndpointCallback(callback func(...any) any, name *string, createIfNotExists *bool) (*IResourceWithEndpoints, error) { + reqArgs := map[string]any{ + "builder": SerializeValue(s.Handle()), + } + if callback != nil { + reqArgs["callback"] = RegisterCallback(callback) + } + if name != nil { + reqArgs["name"] = SerializeValue(name) + } + if createIfNotExists != nil { + reqArgs["createIfNotExists"] = SerializeValue(createIfNotExists) + } + result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpEndpointCallback", reqArgs) + if err != nil { + return nil, err + } + return result.(*IResourceWithEndpoints), nil +} + // WithEndpoint adds a network endpoint func (s *ContainerResource) WithEndpoint(port *float64, targetPort *float64, scheme *string, name *string, env *string, isProxied *bool, isExternal *bool, protocol *ProtocolType) (*IResourceWithEndpoints, error) { reqArgs := map[string]any{ @@ -5507,6 +5587,46 @@ func (s *DotnetToolResource) WithReferenceEndpoint(endpointReference *EndpointRe return result.(*IResourceWithEnvironment), nil } +// WithEndpointCallback updates a named endpoint via callback +func (s *DotnetToolResource) WithEndpointCallback(endpointName string, callback func(...any) any, createIfNotExists *bool) (*IResourceWithEndpoints, error) { + reqArgs := map[string]any{ + "builder": SerializeValue(s.Handle()), + } + reqArgs["endpointName"] = SerializeValue(endpointName) + if callback != nil { + reqArgs["callback"] = RegisterCallback(callback) + } + if createIfNotExists != nil { + reqArgs["createIfNotExists"] = SerializeValue(createIfNotExists) + } + result, err := s.Client().InvokeCapability("Aspire.Hosting/withEndpointCallback", reqArgs) + if err != nil { + return nil, err + } + return result.(*IResourceWithEndpoints), nil +} + +// WithHttpEndpointCallback updates an HTTP endpoint via callback +func (s *DotnetToolResource) WithHttpEndpointCallback(callback func(...any) any, name *string, createIfNotExists *bool) (*IResourceWithEndpoints, error) { + reqArgs := map[string]any{ + "builder": SerializeValue(s.Handle()), + } + if callback != nil { + reqArgs["callback"] = RegisterCallback(callback) + } + if name != nil { + reqArgs["name"] = SerializeValue(name) + } + if createIfNotExists != nil { + reqArgs["createIfNotExists"] = SerializeValue(createIfNotExists) + } + result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpEndpointCallback", reqArgs) + if err != nil { + return nil, err + } + return result.(*IResourceWithEndpoints), nil +} + // WithEndpoint adds a network endpoint func (s *DotnetToolResource) WithEndpoint(port *float64, targetPort *float64, scheme *string, name *string, env *string, isProxied *bool, isExternal *bool, protocol *ProtocolType) (*IResourceWithEndpoints, error) { reqArgs := map[string]any{ @@ -6777,6 +6897,280 @@ func (s *EndpointReferenceExpression) ValueExpression() (*string, error) { return result.(*string), nil } +// EndpointUpdateContext wraps a handle for Aspire.Hosting/Aspire.Hosting.ApplicationModel.EndpointUpdateContext. +type EndpointUpdateContext struct { + HandleWrapperBase +} + +// NewEndpointUpdateContext creates a new EndpointUpdateContext. +func NewEndpointUpdateContext(handle *Handle, client *AspireClient) *EndpointUpdateContext { + return &EndpointUpdateContext{ + HandleWrapperBase: NewHandleWrapperBase(handle, client), + } +} + +// Name gets the Name property +func (s *EndpointUpdateContext) Name() (*string, error) { + reqArgs := map[string]any{ + "context": SerializeValue(s.Handle()), + } + result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.name", reqArgs) + if err != nil { + return nil, err + } + return result.(*string), nil +} + +// Protocol gets the Protocol property +func (s *EndpointUpdateContext) Protocol() (*ProtocolType, error) { + reqArgs := map[string]any{ + "context": SerializeValue(s.Handle()), + } + result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.protocol", reqArgs) + if err != nil { + return nil, err + } + return result.(*ProtocolType), nil +} + +// SetProtocol sets the Protocol property +func (s *EndpointUpdateContext) SetProtocol(value ProtocolType) (*EndpointUpdateContext, error) { + reqArgs := map[string]any{ + "context": SerializeValue(s.Handle()), + } + reqArgs["value"] = SerializeValue(value) + result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setProtocol", reqArgs) + if err != nil { + return nil, err + } + return result.(*EndpointUpdateContext), nil +} + +// Port gets the Port property +func (s *EndpointUpdateContext) Port() (*float64, error) { + reqArgs := map[string]any{ + "context": SerializeValue(s.Handle()), + } + result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.port", reqArgs) + if err != nil { + return nil, err + } + return result.(*float64), nil +} + +// SetPort sets the Port property +func (s *EndpointUpdateContext) SetPort(value float64) (*EndpointUpdateContext, error) { + reqArgs := map[string]any{ + "context": SerializeValue(s.Handle()), + } + reqArgs["value"] = SerializeValue(value) + result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setPort", reqArgs) + if err != nil { + return nil, err + } + return result.(*EndpointUpdateContext), nil +} + +// TargetPort gets the TargetPort property +func (s *EndpointUpdateContext) TargetPort() (*float64, error) { + reqArgs := map[string]any{ + "context": SerializeValue(s.Handle()), + } + result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.targetPort", reqArgs) + if err != nil { + return nil, err + } + return result.(*float64), nil +} + +// SetTargetPort sets the TargetPort property +func (s *EndpointUpdateContext) SetTargetPort(value float64) (*EndpointUpdateContext, error) { + reqArgs := map[string]any{ + "context": SerializeValue(s.Handle()), + } + reqArgs["value"] = SerializeValue(value) + result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setTargetPort", reqArgs) + if err != nil { + return nil, err + } + return result.(*EndpointUpdateContext), nil +} + +// UriScheme gets the UriScheme property +func (s *EndpointUpdateContext) UriScheme() (*string, error) { + reqArgs := map[string]any{ + "context": SerializeValue(s.Handle()), + } + result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.uriScheme", reqArgs) + if err != nil { + return nil, err + } + return result.(*string), nil +} + +// SetUriScheme sets the UriScheme property +func (s *EndpointUpdateContext) SetUriScheme(value string) (*EndpointUpdateContext, error) { + reqArgs := map[string]any{ + "context": SerializeValue(s.Handle()), + } + reqArgs["value"] = SerializeValue(value) + result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setUriScheme", reqArgs) + if err != nil { + return nil, err + } + return result.(*EndpointUpdateContext), nil +} + +// TargetHost gets the TargetHost property +func (s *EndpointUpdateContext) TargetHost() (*string, error) { + reqArgs := map[string]any{ + "context": SerializeValue(s.Handle()), + } + result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.targetHost", reqArgs) + if err != nil { + return nil, err + } + return result.(*string), nil +} + +// SetTargetHost sets the TargetHost property +func (s *EndpointUpdateContext) SetTargetHost(value string) (*EndpointUpdateContext, error) { + reqArgs := map[string]any{ + "context": SerializeValue(s.Handle()), + } + reqArgs["value"] = SerializeValue(value) + result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setTargetHost", reqArgs) + if err != nil { + return nil, err + } + return result.(*EndpointUpdateContext), nil +} + +// Transport gets the Transport property +func (s *EndpointUpdateContext) Transport() (*string, error) { + reqArgs := map[string]any{ + "context": SerializeValue(s.Handle()), + } + result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.transport", reqArgs) + if err != nil { + return nil, err + } + return result.(*string), nil +} + +// SetTransport sets the Transport property +func (s *EndpointUpdateContext) SetTransport(value string) (*EndpointUpdateContext, error) { + reqArgs := map[string]any{ + "context": SerializeValue(s.Handle()), + } + reqArgs["value"] = SerializeValue(value) + result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setTransport", reqArgs) + if err != nil { + return nil, err + } + return result.(*EndpointUpdateContext), nil +} + +// IsExternal gets the IsExternal property +func (s *EndpointUpdateContext) IsExternal() (*bool, error) { + reqArgs := map[string]any{ + "context": SerializeValue(s.Handle()), + } + result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.isExternal", reqArgs) + if err != nil { + return nil, err + } + return result.(*bool), nil +} + +// SetIsExternal sets the IsExternal property +func (s *EndpointUpdateContext) SetIsExternal(value bool) (*EndpointUpdateContext, error) { + reqArgs := map[string]any{ + "context": SerializeValue(s.Handle()), + } + reqArgs["value"] = SerializeValue(value) + result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setIsExternal", reqArgs) + if err != nil { + return nil, err + } + return result.(*EndpointUpdateContext), nil +} + +// IsProxied gets the IsProxied property +func (s *EndpointUpdateContext) IsProxied() (*bool, error) { + reqArgs := map[string]any{ + "context": SerializeValue(s.Handle()), + } + result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.isProxied", reqArgs) + if err != nil { + return nil, err + } + return result.(*bool), nil +} + +// SetIsProxied sets the IsProxied property +func (s *EndpointUpdateContext) SetIsProxied(value bool) (*EndpointUpdateContext, error) { + reqArgs := map[string]any{ + "context": SerializeValue(s.Handle()), + } + reqArgs["value"] = SerializeValue(value) + result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setIsProxied", reqArgs) + if err != nil { + return nil, err + } + return result.(*EndpointUpdateContext), nil +} + +// ExcludeReferenceEndpoint gets the ExcludeReferenceEndpoint property +func (s *EndpointUpdateContext) ExcludeReferenceEndpoint() (*bool, error) { + reqArgs := map[string]any{ + "context": SerializeValue(s.Handle()), + } + result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.excludeReferenceEndpoint", reqArgs) + if err != nil { + return nil, err + } + return result.(*bool), nil +} + +// SetExcludeReferenceEndpoint sets the ExcludeReferenceEndpoint property +func (s *EndpointUpdateContext) SetExcludeReferenceEndpoint(value bool) (*EndpointUpdateContext, error) { + reqArgs := map[string]any{ + "context": SerializeValue(s.Handle()), + } + reqArgs["value"] = SerializeValue(value) + result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setExcludeReferenceEndpoint", reqArgs) + if err != nil { + return nil, err + } + return result.(*EndpointUpdateContext), nil +} + +// TlsEnabled gets the TlsEnabled property +func (s *EndpointUpdateContext) TlsEnabled() (*bool, error) { + reqArgs := map[string]any{ + "context": SerializeValue(s.Handle()), + } + result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.tlsEnabled", reqArgs) + if err != nil { + return nil, err + } + return result.(*bool), nil +} + +// SetTlsEnabled sets the TlsEnabled property +func (s *EndpointUpdateContext) SetTlsEnabled(value bool) (*EndpointUpdateContext, error) { + reqArgs := map[string]any{ + "context": SerializeValue(s.Handle()), + } + reqArgs["value"] = SerializeValue(value) + result, err := s.Client().InvokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setTlsEnabled", reqArgs) + if err != nil { + return nil, err + } + return result.(*EndpointUpdateContext), nil +} + // EnvironmentCallbackContext wraps a handle for Aspire.Hosting/Aspire.Hosting.ApplicationModel.EnvironmentCallbackContext. type EnvironmentCallbackContext struct { HandleWrapperBase @@ -7189,6 +7583,46 @@ func (s *ExecutableResource) WithReferenceEndpoint(endpointReference *EndpointRe return result.(*IResourceWithEnvironment), nil } +// WithEndpointCallback updates a named endpoint via callback +func (s *ExecutableResource) WithEndpointCallback(endpointName string, callback func(...any) any, createIfNotExists *bool) (*IResourceWithEndpoints, error) { + reqArgs := map[string]any{ + "builder": SerializeValue(s.Handle()), + } + reqArgs["endpointName"] = SerializeValue(endpointName) + if callback != nil { + reqArgs["callback"] = RegisterCallback(callback) + } + if createIfNotExists != nil { + reqArgs["createIfNotExists"] = SerializeValue(createIfNotExists) + } + result, err := s.Client().InvokeCapability("Aspire.Hosting/withEndpointCallback", reqArgs) + if err != nil { + return nil, err + } + return result.(*IResourceWithEndpoints), nil +} + +// WithHttpEndpointCallback updates an HTTP endpoint via callback +func (s *ExecutableResource) WithHttpEndpointCallback(callback func(...any) any, name *string, createIfNotExists *bool) (*IResourceWithEndpoints, error) { + reqArgs := map[string]any{ + "builder": SerializeValue(s.Handle()), + } + if callback != nil { + reqArgs["callback"] = RegisterCallback(callback) + } + if name != nil { + reqArgs["name"] = SerializeValue(name) + } + if createIfNotExists != nil { + reqArgs["createIfNotExists"] = SerializeValue(createIfNotExists) + } + result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpEndpointCallback", reqArgs) + if err != nil { + return nil, err + } + return result.(*IResourceWithEndpoints), nil +} + // WithEndpoint adds a network endpoint func (s *ExecutableResource) WithEndpoint(port *float64, targetPort *float64, scheme *string, name *string, env *string, isProxied *bool, isExternal *bool, protocol *ProtocolType) (*IResourceWithEndpoints, error) { reqArgs := map[string]any{ @@ -11904,6 +12338,46 @@ func (s *ProjectResource) WithReferenceEndpoint(endpointReference *EndpointRefer return result.(*IResourceWithEnvironment), nil } +// WithEndpointCallback updates a named endpoint via callback +func (s *ProjectResource) WithEndpointCallback(endpointName string, callback func(...any) any, createIfNotExists *bool) (*IResourceWithEndpoints, error) { + reqArgs := map[string]any{ + "builder": SerializeValue(s.Handle()), + } + reqArgs["endpointName"] = SerializeValue(endpointName) + if callback != nil { + reqArgs["callback"] = RegisterCallback(callback) + } + if createIfNotExists != nil { + reqArgs["createIfNotExists"] = SerializeValue(createIfNotExists) + } + result, err := s.Client().InvokeCapability("Aspire.Hosting/withEndpointCallback", reqArgs) + if err != nil { + return nil, err + } + return result.(*IResourceWithEndpoints), nil +} + +// WithHttpEndpointCallback updates an HTTP endpoint via callback +func (s *ProjectResource) WithHttpEndpointCallback(callback func(...any) any, name *string, createIfNotExists *bool) (*IResourceWithEndpoints, error) { + reqArgs := map[string]any{ + "builder": SerializeValue(s.Handle()), + } + if callback != nil { + reqArgs["callback"] = RegisterCallback(callback) + } + if name != nil { + reqArgs["name"] = SerializeValue(name) + } + if createIfNotExists != nil { + reqArgs["createIfNotExists"] = SerializeValue(createIfNotExists) + } + result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpEndpointCallback", reqArgs) + if err != nil { + return nil, err + } + return result.(*IResourceWithEndpoints), nil +} + // WithEndpoint adds a network endpoint func (s *ProjectResource) WithEndpoint(port *float64, targetPort *float64, scheme *string, name *string, env *string, isProxied *bool, isExternal *bool, protocol *ProtocolType) (*IResourceWithEndpoints, error) { reqArgs := map[string]any{ @@ -14020,6 +14494,46 @@ func (s *TestDatabaseResource) WithReferenceEndpoint(endpointReference *Endpoint return result.(*IResourceWithEnvironment), nil } +// WithEndpointCallback updates a named endpoint via callback +func (s *TestDatabaseResource) WithEndpointCallback(endpointName string, callback func(...any) any, createIfNotExists *bool) (*IResourceWithEndpoints, error) { + reqArgs := map[string]any{ + "builder": SerializeValue(s.Handle()), + } + reqArgs["endpointName"] = SerializeValue(endpointName) + if callback != nil { + reqArgs["callback"] = RegisterCallback(callback) + } + if createIfNotExists != nil { + reqArgs["createIfNotExists"] = SerializeValue(createIfNotExists) + } + result, err := s.Client().InvokeCapability("Aspire.Hosting/withEndpointCallback", reqArgs) + if err != nil { + return nil, err + } + return result.(*IResourceWithEndpoints), nil +} + +// WithHttpEndpointCallback updates an HTTP endpoint via callback +func (s *TestDatabaseResource) WithHttpEndpointCallback(callback func(...any) any, name *string, createIfNotExists *bool) (*IResourceWithEndpoints, error) { + reqArgs := map[string]any{ + "builder": SerializeValue(s.Handle()), + } + if callback != nil { + reqArgs["callback"] = RegisterCallback(callback) + } + if name != nil { + reqArgs["name"] = SerializeValue(name) + } + if createIfNotExists != nil { + reqArgs["createIfNotExists"] = SerializeValue(createIfNotExists) + } + result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpEndpointCallback", reqArgs) + if err != nil { + return nil, err + } + return result.(*IResourceWithEndpoints), nil +} + // WithEndpoint adds a network endpoint func (s *TestDatabaseResource) WithEndpoint(port *float64, targetPort *float64, scheme *string, name *string, env *string, isProxied *bool, isExternal *bool, protocol *ProtocolType) (*IResourceWithEndpoints, error) { reqArgs := map[string]any{ @@ -15680,6 +16194,46 @@ func (s *TestRedisResource) WithReferenceEndpoint(endpointReference *EndpointRef return result.(*IResourceWithEnvironment), nil } +// WithEndpointCallback updates a named endpoint via callback +func (s *TestRedisResource) WithEndpointCallback(endpointName string, callback func(...any) any, createIfNotExists *bool) (*IResourceWithEndpoints, error) { + reqArgs := map[string]any{ + "builder": SerializeValue(s.Handle()), + } + reqArgs["endpointName"] = SerializeValue(endpointName) + if callback != nil { + reqArgs["callback"] = RegisterCallback(callback) + } + if createIfNotExists != nil { + reqArgs["createIfNotExists"] = SerializeValue(createIfNotExists) + } + result, err := s.Client().InvokeCapability("Aspire.Hosting/withEndpointCallback", reqArgs) + if err != nil { + return nil, err + } + return result.(*IResourceWithEndpoints), nil +} + +// WithHttpEndpointCallback updates an HTTP endpoint via callback +func (s *TestRedisResource) WithHttpEndpointCallback(callback func(...any) any, name *string, createIfNotExists *bool) (*IResourceWithEndpoints, error) { + reqArgs := map[string]any{ + "builder": SerializeValue(s.Handle()), + } + if callback != nil { + reqArgs["callback"] = RegisterCallback(callback) + } + if name != nil { + reqArgs["name"] = SerializeValue(name) + } + if createIfNotExists != nil { + reqArgs["createIfNotExists"] = SerializeValue(createIfNotExists) + } + result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpEndpointCallback", reqArgs) + if err != nil { + return nil, err + } + return result.(*IResourceWithEndpoints), nil +} + // WithEndpoint adds a network endpoint func (s *TestRedisResource) WithEndpoint(port *float64, targetPort *float64, scheme *string, name *string, env *string, isProxied *bool, isExternal *bool, protocol *ProtocolType) (*IResourceWithEndpoints, error) { reqArgs := map[string]any{ @@ -17483,6 +18037,46 @@ func (s *TestVaultResource) WithReferenceEndpoint(endpointReference *EndpointRef return result.(*IResourceWithEnvironment), nil } +// WithEndpointCallback updates a named endpoint via callback +func (s *TestVaultResource) WithEndpointCallback(endpointName string, callback func(...any) any, createIfNotExists *bool) (*IResourceWithEndpoints, error) { + reqArgs := map[string]any{ + "builder": SerializeValue(s.Handle()), + } + reqArgs["endpointName"] = SerializeValue(endpointName) + if callback != nil { + reqArgs["callback"] = RegisterCallback(callback) + } + if createIfNotExists != nil { + reqArgs["createIfNotExists"] = SerializeValue(createIfNotExists) + } + result, err := s.Client().InvokeCapability("Aspire.Hosting/withEndpointCallback", reqArgs) + if err != nil { + return nil, err + } + return result.(*IResourceWithEndpoints), nil +} + +// WithHttpEndpointCallback updates an HTTP endpoint via callback +func (s *TestVaultResource) WithHttpEndpointCallback(callback func(...any) any, name *string, createIfNotExists *bool) (*IResourceWithEndpoints, error) { + reqArgs := map[string]any{ + "builder": SerializeValue(s.Handle()), + } + if callback != nil { + reqArgs["callback"] = RegisterCallback(callback) + } + if name != nil { + reqArgs["name"] = SerializeValue(name) + } + if createIfNotExists != nil { + reqArgs["createIfNotExists"] = SerializeValue(createIfNotExists) + } + result, err := s.Client().InvokeCapability("Aspire.Hosting/withHttpEndpointCallback", reqArgs) + if err != nil { + return nil, err + } + return result.(*IResourceWithEndpoints), nil +} + // WithEndpoint adds a network endpoint func (s *TestVaultResource) WithEndpoint(port *float64, targetPort *float64, scheme *string, name *string, env *string, isProxied *bool, isExternal *bool, protocol *ProtocolType) (*IResourceWithEndpoints, error) { reqArgs := map[string]any{ @@ -18695,6 +19289,9 @@ func init() { RegisterHandleWrapper("Aspire.Hosting/Aspire.Hosting.ApplicationModel.EndpointReferenceExpression", func(h *Handle, c *AspireClient) any { return NewEndpointReferenceExpression(h, c) }) + RegisterHandleWrapper("Aspire.Hosting/Aspire.Hosting.ApplicationModel.EndpointUpdateContext", func(h *Handle, c *AspireClient) any { + return NewEndpointUpdateContext(h, c) + }) RegisterHandleWrapper("Aspire.Hosting/Aspire.Hosting.ApplicationModel.EnvironmentCallbackContext", func(h *Handle, c *AspireClient) any { return NewEnvironmentCallbackContext(h, c) }) diff --git a/tests/Aspire.Hosting.CodeGeneration.Java.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.java b/tests/Aspire.Hosting.CodeGeneration.Java.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.java index 9c19bdd9406..c549f42c8cf 100644 --- a/tests/Aspire.Hosting.CodeGeneration.Java.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.java +++ b/tests/Aspire.Hosting.CodeGeneration.Java.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.java @@ -1078,6 +1078,7 @@ public class AspireRegistrations { AspireClient.registerHandleWrapper("Aspire.Hosting/Aspire.Hosting.ApplicationModel.ConnectionStringAvailableEvent", (h, c) -> new ConnectionStringAvailableEvent(h, c)); AspireClient.registerHandleWrapper("Aspire.Hosting/Aspire.Hosting.ApplicationModel.DistributedApplicationModel", (h, c) -> new DistributedApplicationModel(h, c)); AspireClient.registerHandleWrapper("Aspire.Hosting/Aspire.Hosting.ApplicationModel.EndpointReferenceExpression", (h, c) -> new EndpointReferenceExpression(h, c)); + AspireClient.registerHandleWrapper("Aspire.Hosting/Aspire.Hosting.ApplicationModel.EndpointUpdateContext", (h, c) -> new EndpointUpdateContext(h, c)); AspireClient.registerHandleWrapper("Aspire.Hosting/Aspire.Hosting.ApplicationModel.EnvironmentCallbackContext", (h, c) -> new EnvironmentCallbackContext(h, c)); AspireClient.registerHandleWrapper("Aspire.Hosting/Aspire.Hosting.ApplicationModel.IExpressionValue", (h, c) -> new IExpressionValue(h, c)); AspireClient.registerHandleWrapper("Aspire.Hosting/Aspire.Hosting.ApplicationModel.InitializeResourceEvent", (h, c) -> new InitializeResourceEvent(h, c)); @@ -1588,6 +1589,63 @@ public CSharpAppResource withReferenceEndpoint(EndpointReference endpointReferen return this; } + public CSharpAppResource withEndpointCallback(String endpointName, AspireAction1 callback) { + return withEndpointCallback(endpointName, callback, null); + } + + /** Updates a named endpoint via callback */ + public CSharpAppResource withEndpointCallback(String endpointName, AspireAction1 callback, Boolean createIfNotExists) { + Map reqArgs = new HashMap<>(); + reqArgs.put("builder", AspireClient.serializeValue(getHandle())); + reqArgs.put("endpointName", AspireClient.serializeValue(endpointName)); + var callbackId = getClient().registerCallback(args -> { + var obj = (EndpointUpdateContext) args[0]; + callback.invoke(obj); + return null; + }); + if (callbackId != null) { + reqArgs.put("callback", callbackId); + } + if (createIfNotExists != null) { + reqArgs.put("createIfNotExists", AspireClient.serializeValue(createIfNotExists)); + } + getClient().invokeCapability("Aspire.Hosting/withEndpointCallback", reqArgs); + return this; + } + + /** Updates an HTTP endpoint via callback */ + public CSharpAppResource withHttpEndpointCallback(AspireAction1 callback, WithHttpEndpointCallbackOptions options) { + var name = options == null ? null : options.getName(); + var createIfNotExists = options == null ? null : options.getCreateIfNotExists(); + return withHttpEndpointCallbackImpl(callback, name, createIfNotExists); + } + + public CSharpAppResource withHttpEndpointCallback(AspireAction1 callback) { + return withHttpEndpointCallback(callback, null); + } + + /** Updates an HTTP endpoint via callback */ + private CSharpAppResource withHttpEndpointCallbackImpl(AspireAction1 callback, String name, Boolean createIfNotExists) { + Map reqArgs = new HashMap<>(); + reqArgs.put("builder", AspireClient.serializeValue(getHandle())); + var callbackId = getClient().registerCallback(args -> { + var obj = (EndpointUpdateContext) args[0]; + callback.invoke(obj); + return null; + }); + if (callbackId != null) { + reqArgs.put("callback", callbackId); + } + if (name != null) { + reqArgs.put("name", AspireClient.serializeValue(name)); + } + if (createIfNotExists != null) { + reqArgs.put("createIfNotExists", AspireClient.serializeValue(createIfNotExists)); + } + getClient().invokeCapability("Aspire.Hosting/withHttpEndpointCallback", reqArgs); + return this; + } + /** Adds a network endpoint */ public CSharpAppResource withEndpoint(WithEndpointOptions options) { var port = options == null ? null : options.getPort(); @@ -4999,6 +5057,63 @@ public ContainerResource withReferenceEndpoint(EndpointReference endpointReferen return this; } + public ContainerResource withEndpointCallback(String endpointName, AspireAction1 callback) { + return withEndpointCallback(endpointName, callback, null); + } + + /** Updates a named endpoint via callback */ + public ContainerResource withEndpointCallback(String endpointName, AspireAction1 callback, Boolean createIfNotExists) { + Map reqArgs = new HashMap<>(); + reqArgs.put("builder", AspireClient.serializeValue(getHandle())); + reqArgs.put("endpointName", AspireClient.serializeValue(endpointName)); + var callbackId = getClient().registerCallback(args -> { + var obj = (EndpointUpdateContext) args[0]; + callback.invoke(obj); + return null; + }); + if (callbackId != null) { + reqArgs.put("callback", callbackId); + } + if (createIfNotExists != null) { + reqArgs.put("createIfNotExists", AspireClient.serializeValue(createIfNotExists)); + } + getClient().invokeCapability("Aspire.Hosting/withEndpointCallback", reqArgs); + return this; + } + + /** Updates an HTTP endpoint via callback */ + public ContainerResource withHttpEndpointCallback(AspireAction1 callback, WithHttpEndpointCallbackOptions options) { + var name = options == null ? null : options.getName(); + var createIfNotExists = options == null ? null : options.getCreateIfNotExists(); + return withHttpEndpointCallbackImpl(callback, name, createIfNotExists); + } + + public ContainerResource withHttpEndpointCallback(AspireAction1 callback) { + return withHttpEndpointCallback(callback, null); + } + + /** Updates an HTTP endpoint via callback */ + private ContainerResource withHttpEndpointCallbackImpl(AspireAction1 callback, String name, Boolean createIfNotExists) { + Map reqArgs = new HashMap<>(); + reqArgs.put("builder", AspireClient.serializeValue(getHandle())); + var callbackId = getClient().registerCallback(args -> { + var obj = (EndpointUpdateContext) args[0]; + callback.invoke(obj); + return null; + }); + if (callbackId != null) { + reqArgs.put("callback", callbackId); + } + if (name != null) { + reqArgs.put("name", AspireClient.serializeValue(name)); + } + if (createIfNotExists != null) { + reqArgs.put("createIfNotExists", AspireClient.serializeValue(createIfNotExists)); + } + getClient().invokeCapability("Aspire.Hosting/withHttpEndpointCallback", reqArgs); + return this; + } + /** Adds a network endpoint */ public ContainerResource withEndpoint(WithEndpointOptions options) { var port = options == null ? null : options.getPort(); @@ -6702,6 +6817,63 @@ public DotnetToolResource withReferenceEndpoint(EndpointReference endpointRefere return this; } + public DotnetToolResource withEndpointCallback(String endpointName, AspireAction1 callback) { + return withEndpointCallback(endpointName, callback, null); + } + + /** Updates a named endpoint via callback */ + public DotnetToolResource withEndpointCallback(String endpointName, AspireAction1 callback, Boolean createIfNotExists) { + Map reqArgs = new HashMap<>(); + reqArgs.put("builder", AspireClient.serializeValue(getHandle())); + reqArgs.put("endpointName", AspireClient.serializeValue(endpointName)); + var callbackId = getClient().registerCallback(args -> { + var obj = (EndpointUpdateContext) args[0]; + callback.invoke(obj); + return null; + }); + if (callbackId != null) { + reqArgs.put("callback", callbackId); + } + if (createIfNotExists != null) { + reqArgs.put("createIfNotExists", AspireClient.serializeValue(createIfNotExists)); + } + getClient().invokeCapability("Aspire.Hosting/withEndpointCallback", reqArgs); + return this; + } + + /** Updates an HTTP endpoint via callback */ + public DotnetToolResource withHttpEndpointCallback(AspireAction1 callback, WithHttpEndpointCallbackOptions options) { + var name = options == null ? null : options.getName(); + var createIfNotExists = options == null ? null : options.getCreateIfNotExists(); + return withHttpEndpointCallbackImpl(callback, name, createIfNotExists); + } + + public DotnetToolResource withHttpEndpointCallback(AspireAction1 callback) { + return withHttpEndpointCallback(callback, null); + } + + /** Updates an HTTP endpoint via callback */ + private DotnetToolResource withHttpEndpointCallbackImpl(AspireAction1 callback, String name, Boolean createIfNotExists) { + Map reqArgs = new HashMap<>(); + reqArgs.put("builder", AspireClient.serializeValue(getHandle())); + var callbackId = getClient().registerCallback(args -> { + var obj = (EndpointUpdateContext) args[0]; + callback.invoke(obj); + return null; + }); + if (callbackId != null) { + reqArgs.put("callback", callbackId); + } + if (name != null) { + reqArgs.put("name", AspireClient.serializeValue(name)); + } + if (createIfNotExists != null) { + reqArgs.put("createIfNotExists", AspireClient.serializeValue(createIfNotExists)); + } + getClient().invokeCapability("Aspire.Hosting/withHttpEndpointCallback", reqArgs); + return this; + } + /** Adds a network endpoint */ public DotnetToolResource withEndpoint(WithEndpointOptions options) { var port = options == null ? null : options.getPort(); @@ -7934,6 +8106,179 @@ public String valueExpression() { } +// ===== EndpointUpdateContext.java ===== +// EndpointUpdateContext.java - GENERATED CODE - DO NOT EDIT + +package aspire; + +import java.util.*; +import java.util.function.*; + +/** Wrapper for Aspire.Hosting/Aspire.Hosting.ApplicationModel.EndpointUpdateContext. */ +public class EndpointUpdateContext extends HandleWrapperBase { + EndpointUpdateContext(Handle handle, AspireClient client) { + super(handle, client); + } + + /** Gets the Name property */ + public String name() { + Map reqArgs = new HashMap<>(); + reqArgs.put("context", AspireClient.serializeValue(getHandle())); + return (String) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.name", reqArgs); + } + + /** Gets the Protocol property */ + public ProtocolType protocol() { + Map reqArgs = new HashMap<>(); + reqArgs.put("context", AspireClient.serializeValue(getHandle())); + return (ProtocolType) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.protocol", reqArgs); + } + + /** Sets the Protocol property */ + public EndpointUpdateContext setProtocol(ProtocolType value) { + Map reqArgs = new HashMap<>(); + reqArgs.put("context", AspireClient.serializeValue(getHandle())); + reqArgs.put("value", AspireClient.serializeValue(value)); + return (EndpointUpdateContext) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setProtocol", reqArgs); + } + + /** Gets the Port property */ + public double port() { + Map reqArgs = new HashMap<>(); + reqArgs.put("context", AspireClient.serializeValue(getHandle())); + return (double) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.port", reqArgs); + } + + /** Sets the Port property */ + public EndpointUpdateContext setPort(double value) { + Map reqArgs = new HashMap<>(); + reqArgs.put("context", AspireClient.serializeValue(getHandle())); + reqArgs.put("value", AspireClient.serializeValue(value)); + return (EndpointUpdateContext) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setPort", reqArgs); + } + + /** Gets the TargetPort property */ + public double targetPort() { + Map reqArgs = new HashMap<>(); + reqArgs.put("context", AspireClient.serializeValue(getHandle())); + return (double) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.targetPort", reqArgs); + } + + /** Sets the TargetPort property */ + public EndpointUpdateContext setTargetPort(double value) { + Map reqArgs = new HashMap<>(); + reqArgs.put("context", AspireClient.serializeValue(getHandle())); + reqArgs.put("value", AspireClient.serializeValue(value)); + return (EndpointUpdateContext) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setTargetPort", reqArgs); + } + + /** Gets the UriScheme property */ + public String uriScheme() { + Map reqArgs = new HashMap<>(); + reqArgs.put("context", AspireClient.serializeValue(getHandle())); + return (String) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.uriScheme", reqArgs); + } + + /** Sets the UriScheme property */ + public EndpointUpdateContext setUriScheme(String value) { + Map reqArgs = new HashMap<>(); + reqArgs.put("context", AspireClient.serializeValue(getHandle())); + reqArgs.put("value", AspireClient.serializeValue(value)); + return (EndpointUpdateContext) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setUriScheme", reqArgs); + } + + /** Gets the TargetHost property */ + public String targetHost() { + Map reqArgs = new HashMap<>(); + reqArgs.put("context", AspireClient.serializeValue(getHandle())); + return (String) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.targetHost", reqArgs); + } + + /** Sets the TargetHost property */ + public EndpointUpdateContext setTargetHost(String value) { + Map reqArgs = new HashMap<>(); + reqArgs.put("context", AspireClient.serializeValue(getHandle())); + reqArgs.put("value", AspireClient.serializeValue(value)); + return (EndpointUpdateContext) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setTargetHost", reqArgs); + } + + /** Gets the Transport property */ + public String transport() { + Map reqArgs = new HashMap<>(); + reqArgs.put("context", AspireClient.serializeValue(getHandle())); + return (String) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.transport", reqArgs); + } + + /** Sets the Transport property */ + public EndpointUpdateContext setTransport(String value) { + Map reqArgs = new HashMap<>(); + reqArgs.put("context", AspireClient.serializeValue(getHandle())); + reqArgs.put("value", AspireClient.serializeValue(value)); + return (EndpointUpdateContext) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setTransport", reqArgs); + } + + /** Gets the IsExternal property */ + public boolean isExternal() { + Map reqArgs = new HashMap<>(); + reqArgs.put("context", AspireClient.serializeValue(getHandle())); + return (boolean) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.isExternal", reqArgs); + } + + /** Sets the IsExternal property */ + public EndpointUpdateContext setIsExternal(boolean value) { + Map reqArgs = new HashMap<>(); + reqArgs.put("context", AspireClient.serializeValue(getHandle())); + reqArgs.put("value", AspireClient.serializeValue(value)); + return (EndpointUpdateContext) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setIsExternal", reqArgs); + } + + /** Gets the IsProxied property */ + public boolean isProxied() { + Map reqArgs = new HashMap<>(); + reqArgs.put("context", AspireClient.serializeValue(getHandle())); + return (boolean) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.isProxied", reqArgs); + } + + /** Sets the IsProxied property */ + public EndpointUpdateContext setIsProxied(boolean value) { + Map reqArgs = new HashMap<>(); + reqArgs.put("context", AspireClient.serializeValue(getHandle())); + reqArgs.put("value", AspireClient.serializeValue(value)); + return (EndpointUpdateContext) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setIsProxied", reqArgs); + } + + /** Gets the ExcludeReferenceEndpoint property */ + public boolean excludeReferenceEndpoint() { + Map reqArgs = new HashMap<>(); + reqArgs.put("context", AspireClient.serializeValue(getHandle())); + return (boolean) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.excludeReferenceEndpoint", reqArgs); + } + + /** Sets the ExcludeReferenceEndpoint property */ + public EndpointUpdateContext setExcludeReferenceEndpoint(boolean value) { + Map reqArgs = new HashMap<>(); + reqArgs.put("context", AspireClient.serializeValue(getHandle())); + reqArgs.put("value", AspireClient.serializeValue(value)); + return (EndpointUpdateContext) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setExcludeReferenceEndpoint", reqArgs); + } + + /** Gets the TlsEnabled property */ + public boolean tlsEnabled() { + Map reqArgs = new HashMap<>(); + reqArgs.put("context", AspireClient.serializeValue(getHandle())); + return (boolean) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.tlsEnabled", reqArgs); + } + + /** Sets the TlsEnabled property */ + public EndpointUpdateContext setTlsEnabled(boolean value) { + Map reqArgs = new HashMap<>(); + reqArgs.put("context", AspireClient.serializeValue(getHandle())); + reqArgs.put("value", AspireClient.serializeValue(value)); + return (EndpointUpdateContext) getClient().invokeCapability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setTlsEnabled", reqArgs); + } + +} + // ===== EnvironmentCallbackContext.java ===== // EnvironmentCallbackContext.java - GENERATED CODE - DO NOT EDIT @@ -8344,6 +8689,63 @@ public ExecutableResource withReferenceEndpoint(EndpointReference endpointRefere return this; } + public ExecutableResource withEndpointCallback(String endpointName, AspireAction1 callback) { + return withEndpointCallback(endpointName, callback, null); + } + + /** Updates a named endpoint via callback */ + public ExecutableResource withEndpointCallback(String endpointName, AspireAction1 callback, Boolean createIfNotExists) { + Map reqArgs = new HashMap<>(); + reqArgs.put("builder", AspireClient.serializeValue(getHandle())); + reqArgs.put("endpointName", AspireClient.serializeValue(endpointName)); + var callbackId = getClient().registerCallback(args -> { + var obj = (EndpointUpdateContext) args[0]; + callback.invoke(obj); + return null; + }); + if (callbackId != null) { + reqArgs.put("callback", callbackId); + } + if (createIfNotExists != null) { + reqArgs.put("createIfNotExists", AspireClient.serializeValue(createIfNotExists)); + } + getClient().invokeCapability("Aspire.Hosting/withEndpointCallback", reqArgs); + return this; + } + + /** Updates an HTTP endpoint via callback */ + public ExecutableResource withHttpEndpointCallback(AspireAction1 callback, WithHttpEndpointCallbackOptions options) { + var name = options == null ? null : options.getName(); + var createIfNotExists = options == null ? null : options.getCreateIfNotExists(); + return withHttpEndpointCallbackImpl(callback, name, createIfNotExists); + } + + public ExecutableResource withHttpEndpointCallback(AspireAction1 callback) { + return withHttpEndpointCallback(callback, null); + } + + /** Updates an HTTP endpoint via callback */ + private ExecutableResource withHttpEndpointCallbackImpl(AspireAction1 callback, String name, Boolean createIfNotExists) { + Map reqArgs = new HashMap<>(); + reqArgs.put("builder", AspireClient.serializeValue(getHandle())); + var callbackId = getClient().registerCallback(args -> { + var obj = (EndpointUpdateContext) args[0]; + callback.invoke(obj); + return null; + }); + if (callbackId != null) { + reqArgs.put("callback", callbackId); + } + if (name != null) { + reqArgs.put("name", AspireClient.serializeValue(name)); + } + if (createIfNotExists != null) { + reqArgs.put("createIfNotExists", AspireClient.serializeValue(createIfNotExists)); + } + getClient().invokeCapability("Aspire.Hosting/withHttpEndpointCallback", reqArgs); + return this; + } + /** Adds a network endpoint */ public ExecutableResource withEndpoint(WithEndpointOptions options) { var port = options == null ? null : options.getPort(); @@ -13070,6 +13472,63 @@ public ProjectResource withReferenceEndpoint(EndpointReference endpointReference return this; } + public ProjectResource withEndpointCallback(String endpointName, AspireAction1 callback) { + return withEndpointCallback(endpointName, callback, null); + } + + /** Updates a named endpoint via callback */ + public ProjectResource withEndpointCallback(String endpointName, AspireAction1 callback, Boolean createIfNotExists) { + Map reqArgs = new HashMap<>(); + reqArgs.put("builder", AspireClient.serializeValue(getHandle())); + reqArgs.put("endpointName", AspireClient.serializeValue(endpointName)); + var callbackId = getClient().registerCallback(args -> { + var obj = (EndpointUpdateContext) args[0]; + callback.invoke(obj); + return null; + }); + if (callbackId != null) { + reqArgs.put("callback", callbackId); + } + if (createIfNotExists != null) { + reqArgs.put("createIfNotExists", AspireClient.serializeValue(createIfNotExists)); + } + getClient().invokeCapability("Aspire.Hosting/withEndpointCallback", reqArgs); + return this; + } + + /** Updates an HTTP endpoint via callback */ + public ProjectResource withHttpEndpointCallback(AspireAction1 callback, WithHttpEndpointCallbackOptions options) { + var name = options == null ? null : options.getName(); + var createIfNotExists = options == null ? null : options.getCreateIfNotExists(); + return withHttpEndpointCallbackImpl(callback, name, createIfNotExists); + } + + public ProjectResource withHttpEndpointCallback(AspireAction1 callback) { + return withHttpEndpointCallback(callback, null); + } + + /** Updates an HTTP endpoint via callback */ + private ProjectResource withHttpEndpointCallbackImpl(AspireAction1 callback, String name, Boolean createIfNotExists) { + Map reqArgs = new HashMap<>(); + reqArgs.put("builder", AspireClient.serializeValue(getHandle())); + var callbackId = getClient().registerCallback(args -> { + var obj = (EndpointUpdateContext) args[0]; + callback.invoke(obj); + return null; + }); + if (callbackId != null) { + reqArgs.put("callback", callbackId); + } + if (name != null) { + reqArgs.put("name", AspireClient.serializeValue(name)); + } + if (createIfNotExists != null) { + reqArgs.put("createIfNotExists", AspireClient.serializeValue(createIfNotExists)); + } + getClient().invokeCapability("Aspire.Hosting/withHttpEndpointCallback", reqArgs); + return this; + } + /** Adds a network endpoint */ public ProjectResource withEndpoint(WithEndpointOptions options) { var port = options == null ? null : options.getPort(); @@ -15438,6 +15897,63 @@ public TestDatabaseResource withReferenceEndpoint(EndpointReference endpointRefe return this; } + public TestDatabaseResource withEndpointCallback(String endpointName, AspireAction1 callback) { + return withEndpointCallback(endpointName, callback, null); + } + + /** Updates a named endpoint via callback */ + public TestDatabaseResource withEndpointCallback(String endpointName, AspireAction1 callback, Boolean createIfNotExists) { + Map reqArgs = new HashMap<>(); + reqArgs.put("builder", AspireClient.serializeValue(getHandle())); + reqArgs.put("endpointName", AspireClient.serializeValue(endpointName)); + var callbackId = getClient().registerCallback(args -> { + var obj = (EndpointUpdateContext) args[0]; + callback.invoke(obj); + return null; + }); + if (callbackId != null) { + reqArgs.put("callback", callbackId); + } + if (createIfNotExists != null) { + reqArgs.put("createIfNotExists", AspireClient.serializeValue(createIfNotExists)); + } + getClient().invokeCapability("Aspire.Hosting/withEndpointCallback", reqArgs); + return this; + } + + /** Updates an HTTP endpoint via callback */ + public TestDatabaseResource withHttpEndpointCallback(AspireAction1 callback, WithHttpEndpointCallbackOptions options) { + var name = options == null ? null : options.getName(); + var createIfNotExists = options == null ? null : options.getCreateIfNotExists(); + return withHttpEndpointCallbackImpl(callback, name, createIfNotExists); + } + + public TestDatabaseResource withHttpEndpointCallback(AspireAction1 callback) { + return withHttpEndpointCallback(callback, null); + } + + /** Updates an HTTP endpoint via callback */ + private TestDatabaseResource withHttpEndpointCallbackImpl(AspireAction1 callback, String name, Boolean createIfNotExists) { + Map reqArgs = new HashMap<>(); + reqArgs.put("builder", AspireClient.serializeValue(getHandle())); + var callbackId = getClient().registerCallback(args -> { + var obj = (EndpointUpdateContext) args[0]; + callback.invoke(obj); + return null; + }); + if (callbackId != null) { + reqArgs.put("callback", callbackId); + } + if (name != null) { + reqArgs.put("name", AspireClient.serializeValue(name)); + } + if (createIfNotExists != null) { + reqArgs.put("createIfNotExists", AspireClient.serializeValue(createIfNotExists)); + } + getClient().invokeCapability("Aspire.Hosting/withHttpEndpointCallback", reqArgs); + return this; + } + /** Adds a network endpoint */ public TestDatabaseResource withEndpoint(WithEndpointOptions options) { var port = options == null ? null : options.getPort(); @@ -17146,6 +17662,63 @@ public TestRedisResource withReferenceEndpoint(EndpointReference endpointReferen return this; } + public TestRedisResource withEndpointCallback(String endpointName, AspireAction1 callback) { + return withEndpointCallback(endpointName, callback, null); + } + + /** Updates a named endpoint via callback */ + public TestRedisResource withEndpointCallback(String endpointName, AspireAction1 callback, Boolean createIfNotExists) { + Map reqArgs = new HashMap<>(); + reqArgs.put("builder", AspireClient.serializeValue(getHandle())); + reqArgs.put("endpointName", AspireClient.serializeValue(endpointName)); + var callbackId = getClient().registerCallback(args -> { + var obj = (EndpointUpdateContext) args[0]; + callback.invoke(obj); + return null; + }); + if (callbackId != null) { + reqArgs.put("callback", callbackId); + } + if (createIfNotExists != null) { + reqArgs.put("createIfNotExists", AspireClient.serializeValue(createIfNotExists)); + } + getClient().invokeCapability("Aspire.Hosting/withEndpointCallback", reqArgs); + return this; + } + + /** Updates an HTTP endpoint via callback */ + public TestRedisResource withHttpEndpointCallback(AspireAction1 callback, WithHttpEndpointCallbackOptions options) { + var name = options == null ? null : options.getName(); + var createIfNotExists = options == null ? null : options.getCreateIfNotExists(); + return withHttpEndpointCallbackImpl(callback, name, createIfNotExists); + } + + public TestRedisResource withHttpEndpointCallback(AspireAction1 callback) { + return withHttpEndpointCallback(callback, null); + } + + /** Updates an HTTP endpoint via callback */ + private TestRedisResource withHttpEndpointCallbackImpl(AspireAction1 callback, String name, Boolean createIfNotExists) { + Map reqArgs = new HashMap<>(); + reqArgs.put("builder", AspireClient.serializeValue(getHandle())); + var callbackId = getClient().registerCallback(args -> { + var obj = (EndpointUpdateContext) args[0]; + callback.invoke(obj); + return null; + }); + if (callbackId != null) { + reqArgs.put("callback", callbackId); + } + if (name != null) { + reqArgs.put("name", AspireClient.serializeValue(name)); + } + if (createIfNotExists != null) { + reqArgs.put("createIfNotExists", AspireClient.serializeValue(createIfNotExists)); + } + getClient().invokeCapability("Aspire.Hosting/withHttpEndpointCallback", reqArgs); + return this; + } + /** Adds a network endpoint */ public TestRedisResource withEndpoint(WithEndpointOptions options) { var port = options == null ? null : options.getPort(); @@ -18943,6 +19516,63 @@ public TestVaultResource withReferenceEndpoint(EndpointReference endpointReferen return this; } + public TestVaultResource withEndpointCallback(String endpointName, AspireAction1 callback) { + return withEndpointCallback(endpointName, callback, null); + } + + /** Updates a named endpoint via callback */ + public TestVaultResource withEndpointCallback(String endpointName, AspireAction1 callback, Boolean createIfNotExists) { + Map reqArgs = new HashMap<>(); + reqArgs.put("builder", AspireClient.serializeValue(getHandle())); + reqArgs.put("endpointName", AspireClient.serializeValue(endpointName)); + var callbackId = getClient().registerCallback(args -> { + var obj = (EndpointUpdateContext) args[0]; + callback.invoke(obj); + return null; + }); + if (callbackId != null) { + reqArgs.put("callback", callbackId); + } + if (createIfNotExists != null) { + reqArgs.put("createIfNotExists", AspireClient.serializeValue(createIfNotExists)); + } + getClient().invokeCapability("Aspire.Hosting/withEndpointCallback", reqArgs); + return this; + } + + /** Updates an HTTP endpoint via callback */ + public TestVaultResource withHttpEndpointCallback(AspireAction1 callback, WithHttpEndpointCallbackOptions options) { + var name = options == null ? null : options.getName(); + var createIfNotExists = options == null ? null : options.getCreateIfNotExists(); + return withHttpEndpointCallbackImpl(callback, name, createIfNotExists); + } + + public TestVaultResource withHttpEndpointCallback(AspireAction1 callback) { + return withHttpEndpointCallback(callback, null); + } + + /** Updates an HTTP endpoint via callback */ + private TestVaultResource withHttpEndpointCallbackImpl(AspireAction1 callback, String name, Boolean createIfNotExists) { + Map reqArgs = new HashMap<>(); + reqArgs.put("builder", AspireClient.serializeValue(getHandle())); + var callbackId = getClient().registerCallback(args -> { + var obj = (EndpointUpdateContext) args[0]; + callback.invoke(obj); + return null; + }); + if (callbackId != null) { + reqArgs.put("callback", callbackId); + } + if (name != null) { + reqArgs.put("name", AspireClient.serializeValue(name)); + } + if (createIfNotExists != null) { + reqArgs.put("createIfNotExists", AspireClient.serializeValue(createIfNotExists)); + } + getClient().invokeCapability("Aspire.Hosting/withHttpEndpointCallback", reqArgs); + return this; + } + /** Adds a network endpoint */ public TestVaultResource withEndpoint(WithEndpointOptions options) { var port = options == null ? null : options.getPort(); @@ -20277,6 +20907,33 @@ public WithExternalServiceHttpHealthCheckOptions statusCode(Double value) { } +// ===== WithHttpEndpointCallbackOptions.java ===== +// WithHttpEndpointCallbackOptions.java - GENERATED CODE - DO NOT EDIT + +package aspire; + +import java.util.*; +import java.util.function.*; + +/** Options for WithHttpEndpointCallback. */ +public final class WithHttpEndpointCallbackOptions { + private String name; + private Boolean createIfNotExists; + + public String getName() { return name; } + public WithHttpEndpointCallbackOptions name(String value) { + this.name = value; + return this; + } + + public Boolean getCreateIfNotExists() { return createIfNotExists; } + public WithHttpEndpointCallbackOptions createIfNotExists(Boolean value) { + this.createIfNotExists = value; + return this; + } + +} + // ===== WithHttpEndpointOptions.java ===== // WithHttpEndpointOptions.java - GENERATED CODE - DO NOT EDIT @@ -20730,6 +21387,7 @@ public WithVolumeOptions isReadOnly(Boolean value) { .modules/EndpointProperty.java .modules/EndpointReference.java .modules/EndpointReferenceExpression.java +.modules/EndpointUpdateContext.java .modules/EnvironmentCallbackContext.java .modules/ExecutableResource.java .modules/ExecuteCommandContext.java @@ -20810,6 +21468,7 @@ public WithVolumeOptions isReadOnly(Boolean value) { .modules/WithDockerfileOptions.java .modules/WithEndpointOptions.java .modules/WithExternalServiceHttpHealthCheckOptions.java +.modules/WithHttpEndpointCallbackOptions.java .modules/WithHttpEndpointOptions.java .modules/WithHttpHealthCheckOptions.java .modules/WithHttpProbeOptions.java diff --git a/tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.py b/tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.py index fcc8f4e2a7a..9e3f4882c4b 100644 --- a/tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.py +++ b/tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.py @@ -1599,6 +1599,18 @@ class ReferenceParameters(typing.TypedDict, total=False): name: str +class EndpointCallbackParameters(typing.TypedDict, total=False): + endpoint_name: typing.Required[str] + callback: typing.Required[typing.Callable[[EndpointUpdateContext], None]] + create_if_not_exists: bool + + +class HttpEndpointCallbackParameters(typing.TypedDict, total=False): + callback: typing.Required[typing.Callable[[EndpointUpdateContext], None]] + name: str + create_if_not_exists: bool + + class EndpointParameters(typing.TypedDict, total=False): port: int target_port: int @@ -3225,6 +3237,201 @@ def value_expression(self) -> str: return typing.cast(str, result) +class EndpointUpdateContext: + """Type class for EndpointUpdateContext.""" + + def __init__(self, handle: Handle, client: AspireClient) -> None: + self._handle = handle + self._client = client + + def __repr__(self) -> str: + return f"EndpointUpdateContext(handle={self._handle.handle_id})" + + @_uncached_property + def handle(self) -> Handle: + """The underlying object reference handle.""" + return self._handle + + @_cached_property + def name(self) -> str: + """Gets the Name property""" + result = self._client.invoke_capability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.name', + {'context': self._handle} + ) + return typing.cast(str, result) + + @_uncached_property + def protocol(self) -> ProtocolType: + """Gets the Protocol property""" + result = self._client.invoke_capability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.protocol', + {'context': self._handle} + ) + return typing.cast(ProtocolType, result) + + @protocol.setter + def protocol(self, value: ProtocolType) -> None: + """Sets the Protocol property""" + self._client.invoke_capability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setProtocol', + {'context': self._handle, 'value': value} + ) + + @_uncached_property + def port(self) -> int: + """Gets the Port property""" + result = self._client.invoke_capability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.port', + {'context': self._handle} + ) + return typing.cast(int, result) + + @port.setter + def port(self, value: int) -> None: + """Sets the Port property""" + self._client.invoke_capability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setPort', + {'context': self._handle, 'value': value} + ) + + @_uncached_property + def target_port(self) -> int: + """Gets the TargetPort property""" + result = self._client.invoke_capability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.targetPort', + {'context': self._handle} + ) + return typing.cast(int, result) + + @target_port.setter + def target_port(self, value: int) -> None: + """Sets the TargetPort property""" + self._client.invoke_capability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setTargetPort', + {'context': self._handle, 'value': value} + ) + + @_uncached_property + def uri_scheme(self) -> str: + """Gets the UriScheme property""" + result = self._client.invoke_capability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.uriScheme', + {'context': self._handle} + ) + return typing.cast(str, result) + + @uri_scheme.setter + def uri_scheme(self, value: str) -> None: + """Sets the UriScheme property""" + self._client.invoke_capability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setUriScheme', + {'context': self._handle, 'value': value} + ) + + @_uncached_property + def target_host(self) -> str: + """Gets the TargetHost property""" + result = self._client.invoke_capability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.targetHost', + {'context': self._handle} + ) + return typing.cast(str, result) + + @target_host.setter + def target_host(self, value: str) -> None: + """Sets the TargetHost property""" + self._client.invoke_capability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setTargetHost', + {'context': self._handle, 'value': value} + ) + + @_uncached_property + def transport(self) -> str: + """Gets the Transport property""" + result = self._client.invoke_capability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.transport', + {'context': self._handle} + ) + return typing.cast(str, result) + + @transport.setter + def transport(self, value: str) -> None: + """Sets the Transport property""" + self._client.invoke_capability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setTransport', + {'context': self._handle, 'value': value} + ) + + @_uncached_property + def is_external(self) -> bool: + """Gets the IsExternal property""" + result = self._client.invoke_capability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.isExternal', + {'context': self._handle} + ) + return typing.cast(bool, result) + + @is_external.setter + def is_external(self, value: bool) -> None: + """Sets the IsExternal property""" + self._client.invoke_capability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setIsExternal', + {'context': self._handle, 'value': value} + ) + + @_uncached_property + def is_proxied(self) -> bool: + """Gets the IsProxied property""" + result = self._client.invoke_capability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.isProxied', + {'context': self._handle} + ) + return typing.cast(bool, result) + + @is_proxied.setter + def is_proxied(self, value: bool) -> None: + """Sets the IsProxied property""" + self._client.invoke_capability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setIsProxied', + {'context': self._handle, 'value': value} + ) + + @_uncached_property + def exclude_reference_endpoint(self) -> bool: + """Gets the ExcludeReferenceEndpoint property""" + result = self._client.invoke_capability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.excludeReferenceEndpoint', + {'context': self._handle} + ) + return typing.cast(bool, result) + + @exclude_reference_endpoint.setter + def exclude_reference_endpoint(self, value: bool) -> None: + """Sets the ExcludeReferenceEndpoint property""" + self._client.invoke_capability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setExcludeReferenceEndpoint', + {'context': self._handle, 'value': value} + ) + + @_uncached_property + def tls_enabled(self) -> bool: + """Gets the TlsEnabled property""" + result = self._client.invoke_capability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.tlsEnabled', + {'context': self._handle} + ) + return typing.cast(bool, result) + + @tls_enabled.setter + def tls_enabled(self, value: bool) -> None: + """Sets the TlsEnabled property""" + self._client.invoke_capability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setTlsEnabled', + {'context': self._handle, 'value': value} + ) + + class EnvironmentCallbackContext: """Type class for EnvironmentCallbackContext.""" @@ -4832,6 +5039,14 @@ class AbstractResourceWithEndpoints(AbstractResource): def with_mcp_server(self, *, path: str = "/mcp", endpoint_name: str | None = None) -> typing.Self: """Configures an MCP server endpoint on the resource""" + @abc.abstractmethod + def with_endpoint_callback(self, endpoint_name: str, callback: typing.Callable[[EndpointUpdateContext], None], *, create_if_not_exists: bool = True) -> typing.Self: + """Updates a named endpoint via callback""" + + @abc.abstractmethod + def with_http_endpoint_callback(self, callback: typing.Callable[[EndpointUpdateContext], None], *, name: str | None = None, create_if_not_exists: bool = True) -> typing.Self: + """Updates an HTTP endpoint via callback""" + @abc.abstractmethod def with_endpoint(self, *, port: int | None = None, target_port: int | None = None, scheme: str | None = None, name: str | None = None, env: str | None = None, is_proxied: bool = True, is_external: bool | None = None, protocol: ProtocolType | None = None) -> typing.Self: """Adds a network endpoint""" @@ -6126,6 +6341,8 @@ class ContainerResourceKwargs(_BaseResourceKwargs, total=False): reference_uri: tuple[str, str] reference_external_service: ExternalServiceResource reference_endpoint: EndpointReference + endpoint_callback: tuple[str, typing.Callable[[EndpointUpdateContext], None]] | EndpointCallbackParameters + http_endpoint_callback: typing.Callable[[EndpointUpdateContext], None] | HttpEndpointCallbackParameters endpoint: EndpointParameters | typing.Literal[True] http_endpoint: HttpEndpointParameters | typing.Literal[True] https_endpoint: HttpsEndpointParameters | typing.Literal[True] @@ -6521,6 +6738,35 @@ def with_reference_endpoint(self, endpoint_reference: EndpointReference) -> typi self._handle = self._wrap_builder(result) return self + def with_endpoint_callback(self, endpoint_name: str, callback: typing.Callable[[EndpointUpdateContext], None], *, create_if_not_exists: bool = True) -> typing.Self: + """Updates a named endpoint via callback""" + rpc_args: dict[str, typing.Any] = {'builder': self._handle} + rpc_args['endpointName'] = endpoint_name + rpc_args['callback'] = self._client.register_callback(callback) + if create_if_not_exists is not None: + rpc_args['createIfNotExists'] = create_if_not_exists + result = self._client.invoke_capability( + 'Aspire.Hosting/withEndpointCallback', + rpc_args, + ) + self._handle = self._wrap_builder(result) + return self + + def with_http_endpoint_callback(self, callback: typing.Callable[[EndpointUpdateContext], None], *, name: str | None = None, create_if_not_exists: bool = True) -> typing.Self: + """Updates an HTTP endpoint via callback""" + rpc_args: dict[str, typing.Any] = {'builder': self._handle} + rpc_args['callback'] = self._client.register_callback(callback) + if name is not None: + rpc_args['name'] = name + if create_if_not_exists is not None: + rpc_args['createIfNotExists'] = create_if_not_exists + result = self._client.invoke_capability( + 'Aspire.Hosting/withHttpEndpointCallback', + rpc_args, + ) + self._handle = self._wrap_builder(result) + return self + def with_endpoint(self, *, port: int | None = None, target_port: int | None = None, scheme: str | None = None, name: str | None = None, env: str | None = None, is_proxied: bool = True, is_external: bool | None = None, protocol: ProtocolType | None = None) -> typing.Self: """Adds a network endpoint""" rpc_args: dict[str, typing.Any] = {'builder': self._handle} @@ -7081,6 +7327,33 @@ def __init__(self, handle: Handle, client: AspireClient, **kwargs: typing.Unpack handle = self._wrap_builder(client.invoke_capability('Aspire.Hosting/withReferenceEndpoint', rpc_args)) else: raise TypeError("Invalid type for option 'reference_endpoint'. Expected: EndpointReference") + if _endpoint_callback := kwargs.pop("endpoint_callback", None): + if _validate_tuple_types(_endpoint_callback, (str, typing.Callable[[EndpointUpdateContext], None])): + rpc_args: dict[str, typing.Any] = {"builder": handle} + rpc_args["endpointName"] = typing.cast(tuple[str, typing.Callable[[EndpointUpdateContext], None]], _endpoint_callback)[0] + rpc_args["callback"] = client.register_callback(typing.cast(tuple[str, typing.Callable[[EndpointUpdateContext], None]], _endpoint_callback)[1]) + handle = self._wrap_builder(client.invoke_capability('Aspire.Hosting/withEndpointCallback', rpc_args)) + elif _validate_dict_types(_endpoint_callback, EndpointCallbackParameters): + rpc_args: dict[str, typing.Any] = {"builder": handle} + rpc_args["endpointName"] = typing.cast(EndpointCallbackParameters, _endpoint_callback)["endpoint_name"] + rpc_args["callback"] = client.register_callback(typing.cast(EndpointCallbackParameters, _endpoint_callback)["callback"]) + rpc_args["createIfNotExists"] = typing.cast(EndpointCallbackParameters, _endpoint_callback).get("create_if_not_exists") + handle = self._wrap_builder(client.invoke_capability('Aspire.Hosting/withEndpointCallback', rpc_args)) + else: + raise TypeError("Invalid type for option 'endpoint_callback'. Expected: (str, Callable[[EndpointUpdateContext], None]) or EndpointCallbackParameters") + if _http_endpoint_callback := kwargs.pop("http_endpoint_callback", None): + if _validate_type(_http_endpoint_callback, typing.Callable[[EndpointUpdateContext], None]): + rpc_args: dict[str, typing.Any] = {"builder": handle} + rpc_args["callback"] = client.register_callback(typing.cast(typing.Callable[[EndpointUpdateContext], None], _http_endpoint_callback)) + handle = self._wrap_builder(client.invoke_capability('Aspire.Hosting/withHttpEndpointCallback', rpc_args)) + elif _validate_dict_types(_http_endpoint_callback, HttpEndpointCallbackParameters): + rpc_args: dict[str, typing.Any] = {"builder": handle} + rpc_args["callback"] = client.register_callback(typing.cast(HttpEndpointCallbackParameters, _http_endpoint_callback)["callback"]) + rpc_args["name"] = typing.cast(HttpEndpointCallbackParameters, _http_endpoint_callback).get("name") + rpc_args["createIfNotExists"] = typing.cast(HttpEndpointCallbackParameters, _http_endpoint_callback).get("create_if_not_exists") + handle = self._wrap_builder(client.invoke_capability('Aspire.Hosting/withHttpEndpointCallback', rpc_args)) + else: + raise TypeError("Invalid type for option 'http_endpoint_callback'. Expected: Callable[[EndpointUpdateContext], None] or HttpEndpointCallbackParameters") if _endpoint := kwargs.pop("endpoint", None): if _validate_dict_types(_endpoint, EndpointParameters): rpc_args: dict[str, typing.Any] = {"builder": handle} @@ -7313,6 +7586,8 @@ class ProjectResourceKwargs(_BaseResourceKwargs, total=False): reference_uri: tuple[str, str] reference_external_service: ExternalServiceResource reference_endpoint: EndpointReference + endpoint_callback: tuple[str, typing.Callable[[EndpointUpdateContext], None]] | EndpointCallbackParameters + http_endpoint_callback: typing.Callable[[EndpointUpdateContext], None] | HttpEndpointCallbackParameters endpoint: EndpointParameters | typing.Literal[True] http_endpoint: HttpEndpointParameters | typing.Literal[True] https_endpoint: HttpsEndpointParameters | typing.Literal[True] @@ -7545,6 +7820,35 @@ def with_reference_endpoint(self, endpoint_reference: EndpointReference) -> typi self._handle = self._wrap_builder(result) return self + def with_endpoint_callback(self, endpoint_name: str, callback: typing.Callable[[EndpointUpdateContext], None], *, create_if_not_exists: bool = True) -> typing.Self: + """Updates a named endpoint via callback""" + rpc_args: dict[str, typing.Any] = {'builder': self._handle} + rpc_args['endpointName'] = endpoint_name + rpc_args['callback'] = self._client.register_callback(callback) + if create_if_not_exists is not None: + rpc_args['createIfNotExists'] = create_if_not_exists + result = self._client.invoke_capability( + 'Aspire.Hosting/withEndpointCallback', + rpc_args, + ) + self._handle = self._wrap_builder(result) + return self + + def with_http_endpoint_callback(self, callback: typing.Callable[[EndpointUpdateContext], None], *, name: str | None = None, create_if_not_exists: bool = True) -> typing.Self: + """Updates an HTTP endpoint via callback""" + rpc_args: dict[str, typing.Any] = {'builder': self._handle} + rpc_args['callback'] = self._client.register_callback(callback) + if name is not None: + rpc_args['name'] = name + if create_if_not_exists is not None: + rpc_args['createIfNotExists'] = create_if_not_exists + result = self._client.invoke_capability( + 'Aspire.Hosting/withHttpEndpointCallback', + rpc_args, + ) + self._handle = self._wrap_builder(result) + return self + def with_endpoint(self, *, port: int | None = None, target_port: int | None = None, scheme: str | None = None, name: str | None = None, env: str | None = None, is_proxied: bool = True, is_external: bool | None = None, protocol: ProtocolType | None = None) -> typing.Self: """Adds a network endpoint""" rpc_args: dict[str, typing.Any] = {'builder': self._handle} @@ -7988,6 +8292,33 @@ def __init__(self, handle: Handle, client: AspireClient, **kwargs: typing.Unpack handle = self._wrap_builder(client.invoke_capability('Aspire.Hosting/withReferenceEndpoint', rpc_args)) else: raise TypeError("Invalid type for option 'reference_endpoint'. Expected: EndpointReference") + if _endpoint_callback := kwargs.pop("endpoint_callback", None): + if _validate_tuple_types(_endpoint_callback, (str, typing.Callable[[EndpointUpdateContext], None])): + rpc_args: dict[str, typing.Any] = {"builder": handle} + rpc_args["endpointName"] = typing.cast(tuple[str, typing.Callable[[EndpointUpdateContext], None]], _endpoint_callback)[0] + rpc_args["callback"] = client.register_callback(typing.cast(tuple[str, typing.Callable[[EndpointUpdateContext], None]], _endpoint_callback)[1]) + handle = self._wrap_builder(client.invoke_capability('Aspire.Hosting/withEndpointCallback', rpc_args)) + elif _validate_dict_types(_endpoint_callback, EndpointCallbackParameters): + rpc_args: dict[str, typing.Any] = {"builder": handle} + rpc_args["endpointName"] = typing.cast(EndpointCallbackParameters, _endpoint_callback)["endpoint_name"] + rpc_args["callback"] = client.register_callback(typing.cast(EndpointCallbackParameters, _endpoint_callback)["callback"]) + rpc_args["createIfNotExists"] = typing.cast(EndpointCallbackParameters, _endpoint_callback).get("create_if_not_exists") + handle = self._wrap_builder(client.invoke_capability('Aspire.Hosting/withEndpointCallback', rpc_args)) + else: + raise TypeError("Invalid type for option 'endpoint_callback'. Expected: (str, Callable[[EndpointUpdateContext], None]) or EndpointCallbackParameters") + if _http_endpoint_callback := kwargs.pop("http_endpoint_callback", None): + if _validate_type(_http_endpoint_callback, typing.Callable[[EndpointUpdateContext], None]): + rpc_args: dict[str, typing.Any] = {"builder": handle} + rpc_args["callback"] = client.register_callback(typing.cast(typing.Callable[[EndpointUpdateContext], None], _http_endpoint_callback)) + handle = self._wrap_builder(client.invoke_capability('Aspire.Hosting/withHttpEndpointCallback', rpc_args)) + elif _validate_dict_types(_http_endpoint_callback, HttpEndpointCallbackParameters): + rpc_args: dict[str, typing.Any] = {"builder": handle} + rpc_args["callback"] = client.register_callback(typing.cast(HttpEndpointCallbackParameters, _http_endpoint_callback)["callback"]) + rpc_args["name"] = typing.cast(HttpEndpointCallbackParameters, _http_endpoint_callback).get("name") + rpc_args["createIfNotExists"] = typing.cast(HttpEndpointCallbackParameters, _http_endpoint_callback).get("create_if_not_exists") + handle = self._wrap_builder(client.invoke_capability('Aspire.Hosting/withHttpEndpointCallback', rpc_args)) + else: + raise TypeError("Invalid type for option 'http_endpoint_callback'. Expected: Callable[[EndpointUpdateContext], None] or HttpEndpointCallbackParameters") if _endpoint := kwargs.pop("endpoint", None): if _validate_dict_types(_endpoint, EndpointParameters): rpc_args: dict[str, typing.Any] = {"builder": handle} @@ -8229,6 +8560,8 @@ class ExecutableResourceKwargs(_BaseResourceKwargs, total=False): reference_uri: tuple[str, str] reference_external_service: ExternalServiceResource reference_endpoint: EndpointReference + endpoint_callback: tuple[str, typing.Callable[[EndpointUpdateContext], None]] | EndpointCallbackParameters + http_endpoint_callback: typing.Callable[[EndpointUpdateContext], None] | HttpEndpointCallbackParameters endpoint: EndpointParameters | typing.Literal[True] http_endpoint: HttpEndpointParameters | typing.Literal[True] https_endpoint: HttpsEndpointParameters | typing.Literal[True] @@ -8462,6 +8795,35 @@ def with_reference_endpoint(self, endpoint_reference: EndpointReference) -> typi self._handle = self._wrap_builder(result) return self + def with_endpoint_callback(self, endpoint_name: str, callback: typing.Callable[[EndpointUpdateContext], None], *, create_if_not_exists: bool = True) -> typing.Self: + """Updates a named endpoint via callback""" + rpc_args: dict[str, typing.Any] = {'builder': self._handle} + rpc_args['endpointName'] = endpoint_name + rpc_args['callback'] = self._client.register_callback(callback) + if create_if_not_exists is not None: + rpc_args['createIfNotExists'] = create_if_not_exists + result = self._client.invoke_capability( + 'Aspire.Hosting/withEndpointCallback', + rpc_args, + ) + self._handle = self._wrap_builder(result) + return self + + def with_http_endpoint_callback(self, callback: typing.Callable[[EndpointUpdateContext], None], *, name: str | None = None, create_if_not_exists: bool = True) -> typing.Self: + """Updates an HTTP endpoint via callback""" + rpc_args: dict[str, typing.Any] = {'builder': self._handle} + rpc_args['callback'] = self._client.register_callback(callback) + if name is not None: + rpc_args['name'] = name + if create_if_not_exists is not None: + rpc_args['createIfNotExists'] = create_if_not_exists + result = self._client.invoke_capability( + 'Aspire.Hosting/withHttpEndpointCallback', + rpc_args, + ) + self._handle = self._wrap_builder(result) + return self + def with_endpoint(self, *, port: int | None = None, target_port: int | None = None, scheme: str | None = None, name: str | None = None, env: str | None = None, is_proxied: bool = True, is_external: bool | None = None, protocol: ProtocolType | None = None) -> typing.Self: """Adds a network endpoint""" rpc_args: dict[str, typing.Any] = {'builder': self._handle} @@ -8894,6 +9256,33 @@ def __init__(self, handle: Handle, client: AspireClient, **kwargs: typing.Unpack handle = self._wrap_builder(client.invoke_capability('Aspire.Hosting/withReferenceEndpoint', rpc_args)) else: raise TypeError("Invalid type for option 'reference_endpoint'. Expected: EndpointReference") + if _endpoint_callback := kwargs.pop("endpoint_callback", None): + if _validate_tuple_types(_endpoint_callback, (str, typing.Callable[[EndpointUpdateContext], None])): + rpc_args: dict[str, typing.Any] = {"builder": handle} + rpc_args["endpointName"] = typing.cast(tuple[str, typing.Callable[[EndpointUpdateContext], None]], _endpoint_callback)[0] + rpc_args["callback"] = client.register_callback(typing.cast(tuple[str, typing.Callable[[EndpointUpdateContext], None]], _endpoint_callback)[1]) + handle = self._wrap_builder(client.invoke_capability('Aspire.Hosting/withEndpointCallback', rpc_args)) + elif _validate_dict_types(_endpoint_callback, EndpointCallbackParameters): + rpc_args: dict[str, typing.Any] = {"builder": handle} + rpc_args["endpointName"] = typing.cast(EndpointCallbackParameters, _endpoint_callback)["endpoint_name"] + rpc_args["callback"] = client.register_callback(typing.cast(EndpointCallbackParameters, _endpoint_callback)["callback"]) + rpc_args["createIfNotExists"] = typing.cast(EndpointCallbackParameters, _endpoint_callback).get("create_if_not_exists") + handle = self._wrap_builder(client.invoke_capability('Aspire.Hosting/withEndpointCallback', rpc_args)) + else: + raise TypeError("Invalid type for option 'endpoint_callback'. Expected: (str, Callable[[EndpointUpdateContext], None]) or EndpointCallbackParameters") + if _http_endpoint_callback := kwargs.pop("http_endpoint_callback", None): + if _validate_type(_http_endpoint_callback, typing.Callable[[EndpointUpdateContext], None]): + rpc_args: dict[str, typing.Any] = {"builder": handle} + rpc_args["callback"] = client.register_callback(typing.cast(typing.Callable[[EndpointUpdateContext], None], _http_endpoint_callback)) + handle = self._wrap_builder(client.invoke_capability('Aspire.Hosting/withHttpEndpointCallback', rpc_args)) + elif _validate_dict_types(_http_endpoint_callback, HttpEndpointCallbackParameters): + rpc_args: dict[str, typing.Any] = {"builder": handle} + rpc_args["callback"] = client.register_callback(typing.cast(HttpEndpointCallbackParameters, _http_endpoint_callback)["callback"]) + rpc_args["name"] = typing.cast(HttpEndpointCallbackParameters, _http_endpoint_callback).get("name") + rpc_args["createIfNotExists"] = typing.cast(HttpEndpointCallbackParameters, _http_endpoint_callback).get("create_if_not_exists") + handle = self._wrap_builder(client.invoke_capability('Aspire.Hosting/withHttpEndpointCallback', rpc_args)) + else: + raise TypeError("Invalid type for option 'http_endpoint_callback'. Expected: Callable[[EndpointUpdateContext], None] or HttpEndpointCallbackParameters") if _endpoint := kwargs.pop("endpoint", None): if _validate_dict_types(_endpoint, EndpointParameters): rpc_args: dict[str, typing.Any] = {"builder": handle} @@ -9738,6 +10127,7 @@ def create_builder( _register_handle_wrapper("Aspire.Hosting/Aspire.Hosting.ApplicationModel.DistributedApplicationModel", DistributedApplicationModel) _register_handle_wrapper("Aspire.Hosting/Aspire.Hosting.ApplicationModel.EndpointReference", EndpointReference) _register_handle_wrapper("Aspire.Hosting/Aspire.Hosting.ApplicationModel.EndpointReferenceExpression", EndpointReferenceExpression) +_register_handle_wrapper("Aspire.Hosting/Aspire.Hosting.ApplicationModel.EndpointUpdateContext", EndpointUpdateContext) _register_handle_wrapper("Aspire.Hosting/Aspire.Hosting.ApplicationModel.EnvironmentCallbackContext", EnvironmentCallbackContext) _register_handle_wrapper("Aspire.Hosting/Aspire.Hosting.ApplicationModel.ExecuteCommandContext", ExecuteCommandContext) _register_handle_wrapper("Aspire.Hosting/Aspire.Hosting.ApplicationModel.InitializeResourceEvent", InitializeResourceEvent) diff --git a/tests/Aspire.Hosting.CodeGeneration.Rust.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.rs b/tests/Aspire.Hosting.CodeGeneration.Rust.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.rs index 8a31aa3be48..21a43fe9489 100644 --- a/tests/Aspire.Hosting.CodeGeneration.Rust.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.rs +++ b/tests/Aspire.Hosting.CodeGeneration.Rust.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.rs @@ -1020,6 +1020,38 @@ impl CSharpAppResource { Ok(IResourceWithEnvironment::new(handle, self.client.clone())) } + /// Updates a named endpoint via callback + pub fn with_endpoint_callback(&self, endpoint_name: &str, callback: impl Fn(Vec) -> Value + Send + Sync + 'static, create_if_not_exists: Option) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("builder".to_string(), self.handle.to_json()); + args.insert("endpointName".to_string(), serde_json::to_value(&endpoint_name).unwrap_or(Value::Null)); + let callback_id = register_callback(callback); + args.insert("callback".to_string(), Value::String(callback_id)); + if let Some(ref v) = create_if_not_exists { + args.insert("createIfNotExists".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + let result = self.client.invoke_capability("Aspire.Hosting/withEndpointCallback", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(IResourceWithEndpoints::new(handle, self.client.clone())) + } + + /// Updates an HTTP endpoint via callback + pub fn with_http_endpoint_callback(&self, callback: impl Fn(Vec) -> Value + Send + Sync + 'static, name: Option<&str>, create_if_not_exists: Option) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("builder".to_string(), self.handle.to_json()); + let callback_id = register_callback(callback); + args.insert("callback".to_string(), Value::String(callback_id)); + if let Some(ref v) = name { + args.insert("name".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + if let Some(ref v) = create_if_not_exists { + args.insert("createIfNotExists".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + let result = self.client.invoke_capability("Aspire.Hosting/withHttpEndpointCallback", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(IResourceWithEndpoints::new(handle, self.client.clone())) + } + /// Adds a network endpoint pub fn with_endpoint(&self, port: Option, target_port: Option, scheme: Option<&str>, name: Option<&str>, env: Option<&str>, is_proxied: Option, is_external: Option, protocol: Option) -> Result> { let mut args: HashMap = HashMap::new(); @@ -3565,6 +3597,38 @@ impl ContainerResource { Ok(IResourceWithEnvironment::new(handle, self.client.clone())) } + /// Updates a named endpoint via callback + pub fn with_endpoint_callback(&self, endpoint_name: &str, callback: impl Fn(Vec) -> Value + Send + Sync + 'static, create_if_not_exists: Option) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("builder".to_string(), self.handle.to_json()); + args.insert("endpointName".to_string(), serde_json::to_value(&endpoint_name).unwrap_or(Value::Null)); + let callback_id = register_callback(callback); + args.insert("callback".to_string(), Value::String(callback_id)); + if let Some(ref v) = create_if_not_exists { + args.insert("createIfNotExists".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + let result = self.client.invoke_capability("Aspire.Hosting/withEndpointCallback", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(IResourceWithEndpoints::new(handle, self.client.clone())) + } + + /// Updates an HTTP endpoint via callback + pub fn with_http_endpoint_callback(&self, callback: impl Fn(Vec) -> Value + Send + Sync + 'static, name: Option<&str>, create_if_not_exists: Option) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("builder".to_string(), self.handle.to_json()); + let callback_id = register_callback(callback); + args.insert("callback".to_string(), Value::String(callback_id)); + if let Some(ref v) = name { + args.insert("name".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + if let Some(ref v) = create_if_not_exists { + args.insert("createIfNotExists".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + let result = self.client.invoke_capability("Aspire.Hosting/withHttpEndpointCallback", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(IResourceWithEndpoints::new(handle, self.client.clone())) + } + /// Adds a network endpoint pub fn with_endpoint(&self, port: Option, target_port: Option, scheme: Option<&str>, name: Option<&str>, env: Option<&str>, is_proxied: Option, is_external: Option, protocol: Option) -> Result> { let mut args: HashMap = HashMap::new(); @@ -4943,6 +5007,38 @@ impl DotnetToolResource { Ok(IResourceWithEnvironment::new(handle, self.client.clone())) } + /// Updates a named endpoint via callback + pub fn with_endpoint_callback(&self, endpoint_name: &str, callback: impl Fn(Vec) -> Value + Send + Sync + 'static, create_if_not_exists: Option) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("builder".to_string(), self.handle.to_json()); + args.insert("endpointName".to_string(), serde_json::to_value(&endpoint_name).unwrap_or(Value::Null)); + let callback_id = register_callback(callback); + args.insert("callback".to_string(), Value::String(callback_id)); + if let Some(ref v) = create_if_not_exists { + args.insert("createIfNotExists".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + let result = self.client.invoke_capability("Aspire.Hosting/withEndpointCallback", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(IResourceWithEndpoints::new(handle, self.client.clone())) + } + + /// Updates an HTTP endpoint via callback + pub fn with_http_endpoint_callback(&self, callback: impl Fn(Vec) -> Value + Send + Sync + 'static, name: Option<&str>, create_if_not_exists: Option) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("builder".to_string(), self.handle.to_json()); + let callback_id = register_callback(callback); + args.insert("callback".to_string(), Value::String(callback_id)); + if let Some(ref v) = name { + args.insert("name".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + if let Some(ref v) = create_if_not_exists { + args.insert("createIfNotExists".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + let result = self.client.invoke_capability("Aspire.Hosting/withHttpEndpointCallback", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(IResourceWithEndpoints::new(handle, self.client.clone())) + } + /// Adds a network endpoint pub fn with_endpoint(&self, port: Option, target_port: Option, scheme: Option<&str>, name: Option<&str>, env: Option<&str>, is_proxied: Option, is_external: Option, protocol: Option) -> Result> { let mut args: HashMap = HashMap::new(); @@ -5958,6 +6054,220 @@ impl EndpointReferenceExpression { } } +/// Wrapper for Aspire.Hosting/Aspire.Hosting.ApplicationModel.EndpointUpdateContext +pub struct EndpointUpdateContext { + handle: Handle, + client: Arc, +} + +impl HasHandle for EndpointUpdateContext { + fn handle(&self) -> &Handle { + &self.handle + } +} + +impl EndpointUpdateContext { + pub fn new(handle: Handle, client: Arc) -> Self { + Self { handle, client } + } + + pub fn handle(&self) -> &Handle { + &self.handle + } + + pub fn client(&self) -> &Arc { + &self.client + } + + /// Gets the Name property + pub fn name(&self) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("context".to_string(), self.handle.to_json()); + let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.name", args)?; + Ok(serde_json::from_value(result)?) + } + + /// Gets the Protocol property + pub fn protocol(&self) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("context".to_string(), self.handle.to_json()); + let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.protocol", args)?; + Ok(serde_json::from_value(result)?) + } + + /// Sets the Protocol property + pub fn set_protocol(&self, value: ProtocolType) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("context".to_string(), self.handle.to_json()); + args.insert("value".to_string(), serde_json::to_value(&value).unwrap_or(Value::Null)); + let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setProtocol", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(EndpointUpdateContext::new(handle, self.client.clone())) + } + + /// Gets the Port property + pub fn port(&self) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("context".to_string(), self.handle.to_json()); + let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.port", args)?; + Ok(serde_json::from_value(result)?) + } + + /// Sets the Port property + pub fn set_port(&self, value: f64) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("context".to_string(), self.handle.to_json()); + args.insert("value".to_string(), serde_json::to_value(&value).unwrap_or(Value::Null)); + let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setPort", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(EndpointUpdateContext::new(handle, self.client.clone())) + } + + /// Gets the TargetPort property + pub fn target_port(&self) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("context".to_string(), self.handle.to_json()); + let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.targetPort", args)?; + Ok(serde_json::from_value(result)?) + } + + /// Sets the TargetPort property + pub fn set_target_port(&self, value: f64) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("context".to_string(), self.handle.to_json()); + args.insert("value".to_string(), serde_json::to_value(&value).unwrap_or(Value::Null)); + let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setTargetPort", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(EndpointUpdateContext::new(handle, self.client.clone())) + } + + /// Gets the UriScheme property + pub fn uri_scheme(&self) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("context".to_string(), self.handle.to_json()); + let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.uriScheme", args)?; + Ok(serde_json::from_value(result)?) + } + + /// Sets the UriScheme property + pub fn set_uri_scheme(&self, value: &str) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("context".to_string(), self.handle.to_json()); + args.insert("value".to_string(), serde_json::to_value(&value).unwrap_or(Value::Null)); + let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setUriScheme", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(EndpointUpdateContext::new(handle, self.client.clone())) + } + + /// Gets the TargetHost property + pub fn target_host(&self) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("context".to_string(), self.handle.to_json()); + let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.targetHost", args)?; + Ok(serde_json::from_value(result)?) + } + + /// Sets the TargetHost property + pub fn set_target_host(&self, value: &str) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("context".to_string(), self.handle.to_json()); + args.insert("value".to_string(), serde_json::to_value(&value).unwrap_or(Value::Null)); + let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setTargetHost", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(EndpointUpdateContext::new(handle, self.client.clone())) + } + + /// Gets the Transport property + pub fn transport(&self) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("context".to_string(), self.handle.to_json()); + let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.transport", args)?; + Ok(serde_json::from_value(result)?) + } + + /// Sets the Transport property + pub fn set_transport(&self, value: &str) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("context".to_string(), self.handle.to_json()); + args.insert("value".to_string(), serde_json::to_value(&value).unwrap_or(Value::Null)); + let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setTransport", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(EndpointUpdateContext::new(handle, self.client.clone())) + } + + /// Gets the IsExternal property + pub fn is_external(&self) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("context".to_string(), self.handle.to_json()); + let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.isExternal", args)?; + Ok(serde_json::from_value(result)?) + } + + /// Sets the IsExternal property + pub fn set_is_external(&self, value: bool) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("context".to_string(), self.handle.to_json()); + args.insert("value".to_string(), serde_json::to_value(&value).unwrap_or(Value::Null)); + let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setIsExternal", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(EndpointUpdateContext::new(handle, self.client.clone())) + } + + /// Gets the IsProxied property + pub fn is_proxied(&self) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("context".to_string(), self.handle.to_json()); + let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.isProxied", args)?; + Ok(serde_json::from_value(result)?) + } + + /// Sets the IsProxied property + pub fn set_is_proxied(&self, value: bool) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("context".to_string(), self.handle.to_json()); + args.insert("value".to_string(), serde_json::to_value(&value).unwrap_or(Value::Null)); + let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setIsProxied", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(EndpointUpdateContext::new(handle, self.client.clone())) + } + + /// Gets the ExcludeReferenceEndpoint property + pub fn exclude_reference_endpoint(&self) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("context".to_string(), self.handle.to_json()); + let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.excludeReferenceEndpoint", args)?; + Ok(serde_json::from_value(result)?) + } + + /// Sets the ExcludeReferenceEndpoint property + pub fn set_exclude_reference_endpoint(&self, value: bool) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("context".to_string(), self.handle.to_json()); + args.insert("value".to_string(), serde_json::to_value(&value).unwrap_or(Value::Null)); + let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setExcludeReferenceEndpoint", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(EndpointUpdateContext::new(handle, self.client.clone())) + } + + /// Gets the TlsEnabled property + pub fn tls_enabled(&self) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("context".to_string(), self.handle.to_json()); + let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.tlsEnabled", args)?; + Ok(serde_json::from_value(result)?) + } + + /// Sets the TlsEnabled property + pub fn set_tls_enabled(&self, value: bool) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("context".to_string(), self.handle.to_json()); + args.insert("value".to_string(), serde_json::to_value(&value).unwrap_or(Value::Null)); + let result = self.client.invoke_capability("Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setTlsEnabled", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(EndpointUpdateContext::new(handle, self.client.clone())) + } +} + /// Wrapper for Aspire.Hosting/Aspire.Hosting.ApplicationModel.EnvironmentCallbackContext pub struct EnvironmentCallbackContext { handle: Handle, @@ -6309,6 +6619,38 @@ impl ExecutableResource { Ok(IResourceWithEnvironment::new(handle, self.client.clone())) } + /// Updates a named endpoint via callback + pub fn with_endpoint_callback(&self, endpoint_name: &str, callback: impl Fn(Vec) -> Value + Send + Sync + 'static, create_if_not_exists: Option) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("builder".to_string(), self.handle.to_json()); + args.insert("endpointName".to_string(), serde_json::to_value(&endpoint_name).unwrap_or(Value::Null)); + let callback_id = register_callback(callback); + args.insert("callback".to_string(), Value::String(callback_id)); + if let Some(ref v) = create_if_not_exists { + args.insert("createIfNotExists".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + let result = self.client.invoke_capability("Aspire.Hosting/withEndpointCallback", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(IResourceWithEndpoints::new(handle, self.client.clone())) + } + + /// Updates an HTTP endpoint via callback + pub fn with_http_endpoint_callback(&self, callback: impl Fn(Vec) -> Value + Send + Sync + 'static, name: Option<&str>, create_if_not_exists: Option) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("builder".to_string(), self.handle.to_json()); + let callback_id = register_callback(callback); + args.insert("callback".to_string(), Value::String(callback_id)); + if let Some(ref v) = name { + args.insert("name".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + if let Some(ref v) = create_if_not_exists { + args.insert("createIfNotExists".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + let result = self.client.invoke_capability("Aspire.Hosting/withHttpEndpointCallback", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(IResourceWithEndpoints::new(handle, self.client.clone())) + } + /// Adds a network endpoint pub fn with_endpoint(&self, port: Option, target_port: Option, scheme: Option<&str>, name: Option<&str>, env: Option<&str>, is_proxied: Option, is_external: Option, protocol: Option) -> Result> { let mut args: HashMap = HashMap::new(); @@ -10610,6 +10952,38 @@ impl ProjectResource { Ok(IResourceWithEnvironment::new(handle, self.client.clone())) } + /// Updates a named endpoint via callback + pub fn with_endpoint_callback(&self, endpoint_name: &str, callback: impl Fn(Vec) -> Value + Send + Sync + 'static, create_if_not_exists: Option) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("builder".to_string(), self.handle.to_json()); + args.insert("endpointName".to_string(), serde_json::to_value(&endpoint_name).unwrap_or(Value::Null)); + let callback_id = register_callback(callback); + args.insert("callback".to_string(), Value::String(callback_id)); + if let Some(ref v) = create_if_not_exists { + args.insert("createIfNotExists".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + let result = self.client.invoke_capability("Aspire.Hosting/withEndpointCallback", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(IResourceWithEndpoints::new(handle, self.client.clone())) + } + + /// Updates an HTTP endpoint via callback + pub fn with_http_endpoint_callback(&self, callback: impl Fn(Vec) -> Value + Send + Sync + 'static, name: Option<&str>, create_if_not_exists: Option) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("builder".to_string(), self.handle.to_json()); + let callback_id = register_callback(callback); + args.insert("callback".to_string(), Value::String(callback_id)); + if let Some(ref v) = name { + args.insert("name".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + if let Some(ref v) = create_if_not_exists { + args.insert("createIfNotExists".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + let result = self.client.invoke_capability("Aspire.Hosting/withHttpEndpointCallback", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(IResourceWithEndpoints::new(handle, self.client.clone())) + } + /// Adds a network endpoint pub fn with_endpoint(&self, port: Option, target_port: Option, scheme: Option<&str>, name: Option<&str>, env: Option<&str>, is_proxied: Option, is_external: Option, protocol: Option) -> Result> { let mut args: HashMap = HashMap::new(); @@ -12449,6 +12823,38 @@ impl TestDatabaseResource { Ok(IResourceWithEnvironment::new(handle, self.client.clone())) } + /// Updates a named endpoint via callback + pub fn with_endpoint_callback(&self, endpoint_name: &str, callback: impl Fn(Vec) -> Value + Send + Sync + 'static, create_if_not_exists: Option) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("builder".to_string(), self.handle.to_json()); + args.insert("endpointName".to_string(), serde_json::to_value(&endpoint_name).unwrap_or(Value::Null)); + let callback_id = register_callback(callback); + args.insert("callback".to_string(), Value::String(callback_id)); + if let Some(ref v) = create_if_not_exists { + args.insert("createIfNotExists".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + let result = self.client.invoke_capability("Aspire.Hosting/withEndpointCallback", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(IResourceWithEndpoints::new(handle, self.client.clone())) + } + + /// Updates an HTTP endpoint via callback + pub fn with_http_endpoint_callback(&self, callback: impl Fn(Vec) -> Value + Send + Sync + 'static, name: Option<&str>, create_if_not_exists: Option) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("builder".to_string(), self.handle.to_json()); + let callback_id = register_callback(callback); + args.insert("callback".to_string(), Value::String(callback_id)); + if let Some(ref v) = name { + args.insert("name".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + if let Some(ref v) = create_if_not_exists { + args.insert("createIfNotExists".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + let result = self.client.invoke_capability("Aspire.Hosting/withHttpEndpointCallback", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(IResourceWithEndpoints::new(handle, self.client.clone())) + } + /// Adds a network endpoint pub fn with_endpoint(&self, port: Option, target_port: Option, scheme: Option<&str>, name: Option<&str>, env: Option<&str>, is_proxied: Option, is_external: Option, protocol: Option) -> Result> { let mut args: HashMap = HashMap::new(); @@ -13786,6 +14192,38 @@ impl TestRedisResource { Ok(IResourceWithEnvironment::new(handle, self.client.clone())) } + /// Updates a named endpoint via callback + pub fn with_endpoint_callback(&self, endpoint_name: &str, callback: impl Fn(Vec) -> Value + Send + Sync + 'static, create_if_not_exists: Option) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("builder".to_string(), self.handle.to_json()); + args.insert("endpointName".to_string(), serde_json::to_value(&endpoint_name).unwrap_or(Value::Null)); + let callback_id = register_callback(callback); + args.insert("callback".to_string(), Value::String(callback_id)); + if let Some(ref v) = create_if_not_exists { + args.insert("createIfNotExists".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + let result = self.client.invoke_capability("Aspire.Hosting/withEndpointCallback", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(IResourceWithEndpoints::new(handle, self.client.clone())) + } + + /// Updates an HTTP endpoint via callback + pub fn with_http_endpoint_callback(&self, callback: impl Fn(Vec) -> Value + Send + Sync + 'static, name: Option<&str>, create_if_not_exists: Option) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("builder".to_string(), self.handle.to_json()); + let callback_id = register_callback(callback); + args.insert("callback".to_string(), Value::String(callback_id)); + if let Some(ref v) = name { + args.insert("name".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + if let Some(ref v) = create_if_not_exists { + args.insert("createIfNotExists".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + let result = self.client.invoke_capability("Aspire.Hosting/withHttpEndpointCallback", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(IResourceWithEndpoints::new(handle, self.client.clone())) + } + /// Adds a network endpoint pub fn with_endpoint(&self, port: Option, target_port: Option, scheme: Option<&str>, name: Option<&str>, env: Option<&str>, is_proxied: Option, is_external: Option, protocol: Option) -> Result> { let mut args: HashMap = HashMap::new(); @@ -15234,6 +15672,38 @@ impl TestVaultResource { Ok(IResourceWithEnvironment::new(handle, self.client.clone())) } + /// Updates a named endpoint via callback + pub fn with_endpoint_callback(&self, endpoint_name: &str, callback: impl Fn(Vec) -> Value + Send + Sync + 'static, create_if_not_exists: Option) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("builder".to_string(), self.handle.to_json()); + args.insert("endpointName".to_string(), serde_json::to_value(&endpoint_name).unwrap_or(Value::Null)); + let callback_id = register_callback(callback); + args.insert("callback".to_string(), Value::String(callback_id)); + if let Some(ref v) = create_if_not_exists { + args.insert("createIfNotExists".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + let result = self.client.invoke_capability("Aspire.Hosting/withEndpointCallback", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(IResourceWithEndpoints::new(handle, self.client.clone())) + } + + /// Updates an HTTP endpoint via callback + pub fn with_http_endpoint_callback(&self, callback: impl Fn(Vec) -> Value + Send + Sync + 'static, name: Option<&str>, create_if_not_exists: Option) -> Result> { + let mut args: HashMap = HashMap::new(); + args.insert("builder".to_string(), self.handle.to_json()); + let callback_id = register_callback(callback); + args.insert("callback".to_string(), Value::String(callback_id)); + if let Some(ref v) = name { + args.insert("name".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + if let Some(ref v) = create_if_not_exists { + args.insert("createIfNotExists".to_string(), serde_json::to_value(v).unwrap_or(Value::Null)); + } + let result = self.client.invoke_capability("Aspire.Hosting/withHttpEndpointCallback", args)?; + let handle: Handle = serde_json::from_value(result)?; + Ok(IResourceWithEndpoints::new(handle, self.client.clone())) + } + /// Adds a network endpoint pub fn with_endpoint(&self, port: Option, target_port: Option, scheme: Option<&str>, name: Option<&str>, env: Option<&str>, is_proxied: Option, is_external: Option, protocol: Option) -> Result> { let mut args: HashMap = HashMap::new(); diff --git a/tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/HostingContainerResourceCapabilities.verified.txt b/tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/HostingContainerResourceCapabilities.verified.txt index 04910ccc106..faf0d4be256 100644 --- a/tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/HostingContainerResourceCapabilities.verified.txt +++ b/tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/HostingContainerResourceCapabilities.verified.txt @@ -447,6 +447,20 @@ } ] }, + { + CapabilityId: Aspire.Hosting/withEndpointCallback, + MethodName: withEndpointCallback, + TargetType: { + TypeId: Aspire.Hosting/Aspire.Hosting.ApplicationModel.IResourceWithEndpoints, + IsInterface: true + }, + ExpandedTargetTypes: [ + { + TypeId: Aspire.Hosting/Aspire.Hosting.ApplicationModel.ContainerResource, + IsInterface: false + } + ] + }, { CapabilityId: Aspire.Hosting/withEndpointProxySupport, MethodName: withEndpointProxySupport, @@ -615,6 +629,20 @@ } ] }, + { + CapabilityId: Aspire.Hosting/withHttpEndpointCallback, + MethodName: withHttpEndpointCallback, + TargetType: { + TypeId: Aspire.Hosting/Aspire.Hosting.ApplicationModel.IResourceWithEndpoints, + IsInterface: true + }, + ExpandedTargetTypes: [ + { + TypeId: Aspire.Hosting/Aspire.Hosting.ApplicationModel.ContainerResource, + IsInterface: false + } + ] + }, { CapabilityId: Aspire.Hosting/withHttpHealthCheck, MethodName: withHttpHealthCheck, diff --git a/tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts b/tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts index 03c76b21116..779b6a21f83 100644 --- a/tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts +++ b/tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts @@ -91,6 +91,9 @@ type EndpointReferenceHandle = Handle<'Aspire.Hosting/Aspire.Hosting.Application /** Handle to EndpointReferenceExpression */ type EndpointReferenceExpressionHandle = Handle<'Aspire.Hosting/Aspire.Hosting.ApplicationModel.EndpointReferenceExpression'>; +/** Handle to EndpointUpdateContext */ +type EndpointUpdateContextHandle = Handle<'Aspire.Hosting/Aspire.Hosting.ApplicationModel.EndpointUpdateContext'>; + /** Handle to EnvironmentCallbackContext */ type EnvironmentCallbackContextHandle = Handle<'Aspire.Hosting/Aspire.Hosting.ApplicationModel.EnvironmentCallbackContext'>; @@ -594,6 +597,10 @@ export interface WithDockerfileOptions { stage?: string; } +export interface WithEndpointCallbackOptions { + createIfNotExists?: boolean; +} + export interface WithEndpointOptions { port?: number; targetPort?: number; @@ -610,6 +617,11 @@ export interface WithExternalServiceHttpHealthCheckOptions { statusCode?: number; } +export interface WithHttpEndpointCallbackOptions { + name?: string; + createIfNotExists?: boolean; +} + export interface WithHttpEndpointOptions { port?: number; targetPort?: number; @@ -1592,6 +1604,242 @@ class EndpointReferenceExpressionImpl implements EndpointReferenceExpression { } +// ============================================================================ +// EndpointUpdateContext +// ============================================================================ + +export interface EndpointUpdateContext { + toJSON(): MarshalledHandle; + name: { + get: () => Promise; + }; + protocol: { + get: () => Promise; + set: (value: ProtocolType) => Promise; + }; + port: { + get: () => Promise; + set: (value: number) => Promise; + }; + targetPort: { + get: () => Promise; + set: (value: number) => Promise; + }; + uriScheme: { + get: () => Promise; + set: (value: string) => Promise; + }; + targetHost: { + get: () => Promise; + set: (value: string) => Promise; + }; + transport: { + get: () => Promise; + set: (value: string) => Promise; + }; + isExternal: { + get: () => Promise; + set: (value: boolean) => Promise; + }; + isProxied: { + get: () => Promise; + set: (value: boolean) => Promise; + }; + excludeReferenceEndpoint: { + get: () => Promise; + set: (value: boolean) => Promise; + }; + tlsEnabled: { + get: () => Promise; + set: (value: boolean) => Promise; + }; +} + +// ============================================================================ +// EndpointUpdateContextImpl +// ============================================================================ + +/** + * Type class for EndpointUpdateContext. + */ +class EndpointUpdateContextImpl implements EndpointUpdateContext { + constructor(private _handle: EndpointUpdateContextHandle, private _client: AspireClientRpc) {} + + /** Serialize for JSON-RPC transport */ + toJSON(): MarshalledHandle { return this._handle.toJSON(); } + + /** Gets the Name property */ + name = { + get: async (): Promise => { + return await this._client.invokeCapability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.name', + { context: this._handle } + ); + }, + }; + + /** Gets the Protocol property */ + protocol = { + get: async (): Promise => { + return await this._client.invokeCapability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.protocol', + { context: this._handle } + ); + }, + set: async (value: ProtocolType): Promise => { + await this._client.invokeCapability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setProtocol', + { context: this._handle, value } + ); + } + }; + + /** Gets the Port property */ + port = { + get: async (): Promise => { + return await this._client.invokeCapability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.port', + { context: this._handle } + ); + }, + set: async (value: number): Promise => { + await this._client.invokeCapability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setPort', + { context: this._handle, value } + ); + } + }; + + /** Gets the TargetPort property */ + targetPort = { + get: async (): Promise => { + return await this._client.invokeCapability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.targetPort', + { context: this._handle } + ); + }, + set: async (value: number): Promise => { + await this._client.invokeCapability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setTargetPort', + { context: this._handle, value } + ); + } + }; + + /** Gets the UriScheme property */ + uriScheme = { + get: async (): Promise => { + return await this._client.invokeCapability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.uriScheme', + { context: this._handle } + ); + }, + set: async (value: string): Promise => { + await this._client.invokeCapability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setUriScheme', + { context: this._handle, value } + ); + } + }; + + /** Gets the TargetHost property */ + targetHost = { + get: async (): Promise => { + return await this._client.invokeCapability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.targetHost', + { context: this._handle } + ); + }, + set: async (value: string): Promise => { + await this._client.invokeCapability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setTargetHost', + { context: this._handle, value } + ); + } + }; + + /** Gets the Transport property */ + transport = { + get: async (): Promise => { + return await this._client.invokeCapability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.transport', + { context: this._handle } + ); + }, + set: async (value: string): Promise => { + await this._client.invokeCapability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setTransport', + { context: this._handle, value } + ); + } + }; + + /** Gets the IsExternal property */ + isExternal = { + get: async (): Promise => { + return await this._client.invokeCapability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.isExternal', + { context: this._handle } + ); + }, + set: async (value: boolean): Promise => { + await this._client.invokeCapability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setIsExternal', + { context: this._handle, value } + ); + } + }; + + /** Gets the IsProxied property */ + isProxied = { + get: async (): Promise => { + return await this._client.invokeCapability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.isProxied', + { context: this._handle } + ); + }, + set: async (value: boolean): Promise => { + await this._client.invokeCapability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setIsProxied', + { context: this._handle, value } + ); + } + }; + + /** Gets the ExcludeReferenceEndpoint property */ + excludeReferenceEndpoint = { + get: async (): Promise => { + return await this._client.invokeCapability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.excludeReferenceEndpoint', + { context: this._handle } + ); + }, + set: async (value: boolean): Promise => { + await this._client.invokeCapability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setExcludeReferenceEndpoint', + { context: this._handle, value } + ); + } + }; + + /** Gets the TlsEnabled property */ + tlsEnabled = { + get: async (): Promise => { + return await this._client.invokeCapability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.tlsEnabled', + { context: this._handle } + ); + }, + set: async (value: boolean): Promise => { + await this._client.invokeCapability( + 'Aspire.Hosting.ApplicationModel/EndpointUpdateContext.setTlsEnabled', + { context: this._handle, value } + ); + } + }; + +} + // ============================================================================ // EnvironmentCallbackContext // ============================================================================ @@ -8037,6 +8285,8 @@ export interface ContainerResource { withReferenceUri(name: string, uri: string): ContainerResourcePromise; withReferenceExternalService(externalService: ExternalServiceResource): ContainerResourcePromise; withReferenceEndpoint(endpointReference: EndpointReference): ContainerResourcePromise; + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): ContainerResourcePromise; + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): ContainerResourcePromise; withEndpoint(options?: WithEndpointOptions): ContainerResourcePromise; withHttpEndpoint(options?: WithHttpEndpointOptions): ContainerResourcePromise; withHttpsEndpoint(options?: WithHttpsEndpointOptions): ContainerResourcePromise; @@ -8140,6 +8390,8 @@ export interface ContainerResourcePromise extends PromiseLike withReferenceUri(name: string, uri: string): ContainerResourcePromise; withReferenceExternalService(externalService: ExternalServiceResource): ContainerResourcePromise; withReferenceEndpoint(endpointReference: EndpointReference): ContainerResourcePromise; + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): ContainerResourcePromise; + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): ContainerResourcePromise; withEndpoint(options?: WithEndpointOptions): ContainerResourcePromise; withHttpEndpoint(options?: WithHttpEndpointOptions): ContainerResourcePromise; withHttpsEndpoint(options?: WithHttpsEndpointOptions): ContainerResourcePromise; @@ -8787,6 +9039,52 @@ class ContainerResourceImpl extends ResourceBuilderBase return new ContainerResourcePromiseImpl(this._withReferenceEndpointInternal(endpointReference)); } + /** @internal */ + private async _withEndpointCallbackInternal(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, createIfNotExists?: boolean): Promise { + const callbackId = registerCallback(async (objData: unknown) => { + const objHandle = wrapIfHandle(objData) as EndpointUpdateContextHandle; + const obj = new EndpointUpdateContextImpl(objHandle, this._client); + await callback(obj); + }); + const rpcArgs: Record = { builder: this._handle, endpointName, callback: callbackId }; + if (createIfNotExists !== undefined) rpcArgs.createIfNotExists = createIfNotExists; + const result = await this._client.invokeCapability( + 'Aspire.Hosting/withEndpointCallback', + rpcArgs + ); + return new ContainerResourceImpl(result, this._client); + } + + /** Updates a named endpoint via callback */ + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): ContainerResourcePromise { + const createIfNotExists = options?.createIfNotExists; + return new ContainerResourcePromiseImpl(this._withEndpointCallbackInternal(endpointName, callback, createIfNotExists)); + } + + /** @internal */ + private async _withHttpEndpointCallbackInternal(callback: (obj: EndpointUpdateContext) => Promise, name?: string, createIfNotExists?: boolean): Promise { + const callbackId = registerCallback(async (objData: unknown) => { + const objHandle = wrapIfHandle(objData) as EndpointUpdateContextHandle; + const obj = new EndpointUpdateContextImpl(objHandle, this._client); + await callback(obj); + }); + const rpcArgs: Record = { builder: this._handle, callback: callbackId }; + if (name !== undefined) rpcArgs.name = name; + if (createIfNotExists !== undefined) rpcArgs.createIfNotExists = createIfNotExists; + const result = await this._client.invokeCapability( + 'Aspire.Hosting/withHttpEndpointCallback', + rpcArgs + ); + return new ContainerResourceImpl(result, this._client); + } + + /** Updates an HTTP endpoint via callback */ + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): ContainerResourcePromise { + const name = options?.name; + const createIfNotExists = options?.createIfNotExists; + return new ContainerResourcePromiseImpl(this._withHttpEndpointCallbackInternal(callback, name, createIfNotExists)); + } + /** @internal */ private async _withEndpointInternal(port?: number, targetPort?: number, scheme?: string, name?: string, env?: string, isProxied?: boolean, isExternal?: boolean, protocol?: ProtocolType): Promise { const rpcArgs: Record = { builder: this._handle }; @@ -10121,6 +10419,16 @@ class ContainerResourcePromiseImpl implements ContainerResourcePromise { return new ContainerResourcePromiseImpl(this._promise.then(obj => obj.withReferenceEndpoint(endpointReference))); } + /** Updates a named endpoint via callback */ + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): ContainerResourcePromise { + return new ContainerResourcePromiseImpl(this._promise.then(obj => obj.withEndpointCallback(endpointName, callback, options))); + } + + /** Updates an HTTP endpoint via callback */ + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): ContainerResourcePromise { + return new ContainerResourcePromiseImpl(this._promise.then(obj => obj.withHttpEndpointCallback(callback, options))); + } + /** Adds a network endpoint */ withEndpoint(options?: WithEndpointOptions): ContainerResourcePromise { return new ContainerResourcePromiseImpl(this._promise.then(obj => obj.withEndpoint(options))); @@ -10475,6 +10783,8 @@ export interface CSharpAppResource { withReferenceUri(name: string, uri: string): CSharpAppResourcePromise; withReferenceExternalService(externalService: ExternalServiceResource): CSharpAppResourcePromise; withReferenceEndpoint(endpointReference: EndpointReference): CSharpAppResourcePromise; + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): CSharpAppResourcePromise; + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): CSharpAppResourcePromise; withEndpoint(options?: WithEndpointOptions): CSharpAppResourcePromise; withHttpEndpoint(options?: WithHttpEndpointOptions): CSharpAppResourcePromise; withHttpsEndpoint(options?: WithHttpsEndpointOptions): CSharpAppResourcePromise; @@ -10564,6 +10874,8 @@ export interface CSharpAppResourcePromise extends PromiseLike withReferenceUri(name: string, uri: string): CSharpAppResourcePromise; withReferenceExternalService(externalService: ExternalServiceResource): CSharpAppResourcePromise; withReferenceEndpoint(endpointReference: EndpointReference): CSharpAppResourcePromise; + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): CSharpAppResourcePromise; + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): CSharpAppResourcePromise; withEndpoint(options?: WithEndpointOptions): CSharpAppResourcePromise; withHttpEndpoint(options?: WithHttpEndpointOptions): CSharpAppResourcePromise; withHttpsEndpoint(options?: WithHttpsEndpointOptions): CSharpAppResourcePromise; @@ -11000,6 +11312,52 @@ class CSharpAppResourceImpl extends ResourceBuilderBase return new CSharpAppResourcePromiseImpl(this._withReferenceEndpointInternal(endpointReference)); } + /** @internal */ + private async _withEndpointCallbackInternal(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, createIfNotExists?: boolean): Promise { + const callbackId = registerCallback(async (objData: unknown) => { + const objHandle = wrapIfHandle(objData) as EndpointUpdateContextHandle; + const obj = new EndpointUpdateContextImpl(objHandle, this._client); + await callback(obj); + }); + const rpcArgs: Record = { builder: this._handle, endpointName, callback: callbackId }; + if (createIfNotExists !== undefined) rpcArgs.createIfNotExists = createIfNotExists; + const result = await this._client.invokeCapability( + 'Aspire.Hosting/withEndpointCallback', + rpcArgs + ); + return new CSharpAppResourceImpl(result, this._client); + } + + /** Updates a named endpoint via callback */ + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): CSharpAppResourcePromise { + const createIfNotExists = options?.createIfNotExists; + return new CSharpAppResourcePromiseImpl(this._withEndpointCallbackInternal(endpointName, callback, createIfNotExists)); + } + + /** @internal */ + private async _withHttpEndpointCallbackInternal(callback: (obj: EndpointUpdateContext) => Promise, name?: string, createIfNotExists?: boolean): Promise { + const callbackId = registerCallback(async (objData: unknown) => { + const objHandle = wrapIfHandle(objData) as EndpointUpdateContextHandle; + const obj = new EndpointUpdateContextImpl(objHandle, this._client); + await callback(obj); + }); + const rpcArgs: Record = { builder: this._handle, callback: callbackId }; + if (name !== undefined) rpcArgs.name = name; + if (createIfNotExists !== undefined) rpcArgs.createIfNotExists = createIfNotExists; + const result = await this._client.invokeCapability( + 'Aspire.Hosting/withHttpEndpointCallback', + rpcArgs + ); + return new CSharpAppResourceImpl(result, this._client); + } + + /** Updates an HTTP endpoint via callback */ + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): CSharpAppResourcePromise { + const name = options?.name; + const createIfNotExists = options?.createIfNotExists; + return new CSharpAppResourcePromiseImpl(this._withHttpEndpointCallbackInternal(callback, name, createIfNotExists)); + } + /** @internal */ private async _withEndpointInternal(port?: number, targetPort?: number, scheme?: string, name?: string, env?: string, isProxied?: boolean, isExternal?: boolean, protocol?: ProtocolType): Promise { const rpcArgs: Record = { builder: this._handle }; @@ -12260,6 +12618,16 @@ class CSharpAppResourcePromiseImpl implements CSharpAppResourcePromise { return new CSharpAppResourcePromiseImpl(this._promise.then(obj => obj.withReferenceEndpoint(endpointReference))); } + /** Updates a named endpoint via callback */ + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): CSharpAppResourcePromise { + return new CSharpAppResourcePromiseImpl(this._promise.then(obj => obj.withEndpointCallback(endpointName, callback, options))); + } + + /** Updates an HTTP endpoint via callback */ + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): CSharpAppResourcePromise { + return new CSharpAppResourcePromiseImpl(this._promise.then(obj => obj.withHttpEndpointCallback(callback, options))); + } + /** Adds a network endpoint */ withEndpoint(options?: WithEndpointOptions): CSharpAppResourcePromise { return new CSharpAppResourcePromiseImpl(this._promise.then(obj => obj.withEndpoint(options))); @@ -12621,6 +12989,8 @@ export interface DotnetToolResource { withReferenceUri(name: string, uri: string): DotnetToolResourcePromise; withReferenceExternalService(externalService: ExternalServiceResource): DotnetToolResourcePromise; withReferenceEndpoint(endpointReference: EndpointReference): DotnetToolResourcePromise; + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): DotnetToolResourcePromise; + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): DotnetToolResourcePromise; withEndpoint(options?: WithEndpointOptions): DotnetToolResourcePromise; withHttpEndpoint(options?: WithHttpEndpointOptions): DotnetToolResourcePromise; withHttpsEndpoint(options?: WithHttpsEndpointOptions): DotnetToolResourcePromise; @@ -12716,6 +13086,8 @@ export interface DotnetToolResourcePromise extends PromiseLike Promise, options?: WithEndpointCallbackOptions): DotnetToolResourcePromise; + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): DotnetToolResourcePromise; withEndpoint(options?: WithEndpointOptions): DotnetToolResourcePromise; withHttpEndpoint(options?: WithHttpEndpointOptions): DotnetToolResourcePromise; withHttpsEndpoint(options?: WithHttpsEndpointOptions): DotnetToolResourcePromise; @@ -13254,6 +13626,52 @@ class DotnetToolResourceImpl extends ResourceBuilderBase Promise, createIfNotExists?: boolean): Promise { + const callbackId = registerCallback(async (objData: unknown) => { + const objHandle = wrapIfHandle(objData) as EndpointUpdateContextHandle; + const obj = new EndpointUpdateContextImpl(objHandle, this._client); + await callback(obj); + }); + const rpcArgs: Record = { builder: this._handle, endpointName, callback: callbackId }; + if (createIfNotExists !== undefined) rpcArgs.createIfNotExists = createIfNotExists; + const result = await this._client.invokeCapability( + 'Aspire.Hosting/withEndpointCallback', + rpcArgs + ); + return new DotnetToolResourceImpl(result, this._client); + } + + /** Updates a named endpoint via callback */ + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): DotnetToolResourcePromise { + const createIfNotExists = options?.createIfNotExists; + return new DotnetToolResourcePromiseImpl(this._withEndpointCallbackInternal(endpointName, callback, createIfNotExists)); + } + + /** @internal */ + private async _withHttpEndpointCallbackInternal(callback: (obj: EndpointUpdateContext) => Promise, name?: string, createIfNotExists?: boolean): Promise { + const callbackId = registerCallback(async (objData: unknown) => { + const objHandle = wrapIfHandle(objData) as EndpointUpdateContextHandle; + const obj = new EndpointUpdateContextImpl(objHandle, this._client); + await callback(obj); + }); + const rpcArgs: Record = { builder: this._handle, callback: callbackId }; + if (name !== undefined) rpcArgs.name = name; + if (createIfNotExists !== undefined) rpcArgs.createIfNotExists = createIfNotExists; + const result = await this._client.invokeCapability( + 'Aspire.Hosting/withHttpEndpointCallback', + rpcArgs + ); + return new DotnetToolResourceImpl(result, this._client); + } + + /** Updates an HTTP endpoint via callback */ + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): DotnetToolResourcePromise { + const name = options?.name; + const createIfNotExists = options?.createIfNotExists; + return new DotnetToolResourcePromiseImpl(this._withHttpEndpointCallbackInternal(callback, name, createIfNotExists)); + } + /** @internal */ private async _withEndpointInternal(port?: number, targetPort?: number, scheme?: string, name?: string, env?: string, isProxied?: boolean, isExternal?: boolean, protocol?: ProtocolType): Promise { const rpcArgs: Record = { builder: this._handle }; @@ -14534,6 +14952,16 @@ class DotnetToolResourcePromiseImpl implements DotnetToolResourcePromise { return new DotnetToolResourcePromiseImpl(this._promise.then(obj => obj.withReferenceEndpoint(endpointReference))); } + /** Updates a named endpoint via callback */ + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): DotnetToolResourcePromise { + return new DotnetToolResourcePromiseImpl(this._promise.then(obj => obj.withEndpointCallback(endpointName, callback, options))); + } + + /** Updates an HTTP endpoint via callback */ + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): DotnetToolResourcePromise { + return new DotnetToolResourcePromiseImpl(this._promise.then(obj => obj.withHttpEndpointCallback(callback, options))); + } + /** Adds a network endpoint */ withEndpoint(options?: WithEndpointOptions): DotnetToolResourcePromise { return new DotnetToolResourcePromiseImpl(this._promise.then(obj => obj.withEndpoint(options))); @@ -14884,6 +15312,8 @@ export interface ExecutableResource { withReferenceUri(name: string, uri: string): ExecutableResourcePromise; withReferenceExternalService(externalService: ExternalServiceResource): ExecutableResourcePromise; withReferenceEndpoint(endpointReference: EndpointReference): ExecutableResourcePromise; + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): ExecutableResourcePromise; + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): ExecutableResourcePromise; withEndpoint(options?: WithEndpointOptions): ExecutableResourcePromise; withHttpEndpoint(options?: WithHttpEndpointOptions): ExecutableResourcePromise; withHttpsEndpoint(options?: WithHttpsEndpointOptions): ExecutableResourcePromise; @@ -14973,6 +15403,8 @@ export interface ExecutableResourcePromise extends PromiseLike Promise, options?: WithEndpointCallbackOptions): ExecutableResourcePromise; + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): ExecutableResourcePromise; withEndpoint(options?: WithEndpointOptions): ExecutableResourcePromise; withHttpEndpoint(options?: WithHttpEndpointOptions): ExecutableResourcePromise; withHttpsEndpoint(options?: WithHttpsEndpointOptions): ExecutableResourcePromise; @@ -15421,6 +15853,52 @@ class ExecutableResourceImpl extends ResourceBuilderBase Promise, createIfNotExists?: boolean): Promise { + const callbackId = registerCallback(async (objData: unknown) => { + const objHandle = wrapIfHandle(objData) as EndpointUpdateContextHandle; + const obj = new EndpointUpdateContextImpl(objHandle, this._client); + await callback(obj); + }); + const rpcArgs: Record = { builder: this._handle, endpointName, callback: callbackId }; + if (createIfNotExists !== undefined) rpcArgs.createIfNotExists = createIfNotExists; + const result = await this._client.invokeCapability( + 'Aspire.Hosting/withEndpointCallback', + rpcArgs + ); + return new ExecutableResourceImpl(result, this._client); + } + + /** Updates a named endpoint via callback */ + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): ExecutableResourcePromise { + const createIfNotExists = options?.createIfNotExists; + return new ExecutableResourcePromiseImpl(this._withEndpointCallbackInternal(endpointName, callback, createIfNotExists)); + } + + /** @internal */ + private async _withHttpEndpointCallbackInternal(callback: (obj: EndpointUpdateContext) => Promise, name?: string, createIfNotExists?: boolean): Promise { + const callbackId = registerCallback(async (objData: unknown) => { + const objHandle = wrapIfHandle(objData) as EndpointUpdateContextHandle; + const obj = new EndpointUpdateContextImpl(objHandle, this._client); + await callback(obj); + }); + const rpcArgs: Record = { builder: this._handle, callback: callbackId }; + if (name !== undefined) rpcArgs.name = name; + if (createIfNotExists !== undefined) rpcArgs.createIfNotExists = createIfNotExists; + const result = await this._client.invokeCapability( + 'Aspire.Hosting/withHttpEndpointCallback', + rpcArgs + ); + return new ExecutableResourceImpl(result, this._client); + } + + /** Updates an HTTP endpoint via callback */ + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): ExecutableResourcePromise { + const name = options?.name; + const createIfNotExists = options?.createIfNotExists; + return new ExecutableResourcePromiseImpl(this._withHttpEndpointCallbackInternal(callback, name, createIfNotExists)); + } + /** @internal */ private async _withEndpointInternal(port?: number, targetPort?: number, scheme?: string, name?: string, env?: string, isProxied?: boolean, isExternal?: boolean, protocol?: ProtocolType): Promise { const rpcArgs: Record = { builder: this._handle }; @@ -16671,6 +17149,16 @@ class ExecutableResourcePromiseImpl implements ExecutableResourcePromise { return new ExecutableResourcePromiseImpl(this._promise.then(obj => obj.withReferenceEndpoint(endpointReference))); } + /** Updates a named endpoint via callback */ + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): ExecutableResourcePromise { + return new ExecutableResourcePromiseImpl(this._promise.then(obj => obj.withEndpointCallback(endpointName, callback, options))); + } + + /** Updates an HTTP endpoint via callback */ + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): ExecutableResourcePromise { + return new ExecutableResourcePromiseImpl(this._promise.then(obj => obj.withHttpEndpointCallback(callback, options))); + } + /** Adds a network endpoint */ withEndpoint(options?: WithEndpointOptions): ExecutableResourcePromise { return new ExecutableResourcePromiseImpl(this._promise.then(obj => obj.withEndpoint(options))); @@ -19260,6 +19748,8 @@ export interface ProjectResource { withReferenceUri(name: string, uri: string): ProjectResourcePromise; withReferenceExternalService(externalService: ExternalServiceResource): ProjectResourcePromise; withReferenceEndpoint(endpointReference: EndpointReference): ProjectResourcePromise; + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): ProjectResourcePromise; + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): ProjectResourcePromise; withEndpoint(options?: WithEndpointOptions): ProjectResourcePromise; withHttpEndpoint(options?: WithHttpEndpointOptions): ProjectResourcePromise; withHttpsEndpoint(options?: WithHttpsEndpointOptions): ProjectResourcePromise; @@ -19349,6 +19839,8 @@ export interface ProjectResourcePromise extends PromiseLike { withReferenceUri(name: string, uri: string): ProjectResourcePromise; withReferenceExternalService(externalService: ExternalServiceResource): ProjectResourcePromise; withReferenceEndpoint(endpointReference: EndpointReference): ProjectResourcePromise; + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): ProjectResourcePromise; + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): ProjectResourcePromise; withEndpoint(options?: WithEndpointOptions): ProjectResourcePromise; withHttpEndpoint(options?: WithHttpEndpointOptions): ProjectResourcePromise; withHttpsEndpoint(options?: WithHttpsEndpointOptions): ProjectResourcePromise; @@ -19785,6 +20277,52 @@ class ProjectResourceImpl extends ResourceBuilderBase imp return new ProjectResourcePromiseImpl(this._withReferenceEndpointInternal(endpointReference)); } + /** @internal */ + private async _withEndpointCallbackInternal(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, createIfNotExists?: boolean): Promise { + const callbackId = registerCallback(async (objData: unknown) => { + const objHandle = wrapIfHandle(objData) as EndpointUpdateContextHandle; + const obj = new EndpointUpdateContextImpl(objHandle, this._client); + await callback(obj); + }); + const rpcArgs: Record = { builder: this._handle, endpointName, callback: callbackId }; + if (createIfNotExists !== undefined) rpcArgs.createIfNotExists = createIfNotExists; + const result = await this._client.invokeCapability( + 'Aspire.Hosting/withEndpointCallback', + rpcArgs + ); + return new ProjectResourceImpl(result, this._client); + } + + /** Updates a named endpoint via callback */ + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): ProjectResourcePromise { + const createIfNotExists = options?.createIfNotExists; + return new ProjectResourcePromiseImpl(this._withEndpointCallbackInternal(endpointName, callback, createIfNotExists)); + } + + /** @internal */ + private async _withHttpEndpointCallbackInternal(callback: (obj: EndpointUpdateContext) => Promise, name?: string, createIfNotExists?: boolean): Promise { + const callbackId = registerCallback(async (objData: unknown) => { + const objHandle = wrapIfHandle(objData) as EndpointUpdateContextHandle; + const obj = new EndpointUpdateContextImpl(objHandle, this._client); + await callback(obj); + }); + const rpcArgs: Record = { builder: this._handle, callback: callbackId }; + if (name !== undefined) rpcArgs.name = name; + if (createIfNotExists !== undefined) rpcArgs.createIfNotExists = createIfNotExists; + const result = await this._client.invokeCapability( + 'Aspire.Hosting/withHttpEndpointCallback', + rpcArgs + ); + return new ProjectResourceImpl(result, this._client); + } + + /** Updates an HTTP endpoint via callback */ + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): ProjectResourcePromise { + const name = options?.name; + const createIfNotExists = options?.createIfNotExists; + return new ProjectResourcePromiseImpl(this._withHttpEndpointCallbackInternal(callback, name, createIfNotExists)); + } + /** @internal */ private async _withEndpointInternal(port?: number, targetPort?: number, scheme?: string, name?: string, env?: string, isProxied?: boolean, isExternal?: boolean, protocol?: ProtocolType): Promise { const rpcArgs: Record = { builder: this._handle }; @@ -21045,6 +21583,16 @@ class ProjectResourcePromiseImpl implements ProjectResourcePromise { return new ProjectResourcePromiseImpl(this._promise.then(obj => obj.withReferenceEndpoint(endpointReference))); } + /** Updates a named endpoint via callback */ + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): ProjectResourcePromise { + return new ProjectResourcePromiseImpl(this._promise.then(obj => obj.withEndpointCallback(endpointName, callback, options))); + } + + /** Updates an HTTP endpoint via callback */ + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): ProjectResourcePromise { + return new ProjectResourcePromiseImpl(this._promise.then(obj => obj.withHttpEndpointCallback(callback, options))); + } + /** Adds a network endpoint */ withEndpoint(options?: WithEndpointOptions): ProjectResourcePromise { return new ProjectResourcePromiseImpl(this._promise.then(obj => obj.withEndpoint(options))); @@ -21413,6 +21961,8 @@ export interface TestDatabaseResource { withReferenceUri(name: string, uri: string): TestDatabaseResourcePromise; withReferenceExternalService(externalService: ExternalServiceResource): TestDatabaseResourcePromise; withReferenceEndpoint(endpointReference: EndpointReference): TestDatabaseResourcePromise; + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): TestDatabaseResourcePromise; + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): TestDatabaseResourcePromise; withEndpoint(options?: WithEndpointOptions): TestDatabaseResourcePromise; withHttpEndpoint(options?: WithHttpEndpointOptions): TestDatabaseResourcePromise; withHttpsEndpoint(options?: WithHttpsEndpointOptions): TestDatabaseResourcePromise; @@ -21516,6 +22066,8 @@ export interface TestDatabaseResourcePromise extends PromiseLike Promise, options?: WithEndpointCallbackOptions): TestDatabaseResourcePromise; + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): TestDatabaseResourcePromise; withEndpoint(options?: WithEndpointOptions): TestDatabaseResourcePromise; withHttpEndpoint(options?: WithHttpEndpointOptions): TestDatabaseResourcePromise; withHttpsEndpoint(options?: WithHttpsEndpointOptions): TestDatabaseResourcePromise; @@ -22163,6 +22715,52 @@ class TestDatabaseResourceImpl extends ResourceBuilderBase Promise, createIfNotExists?: boolean): Promise { + const callbackId = registerCallback(async (objData: unknown) => { + const objHandle = wrapIfHandle(objData) as EndpointUpdateContextHandle; + const obj = new EndpointUpdateContextImpl(objHandle, this._client); + await callback(obj); + }); + const rpcArgs: Record = { builder: this._handle, endpointName, callback: callbackId }; + if (createIfNotExists !== undefined) rpcArgs.createIfNotExists = createIfNotExists; + const result = await this._client.invokeCapability( + 'Aspire.Hosting/withEndpointCallback', + rpcArgs + ); + return new TestDatabaseResourceImpl(result, this._client); + } + + /** Updates a named endpoint via callback */ + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): TestDatabaseResourcePromise { + const createIfNotExists = options?.createIfNotExists; + return new TestDatabaseResourcePromiseImpl(this._withEndpointCallbackInternal(endpointName, callback, createIfNotExists)); + } + + /** @internal */ + private async _withHttpEndpointCallbackInternal(callback: (obj: EndpointUpdateContext) => Promise, name?: string, createIfNotExists?: boolean): Promise { + const callbackId = registerCallback(async (objData: unknown) => { + const objHandle = wrapIfHandle(objData) as EndpointUpdateContextHandle; + const obj = new EndpointUpdateContextImpl(objHandle, this._client); + await callback(obj); + }); + const rpcArgs: Record = { builder: this._handle, callback: callbackId }; + if (name !== undefined) rpcArgs.name = name; + if (createIfNotExists !== undefined) rpcArgs.createIfNotExists = createIfNotExists; + const result = await this._client.invokeCapability( + 'Aspire.Hosting/withHttpEndpointCallback', + rpcArgs + ); + return new TestDatabaseResourceImpl(result, this._client); + } + + /** Updates an HTTP endpoint via callback */ + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): TestDatabaseResourcePromise { + const name = options?.name; + const createIfNotExists = options?.createIfNotExists; + return new TestDatabaseResourcePromiseImpl(this._withHttpEndpointCallbackInternal(callback, name, createIfNotExists)); + } + /** @internal */ private async _withEndpointInternal(port?: number, targetPort?: number, scheme?: string, name?: string, env?: string, isProxied?: boolean, isExternal?: boolean, protocol?: ProtocolType): Promise { const rpcArgs: Record = { builder: this._handle }; @@ -23497,6 +24095,16 @@ class TestDatabaseResourcePromiseImpl implements TestDatabaseResourcePromise { return new TestDatabaseResourcePromiseImpl(this._promise.then(obj => obj.withReferenceEndpoint(endpointReference))); } + /** Updates a named endpoint via callback */ + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): TestDatabaseResourcePromise { + return new TestDatabaseResourcePromiseImpl(this._promise.then(obj => obj.withEndpointCallback(endpointName, callback, options))); + } + + /** Updates an HTTP endpoint via callback */ + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): TestDatabaseResourcePromise { + return new TestDatabaseResourcePromiseImpl(this._promise.then(obj => obj.withHttpEndpointCallback(callback, options))); + } + /** Adds a network endpoint */ withEndpoint(options?: WithEndpointOptions): TestDatabaseResourcePromise { return new TestDatabaseResourcePromiseImpl(this._promise.then(obj => obj.withEndpoint(options))); @@ -23868,6 +24476,8 @@ export interface TestRedisResource { withReferenceUri(name: string, uri: string): TestRedisResourcePromise; withReferenceExternalService(externalService: ExternalServiceResource): TestRedisResourcePromise; withReferenceEndpoint(endpointReference: EndpointReference): TestRedisResourcePromise; + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): TestRedisResourcePromise; + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): TestRedisResourcePromise; withEndpoint(options?: WithEndpointOptions): TestRedisResourcePromise; withHttpEndpoint(options?: WithHttpEndpointOptions): TestRedisResourcePromise; withHttpsEndpoint(options?: WithHttpsEndpointOptions): TestRedisResourcePromise; @@ -23987,6 +24597,8 @@ export interface TestRedisResourcePromise extends PromiseLike withReferenceUri(name: string, uri: string): TestRedisResourcePromise; withReferenceExternalService(externalService: ExternalServiceResource): TestRedisResourcePromise; withReferenceEndpoint(endpointReference: EndpointReference): TestRedisResourcePromise; + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): TestRedisResourcePromise; + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): TestRedisResourcePromise; withEndpoint(options?: WithEndpointOptions): TestRedisResourcePromise; withHttpEndpoint(options?: WithHttpEndpointOptions): TestRedisResourcePromise; withHttpsEndpoint(options?: WithHttpsEndpointOptions): TestRedisResourcePromise; @@ -24686,6 +25298,52 @@ class TestRedisResourceImpl extends ResourceBuilderBase return new TestRedisResourcePromiseImpl(this._withReferenceEndpointInternal(endpointReference)); } + /** @internal */ + private async _withEndpointCallbackInternal(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, createIfNotExists?: boolean): Promise { + const callbackId = registerCallback(async (objData: unknown) => { + const objHandle = wrapIfHandle(objData) as EndpointUpdateContextHandle; + const obj = new EndpointUpdateContextImpl(objHandle, this._client); + await callback(obj); + }); + const rpcArgs: Record = { builder: this._handle, endpointName, callback: callbackId }; + if (createIfNotExists !== undefined) rpcArgs.createIfNotExists = createIfNotExists; + const result = await this._client.invokeCapability( + 'Aspire.Hosting/withEndpointCallback', + rpcArgs + ); + return new TestRedisResourceImpl(result, this._client); + } + + /** Updates a named endpoint via callback */ + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): TestRedisResourcePromise { + const createIfNotExists = options?.createIfNotExists; + return new TestRedisResourcePromiseImpl(this._withEndpointCallbackInternal(endpointName, callback, createIfNotExists)); + } + + /** @internal */ + private async _withHttpEndpointCallbackInternal(callback: (obj: EndpointUpdateContext) => Promise, name?: string, createIfNotExists?: boolean): Promise { + const callbackId = registerCallback(async (objData: unknown) => { + const objHandle = wrapIfHandle(objData) as EndpointUpdateContextHandle; + const obj = new EndpointUpdateContextImpl(objHandle, this._client); + await callback(obj); + }); + const rpcArgs: Record = { builder: this._handle, callback: callbackId }; + if (name !== undefined) rpcArgs.name = name; + if (createIfNotExists !== undefined) rpcArgs.createIfNotExists = createIfNotExists; + const result = await this._client.invokeCapability( + 'Aspire.Hosting/withHttpEndpointCallback', + rpcArgs + ); + return new TestRedisResourceImpl(result, this._client); + } + + /** Updates an HTTP endpoint via callback */ + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): TestRedisResourcePromise { + const name = options?.name; + const createIfNotExists = options?.createIfNotExists; + return new TestRedisResourcePromiseImpl(this._withHttpEndpointCallbackInternal(callback, name, createIfNotExists)); + } + /** @internal */ private async _withEndpointInternal(port?: number, targetPort?: number, scheme?: string, name?: string, env?: string, isProxied?: boolean, isExternal?: boolean, protocol?: ProtocolType): Promise { const rpcArgs: Record = { builder: this._handle }; @@ -26224,6 +26882,16 @@ class TestRedisResourcePromiseImpl implements TestRedisResourcePromise { return new TestRedisResourcePromiseImpl(this._promise.then(obj => obj.withReferenceEndpoint(endpointReference))); } + /** Updates a named endpoint via callback */ + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): TestRedisResourcePromise { + return new TestRedisResourcePromiseImpl(this._promise.then(obj => obj.withEndpointCallback(endpointName, callback, options))); + } + + /** Updates an HTTP endpoint via callback */ + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): TestRedisResourcePromise { + return new TestRedisResourcePromiseImpl(this._promise.then(obj => obj.withHttpEndpointCallback(callback, options))); + } + /** Adds a network endpoint */ withEndpoint(options?: WithEndpointOptions): TestRedisResourcePromise { return new TestRedisResourcePromiseImpl(this._promise.then(obj => obj.withEndpoint(options))); @@ -26657,6 +27325,8 @@ export interface TestVaultResource { withReferenceUri(name: string, uri: string): TestVaultResourcePromise; withReferenceExternalService(externalService: ExternalServiceResource): TestVaultResourcePromise; withReferenceEndpoint(endpointReference: EndpointReference): TestVaultResourcePromise; + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): TestVaultResourcePromise; + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): TestVaultResourcePromise; withEndpoint(options?: WithEndpointOptions): TestVaultResourcePromise; withHttpEndpoint(options?: WithHttpEndpointOptions): TestVaultResourcePromise; withHttpsEndpoint(options?: WithHttpsEndpointOptions): TestVaultResourcePromise; @@ -26761,6 +27431,8 @@ export interface TestVaultResourcePromise extends PromiseLike withReferenceUri(name: string, uri: string): TestVaultResourcePromise; withReferenceExternalService(externalService: ExternalServiceResource): TestVaultResourcePromise; withReferenceEndpoint(endpointReference: EndpointReference): TestVaultResourcePromise; + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): TestVaultResourcePromise; + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): TestVaultResourcePromise; withEndpoint(options?: WithEndpointOptions): TestVaultResourcePromise; withHttpEndpoint(options?: WithHttpEndpointOptions): TestVaultResourcePromise; withHttpsEndpoint(options?: WithHttpsEndpointOptions): TestVaultResourcePromise; @@ -27409,6 +28081,52 @@ class TestVaultResourceImpl extends ResourceBuilderBase return new TestVaultResourcePromiseImpl(this._withReferenceEndpointInternal(endpointReference)); } + /** @internal */ + private async _withEndpointCallbackInternal(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, createIfNotExists?: boolean): Promise { + const callbackId = registerCallback(async (objData: unknown) => { + const objHandle = wrapIfHandle(objData) as EndpointUpdateContextHandle; + const obj = new EndpointUpdateContextImpl(objHandle, this._client); + await callback(obj); + }); + const rpcArgs: Record = { builder: this._handle, endpointName, callback: callbackId }; + if (createIfNotExists !== undefined) rpcArgs.createIfNotExists = createIfNotExists; + const result = await this._client.invokeCapability( + 'Aspire.Hosting/withEndpointCallback', + rpcArgs + ); + return new TestVaultResourceImpl(result, this._client); + } + + /** Updates a named endpoint via callback */ + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): TestVaultResourcePromise { + const createIfNotExists = options?.createIfNotExists; + return new TestVaultResourcePromiseImpl(this._withEndpointCallbackInternal(endpointName, callback, createIfNotExists)); + } + + /** @internal */ + private async _withHttpEndpointCallbackInternal(callback: (obj: EndpointUpdateContext) => Promise, name?: string, createIfNotExists?: boolean): Promise { + const callbackId = registerCallback(async (objData: unknown) => { + const objHandle = wrapIfHandle(objData) as EndpointUpdateContextHandle; + const obj = new EndpointUpdateContextImpl(objHandle, this._client); + await callback(obj); + }); + const rpcArgs: Record = { builder: this._handle, callback: callbackId }; + if (name !== undefined) rpcArgs.name = name; + if (createIfNotExists !== undefined) rpcArgs.createIfNotExists = createIfNotExists; + const result = await this._client.invokeCapability( + 'Aspire.Hosting/withHttpEndpointCallback', + rpcArgs + ); + return new TestVaultResourceImpl(result, this._client); + } + + /** Updates an HTTP endpoint via callback */ + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): TestVaultResourcePromise { + const name = options?.name; + const createIfNotExists = options?.createIfNotExists; + return new TestVaultResourcePromiseImpl(this._withHttpEndpointCallbackInternal(callback, name, createIfNotExists)); + } + /** @internal */ private async _withEndpointInternal(port?: number, targetPort?: number, scheme?: string, name?: string, env?: string, isProxied?: boolean, isExternal?: boolean, protocol?: ProtocolType): Promise { const rpcArgs: Record = { builder: this._handle }; @@ -28758,6 +29476,16 @@ class TestVaultResourcePromiseImpl implements TestVaultResourcePromise { return new TestVaultResourcePromiseImpl(this._promise.then(obj => obj.withReferenceEndpoint(endpointReference))); } + /** Updates a named endpoint via callback */ + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): TestVaultResourcePromise { + return new TestVaultResourcePromiseImpl(this._promise.then(obj => obj.withEndpointCallback(endpointName, callback, options))); + } + + /** Updates an HTTP endpoint via callback */ + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): TestVaultResourcePromise { + return new TestVaultResourcePromiseImpl(this._promise.then(obj => obj.withHttpEndpointCallback(callback, options))); + } + /** Adds a network endpoint */ withEndpoint(options?: WithEndpointOptions): TestVaultResourcePromise { return new TestVaultResourcePromiseImpl(this._promise.then(obj => obj.withEndpoint(options))); @@ -30677,6 +31405,8 @@ class ResourceWithContainerFilesPromiseImpl implements ResourceWithContainerFile export interface ResourceWithEndpoints { toJSON(): MarshalledHandle; withMcpServer(options?: WithMcpServerOptions): ResourceWithEndpointsPromise; + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): ResourceWithEndpointsPromise; + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): ResourceWithEndpointsPromise; withEndpoint(options?: WithEndpointOptions): ResourceWithEndpointsPromise; withHttpEndpoint(options?: WithHttpEndpointOptions): ResourceWithEndpointsPromise; withHttpsEndpoint(options?: WithHttpsEndpointOptions): ResourceWithEndpointsPromise; @@ -30691,6 +31421,8 @@ export interface ResourceWithEndpoints { export interface ResourceWithEndpointsPromise extends PromiseLike { withMcpServer(options?: WithMcpServerOptions): ResourceWithEndpointsPromise; + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): ResourceWithEndpointsPromise; + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): ResourceWithEndpointsPromise; withEndpoint(options?: WithEndpointOptions): ResourceWithEndpointsPromise; withHttpEndpoint(options?: WithHttpEndpointOptions): ResourceWithEndpointsPromise; withHttpsEndpoint(options?: WithHttpsEndpointOptions): ResourceWithEndpointsPromise; @@ -30731,6 +31463,52 @@ class ResourceWithEndpointsImpl extends ResourceBuilderBase Promise, createIfNotExists?: boolean): Promise { + const callbackId = registerCallback(async (objData: unknown) => { + const objHandle = wrapIfHandle(objData) as EndpointUpdateContextHandle; + const obj = new EndpointUpdateContextImpl(objHandle, this._client); + await callback(obj); + }); + const rpcArgs: Record = { builder: this._handle, endpointName, callback: callbackId }; + if (createIfNotExists !== undefined) rpcArgs.createIfNotExists = createIfNotExists; + const result = await this._client.invokeCapability( + 'Aspire.Hosting/withEndpointCallback', + rpcArgs + ); + return new ResourceWithEndpointsImpl(result, this._client); + } + + /** Updates a named endpoint via callback */ + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): ResourceWithEndpointsPromise { + const createIfNotExists = options?.createIfNotExists; + return new ResourceWithEndpointsPromiseImpl(this._withEndpointCallbackInternal(endpointName, callback, createIfNotExists)); + } + + /** @internal */ + private async _withHttpEndpointCallbackInternal(callback: (obj: EndpointUpdateContext) => Promise, name?: string, createIfNotExists?: boolean): Promise { + const callbackId = registerCallback(async (objData: unknown) => { + const objHandle = wrapIfHandle(objData) as EndpointUpdateContextHandle; + const obj = new EndpointUpdateContextImpl(objHandle, this._client); + await callback(obj); + }); + const rpcArgs: Record = { builder: this._handle, callback: callbackId }; + if (name !== undefined) rpcArgs.name = name; + if (createIfNotExists !== undefined) rpcArgs.createIfNotExists = createIfNotExists; + const result = await this._client.invokeCapability( + 'Aspire.Hosting/withHttpEndpointCallback', + rpcArgs + ); + return new ResourceWithEndpointsImpl(result, this._client); + } + + /** Updates an HTTP endpoint via callback */ + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): ResourceWithEndpointsPromise { + const name = options?.name; + const createIfNotExists = options?.createIfNotExists; + return new ResourceWithEndpointsPromiseImpl(this._withHttpEndpointCallbackInternal(callback, name, createIfNotExists)); + } + /** @internal */ private async _withEndpointInternal(port?: number, targetPort?: number, scheme?: string, name?: string, env?: string, isProxied?: boolean, isExternal?: boolean, protocol?: ProtocolType): Promise { const rpcArgs: Record = { builder: this._handle }; @@ -30963,6 +31741,16 @@ class ResourceWithEndpointsPromiseImpl implements ResourceWithEndpointsPromise { return new ResourceWithEndpointsPromiseImpl(this._promise.then(obj => obj.withMcpServer(options))); } + /** Updates a named endpoint via callback */ + withEndpointCallback(endpointName: string, callback: (obj: EndpointUpdateContext) => Promise, options?: WithEndpointCallbackOptions): ResourceWithEndpointsPromise { + return new ResourceWithEndpointsPromiseImpl(this._promise.then(obj => obj.withEndpointCallback(endpointName, callback, options))); + } + + /** Updates an HTTP endpoint via callback */ + withHttpEndpointCallback(callback: (obj: EndpointUpdateContext) => Promise, options?: WithHttpEndpointCallbackOptions): ResourceWithEndpointsPromise { + return new ResourceWithEndpointsPromiseImpl(this._promise.then(obj => obj.withHttpEndpointCallback(callback, options))); + } + /** Adds a network endpoint */ withEndpoint(options?: WithEndpointOptions): ResourceWithEndpointsPromise { return new ResourceWithEndpointsPromiseImpl(this._promise.then(obj => obj.withEndpoint(options))); @@ -31766,6 +32554,7 @@ registerHandleWrapper('Aspire.Hosting/Aspire.Hosting.DistributedApplicationExecu registerHandleWrapper('Aspire.Hosting/Aspire.Hosting.ApplicationModel.DistributedApplicationModel', (handle, client) => new DistributedApplicationModelImpl(handle as DistributedApplicationModelHandle, client)); registerHandleWrapper('Aspire.Hosting/Aspire.Hosting.ApplicationModel.EndpointReference', (handle, client) => new EndpointReferenceImpl(handle as EndpointReferenceHandle, client)); registerHandleWrapper('Aspire.Hosting/Aspire.Hosting.ApplicationModel.EndpointReferenceExpression', (handle, client) => new EndpointReferenceExpressionImpl(handle as EndpointReferenceExpressionHandle, client)); +registerHandleWrapper('Aspire.Hosting/Aspire.Hosting.ApplicationModel.EndpointUpdateContext', (handle, client) => new EndpointUpdateContextImpl(handle as EndpointUpdateContextHandle, client)); registerHandleWrapper('Aspire.Hosting/Aspire.Hosting.ApplicationModel.EnvironmentCallbackContext', (handle, client) => new EnvironmentCallbackContextImpl(handle as EnvironmentCallbackContextHandle, client)); registerHandleWrapper('Aspire.Hosting/Aspire.Hosting.ApplicationModel.ExecuteCommandContext', (handle, client) => new ExecuteCommandContextImpl(handle as ExecuteCommandContextHandle, client)); registerHandleWrapper('Aspire.Hosting/Aspire.Hosting.ApplicationModel.InitializeResourceEvent', (handle, client) => new InitializeResourceEventImpl(handle as InitializeResourceEventHandle, client)); diff --git a/tests/Aspire.Hosting.Tests/WithEndpointTests.cs b/tests/Aspire.Hosting.Tests/WithEndpointTests.cs index a12b97d4b89..b1ffaf44eb0 100644 --- a/tests/Aspire.Hosting.Tests/WithEndpointTests.cs +++ b/tests/Aspire.Hosting.Tests/WithEndpointTests.cs @@ -5,6 +5,8 @@ using Aspire.Hosting.Utils; using Microsoft.AspNetCore.InternalTesting; using Microsoft.Extensions.DependencyInjection; +using System.Linq.Expressions; +using System.Net.Sockets; namespace Aspire.Hosting.Tests; @@ -153,6 +155,30 @@ public void WithEndpointCallbackRunsIfEndpointDoesntExistAndCreateIfNotExistsIsT Assert.True(projectA.Resource.TryGetAnnotationsOfType(out _)); } + [Fact] + public void WithHttpEndpointCallbackCreatesHttpEndpointWhenMissing() + { + using var builder = TestDistributedApplicationBuilder.Create(); + + var container = builder.AddContainer("app", "image"); + var endpointUpdateContextType = typeof(ContainerResource).Assembly.GetType("Aspire.Hosting.ApplicationModel.EndpointUpdateContext", throwOnError: true)!; + var callback = Expression.Lambda(typeof(Action<>).MakeGenericType(endpointUpdateContextType), Expression.Empty(), Expression.Parameter(endpointUpdateContextType, "context")).Compile(); + var withHttpEndpointCallbackMethod = typeof(ResourceBuilderExtensions) + .GetMethods(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic) + .Single(method => method is { Name: nameof(ResourceBuilderExtensions.WithHttpEndpointCallback), IsGenericMethodDefinition: true }); + + _ = withHttpEndpointCallbackMethod + .MakeGenericMethod(typeof(ContainerResource)) + .Invoke(null, new object?[] { container, callback, "callback-http", true }); + + var endpoint = container.Resource.Annotations.OfType() + .Single(endpoint => string.Equals(endpoint.Name, "callback-http", EndpointAnnotationName)); + + Assert.Equal("http", endpoint.UriScheme); + Assert.Equal("http", endpoint.Transport); + Assert.Equal(ProtocolType.Tcp, endpoint.Protocol); + } + [Fact] public void EndpointsWithTwoPortsSameNameThrows() { diff --git a/tests/PolyglotAppHosts/Aspire.Hosting/Java/AppHost.java b/tests/PolyglotAppHosts/Aspire.Hosting/Java/AppHost.java index dc0b4f3e247..36671bd9d38 100644 --- a/tests/PolyglotAppHosts/Aspire.Hosting/Java/AppHost.java +++ b/tests/PolyglotAppHosts/Aspire.Hosting/Java/AppHost.java @@ -14,6 +14,7 @@ void main() throws Exception { container.withDockerfileBaseImage(new WithDockerfileBaseImageOptions().buildImage("mcr.microsoft.com/dotnet/sdk:8.0")); container.withImageRegistry("docker.io"); dockerContainer.withHttpEndpoint(new WithHttpEndpointOptions().name("http").targetPort(80.0)); + dockerContainer.withHttpEndpointCallback((updateContext) -> { updateContext.setPort(8080.0); updateContext.setIsProxied(false); }, new WithHttpEndpointCallbackOptions().name("http").createIfNotExists(false)); var endpoint = dockerContainer.getEndpoint("http"); var expr = ReferenceExpression.refExpr("Host=%s", endpoint); var builtConnectionString = builder.addConnectionStringBuilder("customcs", (connectionStringBuilder) -> { var _isEmpty = connectionStringBuilder.isEmpty(); connectionStringBuilder.appendLiteral("Host="); connectionStringBuilder.appendValueProvider(endpoint); connectionStringBuilder.appendLiteral(";Key="); connectionStringBuilder.appendValueProvider(secretParam); var _builtExpression = connectionStringBuilder.build(); }); @@ -76,8 +77,15 @@ void main() throws Exception { container.onResourceReady((resourceReadyEvent) -> { var _resource = resourceReadyEvent.resource(); var services = resourceReadyEvent.services(); var loggerFactory = services.getLoggerFactory(); var logger = loggerFactory.createLogger("ValidationAppHost.ResourceReady"); logger.logInformation("ResourceReady"); }); container.withEnvironment("MY_VAR", "value"); container.withEndpoint(); + container.withEndpoint(new WithEndpointOptions().name("callback-endpoint")); + container.withEndpointCallback("callback-endpoint", (updateContext) -> { updateContext.setPort(5001.0); updateContext.setTargetPort(5002.0); updateContext.setIsExternal(false); }, false); container.withHttpEndpoint(); + container.withHttpEndpoint(new WithHttpEndpointOptions().name("callback-http")); + container.withHttpEndpointCallback((updateContext) -> { updateContext.setPort(8081.0); updateContext.setTargetPort(8082.0); updateContext.setIsProxied(false); }, new WithHttpEndpointCallbackOptions().name("callback-http").createIfNotExists(false)); + container.withHttpEndpointCallback((updateContext) -> { updateContext.setPort(8083.0); updateContext.setTargetPort(8084.0); updateContext.setIsProxied(false); }, new WithHttpEndpointCallbackOptions().name("created-http")); container.withHttpsEndpoint(); + container.withHttpsEndpoint(new WithHttpsEndpointOptions().name("callback-https")); + container.withEndpointCallback("callback-https", (updateContext) -> { updateContext.setPort(8444.0); updateContext.setTargetPort(8443.0); updateContext.setIsProxied(false); }, false); container.withExternalHttpEndpoints(); container.asHttp2Service(); container.withArgs(new String[] { "--verbose" }); diff --git a/tests/PolyglotAppHosts/Aspire.Hosting/Python/apphost.py b/tests/PolyglotAppHosts/Aspire.Hosting/Python/apphost.py index 6517d69641b..7512d47c15d 100644 --- a/tests/PolyglotAppHosts/Aspire.Hosting/Python/apphost.py +++ b/tests/PolyglotAppHosts/Aspire.Hosting/Python/apphost.py @@ -5,6 +5,30 @@ with create_builder() as builder: + def update_existing_http_endpoint(endpoint): + endpoint.port = 8080 + endpoint.is_proxied = False + + def update_endpoint(endpoint): + endpoint.port = 5001 + endpoint.target_port = 5002 + endpoint.is_external = False + + def update_http_endpoint(endpoint): + endpoint.port = 8081 + endpoint.target_port = 8082 + endpoint.is_proxied = False + + def update_created_http_endpoint(endpoint): + endpoint.port = 8083 + endpoint.target_port = 8084 + endpoint.is_proxied = False + + def update_https_endpoint(endpoint): + endpoint.port = 8444 + endpoint.target_port = 8443 + endpoint.is_proxied = False + # addContainer (pre-existing) container = builder.add_container("resource", "image") # addDockerfile @@ -27,8 +51,9 @@ # withImageRegistry container.with_image_registry("docker.io") # =================================================================== - docker_container.with_http_endpoint() - endpoint = docker_container.get_endpoint("default") + docker_container.with_http_endpoint(name="http", target_port=80) + docker_container.with_http_endpoint_callback(update_existing_http_endpoint, name="http", create_if_not_exists=False) + endpoint = docker_container.get_endpoint("http") expr = "expression" built_connection_string = builder.add_connection_string_builder("connection-string", lambda *_args, **_kwargs: None) built_connection_string.with_connection_property("Key", "Value") @@ -120,10 +145,17 @@ container.with_environment("KEY", "value") # withEndpoint container.with_endpoint() + container.with_endpoint(name="callback-endpoint") + container.with_endpoint_callback("callback-endpoint", update_endpoint, create_if_not_exists=False) # withHttpEndpoint container.with_http_endpoint() + container.with_http_endpoint(name="callback-http") + container.with_http_endpoint_callback(update_http_endpoint, name="callback-http", create_if_not_exists=False) + container.with_http_endpoint_callback(update_created_http_endpoint, name="created-http") # withHttpsEndpoint container.with_https_endpoint() + container.with_https_endpoint(name="callback-https") + container.with_endpoint_callback("callback-https", update_https_endpoint, create_if_not_exists=False) # withExternalHttpEndpoints container.with_external_http_endpoints() # asHttp2Service diff --git a/tests/PolyglotAppHosts/Aspire.Hosting/TypeScript/apphost.ts b/tests/PolyglotAppHosts/Aspire.Hosting/TypeScript/apphost.ts index 5275ce502b4..a2d1364c55f 100644 --- a/tests/PolyglotAppHosts/Aspire.Hosting/TypeScript/apphost.ts +++ b/tests/PolyglotAppHosts/Aspire.Hosting/TypeScript/apphost.ts @@ -52,6 +52,10 @@ await container.withImageRegistry("docker.io"); // =================================================================== await dockerContainer.withHttpEndpoint({ name: "http", targetPort: 80 }); +await dockerContainer.withHttpEndpointCallback(async (updateContext) => { + await updateContext.port.set(8080); + await updateContext.isProxied.set(false); +}, { name: "http", createIfNotExists: false }); const endpoint = await dockerContainer.getEndpoint("http"); const expr = refExpr`Host=${endpoint}`; @@ -375,12 +379,35 @@ await container.withEnvironment("MY_VAR", "value"); // withEndpoint await container.withEndpoint(); +await container.withEndpoint({ name: "callback-endpoint" }); +await container.withEndpointCallback("callback-endpoint", async (updateContext) => { + await updateContext.port.set(5001); + await updateContext.targetPort.set(5002); + await updateContext.isExternal.set(false); +}, { createIfNotExists: false }); // withHttpEndpoint await container.withHttpEndpoint(); +await container.withHttpEndpoint({ name: "callback-http" }); +await container.withHttpEndpointCallback(async (updateContext) => { + await updateContext.port.set(8081); + await updateContext.targetPort.set(8082); + await updateContext.isProxied.set(false); +}, { name: "callback-http", createIfNotExists: false }); +await container.withHttpEndpointCallback(async (updateContext) => { + await updateContext.port.set(8083); + await updateContext.targetPort.set(8084); + await updateContext.isProxied.set(false); +}, { name: "created-http" }); // withHttpsEndpoint await container.withHttpsEndpoint(); +await container.withHttpsEndpoint({ name: "callback-https" }); +await container.withEndpointCallback("callback-https", async (updateContext) => { + await updateContext.port.set(8444); + await updateContext.targetPort.set(8443); + await updateContext.isProxied.set(false); +}, { createIfNotExists: false }); // withExternalHttpEndpoints await container.withExternalHttpEndpoints();