-
Notifications
You must be signed in to change notification settings - Fork 136
Update MinioClientSettings to UseSsl parsing #943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update MinioClientSettings to UseSsl parsing #943
Conversation
Co-authored-by: josemalm32 <23101537+josemalm32@users.noreply.github.com>
…ling Co-authored-by: josemalm32 <23101537+josemalm32@users.noreply.github.com>
|
@dotnet-policy-service agree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the MinioClientSettings connection string parsing to introduce explicit handling of the UseSsl property and prevents automatic inference of SSL usage from URI schemes. The key change is that UseSsl now defaults to false and must be explicitly set in connection strings or configuration.
Key changes:
- Added explicit
UseSslproperty handling with support for multiple key variants (UseSsl,UseSSL,Ssl) - Introduced strict boolean parsing that only accepts "true"/"false" strings (case-insensitive), rejecting numeric and yes/no values
- Modified connection string parsing to never infer
UseSslfrom URI schemes (https:// or http://)
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/CommunityToolkit.Aspire.Minio.Client/MinioClientSettings.cs |
Refactored ParseConnectionString to handle UseSsl explicitly with strict boolean parsing; added early return for null/whitespace; added TryParseBool helper method |
tests/CommunityToolkit.Aspire.Minio.Client.Tests/ConfigurationTests.cs |
Added comprehensive test coverage for UseSsl behavior including default value, explicit true/false, key variants, rejected formats, and non-inference from URI schemes |
Comments suppressed due to low confidence (1)
src/CommunityToolkit.Aspire.Minio.Client/MinioClientSettings.cs:100
- The method lacks XML documentation comments. All public and internal methods should have XML doc comments per project conventions. Add a summary explaining the strict parsing behavior and document the parameters and return value.
// Strict boolean parsing: only accepts bool or the strings "true"/"false" (case-insensitive).
private static bool TryParseBool(object? value, out bool result)
| private const string ConnectionStringEndpoint = "Endpoint"; | ||
| private const string AccessKey = "AccessKey"; | ||
| private const string SecretKey = "SecretKey"; | ||
| private static readonly string[] UseSslKeys = new[] { "UseSsl", "UseSSL", "Ssl" }; |
Copilot
AI
Nov 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use collection expression syntax instead of array initializer for consistency with project coding style. Change to: private static readonly string[] UseSslKeys = [\"UseSsl\", \"UseSSL\", \"Ssl\"];
| foreach (var key in UseSslKeys) | ||
| { | ||
| if (connectionBuilder.TryGetValue(key, out var useSslObj)) | ||
| { | ||
| Credentials = new MinioCredentials | ||
| if (TryParseBool(useSslObj, out var parsed)) | ||
| { | ||
| AccessKey = accessKey.ToString()!, SecretKey = secretKey.ToString()! | ||
| }; | ||
| UseSsl = parsed; | ||
| break; | ||
| } | ||
| } | ||
| } |
Copilot
AI
Nov 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This foreach loop implicitly filters its target sequence - consider filtering the sequence explicitly using '.Where(...)'.
| if (connectionBuilder.TryGetValue(key, out var useSslObj)) | ||
| { | ||
| Credentials = new MinioCredentials | ||
| if (TryParseBool(useSslObj, out var parsed)) | ||
| { | ||
| AccessKey = accessKey.ToString()!, SecretKey = secretKey.ToString()! | ||
| }; | ||
| UseSsl = parsed; | ||
| break; | ||
| } | ||
| } |
Copilot
AI
Nov 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 'if' statements can be combined.
| Assert.Null(settings.Endpoint); | ||
|
|
||
| settings = new MinioClientSettings(); | ||
| settings.ParseConnectionString(""); |
There was a problem hiding this comment.
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
src/CommunityToolkit.Aspire.Minio.Client/MinioClientSettings.cs
Outdated
Show resolved
Hide resolved
|
PR itself looks good! I'm a little bit concerned about turning off security features by default, though, is it more convenient? |
|
Thanks for review 💯 If you use Minio locally, it is simpler to have SSL set to false. There is no need to configure self-signed certificates. And I suppose that if it is activated, the Hosting.MinIO package would have to be modified. The idea of adding SSL to the connection string is for production environments. In my case, I tried to connect but never succeeded because I always ended up calling port 80 (non-SSL) instead of 443 (SSL). Thanks |
| private const string ConnectionStringEndpoint = "Endpoint"; | ||
| private const string AccessKey = "AccessKey"; | ||
| private const string SecretKey = "SecretKey"; | ||
| private static readonly string[] UseSslKeys = new[] { "UseSsl", "UseSSL", "Ssl" }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DbConnectionStringBuilder is case insensitive when using TryGetValue: https://lab.razor.fyi/#bc69SgQxFAVgdrVwUy0-QZhqBiQws2VI4ywoYjGw_oCVSTYOkZl7l5tkfxALe99A8H0sfB9LWVRcxPKcjwOHvQwZawhb0r2w4fB5mIKHls82Ibpest0kpjpqUWPfI0jGlpq4DYYrDm7Fp6ZGAGejR5hF8tAeJ9_NHeUFf2Cjv6h4doohKm2sbJCiKqtqIi-DI6U1IchGh7BCmitt1uUP3eNvv8BUVpOMPUrGaoSAnRPX5KM79-ByG4y4oM2Ji1e6Sy7PFt-77Ihjinx7frmVopD_zL9Inu1RgpvRwcfr-9Pb3Xj_drAefAI
We should only care about a single key, UseSsl.
| } | ||
| } | ||
|
|
||
| // Strict boolean parsing: only accepts bool or the strings "true"/"false" (case-insensitive). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? bool.TryParse is case insensitive so do we really care? This seems like code for codes sake.
Refactor SSL key handling and remove unused boolean parsing method.
Removed multiple tests for SSL connection string parsing.
| { | ||
| Credentials = new MinioCredentials | ||
| { | ||
| AccessKey = accessKey.ToString()!, SecretKey = secretKey.ToString()! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can simplify this logic by using some pattern matching to avoid having to use ? and !:
|
Adjusted with the required changes. Thanks 💯 |
|
Some tests fail and need fixing :( Apart from that looks great! |
| if (connectionBuilder.TryGetValue(UseSslKey, out var useSslObj)) | ||
| { | ||
| Endpoint = serviceUri; | ||
| if (bool.TryParse(useSslObj, out var parsed)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that you need to explicitly cast useSslObj to string over here
Fix compilation error and improve readability of SSL parsing.
|
Fix compilation error and improve readability of SSL parsing. Thanks to both of you😄 |
aaronpowell
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and we're almost ready to merge
| public void ParseConnectionString_HttpsUri_DoesNotInferUseSsl() | ||
| { | ||
| var settings = new MinioClientSettings(); | ||
| settings.ParseConnectionString("https://minio.example.com:9000"); |
There was a problem hiding this comment.
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
|
@josemalm32 can you get this actioned in the next day so it can make the release this week with aspire 13 |
|
Hi @aaronpowell Sorry for the delay. With the latest change, the tests are working fine. I've tried running it locally and it works. Thanks 😄 |
Changes made: