-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Improvements to RunWithHttpsDevCert extensions #667
Draft
DamianEdwards
wants to merge
33
commits into
main
Choose a base branch
from
damianedwards/CreateTempSubdirectory
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
772bf41
Use Directory.CreateTempSubDirectory instead of Path.GetTempDir
DamianEdwards 61e8e77
Update DevCertHostingExtensions.cs
DamianEdwards 88d1363
Put dev-cert in /obj (or user temp if not available)
DamianEdwards 21a3172
Update DevCertHostingExtensions.cs
DamianEdwards b31c3e0
Fix typo
DamianEdwards f6f0c1b
WIP
DamianEdwards 898321e
More WIP
DamianEdwards f7d0f93
WIPpy
DamianEdwards 0e30ab5
Working now
DamianEdwards bc59278
Update Metrics sample
DamianEdwards 78eacd0
Fix
DamianEdwards fa88fca
Run Redis with the dev cert in the Node sample
DamianEdwards 6f2bda3
Update RedisHostingExtensions.cs
DamianEdwards c692ad4
Update Directory.Build.targets
DamianEdwards c14cacb
Don't use cert with Redis for now
DamianEdwards 25feb3c
Insert resource logger at 0
DamianEdwards e23cec6
Enable DCP logs
DamianEdwards cbd2813
Update ci.yml
DamianEdwards fc132fe
Update ci.yml
DamianEdwards 29a126d
Update ci.yml
DamianEdwards ef10a2c
pls give me logs!
DamianEdwards 90a1322
Fix double slashes
DamianEdwards b53e2ec
Update ci.yml
DamianEdwards b47d9c8
moar logs!
DamianEdwards 995a77e
grrrrr
DamianEdwards bf36d18
quote container args
DamianEdwards e328cff
Revert "quote container args"
DamianEdwards c35823c
Update all to latest 9.1 SDK
DamianEdwards 33fa711
Revert "Update all to latest 9.1 SDK"
DamianEdwards dfc257b
Don't bind mount the dev-cert folder to see if container starts
DamianEdwards 073f519
Add bind mount back but don't pass Redis TLS args
DamianEdwards 974bc2d
Use SetUnixFileMode
DamianEdwards 15376bd
Update DevCertHostingExtensions.cs
DamianEdwards File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
samples/AspireWithNode/AspireWithNode.AppHost/RedisHostingExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace Aspire.Hosting; | ||
|
||
internal static class RedisHostingExtensions | ||
{ | ||
/// <summary> | ||
/// Configures the Redis resource to use the ASP.NET Core HTTPS developer certificate when | ||
/// <paramref name="builder"/>.<see cref="IResourceBuilder{T}.ApplicationBuilder">ApplicationBuilder</see>.<see cref="IDistributedApplicationBuilder.ExecutionContext">ExecutionContext</see>.<see cref="DistributedApplicationExecutionContext.IsRunMode">IsRunMode</see><c> == true</c>.<br/> | ||
/// </summary> | ||
public static IResourceBuilder<RedisResource> RunWithHttpsDevCertificate(this IResourceBuilder<RedisResource> builder) | ||
{ | ||
if (builder.ApplicationBuilder.ExecutionContext.IsRunMode && builder.ApplicationBuilder.Environment.IsDevelopment()) | ||
{ | ||
DevCertHostingExtensions.RunWithHttpsDevCertificate(builder, CertificateFileFormat.Pem, "TLS_CERT_FILE", "TLS_KEY_FILE", (services, certFilePath, certPasswordOrKeyPath) => | ||
{ | ||
// This callback is invoked during the BeforeStartEvent phase if the certificate is successfully exported. | ||
builder.WithConnectionStringRedirection(new RedisTlsConnectionString(builder.Resource)); | ||
|
||
// Configure Redis to use the ASP.NET Core HTTPS development certificate. | ||
builder.WithArgs(context => | ||
{ | ||
context.Args.Add("--port"); | ||
context.Args.Add("0"); | ||
context.Args.Add("--tls-port"); | ||
context.Args.Add(builder.Resource.PrimaryEndpoint.TargetPort.ToString()!); | ||
context.Args.Add("--tls-cert-file"); | ||
context.Args.Add($"{DevCertHostingExtensions.DEV_CERT_BIND_MOUNT_DEST_DIR}/{DevCertHostingExtensions.DEV_CERT_FILE_NAME_PEM}"); | ||
context.Args.Add("--tls-key-file"); | ||
context.Args.Add($"{DevCertHostingExtensions.DEV_CERT_BIND_MOUNT_DEST_DIR}/{DevCertHostingExtensions.DEV_CERT_FILE_NAME_KEY}"); | ||
context.Args.Add("--tls-ca-cert-file"); | ||
context.Args.Add($"{DevCertHostingExtensions.DEV_CERT_BIND_MOUNT_DEST_DIR}/{DevCertHostingExtensions.DEV_CERT_FILE_NAME_PEM}"); | ||
context.Args.Add("--tls-auth-clients"); | ||
context.Args.Add("no"); | ||
}); | ||
|
||
return Task.CompletedTask; | ||
}); | ||
} | ||
|
||
return builder; | ||
} | ||
|
||
private class RedisTlsConnectionString(RedisResource resource) : IResourceWithConnectionString | ||
{ | ||
public string Name { get; } = $"{resource.Name}-tls"; | ||
|
||
public ReferenceExpression ConnectionStringExpression => ReferenceExpression.Create( | ||
$"{resource.PrimaryEndpoint.Property(EndpointProperty.Host)}:{resource.PrimaryEndpoint.Property(EndpointProperty.Port)},Ssl=true"); | ||
|
||
public ResourceAnnotationCollection Annotations { get; } = []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project> | ||
<!-- Embed the path to /obj so that hosting integrations can write files to re-use between runs there --> | ||
<Target Name="EmbedAppHostIntermediateOutputPath" BeforeTargets="GetAssemblyAttributes"> | ||
<ItemGroup> | ||
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute"> | ||
<_Parameter1>apphostprojectbaseintermediateoutputpath</_Parameter1> | ||
<_Parameter2>$(BaseIntermediateOutputPath)</_Parameter2> | ||
</AssemblyAttribute> | ||
</ItemGroup> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wouldn't hurt to stick a comment in here in case someone stumbles in and asks what this is for.