microsoft / microsoft/aspire

AddParameter with random value

Open
#9,929 0 comments 1 reaction 0 assignees View on GitHub
area-app-model
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

Some parameters are only used locally at runtime and setting up a value for them is tedious/useless.

### Describe the solution you'd like

It would be cool if we could define a parameter without bothering about their value. It's only important that we have a reference of *a* value to be shared across multiple services.

I find myself adding this extension method to most of my AppHosts

```csharp
public static IResourceBuilder AddParameterWithRandomValue(this IDistributedApplicationBuilder builder, [ResourceName] string name, bool secret = false)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var value = System.Security.Cryptography.RandomNumberGenerator.GetString(chars, 16);

return builder.AddParameter(name, value, secret: secret);
}
```

And use it as

```csharp
var parentSecretKey = builder.AddParameterWithRandomValue("parentSecretKey");
```

### Additional context

I know there is a `CreateDefaultPasswordParameter` exposed by `ParameterResourceBuilderExtensions`, so probably it should be used instead of `RandomNumberGenerator.GetString`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.