-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This annotation allows for "inputs" to be written to the manifest when needing to generate a value, like a password, at publish time. It is also used in Parameters to model the "input.value" of the parameter.
- Loading branch information
Showing
23 changed files
with
420 additions
and
144 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// 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; | ||
using Aspire.Hosting.Publishing; | ||
|
||
namespace Aspire.Hosting.ApplicationModel; | ||
|
||
/// <summary> | ||
/// Represents a input annotation that describes an input value. | ||
/// </summary> | ||
/// <remarks> | ||
/// This class is used to specify generated passwords, usernames, etc. | ||
/// </remarks> | ||
[DebuggerDisplay("Type = {GetType().Name,nq}, Name = {Name}")] | ||
public sealed class InputAnnotation : IResourceAnnotation | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of <see cref="InputAnnotation"/>. | ||
/// </summary> | ||
public InputAnnotation(string name, string? type = null, bool secret = false) | ||
{ | ||
Name = name; | ||
Type = type; | ||
Secret = secret; | ||
} | ||
|
||
/// <summary> | ||
/// Name of the input. | ||
/// </summary> | ||
public string Name { get; set; } | ||
|
||
/// <summary> | ||
/// The type of the input. | ||
/// </summary> | ||
public string? Type { get; set; } | ||
|
||
/// <summary> | ||
/// Indicates if the input is a secret. | ||
/// </summary> | ||
public bool Secret { get; set; } | ||
|
||
/// <summary> | ||
/// Represents what the | ||
/// </summary> | ||
public InputDefault? Default { get; set; } | ||
} | ||
|
||
/// <summary> | ||
/// Represents how a default value should be retrieved. | ||
/// </summary> | ||
public abstract class InputDefault | ||
{ | ||
/// <summary> | ||
/// Writes the current <see cref="InputDefault"/> to the manifest context. | ||
/// </summary> | ||
/// <param name="context">The context for the manifest publishing operation.</param> | ||
public abstract void WriteToManifest(ManifestPublishingContext context); | ||
} | ||
|
||
/// <summary> | ||
/// Represents that a default value should be generated. | ||
/// </summary> | ||
public sealed class GenerateInputDefault : InputDefault | ||
{ | ||
/// <summary> | ||
/// The minimum length of the generated value. | ||
/// </summary> | ||
public int MinLength { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public override void WriteToManifest(ManifestPublishingContext context) | ||
{ | ||
context.Writer.WriteStartObject("generate"); | ||
context.Writer.WriteNumber("minLength", MinLength); | ||
context.Writer.WriteEndObject(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Aspire.Hosting/ApplicationModel/InputAnnotationExtensions.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,21 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Aspire.Hosting.ApplicationModel; | ||
|
||
/// <summary> | ||
/// Provides extension methods for <see cref="InputAnnotation"/>. | ||
/// </summary> | ||
internal static class InputAnnotationExtensions | ||
{ | ||
internal static T WithDefaultGeneratedPasswordAnnotation<T>(this T builder) | ||
where T : IResourceBuilder<ContainerResource> | ||
{ | ||
builder.WithAnnotation(new InputAnnotation("password", secret: true) | ||
{ | ||
Default = new GenerateInputDefault { MinLength = 10 } | ||
}); | ||
|
||
return builder; | ||
} | ||
} |
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
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
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
Oops, something went wrong.