Browse Source

LegalHold APIs (Set, Get) with Args, Response. (#495)

pull/506/head
P R 5 years ago
committed by GitHub
parent
commit
a0cc80cb61
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 107
      Docs/API.md
  2. 48
      Minio.Examples/Cases/GetLegalHold.cs
  3. 52
      Minio.Examples/Cases/SetLegalHold.cs
  4. 54
      Minio.Functional.Tests/FunctionalTest.cs
  5. 20
      Minio/ApiEndpoints/IObjectOperations.cs
  6. 33
      Minio/ApiEndpoints/ObjectOperations.cs
  7. 45
      Minio/DataModel/ObjectLegalHoldConfiguration.cs
  8. 54
      Minio/DataModel/ObjectOperationsArgs.cs
  9. 30
      Minio/DataModel/ObjectOperationsResponse.cs
  10. 44
      Minio/Exceptions/AuthorizationException.cs
  11. 49
      Minio/Exceptions/MalFormedXMLException.cs
  12. 30
      Minio/Exceptions/MissingObjectLockConfiguration.cs
  13. 22
      Minio/MinioClient.cs

107
Docs/API.md

@ -31,8 +31,8 @@ var s3Client = new MinioClient("s3.amazonaws.com",
| [`listObjectVersions`](#listObjectVersions) | [`removeObjects`](#removeObjects) | | |
| [`listIncompleteUploads`](#listIncompleteUploads) | [`removeIncompleteUpload`](#removeIncompleteUpload) | | |
| [`listenBucketNotifications`](#listenBucketNotifications) | [`selectObjectContent`](#selectObjectContent) | | |
| [`setVersioning`](#setVersioning) | | | |
| [`getVersioning`](#getVersioning) | | | |
| [`setVersioning`](#setVersioning) | [`setLegalHold`](#setLegalHold) | | |
| [`getVersioning`](#getVersioning) | [`getLegalHold`](#getLegalHold) | | |
| [`setBucketEncryption`](#setBucketEncryption) | | | |
| [`getBucketEncryption`](#getBucketEncryption) | | | |
| [`removeBucketEncryption`](#removeBucketEncryption) | | | |
@ -1812,6 +1812,109 @@ catch (MinioException e)
}
```
<a name="setLegalHold"></a>
### SetObjectLegalHoldAsync(SetObjectLegalHoldArgs args)
`Task SetObjectLegalHoldAsync(SetObjectLegalHoldArgs args, CancellationToken cancellationToken = default(CancellationToken))`
Sets the Legal Hold status of an object.
__Parameters__
|Param | Type | Description |
|:--- |:--- |:--- |
| ``args`` | _SetObjectLegalHoldArgs_ | SetObjectLegalHoldArgs Argument Object with bucket, object names, version id(optional) |
| ``cancellationToken``| _System.Threading.CancellationToken_ | Optional parameter. Defaults to default(CancellationToken) |
| Return Type | Exceptions |
|:--- |:--- |
| ``Task`` | Listed Exceptions: |
| | ``AuthorizationException`` : upon access or secret key wrong or not found |
| | ``InvalidBucketNameException`` : upon invalid bucket name |
| | ``InvalidObjectNameException`` : upon invalid object name |
| | ``BucketNotFoundException`` : upon bucket with name not found |
| | ``ObjectNotFoundException`` : upon object with name not found |
| | ``MissingObjectLockConfiguration`` : upon bucket created with object lock not enabled |
| | ``MalFormedXMLException`` : upon configuration XML in http request validation failure |
__Example__
```cs
try
{
// Setting WithLegalHold true, sets Legal hold status to ON.
SetObjectLegalHoldArgs args = new SetObjectLegalHoldArgs()
.WithBucket(bucketName)
.WithObject(objectName)
.WithVersionId(versionId)
.WithLegalHold(true);
await minio.SetObjectLegalHoldAsync(args);
}
catch(MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
```
<a name="getLegalHold"></a>
### GetObjectLegalHoldAsync(GetObjectLegalHoldArgs args)
`Task<bool> GetObjectLegalHoldAsync(GetObjectLegalHoldArgs args, CancellationToken cancellationToken = default(CancellationToken))`
Gets the Legal Hold status of an object.
__Parameters__
|Param | Type | Description |
|:--- |:--- |:--- |
| ``args`` | _GetObjectLegalHoldArgs_ | GetObjectLegalHoldArgs Argument Object with bucket, object names, version id(optional) |
| ``cancellationToken``| _System.Threading.CancellationToken_ | Optional parameter. Defaults to default(CancellationToken) |
| Return Type | Exceptions |
|:--- |:--- |
| ``Task<bool>``: True if LegalHold is enabled, false otherwise. | Listed Exceptions: |
| | ``AuthorizationException`` : upon access or secret key wrong or not found |
| | ``InvalidBucketNameException`` : upon invalid bucket name |
| | ``InvalidObjectNameException`` : upon invalid object name |
| | ``BucketNotFoundException`` : upon bucket with name not found |
| | ``ObjectNotFoundException`` : upon object with name not found |
| | ``MissingObjectLockConfiguration`` : upon bucket created with object lock not enabled |
| | ``MalFormedXMLException`` : upon configuration XML in http request validation failure |
__Example__
```cs
try
{
// Get Legal Hold status a object
var args = new GetObjectLegalHoldArgs()
.WithBucket(bucketName)
.WithObject(objectName)
.WithVersionId(versionId);
bool enabled = await minio.GetObjectLegalHoldAsync(args);
Console.WriteLine("LegalHold Configuration STATUS for " + bucketName + "/" + objectName +
(!string.IsNullOrEmpty(versionId)?" with Version ID " + versionId: " ") +
" : " + (enabled?"ON":"OFF"));
}
catch(MinioException e)
{
Console.WriteLine("Error occurred: " + e);
}
```
## 4. Presigned operations
<a name="presignedGetObject"></a>

48
Minio.Examples/Cases/GetLegalHold.cs

@ -0,0 +1,48 @@
/*
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Threading.Tasks;
namespace Minio.Examples.Cases
{
class GetLegalHold
{
// Get Legal Hold status a object
public async static Task Run(MinioClient minio,
string bucketName = "my-bucket-name",
string objectName = "my-object-name",
string versionId = null)
{
try
{
Console.WriteLine("Running example for API: GetLegalHold, ");
var args = new GetObjectLegalHoldArgs()
.WithBucket(bucketName)
.WithObject(objectName)
.WithVersionId(versionId);
bool enabled = await minio.GetObjectLegalHoldAsync(args);
Console.WriteLine("LegalHold Configuration STATUS for " + bucketName + "/" + objectName +
(!string.IsNullOrEmpty(versionId)?" with Version ID " + versionId: " ") +
" : " + (enabled?"ON":"OFF"));
}
catch (Exception e)
{
Console.WriteLine($"[Object] Exception: {e}");
}
}
}
}

52
Minio.Examples/Cases/SetLegalHold.cs

@ -0,0 +1,52 @@
/*
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Threading.Tasks;
namespace Minio.Examples.Cases
{
class SetLegalHold
{
// Enable Legal Hold
public async static Task Run(MinioClient minio,
string bucketName = "my-bucket-name",
string objectName = "my-object-name",
string versionId = null)
{
try
{
Console.WriteLine("Running example for API: SetLegalHold, enable legal hold");
// Setting WithLegalHold true, sets Legal hold status to ON.
// Setting WithLegalHold false will set Legal hold status to OFF.
SetObjectLegalHoldArgs args = new SetObjectLegalHoldArgs()
.WithBucket(bucketName)
.WithObject(objectName)
.WithVersionId(versionId)
.WithLegalHold(true);
await minio.SetObjectLegalHoldAsync(args);
Console.WriteLine("Legal Hold status for " + bucketName + "/" + objectName +
(string.IsNullOrEmpty(versionId)?" " : " with version id " + versionId + " ") +
" set to ON." );
Console.WriteLine();
}
catch (Exception e)
{
Console.WriteLine($"[Object] Exception: {e}");
}
}
}
}

54
Minio.Functional.Tests/FunctionalTest.cs

@ -75,6 +75,9 @@ namespace Minio.Functional.Tests
private const string getBucketEncryptionSignature = "Task<ServerSideEncryptionConfiguration> GetBucketEncryptionAsync(GetBucketEncryptionArgs args, CancellationToken cancellationToken = default(CancellationToken))";
private const string removeBucketEncryptionSignature = "Task RemoveBucketEncryptionAsync(RemoveBucketEncryptionArgs args, CancellationToken cancellationToken = default(CancellationToken))";
private const string selectObjectSignature = "Task<SelectResponseStream> SelectObjectContentAsync(SelectObjectContentArgs args,CancellationToken cancellationToken = default(CancellationToken))";
private const string setObjectLegalHoldSignature = "Task SetObjectLegalHoldAsync(SetObjectLegalHoldArgs args, CancellationToken cancellationToken = default(CancellationToken))";
private const string getObjectLegalHoldSignature = "Task<bool> GetObjectLegalHoldAsync(GetObjectLegalHoldArgs args, CancellationToken cancellationToken = default(CancellationToken))";
// Create a file of given size from random byte array or optionally create a symbolic link
// to the dataFileName residing in MINT_DATA_DIR
@ -3336,5 +3339,56 @@ namespace Minio.Functional.Tests
#endregion
#region Legal Hold Status
internal async static Task LegalHoldStatusAsync_Test1(MinioClient minio)
{
DateTime startTime = DateTime.Now;
string bucketName = GetRandomName(15);
string objectName = GetRandomObjectName(10);
var args = new Dictionary<string, string>
{
{ "bucketName", bucketName },
{ "objectName", objectName }
};
try
{
await Setup_WithLock_Test(minio, bucketName);
using (MemoryStream filestream = rsg.GenerateStreamFromSeed(1 * KB))
await minio.PutObjectAsync(bucketName,
objectName,
filestream, filestream.Length, null);
SetObjectLegalHoldArgs legalHoldArgs = new SetObjectLegalHoldArgs()
.WithBucket(bucketName)
.WithObject(objectName)
.WithLegalHold(true);
await minio.SetObjectLegalHoldAsync(legalHoldArgs);
new MintLogger(nameof(LegalHoldStatusAsync_Test1), setObjectLegalHoldSignature, "Tests whether SetObjectLegalHoldAsync passes", TestStatus.PASS, (DateTime.Now - startTime), args:args).Log();
}
catch (Exception ex)
{
await TearDown(minio, bucketName);
new MintLogger(nameof(LegalHoldStatusAsync_Test1), setObjectLegalHoldSignature, "Tests whether SetObjectLegalHoldAsync passes", TestStatus.FAIL, (DateTime.Now - startTime), ex.Message, ex.ToString(), args:args).Log();
}
try
{
GetObjectLegalHoldArgs getLegalHoldArgs = new GetObjectLegalHoldArgs()
.WithBucket(bucketName)
.WithObject(objectName);
bool enabled = await minio.GetObjectLegalHoldAsync(getLegalHoldArgs);
Assert.IsTrue(enabled);
await minio.RemoveObjectAsync(bucketName, objectName);
await TearDown(minio, bucketName);
new MintLogger(nameof(LegalHoldStatusAsync_Test1), getObjectLegalHoldSignature, "Tests whether GetObjectLegalHoldAsync passes", TestStatus.PASS, (DateTime.Now - startTime), args:args).Log();
}
catch (Exception ex)
{
await TearDown(minio, bucketName);
new MintLogger(nameof(LegalHoldStatusAsync_Test1), getObjectLegalHoldSignature, "Tests whether GetObjectLegalHoldAsync passes", TestStatus.FAIL, (DateTime.Now - startTime), ex.Message, ex.ToString(), args:args).Log();
}
}
#endregion
}
}

20
Minio/ApiEndpoints/IObjectOperations.cs

@ -27,6 +27,26 @@ namespace Minio
{
public interface IObjectOperations
{
/// <summary>
/// Get the configuration object for Legal Hold Status
/// </summary>
/// <param name="args">GetObjectLegalHoldArgs Arguments Object which has object identifier information - bucket name, object name, version ID</param>
/// <param name="cancellationToken">Optional cancellation token to cancel the operation </param>
/// <returns> True if Legal Hold is ON, false otherwise </returns>
/// <exception cref="InvalidBucketNameException">When bucketName is invalid</exception>
/// <exception cref="InvalidObjectNameException">When objectName is invalid</exception>
Task<bool> GetObjectLegalHoldAsync(GetObjectLegalHoldArgs args, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Set the configuration object for Legal Hold Status
/// </summary>
/// <param name="args">SetObjectLegalHoldArgs Arguments Object which has object identifier information - bucket name, object name, version ID and the status (ON/OFF) of legal-hold</param>
/// <param name="cancellationToken">Optional cancellation token to cancel the operation </param>
/// <returns>Task</returns>
/// <exception cref="InvalidBucketNameException">When bucketName is invalid</exception>
/// <exception cref="InvalidObjectNameException">When objectName is invalid</exception>
Task SetObjectLegalHoldAsync(SetObjectLegalHoldArgs args, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Get an object. The object will be streamed to the callback given by the user.
/// </summary>

33
Minio/ApiEndpoints/ObjectOperations.cs

@ -243,6 +243,39 @@ namespace Minio
return this.authenticator.PresignURL(this.restClient, request, args.Expiry, Region, this.SessionToken);
}
/// <summary>
/// Get the configuration object for Legal Hold Status
/// </summary>
/// <param name="args">GetObjectLegalHoldArgs Arguments Object which has object identifier information - bucket name, object name, version ID</param>
/// <param name="cancellationToken">Optional cancellation token to cancel the operation </param>
/// <returns> True if Legal Hold is ON, false otherwise </returns>
/// <exception cref="InvalidBucketNameException">When bucketName is invalid</exception>
/// <exception cref="InvalidObjectNameException">When objectName is invalid</exception>
public async Task<bool> GetObjectLegalHoldAsync(GetObjectLegalHoldArgs args, CancellationToken cancellationToken = default(CancellationToken))
{
args.Validate();
var request = await this.CreateRequest(args).ConfigureAwait(false);
var response = await this.ExecuteAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
var legalHoldConfig = new GetLegalHoldResponse(response.StatusCode, response.Content);
return (legalHoldConfig.CurrentLegalHoldConfiguration == null)?false: legalHoldConfig.CurrentLegalHoldConfiguration.Status.ToLower().Equals("on");
}
/// <summary>
/// Set the Legal Hold Status using the related configuration
/// </summary>
/// <param name="args">SetObjectLegalHoldArgs Arguments Object which has object identifier information - bucket name, object name, version ID</param>
/// <param name="cancellationToken">Optional cancellation token to cancel the operation</param>
/// <returns> Task </returns>
/// <exception cref="InvalidBucketNameException">When bucket name is invalid</exception>
/// <exception cref="InvalidObjectNameException">When object name is invalid</exception>
public async Task SetObjectLegalHoldAsync(SetObjectLegalHoldArgs args, CancellationToken cancellationToken = default(CancellationToken))
{
args.Validate();
var request = await this.CreateRequest(args).ConfigureAwait(false);
await this.ExecuteAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// Get an object. The object will be streamed to the callback given by the user.

45
Minio/DataModel/ObjectLegalHoldConfiguration.cs

@ -0,0 +1,45 @@
/*
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Xml.Serialization;
namespace Minio.DataModel
{
[Serializable]
[XmlRoot(ElementName = "LegalHold", Namespace = "http://s3.amazonaws.com/doc/2006-03-01/")]
// Legal Hold Configuration for the object. Status - {ON, OFF}.
public class ObjectLegalHoldConfiguration
{
public ObjectLegalHoldConfiguration()
{
this.Status = "OFF";
}
public ObjectLegalHoldConfiguration(bool enable = true)
{
if (enable)
{
this.Status = "ON";
return;
}
this.Status = "OFF";
}
public string Status { get; set; }
}
}

54
Minio/DataModel/ObjectOperationsArgs.cs

@ -20,6 +20,7 @@ using RestSharp;
using Minio.DataModel;
using Minio.Exceptions;
using Minio.Helper;
using System.Security.Cryptography;
namespace Minio
{
@ -400,4 +401,55 @@ namespace Minio
this.RequestMethod = Method.DELETE;
}
}
}
public class GetObjectLegalHoldArgs : ObjectVersionArgs<GetObjectLegalHoldArgs>
{
public GetObjectLegalHoldArgs()
{
this.RequestMethod = Method.GET;
}
public override RestRequest BuildRequest(RestRequest request)
{
request.AddQueryParameter("legal-hold", "");
if( !string.IsNullOrEmpty(this.VersionId) )
{
request.AddQueryParameter("versionId", this.VersionId);
}
return request;
}
}
public class SetObjectLegalHoldArgs : ObjectVersionArgs<SetObjectLegalHoldArgs>
{
internal bool LegalHoldON { get; private set; }
public SetObjectLegalHoldArgs()
{
this.RequestMethod = Method.PUT;
this.LegalHoldON = false;
}
public SetObjectLegalHoldArgs WithLegalHold(bool status)
{
this.LegalHoldON = status;
return this;
}
public override RestRequest BuildRequest(RestRequest request)
{
request.AddQueryParameter("legal-hold", "");
if( !string.IsNullOrEmpty(this.VersionId) )
{
request.AddQueryParameter("versionId", this.VersionId);
}
ObjectLegalHoldConfiguration config = new ObjectLegalHoldConfiguration(this.LegalHoldON);
string body = utils.MarshalXML(config, "http://s3.amazonaws.com/doc/2006-03-01/");
request.AddParameter(new Parameter("text/xml", body, ParameterType.RequestBody));
var md5 = MD5.Create();
byte[] hash = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(body));
string base64 = Convert.ToBase64String(hash);
request.AddOrUpdateParameter("Content-MD5", base64, ParameterType.HttpHeader);
return request;
}
}
}

30
Minio/DataModel/ObjectOperationsResponse.cs

@ -90,4 +90,32 @@ namespace Minio
URIPolicyTuple = Tuple.Create(absURI, args.Policy.GetFormData());
}
}
}
public class GetLegalHoldResponse: GenericResponse
{
internal ObjectLegalHoldConfiguration CurrentLegalHoldConfiguration { get; private set; }
internal string Status { get; private set;}
public GetLegalHoldResponse(HttpStatusCode statusCode, string responseContent)
: base(statusCode, responseContent)
{
if (string.IsNullOrEmpty(responseContent) || !HttpStatusCode.OK.Equals(statusCode))
{
this.CurrentLegalHoldConfiguration = null;
return;
}
using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(responseContent)))
{
CurrentLegalHoldConfiguration = (ObjectLegalHoldConfiguration)new XmlSerializer(typeof(ObjectLegalHoldConfiguration)).Deserialize(stream);
}
if ( this.CurrentLegalHoldConfiguration == null
|| string.IsNullOrEmpty(this.CurrentLegalHoldConfiguration.Status) )
{
Status = "OFF";
}
else
{
Status = this.CurrentLegalHoldConfiguration.Status;
}
}
}
}

44
Minio/Exceptions/AuthorizationException.cs

@ -0,0 +1,44 @@
/*
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage,
* (C) 2017, 2018, 2019, 2020 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
namespace Minio.Exceptions
{
[Serializable]
public class AuthorizationException : Exception
{
internal readonly string resource;
internal readonly string bucketName;
internal readonly string accessKey;
public AuthorizationException()
{
}
public AuthorizationException(string message) : base(message)
{
}
public AuthorizationException(string resource, string bucketName, string message, string accesskey=null) : base(message)
{
this.resource = resource;
this.bucketName = bucketName;
this.accessKey = accesskey;
}
}
}

49
Minio/Exceptions/MalFormedXMLException.cs

@ -0,0 +1,49 @@
/*
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage,
* (C) 2017, 2018, 2019, 2020 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Runtime.Serialization;
namespace Minio.Exceptions
{
[Serializable]
internal class MalFormedXMLException : Exception
{
internal string resource;
internal string bucketName;
internal string key;
public MalFormedXMLException()
{
}
public MalFormedXMLException(string message) : base(message)
{
}
public MalFormedXMLException(string message, Exception innerException) : base(message, innerException)
{
}
public MalFormedXMLException(string resource, string bucketName, string message, string keyName=null) : base(message)
{
this.resource = resource;
this.bucketName = bucketName;
this.key = keyName;
}
}
}

30
Minio/Exceptions/MissingObjectLockConfiguration.cs

@ -0,0 +1,30 @@
/*
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2017 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace Minio.Exceptions
{
public class MissingObjectLockConfiguration : MinioException
{
private readonly string bucketName;
public MissingObjectLockConfiguration(string bucketName, string message) : base(message)
{
this.bucketName = bucketName;
}
public override string ToString() => $"{this.bucketName}: {base.ToString()}";
}
}

22
Minio/MinioClient.cs

@ -637,6 +637,12 @@ namespace Minio
var stream = new MemoryStream(contentBytes);
ErrorResponse errResponse = (ErrorResponse)new XmlSerializer(typeof(ErrorResponse)).Deserialize(stream);
if (response.StatusCode.Equals(HttpStatusCode.Forbidden)
&& (errResponse.Code.Equals("SignatureDoesNotMatch") || errResponse.Code.Equals("InvalidAccessKeyId")))
{
throw new AuthorizationException(errResponse.Resource, errResponse.BucketName, errResponse.Message);
}
// Handle XML response for Bucket Policy not found case
if (response.StatusCode.Equals(HttpStatusCode.NotFound)
&& response.Request.Resource.EndsWith("?policy")
@ -655,6 +661,22 @@ namespace Minio
throw new BucketNotFoundException(errResponse.BucketName, "Not found.");
}
if (response.StatusCode.Equals(HttpStatusCode.BadRequest)
&& errResponse.Code.Equals("MalformedXML"))
{
throw new MalFormedXMLException(errResponse.Resource, errResponse.BucketName, errResponse.Message, errResponse.Key);
}
if (response.StatusCode.Equals(HttpStatusCode.BadRequest)
&& errResponse.Code.Equals("InvalidRequest"))
{
Parameter param = new Parameter("legal-hold", "", ParameterType.QueryString);
if (response.Request.Parameters.Contains(param))
{
throw new MissingObjectLockConfiguration(errResponse.BucketName, errResponse.Message);
}
}
throw new UnexpectedMinioException(errResponse.Message)
{
Response = errResponse,

Loading…
Cancel
Save