-
Notifications
You must be signed in to change notification settings - Fork 756
Makes VolumeNameGenerator public #6531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c060416
d53789b
7e21b6f
050c070
7c679ec
42ad133
22489be
2445ce1
68b0959
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,16 +5,26 @@ | |
|
|
||
| namespace Aspire.Hosting.Utils; | ||
|
|
||
| internal static class VolumeNameGenerator | ||
| /// <summary> | ||
| /// Utility class for generating volume names | ||
| /// </summary> | ||
| public static class VolumeNameGenerator | ||
| { | ||
| /// <summary> | ||
| /// Creates a volume name with the form <c>{applicationName}-{sha256 of apphost path}-{resourceName}-{suffix}</c>, e.g. <c>myapplication-a345f2451-postgres-data</c>. | ||
| /// </summary> | ||
| /// <typeparam name="T">The resource type.</typeparam> | ||
| /// <param name="builder">The resource builder.</param> | ||
| /// <param name="suffix">The suffix to append to the volume name.</param> | ||
| /// <returns>The volume name.</returns> | ||
| /// <exception cref="ArgumentException"></exception> | ||
| public static string CreateVolumeName<T>(IResourceBuilder<T> builder, string suffix) where T : IResource | ||
|
||
| { | ||
| if (!HasOnlyValidChars(suffix)) | ||
| { | ||
| throw new ArgumentException($"The suffix '{suffix}' contains invalid characters. Only [a-zA-Z0-9_.-] are allowed.", nameof(suffix)); | ||
los93sol marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // Creates a volume name with the form < c > $"{applicationName}-{sha256 of apphost path}-{resourceName}-{suffix}</c>, e.g. <c>"myapplication-a345f2451-postgres-data"</c>. | ||
| // Create volume name like "{Sanitize(appname).Lower()}-{sha256.Lower()}-postgres-data" | ||
|
|
||
| // Compute a short hash of the content root path to differentiate between multiple AppHost projects with similar volume names | ||
|
|
@@ -24,6 +34,11 @@ public static string CreateVolumeName<T>(IResourceBuilder<T> builder, string suf | |
| return $"{safeApplicationName}-{applicationHash}-{resourceName}-{suffix}"; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Sanitizes the application name to be used in the volume name. | ||
| /// </summary> | ||
| /// <param name="name">The application name to be sanitized.</param> | ||
| /// <returns>The sanitized application name.</returns> | ||
danmoseley marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public static string Sanitize(string name) | ||
| { | ||
| return string.Create(name.Length, name, static (s, name) => | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.