Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<AnalysisLevel>latest</AnalysisLevel>
<AnalysisMode>Default</AnalysisMode>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>

<IsTestProject>$(MSBuildProjectName.Contains('Test'))</IsTestProject>
Expand Down
2 changes: 1 addition & 1 deletion Minio/ApiEndpoints/ObjectOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ await ExecuteTaskAsync(NoErrorHandlers, requestMessageBuilder, cancellationToken
{
PartNumber = int.Parse(c.Element(ns + "PartNumber").Value,
CultureInfo.CurrentCulture),
ETag = c.Element(ns + "ETag").Value.Replace("\"", string.Empty),
ETag = c.Element(ns + "ETag").Value.Replace("\"", string.Empty, StringComparison.OrdinalIgnoreCase),
Size = long.Parse(c.Element(ns + "Size").Value,
CultureInfo.CurrentCulture)
};
Expand Down
7 changes: 4 additions & 3 deletions Minio/Credentials/IAMAWSProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public AccessCredentials GetCredentials()
url = RequestUtil.MakeTargetURL("sts." + region + ".amazonaws.com", true);
}

IClientProvider provider = new WebIdentityProvider()
var provider = new WebIdentityProvider()
.WithSTSEndpoint(url)
.WithRoleAction("AssumeRoleWithWebIdentity")
.WithDurationInSeconds(null)
Expand Down Expand Up @@ -125,7 +125,7 @@ internal AccessCredentials GetAccessCredentials(string tokenFile)
url = new Uri(urlStr);
}

IClientProvider provider = new WebIdentityProvider()
var provider = new WebIdentityProvider()
.WithJWTSupplier(() =>
{
var tokenContents = File.ReadAllText(tokenFile);
Expand Down Expand Up @@ -238,7 +238,8 @@ public IAMAWSProvider WithEndpoint(string endpoint)
if (string.IsNullOrEmpty(endpoint))
throw new ArgumentException($"'{nameof(endpoint)}' cannot be null or empty.", nameof(endpoint));

if (endpoint.Contains("https") || endpoint.Contains("http"))
if (endpoint.Contains("https", StringComparison.OrdinalIgnoreCase) ||
endpoint.Contains("http", StringComparison.OrdinalIgnoreCase))
CustomEndPoint = new Uri(endpoint);
else
CustomEndPoint = RequestUtil.MakeTargetURL(endpoint, true);
Expand Down
3 changes: 2 additions & 1 deletion Minio/DataModel/Args/PutObjectArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ var hash
#else
var hash = SHA256.HashData(RequestBody.Span);
#endif
var hex = BitConverter.ToString(hash).Replace("-", string.Empty).ToLowerInvariant();
var hex = BitConverter.ToString(hash).Replace("-", string.Empty, StringComparison.OrdinalIgnoreCase)
.ToLowerInvariant();
requestMessageBuilder.AddOrUpdateHeaderParameter("x-amz-content-sha256", hex);
requestMessageBuilder.SetBody(RequestBody);
}
Expand Down
2 changes: 1 addition & 1 deletion Minio/DataModel/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public string ETag
set
{
if (value is not null)
etag = value.Replace("\"", string.Empty);
etag = value.Replace("\"", string.Empty, StringComparison.OrdinalIgnoreCase);
else
etag = null;
}
Expand Down
2 changes: 1 addition & 1 deletion Minio/DataModel/ObjectStat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static ObjectStat FromResponseHeaders(string objectName, IDictionary<stri
objInfo.LastModified = DateTime.Parse(paramValue, CultureInfo.InvariantCulture);
break;
case "etag":
objInfo.ETag = paramValue.Replace("\"", string.Empty);
objInfo.ETag = paramValue.Replace("\"", string.Empty, StringComparison.OrdinalIgnoreCase);
break;
case "content-type":
objInfo.ContentType = paramValue;
Expand Down
2 changes: 1 addition & 1 deletion Minio/DataModel/Part.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public string ETag
set
{
if (value is not null)
etag = value.Replace("\"", string.Empty);
etag = value.Replace("\"", string.Empty, StringComparison.OrdinalIgnoreCase);
else
etag = null;
}
Expand Down
5 changes: 3 additions & 2 deletions Minio/DataModel/Replication/ReplicationConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2021 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -76,7 +76,8 @@ public string MarshalXML()
xs.Serialize(xw, this, ns);
xw.Flush();

str = Utils.RemoveNamespaceInXML(sw.ToString()).Replace("\r", "").Replace("\n", "");
str = Utils.RemoveNamespaceInXML(sw.ToString()).Replace("\r", "", StringComparison.OrdinalIgnoreCase)
.Replace("\n", "", StringComparison.OrdinalIgnoreCase);
}
}
catch (Exception ex)
Expand Down
2 changes: 1 addition & 1 deletion Minio/DataModel/Select/SelectResponseStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private void Start()
payloadStream.Close();
}

private IDictionary<string, string> ExtractHeaders(Span<byte> data)
private Dictionary<string, string> ExtractHeaders(Span<byte> data)
{
var headerMap = new Dictionary<string, string>(StringComparer.Ordinal);
var offset = 0;
Expand Down
8 changes: 4 additions & 4 deletions Minio/Exceptions/CredentialsProviderException.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2021 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -21,11 +21,11 @@ namespace Minio.Exceptions;
[Serializable]
public class CredentialsProviderException : MinioException
{
private readonly string CredentialProviderType;
private readonly string credentialProviderType;

public CredentialsProviderException(string credentialProviderType, string message) : base(message)
{
CredentialProviderType = credentialProviderType;
this.credentialProviderType = credentialProviderType;
}

public CredentialsProviderException(ResponseResult serverResponse) : base(serverResponse)
Expand All @@ -50,6 +50,6 @@ public CredentialsProviderException(string message, Exception innerException) :

public override string ToString()
{
return $"{CredentialProviderType}: {base.ToString()}";
return $"{credentialProviderType}: {base.ToString()}";
}
}
2 changes: 2 additions & 0 deletions Minio/Handlers/DefaultErrorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class DefaultErrorHandler : IApiResponseErrorHandler
{
public void Handle(ResponseResult response)
{
if (response is null) throw new ArgumentNullException(nameof(response));

if (response.StatusCode is < HttpStatusCode.OK or >= HttpStatusCode.BadRequest)
MinioClient.ParseError(response);
}
Expand Down
2 changes: 2 additions & 0 deletions Minio/Handlers/DefaultRetryPolicyHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public DefaultRetryPolicyHandler(Func<Func<Task<ResponseResult>>, Task<ResponseR

public virtual Task<ResponseResult> Handle(Func<Task<ResponseResult>> executeRequestCallback)
{
if (executeRequestCallback is null) throw new ArgumentNullException(nameof(executeRequestCallback));

if (RetryPolicyHandler is not null)
return RetryPolicyHandler.Invoke(executeRequestCallback);

Expand Down
4 changes: 2 additions & 2 deletions Minio/Helper/BuilderUtil.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -26,7 +26,7 @@ public static bool IsAwsDualStackEndpoint(string endpoint)
if (string.IsNullOrEmpty(endpoint))
throw new ArgumentException($"'{nameof(endpoint)}' cannot be null or empty.", nameof(endpoint));

return endpoint.Contains(".dualstack.");
return endpoint.Contains(".dualstack.", StringComparison.OrdinalIgnoreCase);
}

public static bool IsAwsAccelerateEndpoint(string endpoint)
Expand Down
2 changes: 1 addition & 1 deletion Minio/Helper/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ var hashedBytes
}

[SuppressMessage("Design", "MA0051:Method is too long", Justification = "One time list of type mappings")]
private static IDictionary<string, string> AddContentTypeMappings()
private static Dictionary<string, string> AddContentTypeMappings()
{
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
Expand Down
8 changes: 4 additions & 4 deletions Minio/MinioClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public MinioClient()
/// <summary>
/// Default error handling delegate
/// </summary>
private IApiResponseErrorHandler DefaultErrorHandlingDelegate { get; } = new DefaultErrorHandler();
public IApiResponseErrorHandler DefaultErrorHandler { get; set; } = new DefaultErrorHandler();

// Save Credentials from user
internal string AccessKey { get; set; }
Expand Down Expand Up @@ -326,7 +326,7 @@ internal async Task<HttpRequestMessageBuilder> CreateRequest(
if (method == HttpMethod.Put && objectName is null && resourcePath is null)
// use path style for make bucket to workaround "AuthorizationHeaderMalformed" error from s3.amazonaws.com
usePathStyle = true;
else if (resourcePath?.Contains("location") == true)
else if (resourcePath?.Contains("location", StringComparison.OrdinalIgnoreCase) == true)
// use path style for location query
usePathStyle = true;
else if (bucketName.Contains('.', StringComparison.Ordinal) && Secure)
Expand Down Expand Up @@ -608,7 +608,7 @@ private static void ParseErrorFromContent(ResponseResult response)
&& errResponse.Code.Equals("InvalidRequest", StringComparison.OrdinalIgnoreCase))
{
var legalHold = new Dictionary<string, string>(StringComparer.Ordinal) { { "legal-hold", "" } };
if (response.Request.RequestUri.Query.Contains("legalHold"))
if (response.Request.RequestUri.Query.Contains("legalHold", StringComparison.OrdinalIgnoreCase))
throw new MissingObjectLockConfigurationException(errResponse.BucketName, errResponse.Message);
}

Expand Down Expand Up @@ -650,7 +650,7 @@ private void HandleIfErrorResponse(ResponseResult response, IEnumerable<IApiResp
foreach (var handler in handlers) handler.Handle(response);

// Fall back default error handler
DefaultErrorHandlingDelegate.Handle(response);
DefaultErrorHandler.Handle(response);
}

/// <summary>
Expand Down
6 changes: 4 additions & 2 deletions Minio/V4Authenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ ReadOnlySpan<byte> hash
/// <returns>Hexlified string of input bytes</returns>
private string BytesToHex(ReadOnlySpan<byte> checkSum)
{
return BitConverter.ToString(checkSum.ToArray()).Replace("-", string.Empty).ToLowerInvariant();
return BitConverter.ToString(checkSum.ToArray()).Replace("-", string.Empty, StringComparison.OrdinalIgnoreCase)
.ToLowerInvariant();
}

/// <summary>
Expand Down Expand Up @@ -545,7 +546,8 @@ var hash
#else
var hash = SHA256.HashData(body.Span);
#endif
var hex = BitConverter.ToString(hash).Replace("-", string.Empty).ToLowerInvariant();
var hex = BitConverter.ToString(hash).Replace("-", string.Empty, StringComparison.OrdinalIgnoreCase)
.ToLowerInvariant();
requestBuilder.AddOrUpdateHeaderParameter("x-amz-content-sha256", hex);
}
else if (!IsSecure && !requestBuilder.Content.IsEmpty)
Expand Down