Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 37 additions & 19 deletions src/CommunityToolkit.Aspire.Minio.Client/MinioClientSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using Microsoft.Extensions.DependencyInjection;
using Minio;
using System.Data.Common;

Expand All @@ -12,6 +13,7 @@ public sealed class MinioClientSettings
private const string ConnectionStringEndpoint = "Endpoint";
private const string AccessKey = "AccessKey";
private const string SecretKey = "SecretKey";
private const string UseSslKey = "UseSsl";

/// <summary>
/// Endpoint URL
Expand Down Expand Up @@ -42,37 +44,53 @@ public sealed class MinioClientSettings

internal void ParseConnectionString(string? connectionString)
{
if (string.IsNullOrWhiteSpace(connectionString))
{
return;
}

// If the connection string is an absolute URI, use it as endpoint.
if (Uri.TryCreate(connectionString, UriKind.Absolute, out var uri))
{
Endpoint = uri;
return;
}
else

var connectionBuilder = new DbConnectionStringBuilder
{
var connectionBuilder = new DbConnectionStringBuilder
{
ConnectionString = connectionString
};
ConnectionString = connectionString
};

if (connectionBuilder.TryGetValue(ConnectionStringEndpoint, out var endpoint)
&&
Uri.TryCreate(endpoint.ToString(), UriKind.Absolute, out var serviceUri))
if (connectionBuilder.TryGetValue(ConnectionStringEndpoint, out var endpoint)
&&
Uri.TryCreate(endpoint.ToString(), UriKind.Absolute, out var serviceUri))
{
Endpoint = serviceUri;
}

// Check for UseSsl (and variants) in the connection string and parse it if present.
if (connectionBuilder.TryGetValue(UseSslKey, out var useSslObj)
&& useSslObj is string useSslValue
&& bool.TryParse(useSslValue, out var parsed))
{
Endpoint = serviceUri;
UseSsl = parsed;
}

if (connectionBuilder.TryGetValue(AccessKey, out var accessKey)
&&
connectionBuilder.TryGetValue(SecretKey, out var secretKey)
&&
!string.IsNullOrEmpty(accessKey.ToString()) && !string.IsNullOrEmpty(secretKey.ToString()))

if (connectionBuilder.TryGetValue(AccessKey, out var accessKeyValue) &&
connectionBuilder.TryGetValue(SecretKey, out var secretKeyValue) &&
accessKeyValue is string accessKey &&
secretKeyValue is string secretKey &&
!string.IsNullOrEmpty(accessKey) &&
!string.IsNullOrEmpty(secretKey))
{
Credentials = new MinioCredentials
{
AccessKey = accessKey.ToString()!, SecretKey = secretKey.ToString()!
AccessKey = accessKey,
SecretKey = secretKey
};
}
}
}

}

/// <summary>
Expand Down Expand Up @@ -105,4 +123,4 @@ public class MinioCredentials
/// MinIO Secret Key
/// </summary>
public string SecretKey { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,103 @@
[Fact]
public void CredentialsIsNullByDefault() =>
Assert.Null(new MinioClientSettings().Credentials);

[Fact]
public void UseSslIsFalseByDefault()
{
var settings = new MinioClientSettings();
Assert.False(settings.UseSsl);
}

[Fact]
public void ParseConnectionString_HttpsUri_DoesNotInferUseSsl()
{
var settings = new MinioClientSettings();
settings.ParseConnectionString("https://minio.example.com:9000");

Check failure on line 27 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / run-tests / Minio.Client.Tests-ubuntu-latest

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 27 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 27 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / run-tests / Minio.Client.Tests-windows-latest

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 27 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the ParseConnectionString method is internal you'll need to expose it to the test project with <InternalsVisibleTo Include="CommunityToolkit.Aspire.Minio.Client.Tests" />

You'll find a bunch of examples of other projects using InternalsVisibleTo in the repo


Assert.NotNull(settings.Endpoint);
Assert.Equal("https://minio.example.com:9000/", settings.Endpoint.ToString());
Assert.False(settings.UseSsl); // Should remain false since UseSsl was not explicitly set
}

[Fact]
public void ParseConnectionString_HttpUri_DoesNotInferUseSsl()
{
var settings = new MinioClientSettings();
settings.ParseConnectionString("http://minio.example.com:9000");

Check failure on line 38 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / run-tests / Minio.Client.Tests-ubuntu-latest

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 38 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 38 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / run-tests / Minio.Client.Tests-windows-latest

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 38 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Assert.NotNull(settings.Endpoint);
Assert.Equal("http://minio.example.com:9000/", settings.Endpoint.ToString());
Assert.False(settings.UseSsl); // Should remain false
}

[Fact]
public void ParseConnectionString_ExplicitUseSslTrue()
{
var settings = new MinioClientSettings();
settings.ParseConnectionString("Endpoint=http://minio.example.com:9000;UseSsl=true;AccessKey=key;SecretKey=secret");

Check failure on line 49 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / run-tests / Minio.Client.Tests-ubuntu-latest

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 49 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 49 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / run-tests / Minio.Client.Tests-windows-latest

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 49 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Assert.NotNull(settings.Endpoint);
Assert.True(settings.UseSsl);
}

[Fact]
public void ParseConnectionString_ExplicitUseSslFalse()
{
var settings = new MinioClientSettings();
settings.ParseConnectionString("Endpoint=https://minio.example.com:9000;UseSsl=false;AccessKey=key;SecretKey=secret");

Check failure on line 59 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / run-tests / Minio.Client.Tests-ubuntu-latest

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 59 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 59 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / run-tests / Minio.Client.Tests-windows-latest

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 59 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Assert.NotNull(settings.Endpoint);
Assert.False(settings.UseSsl);
}

[Fact]
public void ParseConnectionString_UseSslCaseInsensitive()
{
var settings = new MinioClientSettings();
settings.ParseConnectionString("Endpoint=http://minio.example.com:9000;UseSsl=True;AccessKey=key;SecretKey=secret");

Check failure on line 69 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / run-tests / Minio.Client.Tests-ubuntu-latest

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 69 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 69 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / run-tests / Minio.Client.Tests-windows-latest

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 69 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Assert.True(settings.UseSsl);
}


[Fact]
public void ParseConnectionString_WithCredentials()
{
var settings = new MinioClientSettings();
settings.ParseConnectionString("Endpoint=http://minio.example.com:9000;AccessKey=mykey;SecretKey=mysecret;UseSsl=true");

Check failure on line 79 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / run-tests / Minio.Client.Tests-ubuntu-latest

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 79 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 79 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / run-tests / Minio.Client.Tests-windows-latest

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 79 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Assert.NotNull(settings.Endpoint);
Assert.NotNull(settings.Credentials);
Assert.Equal("mykey", settings.Credentials.AccessKey);
Assert.Equal("mysecret", settings.Credentials.SecretKey);
Assert.True(settings.UseSsl);
}

[Fact]
public void ParseConnectionString_NullOrEmpty_DoesNotThrow()
{
var settings = new MinioClientSettings();
settings.ParseConnectionString(null);

Check failure on line 92 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / run-tests / Minio.Client.Tests-ubuntu-latest

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 92 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 92 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / run-tests / Minio.Client.Tests-windows-latest

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 92 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)
Assert.Null(settings.Endpoint);

settings = new MinioClientSettings();
settings.ParseConnectionString("");

Check failure on line 96 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / run-tests / Minio.Client.Tests-ubuntu-latest

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 96 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 96 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / run-tests / Minio.Client.Tests-windows-latest

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 96 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: string.Empty could be more convenient here

Assert.Null(settings.Endpoint);

settings = new MinioClientSettings();
settings.ParseConnectionString(" ");

Check failure on line 100 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / run-tests / Minio.Client.Tests-ubuntu-latest

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 100 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 100 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / run-tests / Minio.Client.Tests-windows-latest

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 100 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)
Assert.Null(settings.Endpoint);
}

[Fact]
public void ParseConnectionString_HttpsEndpointInConnectionString_DoesNotInferUseSsl()
{
var settings = new MinioClientSettings();
settings.ParseConnectionString("Endpoint=https://minio.example.com:9000;AccessKey=key;SecretKey=secret");

Check failure on line 108 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / run-tests / Minio.Client.Tests-ubuntu-latest

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 108 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 108 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / run-tests / Minio.Client.Tests-windows-latest

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 108 in tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

'MinioClientSettings' does not contain a definition for 'ParseConnectionString' and no accessible extension method 'ParseConnectionString' accepting a first argument of type 'MinioClientSettings' could be found (are you missing a using directive or an assembly reference?)

Assert.NotNull(settings.Endpoint);
Assert.Equal("https://minio.example.com:9000/", settings.Endpoint.ToString());
Assert.False(settings.UseSsl); // Should remain false without explicit UseSsl
}
}
Loading