-
I am writing a hosting provider for oauth2-proxy. I want to proxy projects and other http/s resources via oauth2-proxy upstreams. When I reference a project using .WithReference, the env var for the service is added to my project, and when I viewed in the dashboard, the value is what I am looking for (e.g services__apiservice__http__0: http://host.docker.internal:5455). I have the below extension method to add the upstream project where I pass in the project builder and the endpoint name. I AddReference to the project and AddEnvironment with a callback. But the value for services__apiservice__http__0 is http://localhost:5455. Is there a non-hacky way to get the resolved hostname (host.docker.internal) in my scenario? My ultimate goal is to the the OAUTH2_PROXY_UPSTREAMS environment value with http://host.docker.internal:5455. Not http://localhost:5455. public static IResourceBuilder<OAuth2ProxyResource> WithUpstreamProject(
this IResourceBuilder<OAuth2ProxyResource> builder,
IResourceBuilder<ProjectResource> project,
string endpointName = "http",
string path = "/")
{
builder.WithReference(project)
.WithEnvironment(context =>
{
var envVar = context.EnvironmentVariables[$"services__{project.Resource.Name}__{endpointName}__0"] as EndpointReference;
return Task.CompletedTask;
})
.WaitFor(project);
return builder;
} Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Never mind. I figured it out. public static IResourceBuilder<OAuth2ProxyResource> WithUpstreamProject(
this IResourceBuilder<OAuth2ProxyResource> builder,
IResourceBuilder<ProjectResource> project,
string endpointName = "http",
string path = "/")
{
builder.WithReference(project)
.WithEnvironment(context =>
{
if (context.EnvironmentVariables.GetValueOrDefault("OAUTH2_PROXY_UPSTREAMS") is ReferenceExpression oauth2ProxyUpstreams)
{
context.EnvironmentVariables["OAUTH2_PROXY_UPSTREAMS"] = ReferenceExpression.Create($"{oauth2ProxyUpstreams},{project.Resource.GetEndpoint(endpointName)}{path}");
}
else
{
context.EnvironmentVariables["OAUTH2_PROXY_UPSTREAMS"] = ReferenceExpression.Create($"{project.Resource.GetEndpoint(endpointName)}{path}");
}
return Task.CompletedTask;
})
.WaitFor(project);
return builder;
} |
Beta Was this translation helpful? Give feedback.
Never mind. I figured it out.