-
Notifications
You must be signed in to change notification settings - Fork 861
Refactor name validation to NameValidationPolicyAnnotation with configurable rules #15728
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c2540e5
Revert "Skip name validation for ProjectRebuilderResource (#15724)"
JamesNK fd501c0
Move resource name validation to AddResource/Build with SuppressNameV…
JamesNK c0b0a43
Use ThrowIfNullOrEmpty in Resource ctor to reject empty names
JamesNK f5279b7
Refactor SuppressNameValidationAnnotation to NameValidationPolicyAnno…
JamesNK 5513914
Update
JamesNK 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
67 changes: 67 additions & 0 deletions
67
src/Aspire.Hosting/ApplicationModel/NameValidationPolicyAnnotation.cs
This file contains hidden or 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,67 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Diagnostics; | ||
|
|
||
| namespace Aspire.Hosting.ApplicationModel; | ||
|
|
||
| /// <summary> | ||
| /// Represents an annotation that customizes the name validation rules applied to a resource when | ||
| /// it is added to the application model. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// By default, resource names must be 1–64 ASCII characters long, start with a letter, contain only letters, digits, | ||
| /// and hyphens, and not contain consecutive or trailing hyphens. Use this annotation to relax individual rules. | ||
| /// The <see cref="None"/> policy disables every rule, which is useful for internal resources (such as installers | ||
| /// or rebuilders) that append suffixes to user-provided resource names and are never deployed. | ||
| /// </remarks> | ||
| [DebuggerDisplay("Type = {GetType().Name,nq}")] | ||
| public sealed class NameValidationPolicyAnnotation : IResourceAnnotation | ||
| { | ||
| /// <summary> | ||
| /// The default policy that enforces all standard name validation rules. | ||
| /// </summary> | ||
| public static readonly NameValidationPolicyAnnotation Default = new(); | ||
|
|
||
| /// <summary> | ||
| /// A policy that disables all name validation rules. | ||
| /// </summary> | ||
| public static readonly NameValidationPolicyAnnotation None = new() | ||
| { | ||
| MaxLength = null, | ||
| ValidateStartsWithLetter = false, | ||
| ValidateAllowedCharacters = false, | ||
| ValidateNoConsecutiveHyphens = false, | ||
| ValidateNoTrailingHyphen = false | ||
| }; | ||
|
|
||
| /// <summary> | ||
| /// Gets the maximum allowed length for the resource name, or <see langword="null"/> to disable length validation. | ||
| /// Defaults to <see cref="ModelName.DefaultMaxLength"/>. | ||
| /// </summary> | ||
| public int? MaxLength { get; init; } = ModelName.DefaultMaxLength; | ||
|
|
||
| /// <summary> | ||
| /// Gets a value indicating whether to validate that the name starts with an ASCII letter. | ||
| /// Defaults to <see langword="true"/>. | ||
| /// </summary> | ||
| public bool ValidateStartsWithLetter { get; init; } = ModelName.DefaultValidateStartsWithLetter; | ||
|
|
||
| /// <summary> | ||
| /// Gets a value indicating whether to validate that the name contains only ASCII letters, digits, and hyphens. | ||
| /// Defaults to <see langword="true"/>. | ||
| /// </summary> | ||
| public bool ValidateAllowedCharacters { get; init; } = ModelName.DefaultValidateAllowedCharacters; | ||
|
|
||
| /// <summary> | ||
| /// Gets a value indicating whether to validate that the name does not contain consecutive hyphens. | ||
| /// Defaults to <see langword="true"/>. | ||
| /// </summary> | ||
| public bool ValidateNoConsecutiveHyphens { get; init; } = ModelName.DefaultValidateNoConsecutiveHyphens; | ||
|
|
||
| /// <summary> | ||
| /// Gets a value indicating whether to validate that the name does not end with a hyphen. | ||
| /// Defaults to <see langword="true"/>. | ||
| /// </summary> | ||
| public bool ValidateNoTrailingHyphen { get; init; } = ModelName.DefaultValidateNoTrailingHyphen; | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.