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
2 changes: 1 addition & 1 deletion Minio.Functional.Tests/FunctionalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ internal static async Task DownloadObjectAsync(IMinioClient minio, string url, s
CancellationToken cancellationToken = default)
{
using var response = await minio.WrapperGetAsync(url).ConfigureAwait(false);
if (string.IsNullOrEmpty(Convert.ToString(response.Content)) || !HttpStatusCode.OK.Equals(response.StatusCode))
if (string.IsNullOrEmpty(Convert.ToString(response.Content)) || HttpStatusCode.OK != response.StatusCode)
throw new InvalidOperationException("Unable to download via presigned URL" + nameof(response.Content));

using var fs = new FileStream(filePath, FileMode.CreateNew);
Expand Down
2 changes: 1 addition & 1 deletion Minio.Tests/NegativeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public async Task TestInvalidObjectNameError()
var ex = await Assert.ThrowsExceptionAsync<InvalidObjectNameException>(
() => minio.StatObjectAsync(statObjArgs)).ConfigureAwait(false);
for (var i = 0;
i < tryCount && ex.ServerResponse?.StatusCode.Equals(HttpStatusCode.ServiceUnavailable) == true;
i < tryCount && ex.ServerResponse?.StatusCode == HttpStatusCode.ServiceUnavailable;
++i)
ex = await Assert.ThrowsExceptionAsync<InvalidObjectNameException>(
() => minio.StatObjectAsync(statObjArgs)).ConfigureAwait(false);
Expand Down
4 changes: 2 additions & 2 deletions Minio/ApiEndpoints/BucketOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ await this.ExecuteTaskAsync(ResponseErrorHandlers, requestMessageBuilder,
.ConfigureAwait(false);

var bucketList = new ListAllMyBucketsResult();
if (HttpStatusCode.OK.Equals(response.StatusCode))
if (HttpStatusCode.OK == response.StatusCode)
{
using var stream = response.ContentBytes.AsStream();
bucketList = Utils.DeserializeXml<ListAllMyBucketsResult>(stream);
Expand Down Expand Up @@ -84,7 +84,7 @@ await this.ExecuteTaskAsync(ResponseErrorHandlers, requestMessageBuilder,
catch (InternalClientException ice)
{
return (ice.ServerResponse is null ||
!HttpStatusCode.NotFound.Equals(ice.ServerResponse.StatusCode)) &&
HttpStatusCode.NotFound != ice.ServerResponse.StatusCode) &&
ice.ServerResponse is not null;
}
catch (Exception ex)
Expand Down
2 changes: 1 addition & 1 deletion Minio/BucketRegionCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ internal static async Task<string> Update(IMinioClient client, string bucketName
using var response =
await client.ExecuteTaskAsync(client.ResponseErrorHandlers, requestBuilder).ConfigureAwait(false);

if (response is not null && HttpStatusCode.OK.Equals(response.StatusCode))
if (response is not null && HttpStatusCode.OK == response.StatusCode)
{
var root = XDocument.Parse(response.Content);
location = root.Root.Value;
Expand Down
2 changes: 1 addition & 1 deletion Minio/Credentials/AssumeRoleBaseProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ internal virtual async Task<HttpRequestMessageBuilder> BuildRequest()
internal virtual AccessCredentials ParseResponse(HttpResponseMessage response)
{
var content = Convert.ToString(response.Content, CultureInfo.InvariantCulture);
if (string.IsNullOrEmpty(content) || !HttpStatusCode.OK.Equals(response.StatusCode))
if (string.IsNullOrEmpty(content) || HttpStatusCode.OK != response.StatusCode)
throw new ArgumentNullException(nameof(response), "Unable to generate credentials. Response error.");

using var stream = Encoding.UTF8.GetBytes(content).AsMemory().AsStream();
Expand Down
4 changes: 2 additions & 2 deletions Minio/Credentials/IAMAWSProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public async Task<AccessCredentials> GetAccessCredentials(Uri url)
await Client.ExecuteTaskAsync(Enumerable.Empty<IApiResponseErrorHandler>(), requestBuilder)
.ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(response.Content) ||
!HttpStatusCode.OK.Equals(response.StatusCode))
HttpStatusCode.OK != response.StatusCode)
throw new CredentialsProviderException("IAMAWSProvider",
"Credential Get operation failed with HTTP Status code: " + response.StatusCode);
/*
Expand Down Expand Up @@ -187,7 +187,7 @@ await Client.ExecuteTaskAsync(Enumerable.Empty<IApiResponseErrorHandler>(), requ
.ConfigureAwait(false);

if (string.IsNullOrWhiteSpace(response.Content) ||
!HttpStatusCode.OK.Equals(response.StatusCode))
HttpStatusCode.OK != response.StatusCode)
throw new CredentialsProviderException("IAMAWSProvider",
"Credential Get operation failed with HTTP Status code: " + response.StatusCode);

Expand Down
2 changes: 1 addition & 1 deletion Minio/Credentials/WebIdentityClientGrantsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal override AccessCredentials ParseResponse(HttpResponseMessage response)
// txtBlock.Text = readStream.ReadToEnd();
var content = Convert.ToString(response.Content, CultureInfo.InvariantCulture);
if (string.IsNullOrWhiteSpace(content) ||
!HttpStatusCode.OK.Equals(response.StatusCode))
HttpStatusCode.OK != response.StatusCode)
throw new ArgumentNullException(nameof(response), "Unable to get credentials. Response error.");

using var stream = Encoding.UTF8.GetBytes(content).AsMemory().AsStream();
Expand Down
2 changes: 1 addition & 1 deletion Minio/DataModel/Response/GetBucketEncryptionResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal class GetBucketEncryptionResponse : GenericResponse
internal GetBucketEncryptionResponse(HttpStatusCode statusCode, string responseContent)
: base(statusCode, responseContent)
{
if (string.IsNullOrEmpty(responseContent) || !HttpStatusCode.OK.Equals(statusCode))
if (string.IsNullOrEmpty(responseContent) || HttpStatusCode.OK != statusCode)
{
BucketEncryptionConfiguration = null;
return;
Expand Down
2 changes: 1 addition & 1 deletion Minio/DataModel/Response/GetBucketLifecycleResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal GetBucketLifecycleResponse(HttpStatusCode statusCode, string responseCo
: base(statusCode, responseContent)
{
if (string.IsNullOrEmpty(responseContent) ||
!HttpStatusCode.OK.Equals(statusCode))
HttpStatusCode.OK != statusCode)
{
BucketLifecycle = null;
return;
Expand Down
2 changes: 1 addition & 1 deletion Minio/DataModel/Response/GetBucketNotificationsResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal GetBucketNotificationsResponse(HttpStatusCode statusCode, string respon
: base(statusCode, responseContent)
{
if (string.IsNullOrEmpty(responseContent) ||
!HttpStatusCode.OK.Equals(statusCode))
HttpStatusCode.OK != statusCode)
{
BucketNotificationConfiguration = new BucketNotification();
return;
Expand Down
4 changes: 2 additions & 2 deletions Minio/DataModel/Response/GetBucketReplicationResponse.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, 2021 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -28,7 +28,7 @@ internal GetBucketReplicationResponse(HttpStatusCode statusCode, string response
: base(statusCode, responseContent)
{
if (string.IsNullOrEmpty(responseContent) ||
!HttpStatusCode.OK.Equals(statusCode))
HttpStatusCode.OK != statusCode)
{
Config = null;
return;
Expand Down
2 changes: 1 addition & 1 deletion Minio/DataModel/Response/GetBucketTagsResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal GetBucketTagsResponse(HttpStatusCode statusCode, string responseContent
: base(statusCode, responseContent)
{
if (string.IsNullOrEmpty(responseContent) ||
!HttpStatusCode.OK.Equals(statusCode))
HttpStatusCode.OK != statusCode)
{
BucketTags = null;
return;
Expand Down
2 changes: 1 addition & 1 deletion Minio/DataModel/Response/GetLegalHoldResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class GetLegalHoldResponse : GenericResponse
public GetLegalHoldResponse(HttpStatusCode statusCode, string responseContent)
: base(statusCode, responseContent)
{
if (string.IsNullOrEmpty(responseContent) || !HttpStatusCode.OK.Equals(statusCode))
if (string.IsNullOrEmpty(responseContent) || HttpStatusCode.OK != statusCode)
{
CurrentLegalHoldConfiguration = null;
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal class GetObjectLockConfigurationResponse : GenericResponse
internal GetObjectLockConfigurationResponse(HttpStatusCode statusCode, string responseContent)
: base(statusCode, responseContent)
{
if (string.IsNullOrEmpty(responseContent) || !HttpStatusCode.OK.Equals(statusCode))
if (string.IsNullOrEmpty(responseContent) || HttpStatusCode.OK != statusCode)
{
LockConfiguration = null;
return;
Expand Down
2 changes: 1 addition & 1 deletion Minio/DataModel/Response/GetObjectTagsResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public GetObjectTagsResponse(HttpStatusCode statusCode, string responseContent)
: base(statusCode, responseContent)
{
if (string.IsNullOrEmpty(responseContent) ||
!HttpStatusCode.OK.Equals(statusCode))
HttpStatusCode.OK != statusCode)
{
ObjectTags = null;
return;
Expand Down
2 changes: 1 addition & 1 deletion Minio/DataModel/Response/GetObjectsListResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal GetObjectsListResponse(HttpStatusCode statusCode, string responseConten
: base(statusCode, responseContent)
{
if (string.IsNullOrEmpty(responseContent) ||
!HttpStatusCode.OK.Equals(statusCode))
HttpStatusCode.OK != statusCode)
return;

using var stream = Encoding.UTF8.GetBytes(responseContent).AsMemory().AsStream();
Expand Down
2 changes: 1 addition & 1 deletion Minio/DataModel/Response/GetObjectsVersionsListResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal GetObjectsVersionsListResponse(HttpStatusCode statusCode, string respon
: base(statusCode, responseContent)
{
if (string.IsNullOrEmpty(responseContent) ||
!HttpStatusCode.OK.Equals(statusCode))
HttpStatusCode.OK != statusCode)
return;

using var stream = Encoding.UTF8.GetBytes(responseContent).AsMemory().AsStream();
Expand Down
2 changes: 1 addition & 1 deletion Minio/DataModel/Response/GetPolicyResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal GetPolicyResponse(HttpStatusCode statusCode, string responseContent)
: base(statusCode, responseContent)
{
if (string.IsNullOrEmpty(responseContent) ||
!HttpStatusCode.OK.Equals(statusCode))
HttpStatusCode.OK != statusCode)
return;

Initialize().Wait();
Expand Down
2 changes: 1 addition & 1 deletion Minio/DataModel/Response/GetRetentionResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal class GetRetentionResponse : GenericResponse
public GetRetentionResponse(HttpStatusCode statusCode, string responseContent)
: base(statusCode, responseContent)
{
if (string.IsNullOrEmpty(responseContent) && !HttpStatusCode.OK.Equals(statusCode))
if (string.IsNullOrEmpty(responseContent) && HttpStatusCode.OK != statusCode)
{
CurrentRetentionConfiguration = null;
return;
Expand Down
2 changes: 1 addition & 1 deletion Minio/DataModel/Response/GetVersioningResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal GetVersioningResponse(HttpStatusCode statusCode, string responseContent
: base(statusCode, responseContent)
{
if (string.IsNullOrEmpty(responseContent) ||
!HttpStatusCode.OK.Equals(statusCode))
HttpStatusCode.OK != statusCode)
return;

VersioningConfig = Utils.DeserializeXml<VersioningConfiguration>(responseContent);
Expand Down
2 changes: 1 addition & 1 deletion Minio/DataModel/Response/ListBucketsResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal class ListBucketsResponse : GenericResponse
internal ListBucketsResponse(HttpStatusCode statusCode, string responseContent)
: base(statusCode, responseContent)
{
if (string.IsNullOrEmpty(responseContent) || !HttpStatusCode.OK.Equals(statusCode))
if (string.IsNullOrEmpty(responseContent) || HttpStatusCode.OK != statusCode)
return;

using var stream = Encoding.UTF8.GetBytes(responseContent).AsMemory().AsStream();
Expand Down
44 changes: 22 additions & 22 deletions Minio/MinioClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ internal static void ParseError(ResponseResult response)
throw new ConnectionException(
"Response is nil. Please report this issue https://github.com/minio/minio-dotnet/issues", response);

if (HttpStatusCode.Redirect.Equals(response.StatusCode) ||
HttpStatusCode.TemporaryRedirect.Equals(response.StatusCode) ||
HttpStatusCode.MovedPermanently.Equals(response.StatusCode))
if (HttpStatusCode.Redirect == response.StatusCode ||
HttpStatusCode.TemporaryRedirect == response.StatusCode ||
HttpStatusCode.MovedPermanently == response.StatusCode)
throw new RedirectionException(
"Redirection detected. Please report this issue https://github.com/minio/minio-dotnet/issues");

Expand All @@ -119,11 +119,11 @@ internal static void ParseError(ResponseResult response)

private static void ParseErrorNoContent(ResponseResult response)
{
if (HttpStatusCode.Forbidden.Equals(response.StatusCode)
|| HttpStatusCode.BadRequest.Equals(response.StatusCode)
|| HttpStatusCode.NotFound.Equals(response.StatusCode)
|| HttpStatusCode.MethodNotAllowed.Equals(response.StatusCode)
|| HttpStatusCode.NotImplemented.Equals(response.StatusCode))
if (HttpStatusCode.Forbidden == response.StatusCode
|| HttpStatusCode.BadRequest == response.StatusCode
|| HttpStatusCode.NotFound == response.StatusCode
|| HttpStatusCode.MethodNotAllowed == response.StatusCode
|| HttpStatusCode.NotImplemented == response.StatusCode)
ParseWellKnownErrorNoContent(response);

#pragma warning disable MA0099 // Use Explicit enum value instead of 0
Expand Down Expand Up @@ -158,7 +158,7 @@ private static void ParseWellKnownErrorNoContent(ResponseResult response)
// zero, one or two segments
var resourceSplits = pathAndQuery.Split(separator, 2, StringSplitOptions.RemoveEmptyEntries);

if (HttpStatusCode.NotFound.Equals(response.StatusCode))
if (HttpStatusCode.NotFound == response.StatusCode)
{
var pathLength = resourceSplits.Length;
var isAWS = host.EndsWith("s3.amazonaws.com", StringComparison.OrdinalIgnoreCase);
Expand Down Expand Up @@ -192,7 +192,7 @@ private static void ParseWellKnownErrorNoContent(ResponseResult response)
response);
}
}
else if (HttpStatusCode.BadRequest.Equals(response.StatusCode))
else if (HttpStatusCode.BadRequest == response.StatusCode)
{
var pathLength = resourceSplits.Length;

Expand All @@ -208,7 +208,7 @@ private static void ParseWellKnownErrorNoContent(ResponseResult response)
response);
}
}
else if (HttpStatusCode.Forbidden.Equals(response.StatusCode))
else if (HttpStatusCode.Forbidden == response.StatusCode)
{
errorResponse.Code = "Forbidden";
error = new AccessDeniedException("Access denied on the resource: " + pathAndQuery);
Expand All @@ -223,7 +223,7 @@ private static void ParseErrorFromContent(ResponseResult response)
if (response is null)
throw new ArgumentNullException(nameof(response));

if (response.StatusCode.Equals(HttpStatusCode.NotFound)
if (response.StatusCode == HttpStatusCode.NotFound
&& response.Request.RequestUri.PathAndQuery.EndsWith("?location", StringComparison.OrdinalIgnoreCase)
&& response.Request.Method.Equals(HttpMethod.Get))
{
Expand All @@ -234,57 +234,57 @@ private static void ParseErrorFromContent(ResponseResult response)

var errResponse = Utils.DeserializeXml<ErrorResponse>(response.Content);

if (response.StatusCode.Equals(HttpStatusCode.Forbidden)
if (response.StatusCode == HttpStatusCode.Forbidden
&& (errResponse.Code.Equals("SignatureDoesNotMatch", StringComparison.OrdinalIgnoreCase) ||
errResponse.Code.Equals("InvalidAccessKeyId", StringComparison.OrdinalIgnoreCase)))
throw new AuthorizationException(errResponse.Resource, errResponse.BucketName, errResponse.Message);

// Handle XML response for Bucket Policy not found case
if (response.StatusCode.Equals(HttpStatusCode.NotFound)
if (response.StatusCode == HttpStatusCode.NotFound
&& response.Request.RequestUri.PathAndQuery.EndsWith("?policy", StringComparison.OrdinalIgnoreCase)
&& response.Request.Method.Equals(HttpMethod.Get)
&& string.Equals(errResponse.Code, "NoSuchBucketPolicy", StringComparison.OrdinalIgnoreCase))
throw new ErrorResponseException(errResponse, response) { XmlError = response.Content };

if (response.StatusCode.Equals(HttpStatusCode.NotFound)
if (response.StatusCode == HttpStatusCode.NotFound
&& string.Equals(errResponse.Code, "NoSuchBucket", StringComparison.OrdinalIgnoreCase))
throw new BucketNotFoundException(errResponse.BucketName, "Not found.");

if (response.StatusCode.Equals(HttpStatusCode.BadRequest)
if (response.StatusCode == HttpStatusCode.BadRequest
&& errResponse.Code.Equals("MalformedXML", StringComparison.OrdinalIgnoreCase))
throw new MalFormedXMLException(errResponse.Resource, errResponse.BucketName, errResponse.Message,
errResponse.Key);

if (response.StatusCode.Equals(HttpStatusCode.NotImplemented)
if (response.StatusCode == HttpStatusCode.NotImplemented
&& errResponse.Code.Equals("NotImplemented", StringComparison.OrdinalIgnoreCase))
{
#pragma warning disable MA0025 // Implement the functionality instead of throwing NotImplementedException
throw new NotImplementedException(errResponse.Message);
}
#pragma warning restore MA0025 // Implement the functionality instead of throwing NotImplementedException

if (response.StatusCode.Equals(HttpStatusCode.BadRequest)
if (response.StatusCode == HttpStatusCode.BadRequest
&& errResponse.Code.Equals("InvalidRequest", StringComparison.OrdinalIgnoreCase))
{
_ = new Dictionary<string, string>(StringComparer.Ordinal) { { "legal-hold", "" } };
if (response.Request.RequestUri.Query.Contains("legalHold", StringComparison.OrdinalIgnoreCase))
throw new MissingObjectLockConfigurationException(errResponse.BucketName, errResponse.Message);
}

if (response.StatusCode.Equals(HttpStatusCode.NotFound)
if (response.StatusCode == HttpStatusCode.NotFound
&& errResponse.Code.Equals("ObjectLockConfigurationNotFoundError", StringComparison.OrdinalIgnoreCase))
throw new MissingObjectLockConfigurationException(errResponse.BucketName, errResponse.Message);

if (response.StatusCode.Equals(HttpStatusCode.NotFound)
if (response.StatusCode == HttpStatusCode.NotFound
&& errResponse.Code.Equals("ReplicationConfigurationNotFoundError", StringComparison.OrdinalIgnoreCase))
throw new MissingBucketReplicationConfigurationException(errResponse.BucketName, errResponse.Message);

if (response.StatusCode.Equals(HttpStatusCode.Conflict)
if (response.StatusCode == HttpStatusCode.Conflict
&& errResponse.Code.Equals("BucketAlreadyOwnedByYou", StringComparison.OrdinalIgnoreCase))
throw new ArgumentException("Bucket already owned by you: " + errResponse.BucketName,
nameof(response));

if (response.StatusCode.Equals(HttpStatusCode.PreconditionFailed)
if (response.StatusCode == HttpStatusCode.PreconditionFailed
&& errResponse.Code.Equals("PreconditionFailed", StringComparison.OrdinalIgnoreCase))
throw new PreconditionFailedException("At least one of the pre-conditions you " +
"specified did not hold for object: \"" + errResponse.Resource +
Expand Down