Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ee54180
fix: add oauth scopes to Places proto
gcf-owl-bot[bot] Jan 29, 2025
12c0d70
Co-authored-by: Amanda Tarafa Mas <14878252+amanda-tarafa@users.norep…
mahendra-google Nov 26, 2024
39a1f21
file-scoped namespace and generate bucket name method added
mahendra-google Jan 24, 2025
38fd06f
Adding all tests in single test , addition of generatebucket name method
mahendra-google Jan 24, 2025
dd02b37
adding a blank line between one property and the next
mahendra-google Jan 24, 2025
0258eb2
List Soft Deleted Bucket test case changes
mahendra-google Jan 24, 2025
9a5bfe7
Removal of encryption key support for restore bucket request and remo…
mahendra-google Jan 27, 2025
7efe472
Recommended changes as per internal PR review
mahendra-google Jan 28, 2025
595e6ff
named arguments added while calling create bucket method
mahendra-google Feb 12, 2025
ddd62d1
Update apis/Google.Cloud.Storage.V1/Google.Cloud.Storage.V1.Tests/Get…
mahendra-google Feb 12, 2025
229e343
Update apis/Google.Cloud.Storage.V1/Google.Cloud.Storage.V1/GetBucket…
mahendra-google Feb 12, 2025
beb036c
Update apis/Google.Cloud.Storage.V1/Google.Cloud.Storage.V1.Tests/Lis…
mahendra-google Feb 12, 2025
517b827
restore white space in Google.Cloud.Storage.V1.csproj
mahendra-google Feb 12, 2025
8b89da6
Update GetBucketOptionsTest.cs
mahendra-google Feb 12, 2025
56639b4
Update ListBucketsTest.cs
mahendra-google Feb 12, 2025
ec7aab9
Update GetBucketTest.cs
mahendra-google Feb 12, 2025
25d3356
encryption key removed from RestoreBucketOptions
mahendra-google Feb 12, 2025
1e026b1
Initial commit for Assert.Contains and Assert.All in list bucket test
mahendra-google Feb 18, 2025
678d101
listbucket linters changes
mahendra-google Feb 18, 2025
f7853af
restore bucket linter changes
mahendra-google Feb 18, 2025
620c980
getbucket linter changes
mahendra-google Feb 18, 2025
9120a0f
getbucket linter changes
mahendra-google Feb 24, 2025
51d5487
restore bucket linter changes
mahendra-google Feb 24, 2025
e9accfd
listbucket linter changes
mahendra-google Feb 24, 2025
acc88c5
blank line added in getbucketest
mahendra-google Feb 24, 2025
806ae11
linter changes as per editorconfig file rules
mahendra-google Feb 25, 2025
748e762
Apply suggestions from code review
amanda-tarafa Mar 5, 2025
a955e02
Update apis/Google.Cloud.Storage.V1/Google.Cloud.Storage.V1.Integrati…
amanda-tarafa Mar 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2024 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 System;
using System.Threading.Tasks;
using Xunit;

namespace Google.Cloud.Storage.V1.IntegrationTests;

[Collection(nameof(StorageFixture))]
public class GetBucketTest
{
private readonly StorageFixture _fixture;

public GetBucketTest(StorageFixture fixture)
{
_fixture = fixture;
}

[Fact]
public async Task SoftDeleted()
{
var bucketName = _fixture.GenerateBucketName();
var softDeleteBucket = _fixture.CreateBucket(bucketName, multiVersion: false, softDelete: true);
await _fixture.Client.DeleteBucketAsync(softDeleteBucket.Name, new DeleteBucketOptions { DeleteObjects = true });

var softDeleted = await _fixture.Client.GetBucketAsync(softDeleteBucket.Name, new GetBucketOptions { SoftDeleted = true, Generation = softDeleteBucket.Generation });
Assert.Equal(softDeleteBucket.Name, softDeleted.Name);
Assert.Equal(softDeleteBucket.Generation, softDeleted.Generation);
Assert.NotNull(softDeleted.SoftDeleteTimeDateTimeOffset);
Assert.NotNull(softDeleted.HardDeleteTimeDateTimeOffset);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,32 @@ public void PartialResponses()
}
}

[Fact]
public async Task SoftDeletedOnly()
{
var bucketName = _fixture.GenerateBucketName();
var softDeleteBucket = _fixture.CreateBucket(bucketName, multiVersion: false, softDelete: true);

await _fixture.Client.DeleteBucketAsync(softDeleteBucket.Name, new DeleteBucketOptions { DeleteObjects = true });

var actualBuckets = await _fixture.Client
.ListBucketsAsync(_fixture.ProjectId, new ListBucketsOptions { SoftDeletedOnly = true })
.ToListAsync();

// Check the list cotains the bucket we just soft-deleted.
Assert.Contains(actualBuckets, bucket => bucket.Name == softDeleteBucket.Name && bucket.Generation == softDeleteBucket.Generation);
// Check all the buckets in the list are soft-deleted buckets.
Assert.All(actualBuckets, AssertSoftDeletedBucket);
}

// Validates that the given bucket is soft-deleted.
private void AssertSoftDeletedBucket(Bucket b)
{
Assert.NotNull(b.Generation);
Assert.NotNull(b.HardDeleteTimeDateTimeOffset);
Assert.NotNull(b.SoftDeleteTimeDateTimeOffset);
}

// Fetches buckets using the given options in each possible way, validating that the expected bucket names are returned.
private async Task AssertBuckets(ListBucketsOptions options, params string[] expectedBucketNames)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2024 Google Inc. All Rights Reserved.
//
// 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;
using Xunit;

namespace Google.Cloud.Storage.V1.IntegrationTests;

[Collection(nameof(StorageFixture))]
public class RestoreBucketTest
{
private readonly StorageFixture _fixture;

public RestoreBucketTest(StorageFixture fixture)
{
_fixture = fixture;
}

[Fact]
public async Task RestoreSoftDeletedBucket()
{
var bucketName = _fixture.GenerateBucketName();
var softDeleteBucket = _fixture.CreateBucket(bucketName, multiVersion: false, softDelete: true);
await _fixture.Client.DeleteBucketAsync(softDeleteBucket.Name, new DeleteBucketOptions { DeleteObjects = true });

var restoredBucket = await _fixture.Client.RestoreBucketAsync(softDeleteBucket.Name, softDeleteBucket.Generation.Value);
Assert.Equal(softDeleteBucket.Name, restoredBucket.Name);
Assert.Equal(softDeleteBucket.Generation, restoredBucket.Generation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public void ModifyRequest_DefaultOptions()
Assert.Null(request.IfMetagenerationNotMatch);
Assert.Null(request.Projection);
Assert.Null(request.UserProject);
Assert.Null(request.SoftDeleted);
Assert.Null(request.Generation);
}

[Fact]
Expand All @@ -41,13 +43,17 @@ public void ModifyRequest_PositiveMatchOptions()
{
IfMetagenerationMatch = 1L,
Projection = Projection.Full,
UserProject = "proj"
UserProject = "proj",
SoftDeleted = true,
Generation = long.MaxValue
};
options.ModifyRequest(request);
Assert.Equal(1L, request.IfMetagenerationMatch);
Assert.Null(request.IfMetagenerationNotMatch);
Assert.Equal(ProjectionEnum.Full, request.Projection);
Assert.Equal("proj", request.UserProject);
Assert.True(request.SoftDeleted);
Assert.Equal(long.MaxValue, request.Generation);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void ModifyRequest_DefaultOptions()
Assert.Null(request.Prefix);
Assert.Null(request.MaxResults);
Assert.Null(request.PageToken);
Assert.Null(request.SoftDeleted);
}

[Fact]
Expand All @@ -42,14 +43,16 @@ public void ModifyRequest_AllOptions()
Prefix = "prefix",
Projection = Projection.Full,
PageToken = "nextpage",
Fields = "items(name),nextPageToken"
Fields = "items(name),nextPageToken",
SoftDeletedOnly = true,
};
options.ModifyRequest(request);
Assert.Equal(10, request.MaxResults);
Assert.Equal("prefix", request.Prefix);
Assert.Equal(ProjectionEnum.Full, request.Projection);
Assert.Equal("nextpage", request.PageToken);
Assert.Equal("items(name),nextPageToken", request.Fields);
Assert.True(request.SoftDeleted);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2024 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 Xunit;
using static Google.Apis.Storage.v1.BucketsResource;
using static Google.Apis.Storage.v1.BucketsResource.RestoreRequest;

namespace Google.Cloud.Storage.V1.Tests;
public class RestoreBucketOptionsTest
{
[Fact]
public void ModifyRequest_DefaultOptions()
{
var request = new RestoreRequest(null, "bucket", 2L);
var options = new RestoreBucketOptions();
options.ModifyRequest(request);
Assert.Null(request.Projection);
Assert.Null(request.UserProject);
}

[Fact]
public void ModifyRequest_AllOptions()
{
var request = new RestoreRequest(null, "bucket", 2L);
var options = new RestoreBucketOptions
{
Projection = Projection.Full,
UserProject = "proj"
};
options.ModifyRequest(request);
Assert.Equal(ProjectionEnum.Full, request.Projection);
Assert.Equal("proj", request.UserProject);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ public sealed class GetBucketOptions
/// </summary>
public RetryOptions RetryOptions { get; set; }

/// <summary>
/// The bucket generation to be retrieved. It must be set if <see ref="SoftDelete" /> is true.
/// </summary>
public long? Generation { get; set; }

/// <summary>
/// If true, the soft-deleted version of the bucket will be retrieved.
/// If true, <see ref="Generation" /> must be set.
/// </summary>
public bool? SoftDeleted { get; set; }

internal void ModifyRequest(GetRequest request)
{
if (IfMetagenerationMatch != null && IfMetagenerationNotMatch != null)
Expand All @@ -75,6 +86,15 @@ internal void ModifyRequest(GetRequest request)
{
request.UserProject = UserProject;
}
if (Generation != null)
{
request.Generation = Generation;
}
if (SoftDeleted != null)
{
request.SoftDeleted = SoftDeleted;
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="ConfigureAwaitChecker.Analyzer" PrivateAssets="All" />
<PackageReference Include="Google.Api.Gax.Rest" />
<PackageReference Include="Google.Apis.Storage.v1" VersionOverride="[1.68.0.3431, 2.0.0.0)" />
<PackageReference Include="Google.Apis.Storage.v1" VersionOverride="[1.68.0.3604, 2.0.0.0)" />
</ItemGroup>
<ItemGroup>
<Compile Update="StorageClient.*.cs">
Expand All @@ -23,4 +23,4 @@
<DependentUpon>UrlSigner.cs</DependentUpon>
</Compile>
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public sealed class ListBucketsOptions
/// </summary>
public RetryOptions RetryOptions { get; set; }

/// <summary>
/// If true, only soft-deleted buckets will be listed. The default is false.
/// </summary>
public bool? SoftDeletedOnly { get; set; }

/// <summary>
/// Modifies the specified request for all non-null properties of this options object.
/// </summary>
Expand All @@ -88,6 +93,10 @@ internal void ModifyRequest(ListRequest request)
{
request.Fields = Fields;
}
if (SoftDeletedOnly != null)
{
request.SoftDeleted = SoftDeletedOnly;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2024 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.Api.Gax;
using static Google.Apis.Storage.v1.BucketsResource;
using static Google.Apis.Storage.v1.BucketsResource.RestoreRequest;

namespace Google.Cloud.Storage.V1;

/// <summary>
/// Options for RestoreBucket operations.
/// </summary>
public sealed class RestoreBucketOptions
{
/// <summary>
/// The projection of the restored bucket to return. Note the whole bucket will be restored,
/// except for the bucket's access controls. This only affects
/// what information is returned when restoration is successful.
/// </summary>
public Projection? Projection { get; set; }

/// <summary>
/// If set, this is the ID of the project which will be billed for the request.
/// The caller must have suitable permissions for the project being billed.
/// </summary>
public string UserProject { get; set; }

/// <summary>
/// Options to pass custom retry configuration for each API request.
/// </summary>
public RetryOptions RetryOptions { get; set; }

internal void ModifyRequest(RestoreRequest request)
{
if (Projection != null)
{
request.Projection = GaxPreconditions.CheckEnumValue((ProjectionEnum) Projection, nameof(Projection));
}
if (UserProject != null)
{
request.UserProject = UserProject;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2024 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 System;
using System.Threading;
using System.Threading.Tasks;
using Bucket = Google.Apis.Storage.v1.Data.Bucket;

namespace Google.Cloud.Storage.V1;
public abstract partial class StorageClient
{
/// <summary>
/// Restores a soft-deleted bucket.
/// </summary>
/// <param name="bucket">The name of the bucket. Must not be null.</param>
/// <param name="generation">The specific revision of the bucket to restore.</param>
/// <param name="options">Additional options for the restore operation. May be null, in which case appropriate
/// defaults will be used.</param>
/// <returns>The <see cref="Bucket"/> representation of the restored Storage bucket.</returns>
public virtual Bucket RestoreBucket(string bucket, long generation, RestoreBucketOptions options = null) =>
throw new NotImplementedException();

/// <summary>
/// Restores a soft-deleted bucket.
/// </summary>
/// <param name="bucket">The name of the bucket. Must not be null.</param>
/// <param name="generation">The specific revision of the bucket to restore.</param>
/// <param name="options">Additional options for the restore operation. May be null, in which case appropriate
/// defaults will be used.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A task representing the asynchronous operation, with a result returning the
/// <see cref="Bucket"/> representation of the restored Storage bucket.</returns>
public virtual Task<Bucket> RestoreBucketAsync(
string bucket,
long generation,
RestoreBucketOptions options = null,
CancellationToken cancellationToken = default) => throw new NotImplementedException();
}
Loading