diff --git a/.github/workflows/minio-dotnet-linux.yml b/.github/workflows/minio-dotnet-linux.yml index 9e616d5fa..59c0554f9 100644 --- a/.github/workflows/minio-dotnet-linux.yml +++ b/.github/workflows/minio-dotnet-linux.yml @@ -48,7 +48,7 @@ jobs: - name: Execute Functional Tests env: MINT_MODE: full - SERVER_ENDPOINT: 127.0.0.1:9000 + SERVER_ENDPOINT: localhost:9000 ACCESS_KEY: minio SECRET_KEY: minio123 ENABLE_HTTPS: 1 @@ -57,10 +57,12 @@ jobs: MINIO_SECRET_KEY: minio123 MINIO_KMS_SECRET_KEY: my-minio-key:OSMM+vkKUTCvQs9YL/CVMIMt43HFhkUpqJxTmGl6rYw= run: | - wget --quiet -O /tmp/minio https://dl.min.io/server/minio/release/linux-amd64/minio - chmod +x /tmp/minio - mkdir -p /tmp/minio-config/certs/ - cp Minio.Functional.Tests/certs/* /tmp/minio-config/certs/ - /tmp/minio -C /tmp/minio-config server /tmp/fs{1...4} & - dotnet build Minio.Functional.Tests --configuration Release - dotnet Minio.Functional.Tests/bin/Release/net6.0/Minio.Functional.Tests.dll + wget --quiet -O /tmp/minio https://dl.min.io/server/minio/release/linux-amd64/minio + chmod +x /tmp/minio + mkdir -p /tmp/minio-config/certs/ + cp Minio.Functional.Tests/certs/* /tmp/minio-config/certs/ + sudo cp /tmp/minio-config/certs/public.crt /etc/ssl/certs/ + sudo cp /tmp/minio-config/certs/private.key /etc/ssl/private/ + /tmp/minio -C /tmp/minio-config server /tmp/fs{1...4} & + dotnet build Minio.Functional.Tests --configuration Release + dotnet Minio.Functional.Tests/bin/Release/net6.0/Minio.Functional.Tests.dll \ No newline at end of file diff --git a/Docs/API.md b/Docs/API.md index 3903bbf07..c93ede16a 100644 --- a/Docs/API.md +++ b/Docs/API.md @@ -137,16 +137,14 @@ MinioClient minioClient = new MinioClient() ### AWS S3 ```cs -// 1. public MinioClient(String endpoint, String accessKey, String secretKey) -MinioClient s3Client = new MinioClient("s3.amazonaws.com", - accessKey:"YOUR-ACCESSKEYID", - secretKey:"YOUR-SECRETACCESSKEY"); -// 2. Using Builder with public MinioClient(), Endpoint, Credentials & Secure connection -MinioClient minioClient = new MinioClient() - .WithEndpoint("s3.amazonaws.com") - .WithCredentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY") - .WithSSL() - .Build() +// 1. Using Builder with public MinioClient(), Endpoint, Credentials, Secure connection & proxy +MinioClient s3Client = new MinioClient() + .WithEndpoint("s3.amazonaws.com") + .WithCredentials("YOUR-AWS-ACCESSKEYID", "YOUR-AWS-SECRETACCESSKEY") + .WithSSL() + .WithProxy(proxy) + .Build(); + ``` ## 2. Bucket operations diff --git a/Minio.Functional.Tests/FunctionalTest.cs b/Minio.Functional.Tests/FunctionalTest.cs index c321f97a6..783b5e996 100644 --- a/Minio.Functional.Tests/FunctionalTest.cs +++ b/Minio.Functional.Tests/FunctionalTest.cs @@ -1187,16 +1187,9 @@ internal static async Task RemoveObjects_Test3(MinioClient minio) } } - internal static async Task DownloadObjectAsync(string url, string filePath) + internal static async Task DownloadObjectAsync(MinioClient minio, string url, string filePath) { - var clientHandler = new HttpClientHandler(); - clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => - { - return true; - }; - var client = new HttpClient(clientHandler); - - var response = await client.GetAsync(url); + var response = await minio.WrapperGetAsync(url).ConfigureAwait(false); if (string.IsNullOrEmpty(Convert.ToString(response.Content)) || !HttpStatusCode.OK.Equals(response.StatusCode)) throw new ArgumentNullException("Unable to download via presigned URL"); @@ -1206,18 +1199,11 @@ internal static async Task DownloadObjectAsync(string url, string filePath) } } - internal static async Task UploadObjectAsync(string url, string filePath) + internal static async Task UploadObjectAsync(MinioClient minio, string url, string filePath) { - var clientHandler = new HttpClientHandler(); - clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => - { - return true; - }; - var client = new HttpClient(clientHandler); - using (var strm = new StreamContent(new FileStream(filePath, FileMode.Open, FileAccess.Read))) { - await client.PutAsync(url, strm); + await minio.WrapperPutAsync(url, strm).ConfigureAwait(false); } } @@ -4847,7 +4833,7 @@ internal static async Task PresignedGetObject_Test1(MinioClient minio) .WithExpiry(expiresInt); var presigned_url = await minio.PresignedGetObjectAsync(preArgs); - await DownloadObjectAsync(presigned_url, downloadFile); + await DownloadObjectAsync(minio, presigned_url, downloadFile).ConfigureAwait(false); var writtenInfo = new FileInfo(downloadFile); var file_read_size = writtenInfo.Length; // Compare the size of the file downloaded using the generated @@ -4985,14 +4971,7 @@ internal static async Task PresignedGetObject_Test3(MinioClient minio) .WithRequestDate(reqDate); var presigned_url = await minio.PresignedGetObjectAsync(preArgs); - var clientHandler = new HttpClientHandler(); - clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => - { - return true; - }; - var client = new HttpClient(clientHandler); - - var response = await client.GetAsync(presigned_url); + var response = await minio.WrapperGetAsync(presigned_url).ConfigureAwait(false); if (string.IsNullOrEmpty(Convert.ToString(response.Content)) || !HttpStatusCode.OK.Equals(response.StatusCode)) throw new ArgumentNullException("Unable to download via presigned URL"); @@ -5059,7 +5038,7 @@ internal static async Task PresignedPutObject_Test1(MinioClient minio) .WithObject(objectName) .WithExpiry(1000); var presigned_url = await minio.PresignedPutObjectAsync(presignedPutObjectArgs); - await UploadObjectAsync(presigned_url, fileName); + await UploadObjectAsync(minio, presigned_url, fileName); // Get stats for object from server var statObjectArgs = new StatObjectArgs() .WithBucket(bucketName) diff --git a/Minio.Functional.Tests/Program.cs b/Minio.Functional.Tests/Program.cs index 743a46d46..cec7d436a 100644 --- a/Minio.Functional.Tests/Program.cs +++ b/Minio.Functional.Tests/Program.cs @@ -17,7 +17,6 @@ using System; using System.Net; -using System.Net.Http; namespace Minio.Functional.Tests; @@ -51,21 +50,12 @@ public static void Main(string[] args) MinioClient minioClient = null; - var clientHandler = new HttpClientHandler(); - clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => - { - return true; - }; - clientHandler.UseProxy = false; - var httpClient = new HttpClient(clientHandler); - if (enableHttps == "1") // WithSSL() enables SSL support in MinIO client minioClient = new MinioClient() .WithSSL() .WithCredentials(accessKey, secretKey) .WithEndpoint(endPoint) - .WithHttpClient(httpClient) .Build(); else minioClient = new MinioClient() diff --git a/Minio/MinioClient.cs b/Minio/MinioClient.cs index b342971d0..48a0709b4 100644 --- a/Minio/MinioClient.cs +++ b/Minio/MinioClient.cs @@ -94,6 +94,7 @@ public MinioClient() /// Creates and returns an MinIO Client with custom HTTP Client /// /// Client with no arguments to be used with other builder methods + [Obsolete("Use MinioClient() and Builder method .WithHttpClient(httpClient)")] public MinioClient(HttpClient httpClient) { Region = ""; @@ -175,6 +176,23 @@ private static string SystemUserAgent /// private string FullUserAgent => $"{SystemUserAgent} {CustomUserAgent}"; + /// + /// Runs httpClient's GetAsync method + /// + public async Task WrapperGetAsync(string url) + { + var response = await HTTPClient.GetAsync(url).ConfigureAwait(false); + return response; + } + + /// + /// Runs httpClient's PutObjectAsync method + /// + public async Task WrapperPutAsync(string url, StreamContent strm) + { + await Task.Run(async () => await HTTPClient.PutAsync(url, strm).ConfigureAwait(false)).ConfigureAwait(false); + } + /// /// Resolve region of the bucket. ///