Browse Source

Bump up Restsharp dependency to 106.10.1 (#389)

Fixes #384,#386
pull/401/head 3.1.11
poornas 5 years ago
committed by GitHub
parent
commit
1468c43888
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 70
      Minio/ApiEndpoints/BucketOperations.cs
  2. 97
      Minio/ApiEndpoints/ObjectOperations.cs
  3. 4
      Minio/BucketRegionCache.cs
  4. 2
      Minio/Minio.csproj
  5. 2
      Minio/MinioClient.cs
  6. 44
      Minio/V4Authenticator.cs

70
Minio/ApiEndpoints/BucketOperations.cs

@ -130,7 +130,7 @@ namespace Minio
/// <returns>Task</returns>
public async Task RemoveBucketAsync(string bucketName, CancellationToken cancellationToken = default(CancellationToken))
{
var request = await this.CreateRequest(Method.DELETE, bucketName, resourcePath: null).ConfigureAwait(false);
var request = await this.CreateRequest(Method.DELETE, bucketName).ConfigureAwait(false);
var response = await this.ExecuteTaskAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
}
@ -212,8 +212,7 @@ namespace Minio
/// <param name="cancellationToken">Optional cancellation token to cancel the operation</param>
private async Task<Tuple<ListBucketResult, List<Item>>> GetObjectListAsync(string bucketName, string prefix, string delimiter, string marker, CancellationToken cancellationToken = default(CancellationToken))
{
var queries = new List<string>();
var queryMap = new Dictionary<string,string>();
// null values are treated as empty strings.
if (delimiter == null)
{
@ -229,20 +228,16 @@ namespace Minio
{
marker = string.Empty;
}
queries.Add("delimiter=" + Uri.EscapeDataString(delimiter));
queries.Add("prefix=" + Uri.EscapeDataString(prefix));
queries.Add("max-keys=1000");
queries.Add("marker=" + Uri.EscapeDataString(marker));
queries.Add("encoding-type=url");
string query = string.Join("&", queries);
var request = await this.CreateRequest(Method.GET,
bucketName,
resourcePath: "?" + query)
bucketName)
.ConfigureAwait(false);
request.AddQueryParameter("delimiter",Uri.EscapeDataString(delimiter));
request.AddQueryParameter("prefix", Uri.EscapeDataString(prefix));
request.AddQueryParameter("max-keys", "1000");
request.AddQueryParameter("marker",Uri.EscapeDataString(marker));
request.AddQueryParameter("encoding-type","url");
var response = await this.ExecuteTaskAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
var contentBytes = System.Text.Encoding.UTF8.GetBytes(response.Content);
@ -286,13 +281,10 @@ namespace Minio
{
IRestResponse response = null;
var path = $"{bucketName}?policy";
var request = await this.CreateRequest(Method.GET, bucketName,
contentType: "application/json",
resourcePath: "?policy")
contentType: "application/json")
.ConfigureAwait(false);
request.AddQueryParameter("policy","");
string policyString = null;
response = await this.ExecuteTaskAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
var contentBytes = System.Text.Encoding.UTF8.GetBytes(response.Content);
@ -315,11 +307,10 @@ namespace Minio
public async Task SetPolicyAsync(string bucketName, string policyJson, CancellationToken cancellationToken = default(CancellationToken))
{
var request = await this.CreateRequest(Method.PUT, bucketName,
resourcePath: "?policy",
contentType: "application/json",
body: policyJson)
contentType: "application/json")
.ConfigureAwait(false);
request.AddQueryParameter("policy","");
request.AddJsonBody(policyJson);
IRestResponse response = await this.ExecuteTaskAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
}
@ -333,9 +324,9 @@ namespace Minio
{
utils.ValidateBucketName(bucketName);
var request = await this.CreateRequest(Method.GET,
bucketName,
resourcePath: "?notification")
bucketName)
.ConfigureAwait(false);
request.AddQueryParameter("notification","");
var response = await this.ExecuteTaskAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
var contentBytes = System.Text.Encoding.UTF8.GetBytes(response.Content);
@ -355,13 +346,14 @@ namespace Minio
public async Task SetBucketNotificationsAsync(string bucketName, BucketNotification notification, CancellationToken cancellationToken = default(CancellationToken))
{
utils.ValidateBucketName(bucketName);
var request = await this.CreateRequest(Method.PUT, bucketName,
resourcePath: "?notification")
var request = await this.CreateRequest(Method.PUT, bucketName)
.ConfigureAwait(false);
request.AddQueryParameter("notification","");
var bodyString = notification.ToString();
request.XmlSerializer = new RestSharp.Serializers.DotNetXmlSerializer();
request.RequestFormat = DataFormat.Xml;
request.AddBody(notification);
var body = System.Text.Encoding.UTF8.GetBytes(bodyString);
request.AddParameter("application/xml", body, RestSharp.ParameterType.RequestBody);
IRestResponse response = await this.ExecuteTaskAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
}
@ -399,19 +391,15 @@ namespace Minio
{
while (isRunning)
{
var queries = new List<string>();
queries.Add("prefix=" + Uri.EscapeDataString(prefix));
queries.Add("suffix=" + Uri.EscapeDataString(suffix));
var request = await this.CreateRequest(Method.GET,
bucketName)
.ConfigureAwait(false);
request.AddQueryParameter("prefix",prefix);
request.AddQueryParameter("sufffix",suffix);
foreach (var eventType in events)
{
queries.Add("events=" + Uri.EscapeDataString(eventType.value));
request.AddQueryParameter("events",eventType.value);
}
string query = string.Join("&", queries);
var request = await this.CreateRequest(Method.GET,
bucketName,
resourcePath: "?" + query)
.ConfigureAwait(false);
var startTime = DateTime.Now;
// Logs full url when HTTPtracing is enabled (as in MinioClient.ExecuteTaskAsync)

97
Minio/ApiEndpoints/ObjectOperations.cs

@ -23,6 +23,7 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Web;
using System.Linq;
using System.Reactive.Linq;
using System.Threading;
@ -205,13 +206,12 @@ namespace Minio
}
var selectReqBytes = System.Text.Encoding.UTF8.GetBytes(opts.MarshalXML());
string resourcePath = "?select=&select-type=2";
var request = await this.CreateRequest(Method.POST, bucketName,
objectName: objectName,
resourcePath: resourcePath,
headerMap: sseHeaders)
.ConfigureAwait(false);
request.AddQueryParameter("select","");
request.AddQueryParameter("select-type","2");
request.AddParameter("application/xml", selectReqBytes, ParameterType.RequestBody);
var response = await this.ExecuteTaskAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
@ -364,11 +364,10 @@ namespace Minio
/// <returns></returns>
private async Task CompleteMultipartUploadAsync(string bucketName, string objectName, string uploadId, Dictionary<int, string> etags, CancellationToken cancellationToken)
{
string resourcePath = $"?uploadId={uploadId}";
var request = await this.CreateRequest(Method.POST, bucketName,
objectName: objectName,
resourcePath: resourcePath)
objectName: objectName)
.ConfigureAwait(false);
request.AddQueryParameter("uploadId",$"{uploadId}");
List<XElement> parts = new List<XElement>();
@ -427,16 +426,15 @@ namespace Minio
/// <returns></returns>
private async Task<Tuple<ListPartsResult, List<Part>>> GetListPartsAsync(string bucketName, string objectName, string uploadId, int partNumberMarker, CancellationToken cancellationToken)
{
var resourcePath = $"?uploadId={uploadId}";
var request = await this.CreateRequest(Method.GET, bucketName,
objectName: objectName)
.ConfigureAwait(false);
request.AddQueryParameter("uploadId",$"{uploadId}");
if (partNumberMarker > 0)
{
resourcePath += $"&part-number-marker={partNumberMarker}";
request.AddQueryParameter("part-number-marker",$"{partNumberMarker}");
}
resourcePath += "&max-parts=1000";
var request = await this.CreateRequest(Method.GET, bucketName,
objectName: objectName,
resourcePath: resourcePath)
.ConfigureAwait(false);
request.AddQueryParameter("max-parts","1000");
var response = await this.ExecuteTaskAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
@ -471,14 +469,14 @@ namespace Minio
/// <returns></returns>
private async Task<string> NewMultipartUploadAsync(string bucketName, string objectName, Dictionary<string, string> metaData, Dictionary<string, string> sseHeaders, CancellationToken cancellationToken = default(CancellationToken))
{
var resource = "?uploads";
foreach (KeyValuePair<string, string> kv in sseHeaders)
{
metaData.Add(kv.Key, kv.Value);
}
var request = await this.CreateRequest(Method.POST, bucketName, objectName: objectName,
headerMap: metaData, resourcePath: resource).ConfigureAwait(false);
headerMap: metaData).ConfigureAwait(false);
request.AddQueryParameter("uploads","");
var response = await this.ExecuteTaskAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
@ -505,12 +503,6 @@ namespace Minio
/// <returns></returns>
private async Task<string> PutObjectAsync(string bucketName, string objectName, string uploadId, int partNumber, byte[] data, Dictionary<string, string> metaData, Dictionary<string, string> sseHeaders, CancellationToken cancellationToken)
{
var resource = string.Empty;
if (!string.IsNullOrEmpty(uploadId) && partNumber > 0)
{
resource += $"?uploadId={uploadId}&partNumber={partNumber}";
}
// For multi-part upload requests, metadata needs to be passed in the NewMultiPartUpload request
string contentType = metaData["Content-Type"];
if (uploadId != null)
@ -526,9 +518,13 @@ namespace Minio
objectName: objectName,
contentType: contentType,
headerMap: metaData,
body: data,
resourcePath: resource)
body: data)
.ConfigureAwait(false);
if (!string.IsNullOrEmpty(uploadId) && partNumber > 0)
{
request.AddQueryParameter("uploadId",$"{uploadId}");
request.AddQueryParameter("partNumber",$"{partNumber}");
}
var response = await this.ExecuteTaskAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
@ -560,8 +556,6 @@ namespace Minio
string delimiter,
CancellationToken cancellationToken)
{
var queries = new List<string>();
// null values are treated as empty strings.
if (delimiter == null)
{
@ -580,17 +574,13 @@ namespace Minio
uploadIdMarker = string.Empty;
}
queries.Add("uploads");
queries.Add("prefix=" + Uri.EscapeDataString(prefix));
queries.Add("delimiter=" + Uri.EscapeDataString(delimiter));
queries.Add("key-marker=" + Uri.EscapeDataString(keyMarker));
queries.Add("upload-id-marker=" + uploadIdMarker);
queries.Add("max-uploads=1000");
string query = string.Join("&", queries);
var request = await this.CreateRequest(Method.GET, bucketName, resourcePath: "?" + query).ConfigureAwait(false);
var request = await this.CreateRequest(Method.GET, bucketName).ConfigureAwait(false);
request.AddQueryParameter("uploads","");
request.AddQueryParameter("prefix" , Uri.EscapeDataString(prefix));
request.AddQueryParameter("delimiter" ,Uri.EscapeDataString(delimiter));
request.AddQueryParameter("key-marker" , Uri.EscapeDataString(keyMarker));
request.AddQueryParameter("upload-id-marker" ,Uri.EscapeDataString(uploadIdMarker));
request.AddQueryParameter("max-uploads","1000");
var response = await this.ExecuteTaskAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
var contentBytes = System.Text.Encoding.UTF8.GetBytes(response.Content);
@ -627,7 +617,6 @@ namespace Minio
{
return this.listIncompleteUploads(bucketName, prefix, null, cancellationToken);
}
return this.listIncompleteUploads(bucketName, prefix, "/", cancellationToken);
}
@ -691,14 +680,10 @@ namespace Minio
/// <returns></returns>
private async Task RemoveUploadAsync(string bucketName, string objectName, string uploadId, CancellationToken cancellationToken)
{
// var resourcePath = "/" + utils.UrlEncode(objectName) + "?uploadId=" + uploadId;
var resourcePath = $"?uploadId={uploadId}";
var request = await this.CreateRequest(Method.DELETE, bucketName,
objectName: objectName,
resourcePath: resourcePath)
objectName: objectName)
.ConfigureAwait(false);
request.AddQueryParameter("uploadId",$"{uploadId}");
var response = await this.ExecuteTaskAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
}
@ -725,8 +710,8 @@ namespace Minio
/// <returns></returns>
private async Task<List<DeleteError>> removeObjectsAsync(string bucketName, List<DeleteObject> objectsList, CancellationToken cancellationToken)
{
string resource = "?delete";
var request = await this.CreateRequest(Method.POST, bucketName, resourcePath: resource).ConfigureAwait(false);
var request = await this.CreateRequest(Method.POST, bucketName).ConfigureAwait(false);
request.AddQueryParameter("delete","");
List<XElement> objects = new List<XElement>();
foreach (var obj in objectsList)
@ -741,7 +726,10 @@ namespace Minio
var bodyString = deleteObjectsRequest.ToString();
var body = System.Text.Encoding.UTF8.GetBytes(bodyString);
request.AddParameter("application/xml", body, RestSharp.ParameterType.RequestBody);
request.AddXmlBody(deleteObjectsRequest);
request.XmlSerializer = new RestSharp.Serializers.DotNetXmlSerializer();
request.RequestFormat = DataFormat.Xml;
var response = await this.ExecuteTaskAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
var contentBytes = System.Text.Encoding.UTF8.GetBytes(response.Content);
DeleteObjectsResult deleteResult = null;
@ -1013,7 +1001,7 @@ namespace Minio
/// <param name="cancellationToken">Optional cancellation token to cancel the operation</param>
/// <param name="type">Type of XML serialization to be applied on the server response</param>
/// <returns></returns>
private async Task<object> CopyObjectRequestAsync(string bucketName, string objectName, string destBucketName, string destObjectName, CopyConditions copyConditions, Dictionary<string, string> customHeaders, string resource, CancellationToken cancellationToken, Type type)
private async Task<object> CopyObjectRequestAsync(string bucketName, string objectName, string destBucketName, string destObjectName, CopyConditions copyConditions, Dictionary<string, string> customHeaders, Dictionary<string, string> queryMap, CancellationToken cancellationToken, Type type)
{
// Escape source object path.
string sourceObjectPath = bucketName + "/" + utils.UrlEncode(objectName);
@ -1026,9 +1014,15 @@ namespace Minio
var request = await this.CreateRequest(Method.PUT, destBucketName,
objectName: destObjectName,
resourcePath: resource,
headerMap: customHeaders)
.ConfigureAwait(false);
if (queryMap != null)
{
foreach (var query in queryMap)
{
request.AddQueryParameter(query.Key,query.Value);
}
}
// Set the object source
request.AddHeader("x-amz-copy-source", sourceObjectPath);
@ -1113,10 +1107,11 @@ namespace Minio
partCondition.byteRangeEnd = partCondition.byteRangeStart + (long)lastPartSize - 1;
}
var resource = string.Empty;
var queryMap = new Dictionary<string,string>();
if (!string.IsNullOrEmpty(uploadId) && partNumber > 0)
{
resource += $"?uploadId={uploadId}&partNumber={partNumber}";
queryMap.Add("uploadId",uploadId);
queryMap.Add("partNumber",partNumber.ToString());
}
var customHeader = new Dictionary<string, string>
@ -1132,7 +1127,7 @@ namespace Minio
{
sseDest.Marshal(customHeader);
}
CopyPartResult cpPartResult = (CopyPartResult)await this.CopyObjectRequestAsync(bucketName, objectName, destBucketName, destObjectName, copyConditions, customHeader, resource, cancellationToken, typeof(CopyPartResult)).ConfigureAwait(false);
CopyPartResult cpPartResult = (CopyPartResult)await this.CopyObjectRequestAsync(bucketName, objectName, destBucketName, destObjectName, copyConditions, customHeader, queryMap, cancellationToken, typeof(CopyPartResult)).ConfigureAwait(false);
totalParts[partNumber - 1] = new Part { PartNumber = partNumber, ETag = cpPartResult.ETag, Size = (long)expectedReadSize };
}

4
Minio/BucketRegionCache.cs

@ -94,13 +94,13 @@ namespace Minio
&& client.SecretKey != null && !Instance.Exists(bucketName))
{
string location = null;
var path = utils.UrlEncode(bucketName) + "?location";
var path = utils.UrlEncode(bucketName);
// Initialize client
Uri requestUrl = RequestUtil.MakeTargetURL(client.BaseUrl, client.Secure);
client.SetTargetURL(requestUrl);
var request = new RestRequest(path, Method.GET);
request.AddQueryParameter("location","");
var response = await client.ExecuteTaskAsync(client.NoErrorHandlers, request).ConfigureAwait(false);
if (HttpStatusCode.OK.Equals(response.StatusCode))

2
Minio/Minio.csproj

@ -36,7 +36,7 @@
<PackageReference Include="SourceLink.Embed.AllSourceFiles" Version="2.8.3" PrivateAssets="All" />
<PackageReference Include="AsyncFixer" Version="1.1.6" PrivateAssets="All" />
<PackageReference Include="RestSharp" Version="106.3.1" />
<PackageReference Include="RestSharp" Version="106.10.1" />
<PackageReference Include="System.Reactive.Linq" Version="4.0.0" />
</ItemGroup>

2
Minio/MinioClient.cs

@ -23,6 +23,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
@ -270,6 +271,7 @@ namespace Minio
authenticator = new V4Authenticator(this.Secure, this.AccessKey, this.SecretKey, this.Region, this.SessionToken);
restClient.Authenticator = authenticator;
restClient.UseUrlEncoder(s => HttpUtility.UrlEncode(s));
}
/// <summary>

44
Minio/V4Authenticator.cs

@ -122,6 +122,7 @@ namespace Minio
string canonicalRequestHash = this.BytesToHex(this.ComputeSha256(canonicalRequestBytes));
string region = this.GetRegion(client.BaseUrl.Host);
string stringToSign = this.GetStringToSign(region, signingDate, canonicalRequestHash);
byte[] signingKey = this.GenerateSigningKey(region, signingDate);
byte[] stringToSignBytes = System.Text.Encoding.UTF8.GetBytes(stringToSign);
@ -379,28 +380,25 @@ namespace Minio
path[0] = $"/{path[0]}";
}
canonicalStringList.AddLast(path[0]);
string query = string.Empty;
// QUERY
if (path.Length == 2)
{
var queryParams = path[1].Split('&').Select(p => p.Split('='))
.ToDictionary(kv => kv[0],
kv => kv.Length > 1
? kv[1] : "");
var sb = new StringBuilder();
var queryKeys = new List<string>(queryParams.Keys);
queryKeys.Sort(StringComparer.Ordinal);
foreach (var p in queryKeys)
{
if (sb.Length > 0)
sb.Append("&");
sb.AppendFormat("{0}={1}", p, queryParams[p]);
}
Dictionary<string,string> queryParams = new Dictionary<string,string>();
query = sb.ToString();
foreach (var p in request.Parameters)
{
if (p.Type == ParameterType.QueryString){
queryParams.Add((string)p.Name, Uri.EscapeDataString((string)p.Value));
}
}
var sb1 = new StringBuilder();
var queryKeys = new List<string>(queryParams.Keys);
queryKeys.Sort(StringComparer.Ordinal);
foreach (var p in queryKeys)
{
if (sb1.Length > 0)
sb1.Append("&");
sb1.AppendFormat("{0}={1}", p, queryParams[p]);
}
query = sb1.ToString();
canonicalStringList.AddLast(query);
foreach (string header in headersToSign.Keys)
@ -536,11 +534,11 @@ namespace Minio
{
return;
}
bool isMultiDeleteRequest = false;
if (request.Method == Method.POST && request.Resource.EndsWith("?delete"))
var isMultiDeleteRequest = false;
if (request.Method == Method.POST)
{
isMultiDeleteRequest = true;
var deleteParm = request.Parameters.Any(p => p.Name.Equals("delete",StringComparison.OrdinalIgnoreCase));
isMultiDeleteRequest = !(deleteParm == null) || (deleteParm.Equals(null));
}
// For insecure, authenticated requests set sha256 header instead of MD5.

Loading…
Cancel
Save