-
Notifications
You must be signed in to change notification settings - Fork 1.2k
samples(storage): add samples and test cases for storage to support bucket restore feature #2963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
amanda-tarafa
merged 16 commits into
GoogleCloudPlatform:main
from
mahendra-google:restore_bucket_soft_delete_phase_2
Apr 10, 2025
Merged
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0a8bccf
Initial code changes for storage samples of GetSoftDeletedBucket, Lis…
mahendra-google bd7b348
listSoftDeletedBuckets sample and test case added
mahendra-google 311edf2
Google.Cloud.Storage.V1 version update to get soft delete bucket meta…
mahendra-google ba028ed
get and restore samples and test cases for soft delete feature phase 2
mahendra-google c22b190
method name change in fixture from CreateSoftDeleteBucket to CreateBu…
mahendra-google 15d8d3d
Method descriptions are added for samples i.e getsoftdeleted , lists…
mahendra-google a79ad89
Merge branch 'main' into restore_bucket_soft_delete_phase_2
mahendra-google 38de450
Update RestoreBucketTest.cs
mahendra-google dcfad28
Update storage/api/Storage.Samples/GetSoftDeletedBucket.cs
mahendra-google 7ff99de
Update storage/api/Storage.Samples/GetSoftDeletedBucket.cs
mahendra-google 41514e6
Update storage/api/Storage.Samples/RestoreSoftDeletedBucket.cs
mahendra-google 49d5833
copyright year change
mahendra-google dcc8ece
softdelete bucket test changes
mahendra-google 3cea8da
test changes
mahendra-google 09b32b5
listbucket test undo changes
mahendra-google da5295b
Method name changes in soft delete bucket tests
mahendra-google File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,43 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// 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 | ||
// | ||
// https://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 Google.Cloud.Storage.V1; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
[Collection(nameof(StorageFixture))] | ||
public class GetBucketTest | ||
{ | ||
private readonly StorageFixture _fixture; | ||
|
||
public GetBucketTest(StorageFixture fixture) | ||
{ | ||
_fixture = fixture; | ||
} | ||
|
||
[Fact] | ||
public async Task SoftDeleted() | ||
{ | ||
GetSoftDeletedBucketSample getSoftDeletedBucketSample = new GetSoftDeletedBucketSample(); | ||
var bucketName = _fixture.GenerateBucketName(); | ||
var softDeleteBucket = _fixture.CreateBucket(bucketName, multiVersion: false, softDelete: true, registerForDeletion: true); | ||
await _fixture.Client.DeleteBucketAsync(softDeleteBucket.Name, new DeleteBucketOptions { DeleteObjects = true }); | ||
mahendra-google marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
var softDeleted = getSoftDeletedBucketSample.GetSoftDeletedBucket(softDeleteBucket.Name, softDeleteBucket.Generation); | ||
Assert.Equal(softDeleteBucket.Name, softDeleted.Name); | ||
Assert.Equal(softDeleteBucket.Generation, softDeleted.Generation); | ||
Assert.NotNull(softDeleted.SoftDeleteTimeDateTimeOffset); | ||
Assert.NotNull(softDeleted.HardDeleteTimeDateTimeOffset); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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,41 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// 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 | ||
// | ||
// https://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 Google.Cloud.Storage.V1; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
[Collection(nameof(StorageFixture))] | ||
public class RestoreBucketTest | ||
{ | ||
private readonly StorageFixture _fixture; | ||
|
||
public RestoreBucketTest(StorageFixture fixture) | ||
{ | ||
_fixture = fixture; | ||
} | ||
|
||
[Fact] | ||
public async Task RestoreSoftDeletedBucket() | ||
{ | ||
RestoreSoftDeletedBucketSample restoreSoftDeletedBucketSample = new RestoreSoftDeletedBucketSample(); | ||
var bucketName = _fixture.GenerateBucketName(); | ||
var softDeleteBucket = _fixture.CreateBucket(bucketName, multiVersion: false, softDelete: true, registerForDeletion: true); | ||
await _fixture.Client.DeleteBucketAsync(softDeleteBucket.Name, new DeleteBucketOptions { DeleteObjects = true }); | ||
|
||
var restoredBucket = restoreSoftDeletedBucketSample.RestoreSoftDeletedBucket(softDeleteBucket.Name, softDeleteBucket.Generation.Value); | ||
Assert.Equal(softDeleteBucket.Name, restoredBucket.Name); | ||
Assert.Equal(softDeleteBucket.Generation, restoredBucket.Generation); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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,41 @@ | ||
// Copyright 2024 Google Inc. | ||
mahendra-google marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// | ||
// 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. | ||
|
||
// [START storage_get_soft_deleted_bucket] | ||
|
||
using Google.Apis.Storage.v1.Data; | ||
using Google.Cloud.Storage.V1; | ||
using System; | ||
|
||
public class GetSoftDeletedBucketSample | ||
{ | ||
/// <summary> | ||
/// Get a soft deleted bucket. | ||
/// </summary> | ||
/// <param name="bucketName">The name of the bucket.</param> | ||
/// <param name="generation">The generation of the bucket.</param> | ||
public Bucket GetSoftDeletedBucket( | ||
string bucketName = "your-unique-bucket-name", | ||
long? generation = 123456789) | ||
{ | ||
var client = StorageClient.Create(); | ||
var bucket = client.GetBucket(bucketName, new GetBucketOptions { SoftDeleted = true, Generation = generation }); | ||
mahendra-google marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Console.WriteLine($"Bucket:\t{bucket.Name}"); | ||
Console.WriteLine($"Bucket Generation:\t{bucket.Generation}"); | ||
Console.WriteLine($"Bucket SoftDelete Time:\t{bucket.SoftDeleteTimeDateTimeOffset}"); | ||
Console.WriteLine($"Bucket HardDelete Time:\t{bucket.HardDeleteTimeDateTimeOffset}"); | ||
return bucket; | ||
} | ||
} | ||
// [END storage_get_soft_deleted_bucket] |
This file contains hidden or 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 @@ | ||
// Copyright 2024 Google 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. | ||
|
||
// [START storage_list_soft_deleted_buckets] | ||
|
||
using Google.Apis.Storage.v1.Data; | ||
using Google.Cloud.Storage.V1; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
public class ListSoftDeletedBucketsSample | ||
{ | ||
/// <summary> | ||
/// List soft deleted buckets. | ||
/// </summary> | ||
/// <param name="projectId">The ID of the project to list soft deleted buckets.</param> | ||
public IEnumerable<Bucket> ListSoftDeletedBuckets(string projectId = "your-project-id") | ||
{ | ||
var storage = StorageClient.Create(); | ||
var buckets = storage.ListBuckets(projectId, new ListBucketsOptions { SoftDeletedOnly = true }); | ||
Console.WriteLine("Soft Deleted Buckets are as follows:"); | ||
foreach (var bucket in buckets) | ||
{ | ||
Console.WriteLine(bucket.Name); | ||
} | ||
return buckets; | ||
} | ||
} | ||
// [END storage_list_soft_deleted_buckets] |
This file contains hidden or 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,38 @@ | ||
// Copyright 2024 Google LLC | ||
mahendra-google marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// | ||
// 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 | ||
// | ||
// https://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. | ||
|
||
// [START storage_restore_bucket] | ||
|
||
using Google.Apis.Storage.v1.Data; | ||
using Google.Cloud.Storage.V1; | ||
using System; | ||
public class RestoreSoftDeletedBucketSample | ||
{ | ||
/// <summary> | ||
/// Restores a soft deleted bucket. | ||
/// </summary> | ||
/// <param name="bucketName">The name of the bucket to restore.</param> | ||
/// <param name="generation">The generation of the bucket.</param> | ||
public Bucket RestoreSoftDeletedBucket( | ||
string bucketName = "your-unique-bucket-name", | ||
long generation = 123456789) | ||
{ | ||
var client = StorageClient.Create(); | ||
var restored = client.RestoreBucket(bucketName, generation); | ||
Console.WriteLine($"Bucket Name:\t {restored.Name}"); | ||
Console.WriteLine($"Bucket Generation:\t {restored.Generation}"); | ||
return restored; | ||
} | ||
} | ||
// [END storage_restore_bucket] |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.