namespace Aspire.Hosting.ApplicationModel;
///
/// A resource that represents a MiniO storage
///
/// The name of the resource
/// A parameter that contains the MiniO server admin user name, or null to
/// A parameter that contains the Minio server admin password
public sealed class MinioContainerResource(
string name,
ParameterResource rootUser,
ParameterResource rootPassword) : ContainerResource(name),
IResourceWithConnectionString
{
internal const string PrimaryEndpointName = "http";
internal const string DefaultUserName = "minioadmin";
///
/// The MiniO root user.
///
public ParameterResource RootUser { get; set; } = rootUser;
///
/// The MiniO root password.
///
public ParameterResource RootPassword { get; } = rootPassword;
private EndpointReference? _primaryEndpoint;
///
/// Gets the primary endpoint for the Minio. This endpoint is used for all API calls over HTTP.
///
public EndpointReference PrimaryEndpoint => _primaryEndpoint ??= new(this, PrimaryEndpointName);
///
/// Gets the connection string expression for the Minio
///
public ReferenceExpression ConnectionStringExpression => GetConnectionString();
private ReferenceExpression GetConnectionString()
{
var builder = new ReferenceExpressionBuilder();
builder.Append(
$"Endpoint=http://{PrimaryEndpoint.Property(EndpointProperty.Host)}:{PrimaryEndpoint.Property(EndpointProperty.Port)}");
builder.Append($";AccessKey={RootUser.Value}");
builder.Append($";SecretKey={RootPassword.Value}");
return builder.Build();
}
}