-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
664 additions
and
401 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using Storage.Utils; | ||
using static Storage.Utils.HashHelper; | ||
|
||
namespace Storage; | ||
|
||
/// <summary> | ||
/// Функции управления бакетом | ||
/// </summary> | ||
public sealed partial class S3Client | ||
{ | ||
public async Task<bool> CreateBucket(CancellationToken ct) | ||
{ | ||
HttpResponseMessage response; | ||
using (var request = CreateRequest(HttpMethod.Put)) | ||
{ | ||
response = await Send(request, EmptyPayloadHash, ct).ConfigureAwait(false); | ||
} | ||
|
||
switch (response.StatusCode) | ||
{ | ||
case HttpStatusCode.OK: | ||
response.Dispose(); | ||
return true; | ||
case HttpStatusCode.Conflict: // already exists | ||
response.Dispose(); | ||
return false; | ||
default: | ||
Errors.UnexpectedResult(response); | ||
return false; | ||
} | ||
} | ||
|
||
public async Task<bool> DeleteBucket(CancellationToken ct) | ||
{ | ||
HttpResponseMessage response; | ||
using (var request = CreateRequest(HttpMethod.Delete)) | ||
{ | ||
response = await Send(request, EmptyPayloadHash, ct).ConfigureAwait(false); | ||
} | ||
|
||
switch (response.StatusCode) | ||
{ | ||
case HttpStatusCode.NoContent: | ||
response.Dispose(); | ||
return true; | ||
case HttpStatusCode.NotFound: | ||
response.Dispose(); | ||
return false; | ||
default: | ||
Errors.UnexpectedResult(response); | ||
return false; | ||
} | ||
} | ||
|
||
public async Task<bool> IsBucketExists(CancellationToken ct) | ||
{ | ||
HttpResponseMessage response; | ||
using (var request = CreateRequest(HttpMethod.Head)) | ||
{ | ||
response = await Send(request, EmptyPayloadHash, ct).ConfigureAwait(false); | ||
} | ||
|
||
switch (response.StatusCode) | ||
{ | ||
case HttpStatusCode.OK: | ||
response.Dispose(); | ||
return true; | ||
case HttpStatusCode.NotFound: | ||
response.Dispose(); | ||
return false; | ||
default: | ||
Errors.UnexpectedResult(response); | ||
return false; | ||
} | ||
} | ||
} |
Oops, something went wrong.