forked from CommunityToolkit/Aspire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinioContainerResource.cs
More file actions
81 lines (67 loc) · 3.04 KB
/
MinioContainerResource.cs
File metadata and controls
81 lines (67 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
namespace Aspire.Hosting.ApplicationModel;
/// <summary>
/// A resource that represents a MinIO storage
/// </summary>
public sealed class MinioContainerResource : ContainerResource, IResourceWithConnectionString
{
internal const string PrimaryEndpointName = "http";
internal const string ConsoleEndpointName = "console";
internal const string DefaultUserName = "minioadmin";
/// <summary>
/// Initializes a new instance of the <see cref="MinioContainerResource"/> class.
/// </summary>
/// <param name="name">The name of the resource.</param>
/// <param name="user">A parameter that contains the MinIO server root user name.</param>
/// <param name="password">A parameter that contains the MinIO server root password.</param>
public MinioContainerResource(string name, ParameterResource user, ParameterResource password) : base(name)
{
RootUser = user;
PasswordParameter = password;
}
/// <summary>
/// The MinIO root user.
/// </summary>
public ParameterResource RootUser { get; set; }
/// <summary>
/// The MinIO root password.
/// </summary>
public ParameterResource PasswordParameter { get; set; }
private EndpointReference? _primaryEndpoint;
/// <summary>
/// Gets the primary endpoint for the MinIO. This endpoint is used for all API calls over HTTP.
/// </summary>
public EndpointReference PrimaryEndpoint => _primaryEndpoint ??= new(this, PrimaryEndpointName);
/// <summary>
/// Gets the connection string expression for the Minio
/// </summary>
public ReferenceExpression ConnectionStringExpression => GetConnectionString();
/// <summary>
/// Gets the connection string for the MinIO server.
/// </summary>
/// <param name="cancellationToken"> A <see cref="CancellationToken"/> to observe while waiting for the task to complete.</param>
/// <returns>A connection string for the MinIO server in the form "Host=host;Port=port;Username=postgres;Password=password".</returns>
public ValueTask<string?> GetConnectionStringAsync(CancellationToken cancellationToken = default)
{
if (this.TryGetLastAnnotation<ConnectionStringRedirectAnnotation>(out var connectionStringAnnotation))
{
return connectionStringAnnotation.Resource.GetConnectionStringAsync(cancellationToken);
}
return ConnectionStringExpression.GetValueAsync(cancellationToken);
}
/// <summary>
/// Gets the connection string for the MinIO server.
/// </summary>
private ReferenceExpression GetConnectionString()
{
var builder = new ReferenceExpressionBuilder();
builder.Append(
$"Endpoint=http://{PrimaryEndpoint.Property(EndpointProperty.Host)}:{PrimaryEndpoint.Property(EndpointProperty.Port)}");
builder.Append($";AccessKey={RootUser}");
builder.Append($";SecretKey={PasswordParameter}");
return builder.Build();
}
internal void SetPassword(ParameterResource password)
{
PasswordParameter = password;
}
}