-
Notifications
You must be signed in to change notification settings - Fork 903
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 2 commits
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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably want to think about naming here.. duplicative ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no preference on this, simply changed the visibility. I agree though, Generate seems more consistent and it’s an opportunity to polish it a bit. I’ll update it
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have updated to change the name from CreateVolumeName to Generate as suggested.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @danmoseley Are you good with the changes made?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems fine to me. @davidfowl what is the process around public API naming - is this OK? |
||
| { | ||
| if (!HasOnlyValidChars(suffix)) | ||
| { | ||
| throw new ArgumentException($"The suffix '{suffix}' contains invalid characters. Only [a-zA-Z0-9_.-] are allowed.", nameof(suffix)); | ||
| throw new ArgumentException($"The suffix '{suffix}' contains invalid characters. It must match [a-zA-Z0-9][a-zA-Z0-9_.-]*.", nameof(suffix)); | ||
| } | ||
|
|
||
| // 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
|
||
| 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.