Skip to content

Commit

Permalink
Fix warnings (#766)
Browse files Browse the repository at this point in the history
* Fix warnings

* More fixes

* More warnings

* And more

* More

* More

* Fixes

* Dispose correctly

* Add metadata

* Use uppercase

* No dispose

* Revert

* Headers type

* Don't cancel cancelled task
  • Loading branch information
martijn00 committed Apr 17, 2023
1 parent 1682ce9 commit 91dc25e
Show file tree
Hide file tree
Showing 60 changed files with 406 additions and 301 deletions.
4 changes: 2 additions & 2 deletions Minio.Examples/Cases/CustomRequestLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public void LogRequest(RequestToLog requestToLog, ResponseToLog responseToLog, d

sb.AppendLine("My logger says:");
sb.Append("statusCode: ");
sb.AppendLine(responseToLog.statusCode.ToString());
sb.AppendLine(responseToLog.StatusCode.ToString());
sb.AppendLine();

sb.AppendLine("Response: ");
sb.Append(responseToLog.content);
sb.Append(responseToLog.Content);

Console.WriteLine(sb.ToString());
}
Expand Down
2 changes: 1 addition & 1 deletion Minio.Examples/Cases/GetBucketReplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static class GetBucketReplication
Console.WriteLine($"Got Bucket Replication Configuration set for bucket {bucketName}.");
foreach (var rule in repl.Rules)
{
if (rule.ID != replicationRuleID)
if (!string.Equals(rule.ID, replicationRuleID, StringComparison.OrdinalIgnoreCase))
{
// failed test due to replication rule id mismatch
var errMessage = "Unexpected replication rule ID: " +
Expand Down
2 changes: 1 addition & 1 deletion Minio.Examples/Cases/SetBucketReplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private static string Bash(string cmd)
accessKey = Environment.GetEnvironmentVariable("ACCESS_KEY");
secretKey = Environment.GetEnvironmentVariable("SECRET_KEY");
if (Environment.GetEnvironmentVariable("ENABLE_HTTPS") != null)
if (Environment.GetEnvironmentVariable("ENABLE_HTTPS").Equals("1"))
if (Environment.GetEnvironmentVariable("ENABLE_HTTPS").Equals("1", StringComparison.OrdinalIgnoreCase))
schema = "https://";
}
else
Expand Down
2 changes: 1 addition & 1 deletion Minio.Examples/Cases/SetBucketTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static class SetBucketTags
// Set Tags to the bucket
public static async Task Run(IMinioClient minio,
string bucketName = "my-bucket-name",
Dictionary<string, string> tags = null)
IDictionary<string, string> tags = null)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion Minio.Examples/Cases/SetObjectTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class SetObjectTags
public static async Task Run(IMinioClient minio,
string bucketName = "my-bucket-name",
string objectName = "my-object-name",
Dictionary<string, string> tags = null,
IDictionary<string, string> tags = null,
string versionId = null)
{
try
Expand Down
5 changes: 2 additions & 3 deletions Minio.Examples/Cases/StatObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public static void PrintStat(string bucketObject, ObjectStat statObject)
{
var objectNameInfo = $"{bucketName}-{bucketObject}";
if (!string.IsNullOrEmpty(versionID))
objectNameInfo = objectNameInfo +
$" (Version ID) {me.Response.VersionId} (Delete Marker) {me.Response.DeleteMarker}";
objectNameInfo += $" (Version ID) {me.Response.VersionId} (Delete Marker) {me.Response.DeleteMarker}";

Console.WriteLine($"[StatObject] {objectNameInfo} Exception: {me}");
}
Expand All @@ -74,7 +73,7 @@ public static void PrintStat(string bucketObject, ObjectStat statObject)
}
}

private static void PrintMetaData(Dictionary<string, string> metaData)
private static void PrintMetaData(IDictionary<string, string> metaData)
{
Console.WriteLine("Metadata:");
foreach (var metaPair in metaData) Console.WriteLine(" " + metaPair.Key + ":\t" + metaPair.Value);
Expand Down
3 changes: 2 additions & 1 deletion Minio.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public static async Task Main(string[] args)
secretKey = Environment.GetEnvironmentVariable("SECRET_KEY");
if (Environment.GetEnvironmentVariable("ENABLE_HTTPS") != null)
{
isSecure = Environment.GetEnvironmentVariable("ENABLE_HTTPS").Equals("1");
isSecure = Environment.GetEnvironmentVariable("ENABLE_HTTPS")
.Equals("1", StringComparison.OrdinalIgnoreCase);
if (isSecure && port == 80) port = 443;
}
}
Expand Down
34 changes: 16 additions & 18 deletions Minio.Functional.Tests/FunctionalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ internal static async Task ListBuckets_Test(MinioClient minio)
}
catch (Exception ex)
{
if (ex.Message.StartsWith("Bucket already owned by you"))
if (ex.Message.StartsWith("Bucket already owned by you", StringComparison.OrdinalIgnoreCase))
{
// You have your bucket already created, continue
}
Expand All @@ -495,7 +495,7 @@ internal static async Task ListBuckets_Test(MinioClient minio)
Assert.AreEqual(noOfBuckets, bucketList.Count);
bucketList.ToList().Sort((x, y) =>
{
if (x.Name == y.Name) return 0;
if (string.Equals(x.Name, y.Name, StringComparison.Ordinal)) return 0;
if (x.Name == null) return -1;
if (y.Name == null) return 1;
return x.Name.CompareTo(y.Name);
Expand Down Expand Up @@ -1367,7 +1367,7 @@ internal static async Task PresignedPostPolicy_Test1(MinioClient minio)
Assert.IsTrue(statObject.ObjectName.Equals(objectName, StringComparison.Ordinal));
Assert.AreEqual(statObject.Size, sizeExpected);
Assert.IsTrue(statObject.MetaData["Content-Type"] != null);
Assert.IsTrue(statObject.ContentType.Equals(contentType));
Assert.IsTrue(statObject.ContentType.Equals(contentType, StringComparison.OrdinalIgnoreCase));
Assert.IsTrue(statObject.MetaData[metadataKey].Equals(metadataValue, StringComparison.Ordinal));

new MintLogger("PresignedPostPolicy_Test1", presignedPostPolicySignature,
Expand Down Expand Up @@ -2694,7 +2694,8 @@ internal static async Task ListenBucketNotificationsAsync_Test1(MinioClient mini
// and captured in the receivedJson list, like
// "NotImplemented" api error. If so, we throw an exception
// and skip running this test
if (received.Count > 1 && received[1].json.StartsWith("<Error><Code>"))
if (received.Count > 1 &&
received[1].json.StartsWith("<Error><Code>", StringComparison.OrdinalIgnoreCase))
{
// Although the attribute is called "json",
// returned data in list "received" is in xml
Expand All @@ -2712,7 +2713,7 @@ internal static async Task ListenBucketNotificationsAsync_Test1(MinioClient mini
var err = JsonSerializer.Deserialize<ErrorResponse>(trimmedFull);

Exception ex = new UnexpectedMinioException(err.Message);
if (err.Code == "NotImplemented")
if (string.Equals(err.Code, "NotImplemented", StringComparison.OrdinalIgnoreCase))
ex = new NotImplementedException(err.Message);

throw ex;
Expand All @@ -2723,10 +2724,10 @@ internal static async Task ListenBucketNotificationsAsync_Test1(MinioClient mini
if (notification.Records != null)
{
Assert.AreEqual(1, notification.Records.Count);
Assert.IsTrue(notification.Records[0].eventName.Contains("s3:ObjectCreated:Put"));
Assert.IsTrue(notification.Records[0].EventName.Contains("s3:ObjectCreated:Put"));
Assert.IsTrue(
objectName.Contains(HttpUtility.UrlDecode(notification.Records[0].s3.objectMeta.key)));
Assert.IsTrue(contentType.Contains(notification.Records[0].s3.objectMeta.contentType));
objectName.Contains(HttpUtility.UrlDecode(notification.Records[0].S3.ObjectMeta.Key)));
Assert.IsTrue(contentType.Contains(notification.Records[0].S3.ObjectMeta.ContentType));
eventDetected = true;
break;
}
Expand Down Expand Up @@ -2823,8 +2824,7 @@ void Notify(MinioNotificationRaw data)
var notification = JsonSerializer.Deserialize<MinioNotification>(data.json);
if (notification is not { Records: not null }) return;

foreach (var @event in notification.Records)
rxEventsList.Add(@event);
rxEventsList.AddRange(notification.Records);
}

var listenArgs = new ListenBucketNotificationsArgs()
Expand Down Expand Up @@ -2868,7 +2868,7 @@ void Notify(MinioNotificationRaw data)
throw new ArgumentException("Timeout: while waiting for events");
}

foreach (var ev in rxEventsList) Assert.AreEqual("s3:ObjectCreated:Put", ev.eventName);
foreach (var ev in rxEventsList) Assert.AreEqual("s3:ObjectCreated:Put", ev.EventName);

new MintLogger(nameof(ListenBucketNotificationsAsync_Test2),
listenBucketNotificationsSignature,
Expand Down Expand Up @@ -2962,7 +2962,7 @@ internal static async Task ListenBucketNotificationsAsync_Test3(MinioClient mini
if (!string.IsNullOrEmpty(rxEventData.json))
{
var notification = JsonSerializer.Deserialize<MinioNotification>(rxEventData.json);
Assert.IsTrue(notification.Records[0].eventName
Assert.IsTrue(notification.Records[0].EventName
.Equals("s3:ObjectCreated:Put", StringComparison.OrdinalIgnoreCase));
new MintLogger(nameof(ListenBucketNotificationsAsync_Test3),
listenBucketNotificationsSignature,
Expand Down Expand Up @@ -4744,14 +4744,14 @@ internal static async Task GetObject_3_OffsetLength_Tests(MinioClient minio)
{
var objectSize = (int)filestream.Length;
var expectedFileSize = lengthToBeRead;
var expectedContent = string.Join("", line).Substring(offsetToStartFrom, expectedFileSize);
var expectedContent = string.Concat(line).Substring(offsetToStartFrom, expectedFileSize);
if (lengthToBeRead == 0)
{
expectedFileSize = objectSize - offsetToStartFrom;
var noOfCtrlChars = 1;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) noOfCtrlChars = 2;

expectedContent = string.Join("", line)
expectedContent = string.Concat(line)
.Substring(offsetToStartFrom, expectedFileSize - noOfCtrlChars);
}

Expand Down Expand Up @@ -4784,8 +4784,6 @@ internal static async Task GetObject_3_OffsetLength_Tests(MinioClient minio)
Assert.AreEqual(expectedFileSize, actualFileSize);
// Checking the content
#if NETFRAMEWORK
var actualContent = File.ReadAllText(tempFileName);
#else
Expand Down Expand Up @@ -5300,7 +5298,7 @@ internal static async Task ListObjectVersions_Test1(MinioClient minio)
item =>
{
if (!string.IsNullOrEmpty(prefix))
Assert.IsTrue(item.Key.StartsWith(prefix));
Assert.IsTrue(item.Key.StartsWith(prefix, StringComparison.OrdinalIgnoreCase));
count++;
},
ex => throw ex,
Expand All @@ -5312,7 +5310,7 @@ internal static async Task ListObjectVersions_Test1(MinioClient minio)
var subscription = observable.Subscribe(
item =>
{
Assert.IsTrue(item.Key.StartsWith(prefix));
Assert.IsTrue(item.Key.StartsWith(prefix, StringComparison.OrdinalIgnoreCase));
count++;
},
ex => throw ex,
Expand Down
4 changes: 2 additions & 2 deletions Minio.Functional.Tests/MintLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal sealed class MintLogger
};

public MintLogger(string testName, string function, string description, TestStatus status, TimeSpan duration,
string alert = null, string message = null, string error = null, Dictionary<string, string> args = null)
string alert = null, string message = null, string error = null, IDictionary<string, string> args = null)
{
this.function = function;
this.description = description;
Expand Down Expand Up @@ -82,7 +82,7 @@ internal sealed class MintLogger
/// <summary>
/// Key-value pair of args relevant to test
/// </summary>
public Dictionary<string, string> args { get; }
public IDictionary<string, string> args { get; }

/// <summary>
/// duration of the whole test
Expand Down
4 changes: 2 additions & 2 deletions Minio.Functional.Tests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static async Task Main(string[] args)

var runMode = Environment.GetEnvironmentVariable("MINT_MODE");

if (!string.IsNullOrEmpty(runMode) && runMode == "core")
if (!string.IsNullOrEmpty(runMode) && string.Equals(runMode, "core", StringComparison.OrdinalIgnoreCase))
{
await FunctionalTest.RunCoreTests(minioClient).ConfigureAwait(false);
Environment.Exit(0);
Expand Down Expand Up @@ -230,7 +230,7 @@ public static async Task Main(string[] args)
await FunctionalTest.EncryptedCopyObject_Test2(minioClient).ConfigureAwait(false);
}

if (kmsEnabled != null && kmsEnabled == "1")
if (kmsEnabled != null && string.Equals(kmsEnabled, "1", StringComparison.OrdinalIgnoreCase))
{
await FunctionalTest.PutGetStatEncryptedObject_Test3(minioClient).ConfigureAwait(false);
await FunctionalTest.EncryptedCopyObject_Test3(minioClient).ConfigureAwait(false);
Expand Down
8 changes: 4 additions & 4 deletions Minio.Tests/OperationsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public async Task PresignedGetObject()

if (!await ObjectExistsAsync(client, bucket, objectName).ConfigureAwait(false))
{
var helloData = Encoding.UTF8.GetBytes("hello world");
using var helloStream = helloData.AsMemory().AsStream();
ReadOnlyMemory<byte> helloData = Encoding.UTF8.GetBytes("hello world");
using var helloStream = helloData.AsStream();
var PutObjectArgs = new PutObjectArgs()
.WithBucket(bucket)
.WithObject(objectName)
Expand Down Expand Up @@ -113,8 +113,8 @@ public async Task PresignedGetObjectWithHeaders()

if (!await ObjectExistsAsync(client, bucket, objectName).ConfigureAwait(false))
{
var helloData = Encoding.UTF8.GetBytes("hello world");
using var helloStream = helloData.AsMemory().AsStream();
ReadOnlyMemory<byte> helloData = Encoding.UTF8.GetBytes("hello world");
using var helloStream = helloData.AsStream();
var PutObjectArgs = new PutObjectArgs()
.WithBucket(bucket)
.WithObject(objectName)
Expand Down
23 changes: 13 additions & 10 deletions Minio.Tests/ReuseTcpConnectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ public class ReuseTcpConnectionTest
{
public ReuseTcpConnectionTest()
{
_minioClient = new MinioClient()
minioClient = new MinioClient()
.WithEndpoint(TestHelper.Endpoint)
.WithCredentials(TestHelper.AccessKey, TestHelper.SecretKey)
.WithSSL()
.Build();
}

private MinioClient _minioClient { get; }
private MinioClient minioClient { get; }

private async Task<bool> ObjectExistsAsync(MinioClient client, string bucket, string objectName)
{
if (string.IsNullOrEmpty(bucket))
bucket = "bucket";

try
{
var getObjectArgs = new GetObjectArgs()
.WithBucket("bucket")
.WithBucket(bucket)
.WithObject(objectName)
.WithFile("testfile");
await client.GetObjectAsync(getObjectArgs).ConfigureAwait(false);
Expand All @@ -45,24 +48,24 @@ public async Task ReuseTcpTest()

var bktExistArgs = new BucketExistsArgs()
.WithBucket(bucket);
var found = await _minioClient.BucketExistsAsync(bktExistArgs).ConfigureAwait(false);
var found = await minioClient.BucketExistsAsync(bktExistArgs).ConfigureAwait(false);
if (!found)
{
var mkBktArgs = new MakeBucketArgs()
.WithBucket(bucket);
await _minioClient.MakeBucketAsync(mkBktArgs).ConfigureAwait(false);
await minioClient.MakeBucketAsync(mkBktArgs).ConfigureAwait(false);
}

if (!await ObjectExistsAsync(_minioClient, bucket, objectName).ConfigureAwait(false))
if (!await ObjectExistsAsync(minioClient, bucket, objectName).ConfigureAwait(false))
{
var helloData = Encoding.UTF8.GetBytes("hello world");
var helloStream = helloData.AsMemory().AsStream();
ReadOnlyMemory<byte> helloData = Encoding.UTF8.GetBytes("hello world");
using var helloStream = helloData.AsStream();
var putObjectArgs = new PutObjectArgs()
.WithBucket(bucket)
.WithObject(objectName)
.WithStreamData(helloStream)
.WithObjectSize(helloData.Length);
await _minioClient.PutObjectAsync(putObjectArgs).ConfigureAwait(false);
await minioClient.PutObjectAsync(putObjectArgs).ConfigureAwait(false);
}

await GetObjectLength(bucket, objectName).ConfigureAwait(false);
Expand Down Expand Up @@ -90,7 +93,7 @@ private async Task<double> GetObjectLength(string bucket, string objectName)
.WithBucket(bucket)
.WithObject(objectName)
.WithCallbackStream(stream => stream.Dispose());
await _minioClient.GetObjectAsync(getObjectArgs).ConfigureAwait(false);
await minioClient.GetObjectAsync(getObjectArgs).ConfigureAwait(false);

return objectLength;
}
Expand Down
6 changes: 4 additions & 2 deletions Minio/ApiEndpoints/BucketOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public async Task MakeBucketAsync(MakeBucketArgs args, CancellationToken cancell
if (string.IsNullOrEmpty(args.Location))
args.Location = Region;

if (args.Location == "us-east-1" && !string.IsNullOrEmpty(Region))
if (string.Equals(args.Location, "us-east-1", StringComparison.OrdinalIgnoreCase) &&
!string.IsNullOrEmpty(Region))
args.Location = Region;

args.IsBucketCreationRequest = true;
Expand Down Expand Up @@ -227,7 +228,8 @@ public IObservable<Item> ListObjectsAsync(ListObjectsArgs args, CancellationToke
else
{
var objectList = await GetObjectListAsync(goArgs, cts.Token).ConfigureAwait(false);
if (objectList.Item2.Count == 0 && objectList.Item1.KeyCount.Equals("0") && count == 0)
if (objectList.Item2.Count == 0 &&
objectList.Item1.KeyCount.Equals("0", StringComparison.OrdinalIgnoreCase) && count == 0)
return;
var listObjectsItemResponse = new ListObjectsItemResponse(args, objectList, obs);
Expand Down
4 changes: 2 additions & 2 deletions Minio/ApiEndpoints/IObjectOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public interface IObjectOperations
/// <exception cref="BucketNotFoundException">When bucket is not found</exception>
/// <exception cref="ObjectNotFoundException">When object is not found</exception>
/// <exception cref="MalFormedXMLException">When configuration XML provided is invalid</exception>
Task<(Uri, Dictionary<string, string>)> PresignedPostPolicyAsync(PresignedPostPolicyArgs args);
Task<(Uri, IDictionary<string, string>)> PresignedPostPolicyAsync(PresignedPostPolicyArgs args);

/// <summary>
/// Presigned Put url -returns a presigned url to upload an object without credentials.URL can have a maximum expiry of
Expand Down Expand Up @@ -307,7 +307,7 @@ public interface IObjectOperations
/// </summary>
/// <param name="policy"></param>
/// <returns></returns>
Task<(Uri, Dictionary<string, string>)> PresignedPostPolicyAsync(PostPolicy policy);
Task<(Uri, IDictionary<string, string>)> PresignedPostPolicyAsync(PostPolicy policy);

/// <summary>
/// Gets Tagging values set for this object
Expand Down

0 comments on commit 91dc25e

Please sign in to comment.