"System.InvalidOperationException: The endpoint http
is not allocated for the resource keycloak-webrtc
." generating manifest
#7051
Answered
by
davidfowl
paulomorgado
asked this question in
Q&A
-
I have this resource declared: var idp = builder.AddKeycloak(
name: "keycloak",
adminUsername: builder.AddParameter("KeycloakAdminUsername").ExcludeFromManifest(),
adminPassword: builder.AddParameter("KeycloakAdminPassword").ExcludeFromManifest())
.WithExternalHttpEndpoints()
.WithLifetime(ContainerLifetime.Persistent)
//.WithDataVolume("Database/Keycloak/") // persist data
.WithRealmImport("Configuration/Keycloak/")
.WithDefaults()
.AddRealm("idp")
; Where public static IResourceBuilder<KeycloakResource> WithDefaults(this IResourceBuilder<KeycloakResource> builder)
{
const int DefaultHealthPort = 9000;
const string HealthEndpointName = "health";
builder
.WithImageTag("26.0.7")
.WithArgs(context =>
{
context.Args.Add("--hostname-strict=false");
context.Args.Add("--http-enabled=true");
context.Args.Add("--verbose");
})
.WithEnvironment("KC_PROXY", "edge")
.WithEnvironment("KC_HEALTH_ENABLED", "true")
.WithEnvironment("KEYCLOAK_LOGLEVEL", "DEBUG")
.WithEnvironment("QUARKUS_HTTP_ACCESS_LOG_ENABLED", "true")
.WithEnvironment("QUARKUS_HTTP_ACCESS_LOG_PATTERN", "Request: %r %s %b %D %h %u %rn %t \"%{i,Referer}\" \"%{i,User-Agent}\" %{i,ALL_REQUEST_HEADERS} %{i,body} %{o,ALL_RESPONSE_HEADERS} %{o,body}")
.WithHttpEndpoint(targetPort: DefaultHealthPort, name: HealthEndpointName)
.WithHttpHealthCheck(endpointName: HealthEndpointName, path: "/health/ready")
;
return builder;
}
public static IResourceBuilder<KeycloakRealmResource> AddRealm(
this IResourceBuilder<KeycloakResource> builder,
string name,
string? realmName = null)
{
ArgumentNullException.ThrowIfNull(builder);
// Use the resource name as the realm name if it's not provided
realmName ??= name;
var keycloakRealm = new KeycloakRealmResource(name, realmName, builder.Resource);
return builder.ApplicationBuilder.AddResource(keycloakRealm);
}
public sealed class KeycloakRealmResource(string name, string realmName, KeycloakResource parent) : Resource(name), IResourceWithParent<KeycloakResource>, IResourceWithConnectionString
{
private EndpointReference? _parentEndpoint;
private EndpointReference ParentEndpoint => _parentEndpoint ??= new(Parent, "http");
/// <inheritdoc/>
public ReferenceExpression ConnectionStringExpression => ReferenceExpression.Create(
$"{ParentEndpoint.Property(EndpointProperty.Scheme)}://{ParentEndpoint.Property(EndpointProperty.Host)}:{ParentEndpoint.Property(EndpointProperty.Port)}/realms/{RealmName}/");
/// <inheritdoc/>
public KeycloakResource Parent { get; } = parent;
/// <summary>
/// Gets the name of the realm.
/// </summary>
public string RealmName { get; } = realmName;
} And used as: public static IResourceBuilder<ProjectResource> WithClientAccessTokenHandler(
this IResourceBuilder<ProjectResource> builder,
IResourceBuilder<KeycloakRealmResource> idp,
...)
{
return builder
.WaitFor(idp)
.WithEnvironment("AuthenticationTokenEndpoint__Uri", idp)
...
;
}
public static IResourceBuilder<ProjectResource> WithServerAccessTokenHandler(
this IResourceBuilder<ProjectResource> builder,
IResourceBuilder<KeycloakRealmResource> idp)
{
return builder
.WaitFor(idp)
.WithEnvironment(async ctx =>
{
var baseAddress = await idp.Resource.ConnectionStringExpression.GetValueAsync(default);
ctx.EnvironmentVariables["Authentication__JwtBearerOptions__Authority"] = $"{baseAddress}";
ctx.EnvironmentVariables[Authentication__JwtBearerOptions__Configuration__Issuer"] = $"{baseAddress}";
ctx.EnvironmentVariables["Authentication__JwtBearerOptions__Configuration__AuthorizationEndpoint"] = $"{baseAddress}protocol/openid-connect/auth";
ctx.EnvironmentVariables["Authentication__JwtBearerOptions__Configuration__TokenEndpoint"] = $"{baseAddress}protocol/openid-connect/token";
ctx.EnvironmentVariables["Authentication__JwtBearerOptions__Configuration__UserInfoEndpoint"] = $"{baseAddress}protocol/openid-connect/userinfo";
})
;
} But when I try to generate the publish manifest, I get this:
What am I doing wrong? |
Beta Was this translation helpful? Give feedback.
Answered by
davidfowl
Jan 9, 2025
Replies: 1 comment
-
Read this: dotnet/docs-aspire#2340 (comment) This line of code:
Only works when running. There's no value for the connection string when you are in publish mode. You want to use a ReferenceExpression to defer the evaluation and generate the right format in either mode. .WithEnvironment(async ctx =>
{
var baseAddress = idp.Resource.ConnectionStringExpression;
ctx.EnvironmentVariables["Authentication__JwtBearerOptions__Authority"] = baseAddress;
ctx.EnvironmentVariables["Authentication__JwtBearerOptions__Configuration__Issuer"] = $"{baseAddress}";
ctx.EnvironmentVariables["Authentication__JwtBearerOptions__Configuration__AuthorizationEndpoint"] = ReferenceExpression.Create($"{baseAddress}protocol/openid-connect/auth");
ctx.EnvironmentVariables["Authentication__JwtBearerOptions__Configuration__TokenEndpoint"] = ReferenceExpression.Create($"{baseAddress}protocol/openid-connect/token");
ctx.EnvironmentVariables["Authentication__JwtBearerOptions__Configuration__UserInfoEndpoint"] = ReferenceExpression.Create($"{baseAddress}protocol/openid-connect/userinfo");
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
paulomorgado
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read this:
dotnet/docs-aspire#2340 (comment)
This line of code:
Only works when running. There's no value for the connection string when you are in publish mode.
You want to use a ReferenceExpression to defer the evaluation and generate the right format in either mode.