Skip to content

Commit a29f4b1

Browse files
martijn00ebozduman
andauthored
Next fixes (#779)
* Updates for proj files * Cleanup * Change clientprovider to interface * Use ValueTask for async methods who only call sync * Use Task based stream * Cleans * Fixes * Format * Update tool * Move all to interface * New user and password env * Format * Replaces the shared filename --------- Co-authored-by: Ersan <ersan.bozduman@gmail.com>
1 parent 21b4709 commit a29f4b1

26 files changed

+357
-334
lines changed

.config/dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"isRoot": true,
44
"tools": {
55
"jetbrains.resharper.globaltools": {
6-
"version": "2023.1.0",
6+
"version": "2023.1.1",
77
"commands": [
88
"jb"
99
]

Directory.Build.props

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
<EnableNETAnalyzers>false</EnableNETAnalyzers>
2828
<AnalysisLevel>latest</AnalysisLevel>
29-
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
29+
<AnalysisMode>All</AnalysisMode>
3030

3131
<IsTestProject>$(MSBuildProjectName.Contains('Test'))</IsTestProject>
3232
</PropertyGroup>
@@ -51,8 +51,6 @@
5151
</PropertyGroup>
5252

5353
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
54-
<DebugType>full</DebugType>
55-
<DebugSymbols>true</DebugSymbols>
5654
</PropertyGroup>
5755

5856
<ItemGroup>
@@ -80,7 +78,7 @@
8078
<PrivateAssets>all</PrivateAssets>
8179
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
8280
</PackageReference>
83-
<PackageReference Include="Meziantou.Analyzer" Version="2.0.37">
81+
<PackageReference Include="Meziantou.Analyzer" Version="2.0.48">
8482
<PrivateAssets>all</PrivateAssets>
8583
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
8684
</PackageReference>

Minio.Examples/Cases/ChainedCredentialProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static class ChainedCredentialProvider
2626
public static async Task Run()
2727
{
2828
var provider = new ChainedProvider()
29-
.AddProviders(new ClientProvider[] { new AWSEnvironmentProvider(), new MinioEnvironmentProvider() });
29+
.AddProviders(new IClientProvider[] { new AWSEnvironmentProvider(), new MinioEnvironmentProvider() });
3030
//Chained provider definition here.
3131
using var minioClient = new MinioClient()
3232
.WithEndpoint("s3.amazonaws.com")

Minio.Examples/Cases/GetPartialObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static async Task Run(IMinioClient minio,
4040
.WithBucket(bucketName)
4141
.WithObject(objectName)
4242
.WithOffsetAndLength(1024L, 4096L)
43-
.WithCallbackStream(async stream =>
43+
.WithCallbackStream(async (stream, cancellationToken) =>
4444
{
4545
var fileStream = File.Create(fileName);
4646
await stream.CopyToAsync(fileStream).ConfigureAwait(false);

Minio.Functional.Tests/FunctionalTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5353,7 +5353,7 @@ internal static async Task PresignedGetObject_Test1(MinioClient minio)
53535353
var bucketName = GetRandomName(15);
53545354
var objectName = GetRandomObjectName(10);
53555355
var expiresInt = 1000;
5356-
var downloadFile = "downloadFileName";
5356+
var downloadFile = GetRandomObjectName(10);
53575357

53585358
var args = new Dictionary<string, string>
53595359
{
@@ -5481,7 +5481,7 @@ internal static async Task PresignedGetObject_Test3(MinioClient minio)
54815481
var objectName = GetRandomObjectName(10);
54825482
var expiresInt = 1000;
54835483
var reqDate = DateTime.UtcNow.AddSeconds(-50);
5484-
var downloadFile = "downloadFileName";
5484+
var downloadFile = GetRandomObjectName(10);
54855485
var args = new Dictionary<string, string>
54865486
{
54875487
{ "bucketName", bucketName },

Minio.Tests/RegionTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
namespace Minio.Tests;
2020

2121
[TestClass]
22-
public class TestRegion
22+
public class RegionTest
2323
{
2424
[DataTestMethod]
2525
[DataRow("s3.us-east-2.amazonaws.com", "us-east-2")]

Minio.Tests/UnitTest1.cs

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -165,125 +165,4 @@ public void TestEndpointFailure()
165165
//
166166

167167
#endregion
168-
}
169-
170-
/// <summary>
171-
/// Summary description for UnitTest2
172-
/// </summary>
173-
[TestClass]
174-
public class UnitTest2
175-
{
176-
public UnitTest2()
177-
{
178-
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
179-
| SecurityProtocolType.Tls11
180-
| SecurityProtocolType.Tls12;
181-
using var minio = new MinioClient()
182-
.WithEndpoint(TestHelper.Endpoint)
183-
.WithCredentials(TestHelper.AccessKey, TestHelper.SecretKey)
184-
.WithSSL()
185-
.Build();
186-
}
187-
188-
/// <summary>
189-
/// Gets or sets the test context which provides
190-
/// information about and functionality for the current test run.
191-
/// </summary>
192-
public TestContext TestContext { get; set; }
193-
194-
[TestMethod]
195-
public void TestWithUrl()
196-
{
197-
using var client = new MinioClient()
198-
.WithEndpoint("localhost", 9000)
199-
.WithCredentials("minio", "minio")
200-
.Build();
201-
}
202-
203-
[TestMethod]
204-
public void TestWithoutPort()
205-
{
206-
using var client = new MinioClient()
207-
.WithEndpoint("localhost")
208-
.WithCredentials("minio", "minio")
209-
.Build();
210-
}
211-
212-
[TestMethod]
213-
public void TestWithTrailingSlash()
214-
{
215-
using var client = new MinioClient()
216-
.WithEndpoint("localhost", 9000)
217-
.WithCredentials("minio", "minio")
218-
.Build();
219-
}
220-
221-
[TestMethod]
222-
[ExpectedException(typeof(InvalidEndpointException))]
223-
public void TestUrlFailsWithMalformedScheme()
224-
{
225-
using var client = new MinioClient()
226-
.WithEndpoint("htp://localhost", 9000)
227-
.WithCredentials("minio", "minio")
228-
.Build();
229-
}
230-
231-
[TestMethod]
232-
[ExpectedException(typeof(InvalidEndpointException))]
233-
public void TestUrlFailsWithPath()
234-
{
235-
using var client = new MinioClient().WithEndpoint("localhost:9000/foo").WithCredentials("minio", "minio")
236-
.Build();
237-
}
238-
239-
[TestMethod]
240-
[ExpectedException(typeof(InvalidEndpointException))]
241-
public void TestUrlFailsWithQuery()
242-
{
243-
using var client = new MinioClient()
244-
.WithEndpoint("localhost:9000/?foo=bar")
245-
.WithCredentials("minio", "minio")
246-
.Build();
247-
}
248-
249-
[TestMethod]
250-
[ExpectedException(typeof(ArgumentException))]
251-
public void TestSetAppInfoFailsNullApp()
252-
{
253-
using var client = new MinioClient()
254-
.WithEndpoint("localhost", 9000)
255-
.WithCredentials("minio", "minio")
256-
.Build();
257-
client.SetAppInfo(null, "1.2.2");
258-
}
259-
260-
[TestMethod]
261-
[ExpectedException(typeof(ArgumentException))]
262-
public void TestSetAppInfoFailsNullVersion()
263-
{
264-
using var client = new MinioClient()
265-
.WithEndpoint("localhost", 9000)
266-
.WithCredentials("minio", "minio")
267-
.Build();
268-
client.SetAppInfo("Hello-App", null);
269-
}
270-
271-
[TestMethod]
272-
public void TestSetAppInfoSuccess()
273-
{
274-
using var client = new MinioClient()
275-
.WithEndpoint("localhost", 9000)
276-
.WithCredentials("minio", "minio")
277-
.Build();
278-
client.SetAppInfo("Hello-App", "1.2.1");
279-
}
280-
281-
[TestMethod]
282-
public void TestEndpointSuccess()
283-
{
284-
using var client = new MinioClient()
285-
.WithEndpoint("s3.amazonaws.com")
286-
.WithCredentials("minio", "minio")
287-
.Build();
288-
}
289168
}

Minio.Tests/UnitTest2.cs

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*
2+
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2017 MinIO, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using System.Net;
18+
using Microsoft.VisualStudio.TestTools.UnitTesting;
19+
using Minio.Exceptions;
20+
21+
namespace Minio.Tests;
22+
23+
/// <summary>
24+
/// Summary description for UnitTest2
25+
/// </summary>
26+
[TestClass]
27+
public class UnitTest2
28+
{
29+
public UnitTest2()
30+
{
31+
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
32+
| SecurityProtocolType.Tls11
33+
| SecurityProtocolType.Tls12;
34+
using var minio = new MinioClient()
35+
.WithEndpoint(TestHelper.Endpoint)
36+
.WithCredentials(TestHelper.AccessKey, TestHelper.SecretKey)
37+
.WithSSL()
38+
.Build();
39+
}
40+
41+
/// <summary>
42+
/// Gets or sets the test context which provides
43+
/// information about and functionality for the current test run.
44+
/// </summary>
45+
public TestContext TestContext { get; set; }
46+
47+
[TestMethod]
48+
public void TestWithUrl()
49+
{
50+
using var client = new MinioClient()
51+
.WithEndpoint("localhost", 9000)
52+
.WithCredentials("minio", "minio")
53+
.Build();
54+
}
55+
56+
[TestMethod]
57+
public void TestWithoutPort()
58+
{
59+
using var client = new MinioClient()
60+
.WithEndpoint("localhost")
61+
.WithCredentials("minio", "minio")
62+
.Build();
63+
}
64+
65+
[TestMethod]
66+
public void TestWithTrailingSlash()
67+
{
68+
using var client = new MinioClient()
69+
.WithEndpoint("localhost", 9000)
70+
.WithCredentials("minio", "minio")
71+
.Build();
72+
}
73+
74+
[TestMethod]
75+
[ExpectedException(typeof(InvalidEndpointException))]
76+
public void TestUrlFailsWithMalformedScheme()
77+
{
78+
using var client = new MinioClient()
79+
.WithEndpoint("htp://localhost", 9000)
80+
.WithCredentials("minio", "minio")
81+
.Build();
82+
}
83+
84+
[TestMethod]
85+
[ExpectedException(typeof(InvalidEndpointException))]
86+
public void TestUrlFailsWithPath()
87+
{
88+
using var client = new MinioClient().WithEndpoint("localhost:9000/foo").WithCredentials("minio", "minio")
89+
.Build();
90+
}
91+
92+
[TestMethod]
93+
[ExpectedException(typeof(InvalidEndpointException))]
94+
public void TestUrlFailsWithQuery()
95+
{
96+
using var client = new MinioClient()
97+
.WithEndpoint("localhost:9000/?foo=bar")
98+
.WithCredentials("minio", "minio")
99+
.Build();
100+
}
101+
102+
[TestMethod]
103+
[ExpectedException(typeof(ArgumentException))]
104+
public void TestSetAppInfoFailsNullApp()
105+
{
106+
using var client = new MinioClient()
107+
.WithEndpoint("localhost", 9000)
108+
.WithCredentials("minio", "minio")
109+
.Build();
110+
client.SetAppInfo(null, "1.2.2");
111+
}
112+
113+
[TestMethod]
114+
[ExpectedException(typeof(ArgumentException))]
115+
public void TestSetAppInfoFailsNullVersion()
116+
{
117+
using var client = new MinioClient()
118+
.WithEndpoint("localhost", 9000)
119+
.WithCredentials("minio", "minio")
120+
.Build();
121+
client.SetAppInfo("Hello-App", null);
122+
}
123+
124+
[TestMethod]
125+
public void TestSetAppInfoSuccess()
126+
{
127+
using var client = new MinioClient()
128+
.WithEndpoint("localhost", 9000)
129+
.WithCredentials("minio", "minio")
130+
.Build();
131+
client.SetAppInfo("Hello-App", "1.2.1");
132+
}
133+
134+
[TestMethod]
135+
public void TestEndpointSuccess()
136+
{
137+
using var client = new MinioClient()
138+
.WithEndpoint("s3.amazonaws.com")
139+
.WithCredentials("minio", "minio")
140+
.Build();
141+
}
142+
}

Minio/Credentials/AWSEnvironmentProvider.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,16 @@
1919

2020
namespace Minio.Credentials;
2121

22-
public class AWSEnvironmentProvider : EnvironmentProvider
22+
public class AWSEnvironmentProvider : IClientProvider
2323
{
24-
public override AccessCredentials GetCredentials()
24+
public AccessCredentials GetCredentials()
2525
{
26-
var credentials = new AccessCredentials(GetAccessKey(), GetSecretKey(), GetSessionToken(), default);
27-
return credentials;
26+
return new AccessCredentials(GetAccessKey(), GetSecretKey(), GetSessionToken(), default);
2827
}
2928

30-
public override async Task<AccessCredentials> GetCredentialsAsync()
29+
public ValueTask<AccessCredentials> GetCredentialsAsync()
3130
{
32-
var creds = GetCredentials();
33-
await Task.Yield();
34-
return creds;
31+
return new ValueTask<AccessCredentials>(GetCredentials());
3532
}
3633

3734
internal string GetAccessKey()

0 commit comments

Comments
 (0)