-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Добавил методы ListObjects, ListBuckets
- Loading branch information
Alexander Shumkin
authored and
Alexander Shumkin
committed
Jul 29, 2022
1 parent
c35c4c5
commit 6d89705
Showing
13 changed files
with
319 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
AspNetCore.Yandex.ObjectStorage/Bucket/Builders/BucketListObjectsRequestBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Net.Http; | ||
using AspNetCore.Yandex.ObjectStorage.Bucket.Requests; | ||
using AspNetCore.Yandex.ObjectStorage.Configuration; | ||
using AspNetCore.Yandex.ObjectStorage.Helpers; | ||
|
||
namespace AspNetCore.Yandex.ObjectStorage.Bucket.Builders | ||
{ | ||
internal class BucketListObjectsRequestBuilder | ||
{ | ||
private readonly YandexStorageOptions _options; | ||
private HttpRequestMessage _request; | ||
|
||
internal BucketListObjectsRequestBuilder(YandexStorageOptions options) | ||
{ | ||
_options = options; | ||
} | ||
|
||
internal BucketListObjectsRequestBuilder Build(BucketListObjectsParameters parameters) | ||
{ | ||
var url = $"{_options.Protocol}://{_options.Endpoint}/{parameters.BucketName}?{FormatParameters(parameters)}"; | ||
|
||
var requestMessage = new HttpRequestMessage(HttpMethod.Get, new Uri(url)); | ||
var dateAmz = DateTime.UtcNow; | ||
|
||
requestMessage.AddBothHeaders(_options, dateAmz); | ||
|
||
string[] headers = { "host", "x-amz-content-sha256", "x-amz-date" }; | ||
requestMessage.AddAuthHeader(_options, dateAmz, headers); | ||
_request = requestMessage; | ||
|
||
return this; | ||
} | ||
|
||
internal HttpRequestMessage GetResult() | ||
{ | ||
return _request; | ||
} | ||
|
||
private static string FormatParameters(BucketListObjectsParameters parameters) | ||
{ | ||
var continueToken = string.IsNullOrEmpty(parameters.ContinueToken) | ||
? string.Empty | ||
: $"&continuation-token={parameters.ContinueToken}"; | ||
var delimiter = string.IsNullOrEmpty(parameters.Delimiter) | ||
? string.Empty | ||
: $"&delimiter={parameters.Delimiter}"; | ||
var maxKeys = $"&max-keys={parameters.MaxKeys}"; | ||
var prefix = string.IsNullOrEmpty(parameters.Prefix) | ||
? string.Empty | ||
: $"&prefix={parameters.Prefix}"; | ||
var startAfter = string.IsNullOrEmpty(parameters.StartAfter) | ||
? string.Empty | ||
: $"&start-after={parameters.StartAfter}"; | ||
|
||
return string.Concat("list-type=2", continueToken, delimiter, maxKeys, prefix, startAfter); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
AspNetCore.Yandex.ObjectStorage/Bucket/Builders/BucketListRequestBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Net.Http; | ||
using AspNetCore.Yandex.ObjectStorage.Bucket.Requests; | ||
using AspNetCore.Yandex.ObjectStorage.Configuration; | ||
using AspNetCore.Yandex.ObjectStorage.Helpers; | ||
|
||
namespace AspNetCore.Yandex.ObjectStorage.Bucket.Builders | ||
{ | ||
internal class BucketListRequestBuilder | ||
{ | ||
private readonly YandexStorageOptions _options; | ||
private HttpRequestMessage _request; | ||
|
||
internal BucketListRequestBuilder(YandexStorageOptions options) | ||
{ | ||
_options = options; | ||
} | ||
|
||
internal BucketListRequestBuilder Build() | ||
{ | ||
var url = $"{_options.Protocol}://{_options.Endpoint}"; | ||
|
||
var requestMessage = new HttpRequestMessage(HttpMethod.Get, new Uri(url)); | ||
var dateAmz = DateTime.UtcNow; | ||
|
||
requestMessage.AddBothHeaders(_options, dateAmz); | ||
|
||
string[] headers = { "host", "x-amz-content-sha256", "x-amz-date" }; | ||
requestMessage.AddAuthHeader(_options, dateAmz, headers); | ||
_request = requestMessage; | ||
|
||
return this; | ||
} | ||
|
||
internal HttpRequestMessage GetResult() | ||
{ | ||
return _request; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 18 additions & 1 deletion
19
AspNetCore.Yandex.ObjectStorage/Bucket/Models/BucketListResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,27 @@ | ||
namespace AspNetCore.Yandex.ObjectStorage.Bucket.Models | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Xml.Serialization; | ||
|
||
namespace AspNetCore.Yandex.ObjectStorage.Bucket.Models | ||
{ | ||
/// <summary> | ||
/// https://cloud.yandex.ru/docs/storage/s3/api-ref/bucket/list#response-scheme | ||
/// </summary> | ||
[XmlRoot(ElementName="ListAllMyBucketsResult", Namespace="http://s3.amazonaws.com/doc/2006-03-01/")] | ||
public class BucketListResult | ||
{ | ||
[XmlArray("Buckets", Namespace="http://s3.amazonaws.com/doc/2006-03-01/")] | ||
[XmlArrayItem("Bucket", Namespace="http://s3.amazonaws.com/doc/2006-03-01/")] | ||
public List<Bucket> Buckets { get; set; } | ||
} | ||
|
||
[XmlRoot(ElementName="Bucket", Namespace="http://s3.amazonaws.com/doc/2006-03-01/")] | ||
public class Bucket | ||
{ | ||
[XmlElement(ElementName="Name", Namespace="http://s3.amazonaws.com/doc/2006-03-01/")] | ||
public string Name { get; set; } | ||
[XmlElement(ElementName="CreationDate", Namespace="http://s3.amazonaws.com/doc/2006-03-01/")] | ||
public string CreationDate { get; set; } | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.