From ca82d7464c3a19f78c7858afed2b969ba9cac3bb Mon Sep 17 00:00:00 2001 From: Harsh Nasit <131268456+harshnasitcrest@users.noreply.github.com> Date: Tue, 29 Jul 2025 15:57:06 +0530 Subject: [PATCH 01/24] samples(storage control): add samples for anywhere cache samples(storage): add sample for create anywhere cache samples(storage): add samples for anywhere cache samples(storage): add sample to create anywhere cache samples(storage): add sample to disable anywhere cahce --- .../CreateTemplateTest.cs | 88 +++++++++++++++ .../CreateTemplateWithLabelsTest.cs | 73 ++++++++++++ .../CreateTemplateWithMetadataTest.cs | 59 ++++++++++ .../QuickStartTest.cs | 2 - .../CreateTemplateWithLabels.cs | 98 ++++++++++++++++ .../CreateTemplateWithMetadata.cs | 105 ++++++++++++++++++ .../ModelArmor.Samples.csproj | 2 +- storage/api/README.md | 2 +- .../StorageControlCreateAnywhereCache.cs | 57 ++++++++++ .../StorageControlDisableAnywhereCache.cs | 45 ++++++++ .../StorageControlGetAnywhereCache.cs | 45 ++++++++ .../StorageControlListAnywhereCaches.cs | 50 +++++++++ .../StorageControlPauseAnywhereCache.cs | 45 ++++++++ .../StorageControlResumeAnywhereCache.cs | 45 ++++++++ 14 files changed, 712 insertions(+), 4 deletions(-) create mode 100644 modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateTest.cs create mode 100644 modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateWithLabelsTest.cs create mode 100644 modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateWithMetadataTest.cs create mode 100644 modelarmor/api/ModelArmor.Samples/CreateTemplateWithLabels.cs create mode 100644 modelarmor/api/ModelArmor.Samples/CreateTemplateWithMetadata.cs create mode 100644 storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs create mode 100644 storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs create mode 100644 storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs create mode 100644 storage/api/Storage.Samples/StorageControlListAnywhereCaches.cs create mode 100644 storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs create mode 100644 storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs diff --git a/modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateTest.cs b/modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateTest.cs new file mode 100644 index 00000000000..5b8b39de3de --- /dev/null +++ b/modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateTest.cs @@ -0,0 +1,88 @@ +/* + * 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.ModelArmor.V1; +using Xunit; +using Xunit.Abstractions; + +namespace ModelArmor.Samples.Tests +{ + public class CreateTemplateTests : IClassFixture + { + private readonly ModelArmorFixture _fixture; + private readonly CreateTemplateSample _sample; + + public CreateTemplateTests(ModelArmorFixture fixture, ITestOutputHelper output) + { + _fixture = fixture; + _sample = new CreateTemplateSample(); + } + + [Fact] + public void Runs() + { + TemplateName templateName = _fixture.CreateTemplateName(); + _fixture.RegisterTemplateForCleanup(templateName); + string templateId = templateName.TemplateId; + + // Run the sample. + Template template = _sample.CreateTemplate( + projectId: _fixture.ProjectId, + locationId: _fixture.LocationId, + templateId: templateId + ); + + // Verify the template was created successfully. + Assert.NotNull(template); + Assert.Contains(templateId, template.Name); + + // Verify the template has the expected filter configuration. + Assert.NotNull(template.FilterConfig); + Assert.NotNull(template.FilterConfig.RaiSettings); + var raiFilters = template.FilterConfig.RaiSettings.RaiFilters; + Assert.Equal(4, raiFilters.Count); + + // Assert each filter exists with the expected configuration. + Assert.Contains( + raiFilters, + f => + f.FilterType == RaiFilterType.Dangerous + && f.ConfidenceLevel == DetectionConfidenceLevel.High + ); + + Assert.Contains( + raiFilters, + f => + f.FilterType == RaiFilterType.HateSpeech + && f.ConfidenceLevel == DetectionConfidenceLevel.High + ); + + Assert.Contains( + raiFilters, + f => + f.FilterType == RaiFilterType.SexuallyExplicit + && f.ConfidenceLevel == DetectionConfidenceLevel.LowAndAbove + ); + + Assert.Contains( + raiFilters, + f => + f.FilterType == RaiFilterType.Harassment + && f.ConfidenceLevel == DetectionConfidenceLevel.MediumAndAbove + ); + } + } +} diff --git a/modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateWithLabelsTest.cs b/modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateWithLabelsTest.cs new file mode 100644 index 00000000000..05865ea161b --- /dev/null +++ b/modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateWithLabelsTest.cs @@ -0,0 +1,73 @@ +/* + * 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 System; +using System.Collections.Generic; +using Google.Cloud.ModelArmor.V1; +using Xunit; +using Xunit.Abstractions; + +namespace ModelArmor.Samples.Tests +{ + public class CreateTemplateWithLabelsTests : IClassFixture + { + private readonly ModelArmorFixture _fixture; + private readonly CreateTemplateWithLabelsSample _sample; + + public CreateTemplateWithLabelsTests(ModelArmorFixture fixture, ITestOutputHelper output) + { + _fixture = fixture; + _sample = new CreateTemplateWithLabelsSample(); + } + + [Fact] + public void CreateTemplateWithLabels() + { + string projectId = _fixture.ProjectId; + string locationId = _fixture.LocationId; + + TemplateName templateName = _fixture.CreateTemplateName(); + _fixture.RegisterTemplateForCleanup(templateName); + string templateId = templateName.TemplateId; + + // Run the sample. + Template createdTemplate = _sample.CreateTemplateWithLabels( + projectId: projectId, + locationId: locationId, + templateId: templateId + ); + + // Verify the template was created successfully. + Assert.NotNull(createdTemplate); + Assert.Contains(templateId, createdTemplate.Name); + + // Since labels is not a part of the Create Template API response, + // we retrieve the template to verify labels. + ModelArmorClientBuilder clientBuilder = new ModelArmorClientBuilder + { + Endpoint = $"modelarmor.{locationId}.rep.googleapis.com", + }; + ModelArmorClient client = clientBuilder.Build(); + Template retrievedTemplate = client.GetTemplate(createdTemplate.Name); + + // Verify the labels. + Assert.NotNull(retrievedTemplate.Labels); + Assert.Equal(2, retrievedTemplate.Labels.Count); + Assert.Equal("value1", retrievedTemplate.Labels["key1"]); + Assert.Equal("value2", retrievedTemplate.Labels["key2"]); + } + } +} diff --git a/modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateWithMetadataTest.cs b/modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateWithMetadataTest.cs new file mode 100644 index 00000000000..f327180410d --- /dev/null +++ b/modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateWithMetadataTest.cs @@ -0,0 +1,59 @@ +/* + * 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 System; +using System.Linq; +using Google.Cloud.ModelArmor.V1; +using Xunit; +using Xunit.Abstractions; + +namespace ModelArmor.Samples.Tests +{ + public class CreateTemplateWithMetadataTests : IClassFixture + { + private readonly ModelArmorFixture _fixture; + private readonly CreateTemplateWithMetadataSample _sample; + + public CreateTemplateWithMetadataTests(ModelArmorFixture fixture, ITestOutputHelper output) + { + _fixture = fixture; + _sample = new CreateTemplateWithMetadataSample(); + } + + [Fact] + public void CreateTemplateWithMetadata() + { + string projectId = _fixture.ProjectId; + string locationId = _fixture.LocationId; + + TemplateName templateName = _fixture.CreateTemplateName(); + _fixture.RegisterTemplateForCleanup(templateName); + string templateId = templateName.TemplateId; + + // Run the sample. + Template createdTemplate = _sample.CreateTemplateWithMetadata( + projectId: projectId, + locationId: locationId, + templateId: templateId + ); + + // Verify the expected template metadata. + Assert.NotNull(createdTemplate.TemplateMetadata); + Assert.True(createdTemplate.TemplateMetadata.LogTemplateOperations); + Assert.True(createdTemplate.TemplateMetadata.LogSanitizeOperations); + } + } +} diff --git a/modelarmor/api/ModelArmor.Samples.Tests/QuickStartTest.cs b/modelarmor/api/ModelArmor.Samples.Tests/QuickStartTest.cs index 4316427906b..295920bd3a9 100644 --- a/modelarmor/api/ModelArmor.Samples.Tests/QuickStartTest.cs +++ b/modelarmor/api/ModelArmor.Samples.Tests/QuickStartTest.cs @@ -42,7 +42,5 @@ public void Runs() locationId: templateName.LocationId, templateId: templateName.TemplateId ); - - _fixture.RegisterTemplateForCleanup(templateName); } } diff --git a/modelarmor/api/ModelArmor.Samples/CreateTemplateWithLabels.cs b/modelarmor/api/ModelArmor.Samples/CreateTemplateWithLabels.cs new file mode 100644 index 00000000000..d43b593baf1 --- /dev/null +++ b/modelarmor/api/ModelArmor.Samples/CreateTemplateWithLabels.cs @@ -0,0 +1,98 @@ +/* + * 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. + */ + +// [START modelarmor_create_template_with_labels] +using System; +using System.Collections.Generic; +using Google.Api.Gax.ResourceNames; +using Google.Cloud.ModelArmor.V1; +using Google.Protobuf.Collections; + +namespace ModelArmor.Samples +{ + public class CreateTemplateWithLabelsSample + { + public Template CreateTemplateWithLabels( + string projectId = "my-project", + string locationId = "us-central1", + string templateId = "my-template" + ) + { + // Construct the API endpoint URL. + ModelArmorClientBuilder clientBuilder = new ModelArmorClientBuilder + { + Endpoint = $"modelarmor.{locationId}.rep.googleapis.com", + }; + + // Create the client. + Google.Cloud.ModelArmor.V1.ModelArmorClient client = clientBuilder.Build(); + + // Build the parent resource name. + LocationName parent = LocationName.FromProjectLocation(projectId, locationId); + + // Build the Model Armor template with preferred filters. + // For more details on filters, refer to: + // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters + RaiFilterSettings raiFilterSettings = new RaiFilterSettings(); + raiFilterSettings.RaiFilters.Add( + new RaiFilterSettings.Types.RaiFilter + { + FilterType = RaiFilterType.Dangerous, + ConfidenceLevel = DetectionConfidenceLevel.High, + } + ); + raiFilterSettings.RaiFilters.Add( + new RaiFilterSettings.Types.RaiFilter + { + FilterType = RaiFilterType.HateSpeech, + ConfidenceLevel = DetectionConfidenceLevel.High, + } + ); + raiFilterSettings.RaiFilters.Add( + new RaiFilterSettings.Types.RaiFilter + { + FilterType = RaiFilterType.SexuallyExplicit, + ConfidenceLevel = DetectionConfidenceLevel.LowAndAbove, + } + ); + raiFilterSettings.RaiFilters.Add( + new RaiFilterSettings.Types.RaiFilter + { + FilterType = RaiFilterType.Harassment, + ConfidenceLevel = DetectionConfidenceLevel.MediumAndAbove, + } + ); + + FilterConfig modelArmorFilter = new FilterConfig { RaiSettings = raiFilterSettings }; + + Template template = new Template { FilterConfig = modelArmorFilter }; + + template.Labels.Add("key1", "value1"); + template.Labels.Add("key2", "value2"); + + CreateTemplateRequest request = new CreateTemplateRequest + { + ParentAsLocationName = parent, + TemplateId = templateId, + Template = template, + }; + + Template createdTemplate = client.CreateTemplate(request); + return createdTemplate; + } + } +} +// [END modelarmor_create_template_with_labels] diff --git a/modelarmor/api/ModelArmor.Samples/CreateTemplateWithMetadata.cs b/modelarmor/api/ModelArmor.Samples/CreateTemplateWithMetadata.cs new file mode 100644 index 00000000000..bd8da08fd77 --- /dev/null +++ b/modelarmor/api/ModelArmor.Samples/CreateTemplateWithMetadata.cs @@ -0,0 +1,105 @@ +/* + * 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. + */ + +// [START modelarmor_create_template_with_metadata] +using Google.Api.Gax.ResourceNames; +using Google.Cloud.ModelArmor.V1; + +public class CreateTemplateWithMetadataSample +{ + public Template CreateTemplateWithMetadata( + string projectId = "my-project", + string locationId = "us-central1", + string templateId = "my-template" + ) + { + // Construct the API endpoint URL. + ModelArmorClientBuilder clientBuilder = new ModelArmorClientBuilder + { + Endpoint = $"modelarmor.{locationId}.rep.googleapis.com", + }; + + // Create the client. + Google.Cloud.ModelArmor.V1.ModelArmorClient client = clientBuilder.Build(); + + // Build the parent resource name. + LocationName parent = LocationName.FromProjectLocation(projectId, locationId); + + // Build the Model Armor template with preferred filters. + // For more details on filters, refer to: + // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters + RaiFilterSettings raiFilterSettings = new RaiFilterSettings(); + raiFilterSettings.RaiFilters.Add( + new RaiFilterSettings.Types.RaiFilter + { + FilterType = RaiFilterType.Dangerous, + ConfidenceLevel = DetectionConfidenceLevel.High, + } + ); + raiFilterSettings.RaiFilters.Add( + new RaiFilterSettings.Types.RaiFilter + { + FilterType = RaiFilterType.HateSpeech, + ConfidenceLevel = DetectionConfidenceLevel.High, + } + ); + raiFilterSettings.RaiFilters.Add( + new RaiFilterSettings.Types.RaiFilter + { + FilterType = RaiFilterType.SexuallyExplicit, + ConfidenceLevel = DetectionConfidenceLevel.LowAndAbove, + } + ); + raiFilterSettings.RaiFilters.Add( + new RaiFilterSettings.Types.RaiFilter + { + FilterType = RaiFilterType.Harassment, + ConfidenceLevel = DetectionConfidenceLevel.MediumAndAbove, + } + ); + + FilterConfig modelArmorFilter = new FilterConfig { RaiSettings = raiFilterSettings }; + + // For more details about metadata, refer to the following documentation: + // https://cloud.google.com/security-command-center/docs/reference/model-armor/rest/v1/projects.locations.templates#templatemetadata + Template.Types.TemplateMetadata templateMetadata = new Template.Types.TemplateMetadata + { + LogTemplateOperations = true, + LogSanitizeOperations = true, + }; + + // Create the template with filter config and metadata. + Template template = new Template + { + FilterConfig = modelArmorFilter, + TemplateMetadata = templateMetadata, + }; + + CreateTemplateRequest request = new CreateTemplateRequest + { + ParentAsLocationName = parent, + TemplateId = templateId, + Template = template, + }; + + Template createdTemplate = client.CreateTemplate(request); + System.Console.WriteLine( + $"Successfully created template with name: {createdTemplate.Name}" + ); + return createdTemplate; + } +} +// [END modelarmor_create_template_with_metadata] diff --git a/modelarmor/api/ModelArmor.Samples/ModelArmor.Samples.csproj b/modelarmor/api/ModelArmor.Samples/ModelArmor.Samples.csproj index 91bd4f62433..8a0a414ad19 100644 --- a/modelarmor/api/ModelArmor.Samples/ModelArmor.Samples.csproj +++ b/modelarmor/api/ModelArmor.Samples/ModelArmor.Samples.csproj @@ -1,4 +1,4 @@ - + net8.0 false diff --git a/storage/api/README.md b/storage/api/README.md index ad6ed86fb37..53d8ed62174 100644 --- a/storage/api/README.md +++ b/storage/api/README.md @@ -28,4 +28,4 @@ The samples requires [.NET Core 3.1][net-core] or later. That means using [Storage]: https://cloud.google.com/storage/docs/ [enable-api]: https://console.cloud.google.com/flows/enableapi?apiid=storage_api&showconfirmation=true -[net-core]: https://www.microsoft.com/net/core \ No newline at end of file +[net-core]: https://www.microsoft.com/net/core diff --git a/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs new file mode 100644 index 00000000000..bd1fd5d34db --- /dev/null +++ b/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs @@ -0,0 +1,57 @@ +// 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. + +// [START storage_control_create_anywhere_cache] + +using Google.Cloud.Storage.Control.V2; +using Google.LongRunning; +using System; +using System.Threading.Tasks; + +public class StorageControlCreateAnywhereCacheSample +{ + /// Creates an anywhere cache instance in the specified bucket. + /// The name of the bucket. + /// The zone in which the cache instance will run. + public async Task StorageControlCreateAnywhereCacheAsync(string bucketName = "your-bucket-name", + string zone = "us-east-a") + { + StorageControlClient storageControlClient = StorageControlClient.Create(); + + // Set project to "_" to signify globally scoped bucket. + string parent = $"projects/_/buckets/{bucketName}"; + + AnywhereCache anywhereCache = new AnywhereCache + { + Zone = zone + }; + + var request = new CreateAnywhereCacheRequest + { + AnywhereCache = anywhereCache, + Parent = parent + }; + + // Start a long-running operation (LRO). + Task> createdCacheOperation = storageControlClient.CreateAnywhereCacheAsync(request); + + // Await the LROs completion. + var createdCache = await createdCacheOperation.Result.PollUntilCompletedAsync(); + + Console.WriteLine($"Created Anywhere Cache Instance: {createdCache.Result.AnywhereCacheName}"); + + return createdCache.Result; + } +} +// [END storage_control_create_anywhere_cache] diff --git a/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs new file mode 100644 index 00000000000..5afe9e77d3f --- /dev/null +++ b/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs @@ -0,0 +1,45 @@ +// 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. + +// [START storage_control_disable_anywhere_cache] + +using Google.Cloud.Storage.Control.V2; +using System; + +public class StorageControlDisableAnywhereCacheSample +{ + /// Disables the anywhere cache instance in the specified bucket. + /// The name of the bucket that owns the anywhere cache instance. + /// The name of the zone in which the anywhere cache is located. + public AnywhereCache StorageControlDisableAnywhereCache(string bucketName = "your-bucket-name", + string anywhereCacheId = "us-east1-a") + { + StorageControlClient storageControlClient = StorageControlClient.Create(); + + // Set project to "_" to signify globally scoped bucket. + string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{anywhereCacheId}"; + + var request = new DisableAnywhereCacheRequest + { + Name = anywhereCacheName + }; + + AnywhereCache disabledCache = storageControlClient.DisableAnywhereCache(request); + + Console.WriteLine($"Disabled Anywhere Cache Instance: {disabledCache.Name}"); + + return disabledCache; + } +} +// [END storage_control_disable_anywhere_cache] diff --git a/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs new file mode 100644 index 00000000000..92273ed496b --- /dev/null +++ b/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs @@ -0,0 +1,45 @@ +// 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. + +// [START storage_control_get_anywhere_cache] + +using Google.Cloud.Storage.Control.V2; +using System; + +public class StorageControlGetAnywhereCacheSample +{ + /// Gets an anywhere cache instance for the specified bucket. + /// The name of the bucket that owns the anywhere cache instance. + /// The name of the zone in which the anywhere cache is located. + public AnywhereCache StorageControlGetAnywhereCache(string bucketName = "your-bucket-name", + string anywhereCacheId = "us-east1-a") + { + StorageControlClient storageControlClient = StorageControlClient.Create(); + + // Set project to "_" to signify globally scoped bucket. + string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{anywhereCacheId}"; + + var request = new GetAnywhereCacheRequest + { + Name = anywhereCacheName + }; + + AnywhereCache retrievedCache = storageControlClient.GetAnywhereCache(request); + + Console.WriteLine($"Got Anywhere Cache Instance: {retrievedCache.Name}"); + + return retrievedCache; + } +} +// [END storage_control_get_anywhere_cache] diff --git a/storage/api/Storage.Samples/StorageControlListAnywhereCaches.cs b/storage/api/Storage.Samples/StorageControlListAnywhereCaches.cs new file mode 100644 index 00000000000..279be4ecaa0 --- /dev/null +++ b/storage/api/Storage.Samples/StorageControlListAnywhereCaches.cs @@ -0,0 +1,50 @@ +// 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. + +// [START storage_control_list_anywhere_caches] + +using Google.Api.Gax; +using Google.Cloud.Storage.Control.V2; +using System; +using System.Collections.Generic; + +public class StorageControlListAnywhereCachesSample +{ + /// Lists all anywhere cache instances for the specified bucket. + /// The name of the bucket that owns the anywhere cache instance. + public IEnumerable StorageControlListAnywhereCaches(string bucketName = "your-bucket-name") + { + StorageControlClient storageControlClient = StorageControlClient.Create(); + + // Set project to "_" to signify globally scoped bucket. + string parent = $"projects/_/buckets/{bucketName}"; + + var request = new ListAnywhereCachesRequest + { + Parent = parent + }; + + PagedEnumerable anywhereCaches = storageControlClient.ListAnywhereCaches(request); + + Console.WriteLine($"The Names of Anywhere Cache Instances are as follows:"); + + foreach (AnywhereCache cache in anywhereCaches) + { + Console.WriteLine($"Anywhere Cache Instance: {cache.Name}"); + } + + return anywhereCaches; + } +} +// [END storage_control_list_anywhere_caches] diff --git a/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs new file mode 100644 index 00000000000..691ebbaf9f6 --- /dev/null +++ b/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs @@ -0,0 +1,45 @@ +// 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. + +// [START storage_control_pause_anywhere_cache] + +using Google.Cloud.Storage.Control.V2; +using System; + +public class StorageControlPauseAnywhereCacheSample +{ + /// Pauses an anywhere cache instance in the specified bucket. + /// The name of the bucket that owns the anywhere cache instance. + /// The name of the zone in which the anywhere cache is located. + public AnywhereCache StorageControlPauseAnywhereCache(string bucketName = "your-bucket-name", + string anywhereCacheId = "us-east1-a") + { + StorageControlClient storageControlClient = StorageControlClient.Create(); + + // Set project to "_" to signify globally scoped bucket. + string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{anywhereCacheId}"; + + var request = new PauseAnywhereCacheRequest + { + Name = anywhereCacheName + }; + + AnywhereCache pausedCache = storageControlClient.PauseAnywhereCache(request); + + Console.WriteLine($"Paused Anywhere Cache Instance: {pausedCache.Name}"); + + return pausedCache; + } +} +// [END storage_control_pause_anywhere_cache] diff --git a/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs new file mode 100644 index 00000000000..0703fe7ef44 --- /dev/null +++ b/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs @@ -0,0 +1,45 @@ +// 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. + +// [START storage_control_resume_anywhere_cache] + +using Google.Cloud.Storage.Control.V2; +using System; + +public class StorageControlResumeAnywhereCacheSample +{ + /// Resumes the disabled or paused anywhere cache instance in the specified bucket. + /// The name of the bucket that owns the anywhere cache instance. + /// The name of the zone in which the anywhere cache is located. + public AnywhereCache StorageControlResumeAnywhereCache(string bucketName = "your-bucket-name", + string anywhereCacheId = "us-east1-a") + { + StorageControlClient storageControlClient = StorageControlClient.Create(); + + // Set project to "_" to signify globally scoped bucket. + string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{anywhereCacheId}"; + + var request = new ResumeAnywhereCacheRequest + { + Name = anywhereCacheName + }; + + AnywhereCache resumedCache = storageControlClient.ResumeAnywhereCache(request); + + Console.WriteLine($"Resumed Anywhere Cache Instance: {resumedCache.Name}"); + + return resumedCache; + } +} +// [END storage_control_resume_anywhere_cache] From cbd60f69190c484864e48d3408e224e49bfebd34 Mon Sep 17 00:00:00 2001 From: mahendra-google Date: Wed, 6 Aug 2025 04:00:42 -0700 Subject: [PATCH 02/24] samples(storage): modify sample to create anywhere cache --- .../Storage.Samples/StorageControlCreateAnywhereCache.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs index bd1fd5d34db..1b5eeb9c3ee 100644 --- a/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs @@ -17,14 +17,13 @@ using Google.Cloud.Storage.Control.V2; using Google.LongRunning; using System; -using System.Threading.Tasks; public class StorageControlCreateAnywhereCacheSample { /// Creates an anywhere cache instance in the specified bucket. /// The name of the bucket. /// The zone in which the cache instance will run. - public async Task StorageControlCreateAnywhereCacheAsync(string bucketName = "your-bucket-name", + public Operation StorageControlCreateAnywhereCache(string bucketName = "your-bucket-name", string zone = "us-east-a") { StorageControlClient storageControlClient = StorageControlClient.Create(); @@ -44,14 +43,14 @@ public async Task StorageControlCreateAnywhereCacheAsync(string b }; // Start a long-running operation (LRO). - Task> createdCacheOperation = storageControlClient.CreateAnywhereCacheAsync(request); + Operation createdCacheOperation = storageControlClient.CreateAnywhereCache(request); // Await the LROs completion. - var createdCache = await createdCacheOperation.Result.PollUntilCompletedAsync(); + var createdCache = createdCacheOperation.PollUntilCompleted(); Console.WriteLine($"Created Anywhere Cache Instance: {createdCache.Result.AnywhereCacheName}"); - return createdCache.Result; + return createdCache; } } // [END storage_control_create_anywhere_cache] From 36bb43bb1e238f878fa41195cf1407b68fd44f99 Mon Sep 17 00:00:00 2001 From: mahendra-google Date: Wed, 6 Aug 2025 19:45:49 +0530 Subject: [PATCH 03/24] samples(storage): modify default bucket name --- .../api/Storage.Samples/StorageControlCreateAnywhereCache.cs | 2 +- .../api/Storage.Samples/StorageControlDisableAnywhereCache.cs | 2 +- storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs | 2 +- storage/api/Storage.Samples/StorageControlListAnywhereCaches.cs | 2 +- storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs | 2 +- .../api/Storage.Samples/StorageControlResumeAnywhereCache.cs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs index 1b5eeb9c3ee..9cd20f6342d 100644 --- a/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs @@ -23,7 +23,7 @@ public class StorageControlCreateAnywhereCacheSample /// Creates an anywhere cache instance in the specified bucket. /// The name of the bucket. /// The zone in which the cache instance will run. - public Operation StorageControlCreateAnywhereCache(string bucketName = "your-bucket-name", + public Operation StorageControlCreateAnywhereCache(string bucketName = "your-unique-bucket-name", string zone = "us-east-a") { StorageControlClient storageControlClient = StorageControlClient.Create(); diff --git a/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs index 5afe9e77d3f..732d117dc51 100644 --- a/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs @@ -22,7 +22,7 @@ public class StorageControlDisableAnywhereCacheSample /// Disables the anywhere cache instance in the specified bucket. /// The name of the bucket that owns the anywhere cache instance. /// The name of the zone in which the anywhere cache is located. - public AnywhereCache StorageControlDisableAnywhereCache(string bucketName = "your-bucket-name", + public AnywhereCache StorageControlDisableAnywhereCache(string bucketName = "your-unique-bucket-name", string anywhereCacheId = "us-east1-a") { StorageControlClient storageControlClient = StorageControlClient.Create(); diff --git a/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs index 92273ed496b..a26b6446689 100644 --- a/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs @@ -22,7 +22,7 @@ public class StorageControlGetAnywhereCacheSample /// Gets an anywhere cache instance for the specified bucket. /// The name of the bucket that owns the anywhere cache instance. /// The name of the zone in which the anywhere cache is located. - public AnywhereCache StorageControlGetAnywhereCache(string bucketName = "your-bucket-name", + public AnywhereCache StorageControlGetAnywhereCache(string bucketName = "your-unique-bucket-name", string anywhereCacheId = "us-east1-a") { StorageControlClient storageControlClient = StorageControlClient.Create(); diff --git a/storage/api/Storage.Samples/StorageControlListAnywhereCaches.cs b/storage/api/Storage.Samples/StorageControlListAnywhereCaches.cs index 279be4ecaa0..47652069625 100644 --- a/storage/api/Storage.Samples/StorageControlListAnywhereCaches.cs +++ b/storage/api/Storage.Samples/StorageControlListAnywhereCaches.cs @@ -23,7 +23,7 @@ public class StorageControlListAnywhereCachesSample { /// Lists all anywhere cache instances for the specified bucket. /// The name of the bucket that owns the anywhere cache instance. - public IEnumerable StorageControlListAnywhereCaches(string bucketName = "your-bucket-name") + public IEnumerable StorageControlListAnywhereCaches(string bucketName = "your-unique-bucket-name") { StorageControlClient storageControlClient = StorageControlClient.Create(); diff --git a/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs index 691ebbaf9f6..3735a390d4d 100644 --- a/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs @@ -22,7 +22,7 @@ public class StorageControlPauseAnywhereCacheSample /// Pauses an anywhere cache instance in the specified bucket. /// The name of the bucket that owns the anywhere cache instance. /// The name of the zone in which the anywhere cache is located. - public AnywhereCache StorageControlPauseAnywhereCache(string bucketName = "your-bucket-name", + public AnywhereCache StorageControlPauseAnywhereCache(string bucketName = "your-unique-bucket-name", string anywhereCacheId = "us-east1-a") { StorageControlClient storageControlClient = StorageControlClient.Create(); diff --git a/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs index 0703fe7ef44..5f3ceb7c3c8 100644 --- a/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs @@ -22,7 +22,7 @@ public class StorageControlResumeAnywhereCacheSample /// Resumes the disabled or paused anywhere cache instance in the specified bucket. /// The name of the bucket that owns the anywhere cache instance. /// The name of the zone in which the anywhere cache is located. - public AnywhereCache StorageControlResumeAnywhereCache(string bucketName = "your-bucket-name", + public AnywhereCache StorageControlResumeAnywhereCache(string bucketName = "your-unique-bucket-name", string anywhereCacheId = "us-east1-a") { StorageControlClient storageControlClient = StorageControlClient.Create(); From b435193b7b5205cbdef76ecb34d7d061e60ba3cc Mon Sep 17 00:00:00 2001 From: mahendra-google Date: Wed, 13 Aug 2025 01:27:34 -0700 Subject: [PATCH 04/24] samples(storage): add samples to update anyhere cache --- .../StorageControlUpdateAnywhereCache.cs | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs diff --git a/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs new file mode 100644 index 00000000000..e7af3d7f91e --- /dev/null +++ b/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs @@ -0,0 +1,62 @@ +// 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. + +// [START storage_control_update_anywhere_cache] + +using Google.Cloud.Storage.Control.V2; +using Google.LongRunning; +using Google.Protobuf.WellKnownTypes; +using System; +using System.Threading.Tasks; + +public class StorageControlUpdateAnywhereCacheSample +{ + /// Updates the running anywhere cache instance for the specified bucket. + /// The name of the bucket that owns the anywhere cache instance. + /// The name of the zone in which the anywhere cache is located. + /// The cache's admission policy. Values can be admit-on-first-miss or admit-on-second-miss. If not specified, it defaults to admit-on-first-miss. + public Operation StorageControlUpdateAnywhereCache(string bucketName = "your-bucket-name", + string anywhereCacheId = "us-east1-a", + string admissionPolicy = "admit-on-first-miss") + { + StorageControlClient storageControlClient = StorageControlClient.Create(); + + // Set project to "_" to signify globally scoped bucket. + string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{anywhereCacheId}"; + + var anywhereCache = new AnywhereCache + { + Name = anywhereCacheName, + AdmissionPolicy = admissionPolicy + }; + FieldMask fieldMask = new FieldMask { Paths = { "admission_policy" } }; + + var request = new UpdateAnywhereCacheRequest + { + AnywhereCache = anywhereCache, + UpdateMask = fieldMask + }; + + // Start a long-running operation (LRO). + Operation updatedCacheOperation = storageControlClient.UpdateAnywhereCache(request); + + // Await the LROs completion. + var updatedCache = updatedCacheOperation.PollUntilCompleted(); + + Console.WriteLine($"Updated Anywhere Cache Instance: {updatedCache.Result.Name}, New Cache Admission Policy: {updatedCache.Result.AdmissionPolicy}"); + + return updatedCache; + } +} +// [END storage_control_update_anywhere_cache] From 9356839cef9afb7126997968db5fc9646d33bd84 Mon Sep 17 00:00:00 2001 From: mahendra-google Date: Wed, 13 Aug 2025 04:45:01 -0700 Subject: [PATCH 05/24] samples(storage): Remove unused assembly reference --- storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs index e7af3d7f91e..a125e9489cb 100644 --- a/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs @@ -18,7 +18,6 @@ using Google.LongRunning; using Google.Protobuf.WellKnownTypes; using System; -using System.Threading.Tasks; public class StorageControlUpdateAnywhereCacheSample { From 966586ae5c21d20315a39a9f2232b89d293a31a5 Mon Sep 17 00:00:00 2001 From: mahendra-google Date: Thu, 4 Sep 2025 03:03:07 -0700 Subject: [PATCH 06/24] samples(storage): add test to list anywhere cache --- .../StorageControlListAnywhereCachesTest.cs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 storage/api/Storage.Samples.Tests/StorageControlListAnywhereCachesTest.cs diff --git a/storage/api/Storage.Samples.Tests/StorageControlListAnywhereCachesTest.cs b/storage/api/Storage.Samples.Tests/StorageControlListAnywhereCachesTest.cs new file mode 100644 index 00000000000..b8e7fb5e018 --- /dev/null +++ b/storage/api/Storage.Samples.Tests/StorageControlListAnywhereCachesTest.cs @@ -0,0 +1,54 @@ +// 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.Control.V2; +using Xunit; + +[Collection(nameof(StorageFixture))] +public class StorageControlListAnywhereCachesTest +{ + private readonly StorageFixture _fixture; + + public StorageControlListAnywhereCachesTest(StorageFixture fixture) + { + _fixture = fixture; + } + + [Fact] + public void TestStorageControlListAnywhereCaches() + { + StorageControlCreateAnywhereCacheSample createCacheSample = new StorageControlCreateAnywhereCacheSample(); + + var bucketName = _fixture.GenerateBucketName(); + _fixture.CreateBucket(bucketName, "us"); + + var createdCache = createCacheSample.StorageControlCreateAnywhereCache(bucketName, "us-west1-a"); + + StorageControlListAnywhereCachesSample listCacheSample = new StorageControlListAnywhereCachesSample(); + var listCaches = listCacheSample.StorageControlListAnywhereCaches(bucketName); + // Check the list contains the anywhere cache we just created. + Assert.Contains(listCaches, anywhereCache => anywhereCache.Name == createdCache.Result.Name && anywhereCache.AdmissionPolicy == createdCache.Result.AdmissionPolicy && anywhereCache.Ttl == createdCache.Result.Ttl); + Assert.All(listCaches, AssertAnywhereCache); + } + + // Validates anywhere cache metadata. + private void AssertAnywhereCache(AnywhereCache c) + { + Assert.NotNull(c.AnywhereCacheName); + Assert.NotNull(c.Name); + Assert.NotNull(c.AdmissionPolicy); + Assert.NotNull(c.Zone); + Assert.NotNull(c.Ttl); + } +} From 963ed6c9d53370b7942836a0493db0cd58338fbf Mon Sep 17 00:00:00 2001 From: mahendra-google Date: Thu, 4 Sep 2025 05:07:11 -0700 Subject: [PATCH 07/24] samples(storage); add tests for anywhere cache --- .../StorageControlCreateAnywhereCacheTest.cs | 44 +++++++++++++++++ .../StorageControlDisableAnywhereCacheTest.cs | 42 +++++++++++++++++ .../StorageControlGetAnywhereCacheTest.cs | 43 +++++++++++++++++ .../StorageControlPauseAnywhereCacheTest.cs | 43 +++++++++++++++++ .../StorageControlResumeAnywhereCacheTest.cs | 47 +++++++++++++++++++ .../StorageControlUpdateAnywhereCacheTest.cs | 46 ++++++++++++++++++ 6 files changed, 265 insertions(+) create mode 100644 storage/api/Storage.Samples.Tests/StorageControlCreateAnywhereCacheTest.cs create mode 100644 storage/api/Storage.Samples.Tests/StorageControlDisableAnywhereCacheTest.cs create mode 100644 storage/api/Storage.Samples.Tests/StorageControlGetAnywhereCacheTest.cs create mode 100644 storage/api/Storage.Samples.Tests/StorageControlPauseAnywhereCacheTest.cs create mode 100644 storage/api/Storage.Samples.Tests/StorageControlResumeAnywhereCacheTest.cs create mode 100644 storage/api/Storage.Samples.Tests/StorageControlUpdateAnywhereCacheTest.cs diff --git a/storage/api/Storage.Samples.Tests/StorageControlCreateAnywhereCacheTest.cs b/storage/api/Storage.Samples.Tests/StorageControlCreateAnywhereCacheTest.cs new file mode 100644 index 00000000000..775e2f7dcc2 --- /dev/null +++ b/storage/api/Storage.Samples.Tests/StorageControlCreateAnywhereCacheTest.cs @@ -0,0 +1,44 @@ +// 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 Xunit; + +[Collection(nameof(StorageFixture))] +public class StorageControlCreateAnywhereCacheTest +{ + private readonly StorageFixture _fixture; + + public StorageControlCreateAnywhereCacheTest(StorageFixture fixture) + { + _fixture = fixture; + } + + [Fact] + public void TestStorageControlCreateAnywhereCache() + { + StorageControlCreateAnywhereCacheSample createCacheSample = new StorageControlCreateAnywhereCacheSample(); + + var bucketName = _fixture.GenerateBucketName(); + _fixture.CreateBucket(bucketName, "us"); + + var createdCache = createCacheSample.StorageControlCreateAnywhereCache(bucketName, "us-west1-a"); + + Assert.NotNull(createdCache); + Assert.NotNull(createdCache.Result.AnywhereCacheName); + Assert.NotNull(createdCache.Result.Name); + Assert.NotNull(createdCache.Result.AdmissionPolicy); + Assert.NotNull(createdCache.Result.Zone); + Assert.NotNull(createdCache.Result.Ttl); + } +} diff --git a/storage/api/Storage.Samples.Tests/StorageControlDisableAnywhereCacheTest.cs b/storage/api/Storage.Samples.Tests/StorageControlDisableAnywhereCacheTest.cs new file mode 100644 index 00000000000..5e8bbef6a69 --- /dev/null +++ b/storage/api/Storage.Samples.Tests/StorageControlDisableAnywhereCacheTest.cs @@ -0,0 +1,42 @@ +// 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 Xunit; + +[Collection(nameof(StorageFixture))] +public class StorageControlDisableAnywhereCacheTest +{ + private readonly StorageFixture _fixture; + + public StorageControlDisableAnywhereCacheTest(StorageFixture fixture) + { + _fixture = fixture; + } + + [Fact] + public void TestStorageControlDisableAnywhereCache() + { + StorageControlCreateAnywhereCacheSample createCacheSample = new StorageControlCreateAnywhereCacheSample(); + + var bucketName = _fixture.GenerateBucketName(); + _fixture.CreateBucket(bucketName, "us"); + + var createdCache = createCacheSample.StorageControlCreateAnywhereCache(bucketName, "us-west1-a"); + + StorageControlDisableAnywhereCacheSample disableCacheSample = new StorageControlDisableAnywhereCacheSample(); + var disabledCache = disableCacheSample.StorageControlDisableAnywhereCache(bucketName, createdCache.Result.Zone); + + Assert.Equal("disabled", disabledCache.State); + } +} diff --git a/storage/api/Storage.Samples.Tests/StorageControlGetAnywhereCacheTest.cs b/storage/api/Storage.Samples.Tests/StorageControlGetAnywhereCacheTest.cs new file mode 100644 index 00000000000..376e5e4ffcf --- /dev/null +++ b/storage/api/Storage.Samples.Tests/StorageControlGetAnywhereCacheTest.cs @@ -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.Control.V2; +using Xunit; + +[Collection(nameof(StorageFixture))] +public class StorageControlGetAnywhereCacheTest +{ + private readonly StorageFixture _fixture; + + public StorageControlGetAnywhereCacheTest(StorageFixture fixture) + { + _fixture = fixture; + } + + [Fact] + public void TestStorageControlGetAnywhereCache() + { + StorageControlCreateAnywhereCacheSample createCacheSample = new StorageControlCreateAnywhereCacheSample(); + + var bucketName = _fixture.GenerateBucketName(); + _fixture.CreateBucket(bucketName, "us"); + + var createdCache = createCacheSample.StorageControlCreateAnywhereCache(bucketName, "us-west1-a"); + + StorageControlGetAnywhereCacheSample getCacheSample = new StorageControlGetAnywhereCacheSample(); + var getCache = getCacheSample.StorageControlGetAnywhereCache(bucketName, createdCache.Result.Zone); + + Assert.Equal(createdCache.Result.Name, getCache.Name); + } +} diff --git a/storage/api/Storage.Samples.Tests/StorageControlPauseAnywhereCacheTest.cs b/storage/api/Storage.Samples.Tests/StorageControlPauseAnywhereCacheTest.cs new file mode 100644 index 00000000000..208206713ca --- /dev/null +++ b/storage/api/Storage.Samples.Tests/StorageControlPauseAnywhereCacheTest.cs @@ -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 Xunit; + +[Collection(nameof(StorageFixture))] +public class StorageControlPauseAnywhereCacheTest +{ + private readonly StorageFixture _fixture; + + public StorageControlPauseAnywhereCacheTest(StorageFixture fixture) + { + _fixture = fixture; + } + + [Fact] + public void TestStorageControlPauseAnywhereCache() + { + StorageControlCreateAnywhereCacheSample createCacheSample = new StorageControlCreateAnywhereCacheSample(); + + var bucketName = _fixture.GenerateBucketName(); + _fixture.CreateBucket(bucketName, "us"); + + var createdCache = createCacheSample.StorageControlCreateAnywhereCache(bucketName, "us-west1-a"); + + StorageControlPauseAnywhereCacheSample pauseCacheSample = new StorageControlPauseAnywhereCacheSample(); + + var pausedCache = pauseCacheSample.StorageControlPauseAnywhereCache(bucketName, createdCache.Result.Zone); + + Assert.Equal("paused", pausedCache.State); + } +} diff --git a/storage/api/Storage.Samples.Tests/StorageControlResumeAnywhereCacheTest.cs b/storage/api/Storage.Samples.Tests/StorageControlResumeAnywhereCacheTest.cs new file mode 100644 index 00000000000..efc33dda727 --- /dev/null +++ b/storage/api/Storage.Samples.Tests/StorageControlResumeAnywhereCacheTest.cs @@ -0,0 +1,47 @@ +// 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 Xunit; + +[Collection(nameof(StorageFixture))] +public class StorageControlResumeAnywhereCacheTest +{ + private readonly StorageFixture _fixture; + + public StorageControlResumeAnywhereCacheTest(StorageFixture fixture) + { + _fixture = fixture; + } + + [Fact] + public void TestStorageControlResumeAnywhereCache() + { + StorageControlCreateAnywhereCacheSample createCacheSample = new StorageControlCreateAnywhereCacheSample(); + + var bucketName = _fixture.GenerateBucketName(); + _fixture.CreateBucket(bucketName, "us"); + + var createdCache = createCacheSample.StorageControlCreateAnywhereCache(bucketName, "us-west1-a"); + + StorageControlPauseAnywhereCacheSample pauseCacheSample = new StorageControlPauseAnywhereCacheSample(); + + var pausedCache = pauseCacheSample.StorageControlPauseAnywhereCache(bucketName, createdCache.Result.Zone); + + StorageControlResumeAnywhereCacheSample resumeCacheSample = new StorageControlResumeAnywhereCacheSample(); + + var resumedCache = resumeCacheSample.StorageControlResumeAnywhereCache(bucketName, pausedCache.Zone); + + Assert.Equal("running", resumedCache.State); + } +} diff --git a/storage/api/Storage.Samples.Tests/StorageControlUpdateAnywhereCacheTest.cs b/storage/api/Storage.Samples.Tests/StorageControlUpdateAnywhereCacheTest.cs new file mode 100644 index 00000000000..9c4ed9be057 --- /dev/null +++ b/storage/api/Storage.Samples.Tests/StorageControlUpdateAnywhereCacheTest.cs @@ -0,0 +1,46 @@ +// 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 Xunit; + +[Collection(nameof(StorageFixture))] +public class StorageControlUpdateAnywhereCacheTest +{ + private readonly StorageFixture _fixture; + + public StorageControlUpdateAnywhereCacheTest(StorageFixture fixture) + { + _fixture = fixture; + } + + [Fact] + public void TestStorageControlUpdateAnywhereCache() + { + StorageControlCreateAnywhereCacheSample createCacheSample = new StorageControlCreateAnywhereCacheSample(); + var bucketName = _fixture.GenerateBucketName(); + _fixture.CreateBucket(bucketName, "us"); + + var createdCache = createCacheSample.StorageControlCreateAnywhereCache(bucketName, "us-west1-a"); + + string newAdmissionPolicy = "admit-on-second-miss"; + StorageControlUpdateAnywhereCacheSample updateCacheSample = new StorageControlUpdateAnywhereCacheSample(); + var updatedCache = updateCacheSample.StorageControlUpdateAnywhereCache(bucketName, createdCache.Result.Zone, newAdmissionPolicy); + + Assert.NotNull(updatedCache); + Assert.Equal(newAdmissionPolicy, updatedCache.Result.AdmissionPolicy); + Assert.Equal(createdCache.Result.AnywhereCacheName, updatedCache.Result.AnywhereCacheName); + Assert.Equal(createdCache.Result.Ttl, updatedCache.Result.Ttl); + Assert.Equal(createdCache.Result.Zone, updatedCache.Result.Zone); + } +} From bbbdfc7fdd596ad66d9a5d666acbb74dc50fd9c9 Mon Sep 17 00:00:00 2001 From: mahendra-google Date: Thu, 4 Sep 2025 05:25:41 -0700 Subject: [PATCH 08/24] samples(storage): remove unused namespace --- .../Storage.Samples.Tests/StorageControlGetAnywhereCacheTest.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/storage/api/Storage.Samples.Tests/StorageControlGetAnywhereCacheTest.cs b/storage/api/Storage.Samples.Tests/StorageControlGetAnywhereCacheTest.cs index 376e5e4ffcf..6c05019b0f1 100644 --- a/storage/api/Storage.Samples.Tests/StorageControlGetAnywhereCacheTest.cs +++ b/storage/api/Storage.Samples.Tests/StorageControlGetAnywhereCacheTest.cs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -using Google.Cloud.Storage.Control.V2; using Xunit; [Collection(nameof(StorageFixture))] From 20e8e0853bcbb487d4b7f8a5d8cc29675cdc54ef Mon Sep 17 00:00:00 2001 From: mahendra-google Date: Mon, 8 Sep 2025 00:20:51 -0700 Subject: [PATCH 09/24] Revert test Code --- .../StorageControlCreateAnywhereCacheTest.cs | 44 ----------------- .../StorageControlDisableAnywhereCacheTest.cs | 42 ----------------- .../StorageControlGetAnywhereCacheTest.cs | 42 ----------------- .../StorageControlPauseAnywhereCacheTest.cs | 43 ----------------- .../StorageControlResumeAnywhereCacheTest.cs | 47 ------------------- .../StorageControlUpdateAnywhereCacheTest.cs | 46 ------------------ 6 files changed, 264 deletions(-) delete mode 100644 storage/api/Storage.Samples.Tests/StorageControlCreateAnywhereCacheTest.cs delete mode 100644 storage/api/Storage.Samples.Tests/StorageControlDisableAnywhereCacheTest.cs delete mode 100644 storage/api/Storage.Samples.Tests/StorageControlGetAnywhereCacheTest.cs delete mode 100644 storage/api/Storage.Samples.Tests/StorageControlPauseAnywhereCacheTest.cs delete mode 100644 storage/api/Storage.Samples.Tests/StorageControlResumeAnywhereCacheTest.cs delete mode 100644 storage/api/Storage.Samples.Tests/StorageControlUpdateAnywhereCacheTest.cs diff --git a/storage/api/Storage.Samples.Tests/StorageControlCreateAnywhereCacheTest.cs b/storage/api/Storage.Samples.Tests/StorageControlCreateAnywhereCacheTest.cs deleted file mode 100644 index 775e2f7dcc2..00000000000 --- a/storage/api/Storage.Samples.Tests/StorageControlCreateAnywhereCacheTest.cs +++ /dev/null @@ -1,44 +0,0 @@ -// 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 Xunit; - -[Collection(nameof(StorageFixture))] -public class StorageControlCreateAnywhereCacheTest -{ - private readonly StorageFixture _fixture; - - public StorageControlCreateAnywhereCacheTest(StorageFixture fixture) - { - _fixture = fixture; - } - - [Fact] - public void TestStorageControlCreateAnywhereCache() - { - StorageControlCreateAnywhereCacheSample createCacheSample = new StorageControlCreateAnywhereCacheSample(); - - var bucketName = _fixture.GenerateBucketName(); - _fixture.CreateBucket(bucketName, "us"); - - var createdCache = createCacheSample.StorageControlCreateAnywhereCache(bucketName, "us-west1-a"); - - Assert.NotNull(createdCache); - Assert.NotNull(createdCache.Result.AnywhereCacheName); - Assert.NotNull(createdCache.Result.Name); - Assert.NotNull(createdCache.Result.AdmissionPolicy); - Assert.NotNull(createdCache.Result.Zone); - Assert.NotNull(createdCache.Result.Ttl); - } -} diff --git a/storage/api/Storage.Samples.Tests/StorageControlDisableAnywhereCacheTest.cs b/storage/api/Storage.Samples.Tests/StorageControlDisableAnywhereCacheTest.cs deleted file mode 100644 index 5e8bbef6a69..00000000000 --- a/storage/api/Storage.Samples.Tests/StorageControlDisableAnywhereCacheTest.cs +++ /dev/null @@ -1,42 +0,0 @@ -// 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 Xunit; - -[Collection(nameof(StorageFixture))] -public class StorageControlDisableAnywhereCacheTest -{ - private readonly StorageFixture _fixture; - - public StorageControlDisableAnywhereCacheTest(StorageFixture fixture) - { - _fixture = fixture; - } - - [Fact] - public void TestStorageControlDisableAnywhereCache() - { - StorageControlCreateAnywhereCacheSample createCacheSample = new StorageControlCreateAnywhereCacheSample(); - - var bucketName = _fixture.GenerateBucketName(); - _fixture.CreateBucket(bucketName, "us"); - - var createdCache = createCacheSample.StorageControlCreateAnywhereCache(bucketName, "us-west1-a"); - - StorageControlDisableAnywhereCacheSample disableCacheSample = new StorageControlDisableAnywhereCacheSample(); - var disabledCache = disableCacheSample.StorageControlDisableAnywhereCache(bucketName, createdCache.Result.Zone); - - Assert.Equal("disabled", disabledCache.State); - } -} diff --git a/storage/api/Storage.Samples.Tests/StorageControlGetAnywhereCacheTest.cs b/storage/api/Storage.Samples.Tests/StorageControlGetAnywhereCacheTest.cs deleted file mode 100644 index 6c05019b0f1..00000000000 --- a/storage/api/Storage.Samples.Tests/StorageControlGetAnywhereCacheTest.cs +++ /dev/null @@ -1,42 +0,0 @@ -// 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 Xunit; - -[Collection(nameof(StorageFixture))] -public class StorageControlGetAnywhereCacheTest -{ - private readonly StorageFixture _fixture; - - public StorageControlGetAnywhereCacheTest(StorageFixture fixture) - { - _fixture = fixture; - } - - [Fact] - public void TestStorageControlGetAnywhereCache() - { - StorageControlCreateAnywhereCacheSample createCacheSample = new StorageControlCreateAnywhereCacheSample(); - - var bucketName = _fixture.GenerateBucketName(); - _fixture.CreateBucket(bucketName, "us"); - - var createdCache = createCacheSample.StorageControlCreateAnywhereCache(bucketName, "us-west1-a"); - - StorageControlGetAnywhereCacheSample getCacheSample = new StorageControlGetAnywhereCacheSample(); - var getCache = getCacheSample.StorageControlGetAnywhereCache(bucketName, createdCache.Result.Zone); - - Assert.Equal(createdCache.Result.Name, getCache.Name); - } -} diff --git a/storage/api/Storage.Samples.Tests/StorageControlPauseAnywhereCacheTest.cs b/storage/api/Storage.Samples.Tests/StorageControlPauseAnywhereCacheTest.cs deleted file mode 100644 index 208206713ca..00000000000 --- a/storage/api/Storage.Samples.Tests/StorageControlPauseAnywhereCacheTest.cs +++ /dev/null @@ -1,43 +0,0 @@ -// 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 Xunit; - -[Collection(nameof(StorageFixture))] -public class StorageControlPauseAnywhereCacheTest -{ - private readonly StorageFixture _fixture; - - public StorageControlPauseAnywhereCacheTest(StorageFixture fixture) - { - _fixture = fixture; - } - - [Fact] - public void TestStorageControlPauseAnywhereCache() - { - StorageControlCreateAnywhereCacheSample createCacheSample = new StorageControlCreateAnywhereCacheSample(); - - var bucketName = _fixture.GenerateBucketName(); - _fixture.CreateBucket(bucketName, "us"); - - var createdCache = createCacheSample.StorageControlCreateAnywhereCache(bucketName, "us-west1-a"); - - StorageControlPauseAnywhereCacheSample pauseCacheSample = new StorageControlPauseAnywhereCacheSample(); - - var pausedCache = pauseCacheSample.StorageControlPauseAnywhereCache(bucketName, createdCache.Result.Zone); - - Assert.Equal("paused", pausedCache.State); - } -} diff --git a/storage/api/Storage.Samples.Tests/StorageControlResumeAnywhereCacheTest.cs b/storage/api/Storage.Samples.Tests/StorageControlResumeAnywhereCacheTest.cs deleted file mode 100644 index efc33dda727..00000000000 --- a/storage/api/Storage.Samples.Tests/StorageControlResumeAnywhereCacheTest.cs +++ /dev/null @@ -1,47 +0,0 @@ -// 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 Xunit; - -[Collection(nameof(StorageFixture))] -public class StorageControlResumeAnywhereCacheTest -{ - private readonly StorageFixture _fixture; - - public StorageControlResumeAnywhereCacheTest(StorageFixture fixture) - { - _fixture = fixture; - } - - [Fact] - public void TestStorageControlResumeAnywhereCache() - { - StorageControlCreateAnywhereCacheSample createCacheSample = new StorageControlCreateAnywhereCacheSample(); - - var bucketName = _fixture.GenerateBucketName(); - _fixture.CreateBucket(bucketName, "us"); - - var createdCache = createCacheSample.StorageControlCreateAnywhereCache(bucketName, "us-west1-a"); - - StorageControlPauseAnywhereCacheSample pauseCacheSample = new StorageControlPauseAnywhereCacheSample(); - - var pausedCache = pauseCacheSample.StorageControlPauseAnywhereCache(bucketName, createdCache.Result.Zone); - - StorageControlResumeAnywhereCacheSample resumeCacheSample = new StorageControlResumeAnywhereCacheSample(); - - var resumedCache = resumeCacheSample.StorageControlResumeAnywhereCache(bucketName, pausedCache.Zone); - - Assert.Equal("running", resumedCache.State); - } -} diff --git a/storage/api/Storage.Samples.Tests/StorageControlUpdateAnywhereCacheTest.cs b/storage/api/Storage.Samples.Tests/StorageControlUpdateAnywhereCacheTest.cs deleted file mode 100644 index 9c4ed9be057..00000000000 --- a/storage/api/Storage.Samples.Tests/StorageControlUpdateAnywhereCacheTest.cs +++ /dev/null @@ -1,46 +0,0 @@ -// 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 Xunit; - -[Collection(nameof(StorageFixture))] -public class StorageControlUpdateAnywhereCacheTest -{ - private readonly StorageFixture _fixture; - - public StorageControlUpdateAnywhereCacheTest(StorageFixture fixture) - { - _fixture = fixture; - } - - [Fact] - public void TestStorageControlUpdateAnywhereCache() - { - StorageControlCreateAnywhereCacheSample createCacheSample = new StorageControlCreateAnywhereCacheSample(); - var bucketName = _fixture.GenerateBucketName(); - _fixture.CreateBucket(bucketName, "us"); - - var createdCache = createCacheSample.StorageControlCreateAnywhereCache(bucketName, "us-west1-a"); - - string newAdmissionPolicy = "admit-on-second-miss"; - StorageControlUpdateAnywhereCacheSample updateCacheSample = new StorageControlUpdateAnywhereCacheSample(); - var updatedCache = updateCacheSample.StorageControlUpdateAnywhereCache(bucketName, createdCache.Result.Zone, newAdmissionPolicy); - - Assert.NotNull(updatedCache); - Assert.Equal(newAdmissionPolicy, updatedCache.Result.AdmissionPolicy); - Assert.Equal(createdCache.Result.AnywhereCacheName, updatedCache.Result.AnywhereCacheName); - Assert.Equal(createdCache.Result.Ttl, updatedCache.Result.Ttl); - Assert.Equal(createdCache.Result.Zone, updatedCache.Result.Zone); - } -} From 311d8e181856653f01d19f6c22f6213b07bc7636 Mon Sep 17 00:00:00 2001 From: mahendra-google Date: Mon, 8 Sep 2025 00:22:41 -0700 Subject: [PATCH 10/24] Revert "samples(storage): add test to list anywhere cache" This reverts commit 966586ae5c21d20315a39a9f2232b89d293a31a5. --- .../StorageControlListAnywhereCachesTest.cs | 54 ------------------- 1 file changed, 54 deletions(-) delete mode 100644 storage/api/Storage.Samples.Tests/StorageControlListAnywhereCachesTest.cs diff --git a/storage/api/Storage.Samples.Tests/StorageControlListAnywhereCachesTest.cs b/storage/api/Storage.Samples.Tests/StorageControlListAnywhereCachesTest.cs deleted file mode 100644 index b8e7fb5e018..00000000000 --- a/storage/api/Storage.Samples.Tests/StorageControlListAnywhereCachesTest.cs +++ /dev/null @@ -1,54 +0,0 @@ -// 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.Control.V2; -using Xunit; - -[Collection(nameof(StorageFixture))] -public class StorageControlListAnywhereCachesTest -{ - private readonly StorageFixture _fixture; - - public StorageControlListAnywhereCachesTest(StorageFixture fixture) - { - _fixture = fixture; - } - - [Fact] - public void TestStorageControlListAnywhereCaches() - { - StorageControlCreateAnywhereCacheSample createCacheSample = new StorageControlCreateAnywhereCacheSample(); - - var bucketName = _fixture.GenerateBucketName(); - _fixture.CreateBucket(bucketName, "us"); - - var createdCache = createCacheSample.StorageControlCreateAnywhereCache(bucketName, "us-west1-a"); - - StorageControlListAnywhereCachesSample listCacheSample = new StorageControlListAnywhereCachesSample(); - var listCaches = listCacheSample.StorageControlListAnywhereCaches(bucketName); - // Check the list contains the anywhere cache we just created. - Assert.Contains(listCaches, anywhereCache => anywhereCache.Name == createdCache.Result.Name && anywhereCache.AdmissionPolicy == createdCache.Result.AdmissionPolicy && anywhereCache.Ttl == createdCache.Result.Ttl); - Assert.All(listCaches, AssertAnywhereCache); - } - - // Validates anywhere cache metadata. - private void AssertAnywhereCache(AnywhereCache c) - { - Assert.NotNull(c.AnywhereCacheName); - Assert.NotNull(c.Name); - Assert.NotNull(c.AdmissionPolicy); - Assert.NotNull(c.Zone); - Assert.NotNull(c.Ttl); - } -} From 5f00e7d693062c5235e9950610416d15a9d2acc4 Mon Sep 17 00:00:00 2001 From: Mahendra Date: Mon, 8 Sep 2025 13:36:39 +0530 Subject: [PATCH 11/24] Update README.md --- storage/api/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/storage/api/README.md b/storage/api/README.md index 53d8ed62174..b6903e2abab 100644 --- a/storage/api/README.md +++ b/storage/api/README.md @@ -29,3 +29,6 @@ The samples requires [.NET Core 3.1][net-core] or later. That means using [Storage]: https://cloud.google.com/storage/docs/ [enable-api]: https://console.cloud.google.com/flows/enableapi?apiid=storage_api&showconfirmation=true [net-core]: https://www.microsoft.com/net/core + +## Note +Tests for Anywhere cache Sample are not included due to the long operation times typical for cache operations. From 0a1272ef836237e947d94f913b074ac916e1f28f Mon Sep 17 00:00:00 2001 From: Mahendra Date: Mon, 8 Sep 2025 13:47:15 +0530 Subject: [PATCH 12/24] Update storage/api/README.md Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- storage/api/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/api/README.md b/storage/api/README.md index b6903e2abab..9dc098261f5 100644 --- a/storage/api/README.md +++ b/storage/api/README.md @@ -31,4 +31,4 @@ The samples requires [.NET Core 3.1][net-core] or later. That means using [net-core]: https://www.microsoft.com/net/core ## Note -Tests for Anywhere cache Sample are not included due to the long operation times typical for cache operations. +Tests for the Anywhere Cache samples are not included due to the long operation times typical for cache operations. From 18f2f6841abc3cf710aa2b167285130c2d90626e Mon Sep 17 00:00:00 2001 From: mahendra-google Date: Tue, 9 Sep 2025 04:11:35 -0700 Subject: [PATCH 13/24] samples(storage control): modify parameter name in sample methods --- .../Storage.Samples/StorageControlCreateAnywhereCache.cs | 6 +++--- .../Storage.Samples/StorageControlDisableAnywhereCache.cs | 6 +++--- .../api/Storage.Samples/StorageControlGetAnywhereCache.cs | 6 +++--- .../api/Storage.Samples/StorageControlPauseAnywhereCache.cs | 6 +++--- .../Storage.Samples/StorageControlResumeAnywhereCache.cs | 6 +++--- .../Storage.Samples/StorageControlUpdateAnywhereCache.cs | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs index 9cd20f6342d..230cc1ca283 100644 --- a/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs @@ -22,9 +22,9 @@ public class StorageControlCreateAnywhereCacheSample { /// Creates an anywhere cache instance in the specified bucket. /// The name of the bucket. - /// The zone in which the cache instance will run. + /// The name of the zone in which the cache instance will run. public Operation StorageControlCreateAnywhereCache(string bucketName = "your-unique-bucket-name", - string zone = "us-east-a") + string zoneName = "us-east-a") { StorageControlClient storageControlClient = StorageControlClient.Create(); @@ -33,7 +33,7 @@ public Operation StorageControlCreat AnywhereCache anywhereCache = new AnywhereCache { - Zone = zone + Zone = zoneName }; var request = new CreateAnywhereCacheRequest diff --git a/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs index 732d117dc51..26d760de291 100644 --- a/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs @@ -21,14 +21,14 @@ public class StorageControlDisableAnywhereCacheSample { /// Disables the anywhere cache instance in the specified bucket. /// The name of the bucket that owns the anywhere cache instance. - /// The name of the zone in which the anywhere cache is located. + /// The name of the zone in which the anywhere cache is located. public AnywhereCache StorageControlDisableAnywhereCache(string bucketName = "your-unique-bucket-name", - string anywhereCacheId = "us-east1-a") + string zoneName = "us-east1-a") { StorageControlClient storageControlClient = StorageControlClient.Create(); // Set project to "_" to signify globally scoped bucket. - string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{anywhereCacheId}"; + string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{zoneName}"; var request = new DisableAnywhereCacheRequest { diff --git a/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs index a26b6446689..fa5af8508be 100644 --- a/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs @@ -21,14 +21,14 @@ public class StorageControlGetAnywhereCacheSample { /// Gets an anywhere cache instance for the specified bucket. /// The name of the bucket that owns the anywhere cache instance. - /// The name of the zone in which the anywhere cache is located. + /// The name of the zone in which the anywhere cache is located. public AnywhereCache StorageControlGetAnywhereCache(string bucketName = "your-unique-bucket-name", - string anywhereCacheId = "us-east1-a") + string zoneName = "us-east1-a") { StorageControlClient storageControlClient = StorageControlClient.Create(); // Set project to "_" to signify globally scoped bucket. - string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{anywhereCacheId}"; + string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{zoneName}"; var request = new GetAnywhereCacheRequest { diff --git a/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs index 3735a390d4d..d51d5ca5bfe 100644 --- a/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs @@ -21,14 +21,14 @@ public class StorageControlPauseAnywhereCacheSample { /// Pauses an anywhere cache instance in the specified bucket. /// The name of the bucket that owns the anywhere cache instance. - /// The name of the zone in which the anywhere cache is located. + /// The name of the zone in which the anywhere cache is located. public AnywhereCache StorageControlPauseAnywhereCache(string bucketName = "your-unique-bucket-name", - string anywhereCacheId = "us-east1-a") + string zoneName = "us-east1-a") { StorageControlClient storageControlClient = StorageControlClient.Create(); // Set project to "_" to signify globally scoped bucket. - string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{anywhereCacheId}"; + string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{zoneName}"; var request = new PauseAnywhereCacheRequest { diff --git a/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs index 5f3ceb7c3c8..6693985b58a 100644 --- a/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs @@ -21,14 +21,14 @@ public class StorageControlResumeAnywhereCacheSample { /// Resumes the disabled or paused anywhere cache instance in the specified bucket. /// The name of the bucket that owns the anywhere cache instance. - /// The name of the zone in which the anywhere cache is located. + /// The name of the zone in which the anywhere cache is located. public AnywhereCache StorageControlResumeAnywhereCache(string bucketName = "your-unique-bucket-name", - string anywhereCacheId = "us-east1-a") + string zoneName = "us-east1-a") { StorageControlClient storageControlClient = StorageControlClient.Create(); // Set project to "_" to signify globally scoped bucket. - string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{anywhereCacheId}"; + string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{zoneName}"; var request = new ResumeAnywhereCacheRequest { diff --git a/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs index a125e9489cb..15d7a659667 100644 --- a/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs @@ -23,16 +23,16 @@ public class StorageControlUpdateAnywhereCacheSample { /// Updates the running anywhere cache instance for the specified bucket. /// The name of the bucket that owns the anywhere cache instance. - /// The name of the zone in which the anywhere cache is located. + /// The name of the zone in which the anywhere cache is located. /// The cache's admission policy. Values can be admit-on-first-miss or admit-on-second-miss. If not specified, it defaults to admit-on-first-miss. public Operation StorageControlUpdateAnywhereCache(string bucketName = "your-bucket-name", - string anywhereCacheId = "us-east1-a", + string zoneName = "us-east1-a", string admissionPolicy = "admit-on-first-miss") { StorageControlClient storageControlClient = StorageControlClient.Create(); // Set project to "_" to signify globally scoped bucket. - string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{anywhereCacheId}"; + string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{zoneName}"; var anywhereCache = new AnywhereCache { From d9c95d76cb53dfd92dd3dc13a2363913a80146fb Mon Sep 17 00:00:00 2001 From: Mahendra Date: Tue, 9 Sep 2025 17:11:49 +0530 Subject: [PATCH 14/24] Update storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- .../Storage.Samples/StorageControlCreateAnywhereCache.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs index 230cc1ca283..3dfc5811f97 100644 --- a/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs @@ -2,14 +2,14 @@ // // 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 +// You may obtain a copy of the License at // -// https://www.apache.org/licenses/LICENSE-2.0 +// https://www.apache.org/licenses/LICENSE-2.0 // -// Unless required by applicable law or agreed to in writing, software +// 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 +// See the License for the specific language governing permissions and // limitations under the License. // [START storage_control_create_anywhere_cache] From a1753a199951e1dfd274c3165a3ba649e0893f75 Mon Sep 17 00:00:00 2001 From: Mahendra Date: Wed, 10 Sep 2025 15:10:44 +0530 Subject: [PATCH 15/24] Update README.md --- storage/api/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/api/README.md b/storage/api/README.md index 9dc098261f5..32941e4b635 100644 --- a/storage/api/README.md +++ b/storage/api/README.md @@ -31,4 +31,4 @@ The samples requires [.NET Core 3.1][net-core] or later. That means using [net-core]: https://www.microsoft.com/net/core ## Note -Tests for the Anywhere Cache samples are not included due to the long operation times typical for cache operations. +Tests for the Anywhere Cache samples are not included because creating an AnywhereCache can take an extremely long time, sometimes up to 48 hours. From 352f7826d3ae3c6e658f085e92b1eadd9568cc1e Mon Sep 17 00:00:00 2001 From: mahendra-google Date: Wed, 10 Sep 2025 04:30:56 -0700 Subject: [PATCH 16/24] samples(storagecontrol): remove trailing whitespaces from google gemini code review --- .../Storage.Samples/StorageControlDisableAnywhereCache.cs | 8 ++++---- .../api/Storage.Samples/StorageControlGetAnywhereCache.cs | 8 ++++---- .../Storage.Samples/StorageControlListAnywhereCaches.cs | 8 ++++---- .../Storage.Samples/StorageControlPauseAnywhereCache.cs | 8 ++++---- .../Storage.Samples/StorageControlResumeAnywhereCache.cs | 8 ++++---- .../Storage.Samples/StorageControlUpdateAnywhereCache.cs | 8 ++++---- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs index 26d760de291..7ec8888ce73 100644 --- a/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs @@ -2,14 +2,14 @@ // // 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 +// You may obtain a copy of the License at // -// https://www.apache.org/licenses/LICENSE-2.0 +// https://www.apache.org/licenses/LICENSE-2.0 // -// Unless required by applicable law or agreed to in writing, software +// 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 +// See the License for the specific language governing permissions and // limitations under the License. // [START storage_control_disable_anywhere_cache] diff --git a/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs index fa5af8508be..3e73baaf92c 100644 --- a/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs @@ -2,14 +2,14 @@ // // 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 +// You may obtain a copy of the License at // -// https://www.apache.org/licenses/LICENSE-2.0 +// https://www.apache.org/licenses/LICENSE-2.0 // -// Unless required by applicable law or agreed to in writing, software +// 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 +// See the License for the specific language governing permissions and // limitations under the License. // [START storage_control_get_anywhere_cache] diff --git a/storage/api/Storage.Samples/StorageControlListAnywhereCaches.cs b/storage/api/Storage.Samples/StorageControlListAnywhereCaches.cs index 47652069625..7934e192ea3 100644 --- a/storage/api/Storage.Samples/StorageControlListAnywhereCaches.cs +++ b/storage/api/Storage.Samples/StorageControlListAnywhereCaches.cs @@ -2,14 +2,14 @@ // // 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 +// You may obtain a copy of the License at // -// https://www.apache.org/licenses/LICENSE-2.0 +// https://www.apache.org/licenses/LICENSE-2.0 // -// Unless required by applicable law or agreed to in writing, software +// 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 +// See the License for the specific language governing permissions and // limitations under the License. // [START storage_control_list_anywhere_caches] diff --git a/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs index d51d5ca5bfe..9a45ca5fe24 100644 --- a/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs @@ -2,14 +2,14 @@ // // 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 +// You may obtain a copy of the License at // -// https://www.apache.org/licenses/LICENSE-2.0 +// https://www.apache.org/licenses/LICENSE-2.0 // -// Unless required by applicable law or agreed to in writing, software +// 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 +// See the License for the specific language governing permissions and // limitations under the License. // [START storage_control_pause_anywhere_cache] diff --git a/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs index 6693985b58a..c08e2fc2370 100644 --- a/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs @@ -2,14 +2,14 @@ // // 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 +// You may obtain a copy of the License at // -// https://www.apache.org/licenses/LICENSE-2.0 +// https://www.apache.org/licenses/LICENSE-2.0 // -// Unless required by applicable law or agreed to in writing, software +// 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 +// See the License for the specific language governing permissions and // limitations under the License. // [START storage_control_resume_anywhere_cache] diff --git a/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs index 15d7a659667..3e142f03544 100644 --- a/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs @@ -2,14 +2,14 @@ // // 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 +// You may obtain a copy of the License at // -// https://www.apache.org/licenses/LICENSE-2.0 +// https://www.apache.org/licenses/LICENSE-2.0 // -// Unless required by applicable law or agreed to in writing, software +// 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 +// See the License for the specific language governing permissions and // limitations under the License. // [START storage_control_update_anywhere_cache] From 6d27cf4353bbf6934a85c9f7b6170022ae9feaef Mon Sep 17 00:00:00 2001 From: Mahendra Date: Thu, 11 Sep 2025 19:41:49 +0530 Subject: [PATCH 17/24] samples(storagecontrol): modify zoneName default parameter value in StorageControlCreateAnywhereCache.cs --- .../api/Storage.Samples/StorageControlCreateAnywhereCache.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs index 3dfc5811f97..5a6ec5a75d3 100644 --- a/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs @@ -24,7 +24,7 @@ public class StorageControlCreateAnywhereCacheSample /// The name of the bucket. /// The name of the zone in which the cache instance will run. public Operation StorageControlCreateAnywhereCache(string bucketName = "your-unique-bucket-name", - string zoneName = "us-east-a") + string zoneName = "us-east1-a") { StorageControlClient storageControlClient = StorageControlClient.Create(); From 07b9318ba57b8f3a1a7e9aea207ae9a14f51d59b Mon Sep 17 00:00:00 2001 From: mahendra-google Date: Thu, 11 Sep 2025 23:42:55 -0700 Subject: [PATCH 18/24] samples(storagecontrol): modify parameter name for samples --- .../Storage.Samples/StorageControlDisableAnywhereCache.cs | 6 +++--- .../api/Storage.Samples/StorageControlGetAnywhereCache.cs | 6 +++--- .../api/Storage.Samples/StorageControlPauseAnywhereCache.cs | 6 +++--- .../Storage.Samples/StorageControlResumeAnywhereCache.cs | 6 +++--- .../Storage.Samples/StorageControlUpdateAnywhereCache.cs | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs index 7ec8888ce73..5b2f2c34878 100644 --- a/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs @@ -21,14 +21,14 @@ public class StorageControlDisableAnywhereCacheSample { /// Disables the anywhere cache instance in the specified bucket. /// The name of the bucket that owns the anywhere cache instance. - /// The name of the zone in which the anywhere cache is located. + /// The name of the zone in which the anywhere cache is located. public AnywhereCache StorageControlDisableAnywhereCache(string bucketName = "your-unique-bucket-name", - string zoneName = "us-east1-a") + string anywhereCacheId = "us-east1-a") { StorageControlClient storageControlClient = StorageControlClient.Create(); // Set project to "_" to signify globally scoped bucket. - string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{zoneName}"; + string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{anywhereCacheId}"; var request = new DisableAnywhereCacheRequest { diff --git a/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs index 3e73baaf92c..e7d6c706445 100644 --- a/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs @@ -21,14 +21,14 @@ public class StorageControlGetAnywhereCacheSample { /// Gets an anywhere cache instance for the specified bucket. /// The name of the bucket that owns the anywhere cache instance. - /// The name of the zone in which the anywhere cache is located. + /// The name of the zone in which the anywhere cache is located. public AnywhereCache StorageControlGetAnywhereCache(string bucketName = "your-unique-bucket-name", - string zoneName = "us-east1-a") + string anywhereCacheId = "us-east1-a") { StorageControlClient storageControlClient = StorageControlClient.Create(); // Set project to "_" to signify globally scoped bucket. - string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{zoneName}"; + string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{anywhereCacheId}"; var request = new GetAnywhereCacheRequest { diff --git a/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs index 9a45ca5fe24..1884a265500 100644 --- a/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs @@ -21,14 +21,14 @@ public class StorageControlPauseAnywhereCacheSample { /// Pauses an anywhere cache instance in the specified bucket. /// The name of the bucket that owns the anywhere cache instance. - /// The name of the zone in which the anywhere cache is located. + /// The name of the zone in which the anywhere cache is located. public AnywhereCache StorageControlPauseAnywhereCache(string bucketName = "your-unique-bucket-name", - string zoneName = "us-east1-a") + string anywhereCacheId = "us-east1-a") { StorageControlClient storageControlClient = StorageControlClient.Create(); // Set project to "_" to signify globally scoped bucket. - string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{zoneName}"; + string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{anywhereCacheId}"; var request = new PauseAnywhereCacheRequest { diff --git a/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs index c08e2fc2370..c8f5a54f113 100644 --- a/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs @@ -21,14 +21,14 @@ public class StorageControlResumeAnywhereCacheSample { /// Resumes the disabled or paused anywhere cache instance in the specified bucket. /// The name of the bucket that owns the anywhere cache instance. - /// The name of the zone in which the anywhere cache is located. + /// The name of the zone in which the anywhere cache is located. public AnywhereCache StorageControlResumeAnywhereCache(string bucketName = "your-unique-bucket-name", - string zoneName = "us-east1-a") + string anywhereCacheId = "us-east1-a") { StorageControlClient storageControlClient = StorageControlClient.Create(); // Set project to "_" to signify globally scoped bucket. - string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{zoneName}"; + string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{anywhereCacheId}"; var request = new ResumeAnywhereCacheRequest { diff --git a/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs index 3e142f03544..96e22f3938a 100644 --- a/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs @@ -23,16 +23,16 @@ public class StorageControlUpdateAnywhereCacheSample { /// Updates the running anywhere cache instance for the specified bucket. /// The name of the bucket that owns the anywhere cache instance. - /// The name of the zone in which the anywhere cache is located. + /// The name of the zone in which the anywhere cache is located. /// The cache's admission policy. Values can be admit-on-first-miss or admit-on-second-miss. If not specified, it defaults to admit-on-first-miss. public Operation StorageControlUpdateAnywhereCache(string bucketName = "your-bucket-name", - string zoneName = "us-east1-a", + string anywhereCacheId = "us-east1-a", string admissionPolicy = "admit-on-first-miss") { StorageControlClient storageControlClient = StorageControlClient.Create(); // Set project to "_" to signify globally scoped bucket. - string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{zoneName}"; + string anywhereCacheName = $"projects/_/buckets/{bucketName}/anywhereCaches/{anywhereCacheId}"; var anywhereCache = new AnywhereCache { From a07f19db67260a957fd20072e67d38c3dab52c77 Mon Sep 17 00:00:00 2001 From: mahendra-google Date: Sun, 14 Sep 2025 23:32:55 -0700 Subject: [PATCH 19/24] samples(storagecontrol): modify parameter description of anywherecacheid in samples --- .../api/Storage.Samples/StorageControlDisableAnywhereCache.cs | 2 +- storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs | 2 +- storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs | 2 +- .../api/Storage.Samples/StorageControlResumeAnywhereCache.cs | 2 +- .../api/Storage.Samples/StorageControlUpdateAnywhereCache.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs index 5b2f2c34878..c68fae03167 100644 --- a/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs @@ -21,7 +21,7 @@ public class StorageControlDisableAnywhereCacheSample { /// Disables the anywhere cache instance in the specified bucket. /// The name of the bucket that owns the anywhere cache instance. - /// The name of the zone in which the anywhere cache is located. + /// The unique identifier of the cache instance to disable. public AnywhereCache StorageControlDisableAnywhereCache(string bucketName = "your-unique-bucket-name", string anywhereCacheId = "us-east1-a") { diff --git a/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs index e7d6c706445..0f88ca2ad84 100644 --- a/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs @@ -21,7 +21,7 @@ public class StorageControlGetAnywhereCacheSample { /// Gets an anywhere cache instance for the specified bucket. /// The name of the bucket that owns the anywhere cache instance. - /// The name of the zone in which the anywhere cache is located. + /// The unique identifier of the cache instance. public AnywhereCache StorageControlGetAnywhereCache(string bucketName = "your-unique-bucket-name", string anywhereCacheId = "us-east1-a") { diff --git a/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs index 1884a265500..9ad7ffb713a 100644 --- a/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs @@ -21,7 +21,7 @@ public class StorageControlPauseAnywhereCacheSample { /// Pauses an anywhere cache instance in the specified bucket. /// The name of the bucket that owns the anywhere cache instance. - /// The name of the zone in which the anywhere cache is located. + /// The unique identifier of the cache instance to pause. public AnywhereCache StorageControlPauseAnywhereCache(string bucketName = "your-unique-bucket-name", string anywhereCacheId = "us-east1-a") { diff --git a/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs index c8f5a54f113..94a97865460 100644 --- a/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs @@ -21,7 +21,7 @@ public class StorageControlResumeAnywhereCacheSample { /// Resumes the disabled or paused anywhere cache instance in the specified bucket. /// The name of the bucket that owns the anywhere cache instance. - /// The name of the zone in which the anywhere cache is located. + /// The unique identifier of the cache instance to resume. public AnywhereCache StorageControlResumeAnywhereCache(string bucketName = "your-unique-bucket-name", string anywhereCacheId = "us-east1-a") { diff --git a/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs b/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs index 96e22f3938a..bc654bc6703 100644 --- a/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs +++ b/storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs @@ -23,7 +23,7 @@ public class StorageControlUpdateAnywhereCacheSample { /// Updates the running anywhere cache instance for the specified bucket. /// The name of the bucket that owns the anywhere cache instance. - /// The name of the zone in which the anywhere cache is located. + /// The unique identifier of the cache instance to update. /// The cache's admission policy. Values can be admit-on-first-miss or admit-on-second-miss. If not specified, it defaults to admit-on-first-miss. public Operation StorageControlUpdateAnywhereCache(string bucketName = "your-bucket-name", string anywhereCacheId = "us-east1-a", From 46de3edb22bbca08a5652a2f5a016375e6adf9f7 Mon Sep 17 00:00:00 2001 From: mahendra-google Date: Mon, 15 Sep 2025 00:22:28 -0700 Subject: [PATCH 20/24] samples(storagecontrol): undo changes --- .../CreateTemplateTest.cs | 88 --------------- .../CreateTemplateWithLabelsTest.cs | 73 ------------ .../CreateTemplateWithMetadataTest.cs | 59 ---------- .../QuickStartTest.cs | 2 + .../CreateTemplateWithLabels.cs | 98 ---------------- .../CreateTemplateWithMetadata.cs | 105 ------------------ 6 files changed, 2 insertions(+), 423 deletions(-) delete mode 100644 modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateTest.cs delete mode 100644 modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateWithLabelsTest.cs delete mode 100644 modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateWithMetadataTest.cs delete mode 100644 modelarmor/api/ModelArmor.Samples/CreateTemplateWithLabels.cs delete mode 100644 modelarmor/api/ModelArmor.Samples/CreateTemplateWithMetadata.cs diff --git a/modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateTest.cs b/modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateTest.cs deleted file mode 100644 index 5b8b39de3de..00000000000 --- a/modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateTest.cs +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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.ModelArmor.V1; -using Xunit; -using Xunit.Abstractions; - -namespace ModelArmor.Samples.Tests -{ - public class CreateTemplateTests : IClassFixture - { - private readonly ModelArmorFixture _fixture; - private readonly CreateTemplateSample _sample; - - public CreateTemplateTests(ModelArmorFixture fixture, ITestOutputHelper output) - { - _fixture = fixture; - _sample = new CreateTemplateSample(); - } - - [Fact] - public void Runs() - { - TemplateName templateName = _fixture.CreateTemplateName(); - _fixture.RegisterTemplateForCleanup(templateName); - string templateId = templateName.TemplateId; - - // Run the sample. - Template template = _sample.CreateTemplate( - projectId: _fixture.ProjectId, - locationId: _fixture.LocationId, - templateId: templateId - ); - - // Verify the template was created successfully. - Assert.NotNull(template); - Assert.Contains(templateId, template.Name); - - // Verify the template has the expected filter configuration. - Assert.NotNull(template.FilterConfig); - Assert.NotNull(template.FilterConfig.RaiSettings); - var raiFilters = template.FilterConfig.RaiSettings.RaiFilters; - Assert.Equal(4, raiFilters.Count); - - // Assert each filter exists with the expected configuration. - Assert.Contains( - raiFilters, - f => - f.FilterType == RaiFilterType.Dangerous - && f.ConfidenceLevel == DetectionConfidenceLevel.High - ); - - Assert.Contains( - raiFilters, - f => - f.FilterType == RaiFilterType.HateSpeech - && f.ConfidenceLevel == DetectionConfidenceLevel.High - ); - - Assert.Contains( - raiFilters, - f => - f.FilterType == RaiFilterType.SexuallyExplicit - && f.ConfidenceLevel == DetectionConfidenceLevel.LowAndAbove - ); - - Assert.Contains( - raiFilters, - f => - f.FilterType == RaiFilterType.Harassment - && f.ConfidenceLevel == DetectionConfidenceLevel.MediumAndAbove - ); - } - } -} diff --git a/modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateWithLabelsTest.cs b/modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateWithLabelsTest.cs deleted file mode 100644 index 05865ea161b..00000000000 --- a/modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateWithLabelsTest.cs +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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 System; -using System.Collections.Generic; -using Google.Cloud.ModelArmor.V1; -using Xunit; -using Xunit.Abstractions; - -namespace ModelArmor.Samples.Tests -{ - public class CreateTemplateWithLabelsTests : IClassFixture - { - private readonly ModelArmorFixture _fixture; - private readonly CreateTemplateWithLabelsSample _sample; - - public CreateTemplateWithLabelsTests(ModelArmorFixture fixture, ITestOutputHelper output) - { - _fixture = fixture; - _sample = new CreateTemplateWithLabelsSample(); - } - - [Fact] - public void CreateTemplateWithLabels() - { - string projectId = _fixture.ProjectId; - string locationId = _fixture.LocationId; - - TemplateName templateName = _fixture.CreateTemplateName(); - _fixture.RegisterTemplateForCleanup(templateName); - string templateId = templateName.TemplateId; - - // Run the sample. - Template createdTemplate = _sample.CreateTemplateWithLabels( - projectId: projectId, - locationId: locationId, - templateId: templateId - ); - - // Verify the template was created successfully. - Assert.NotNull(createdTemplate); - Assert.Contains(templateId, createdTemplate.Name); - - // Since labels is not a part of the Create Template API response, - // we retrieve the template to verify labels. - ModelArmorClientBuilder clientBuilder = new ModelArmorClientBuilder - { - Endpoint = $"modelarmor.{locationId}.rep.googleapis.com", - }; - ModelArmorClient client = clientBuilder.Build(); - Template retrievedTemplate = client.GetTemplate(createdTemplate.Name); - - // Verify the labels. - Assert.NotNull(retrievedTemplate.Labels); - Assert.Equal(2, retrievedTemplate.Labels.Count); - Assert.Equal("value1", retrievedTemplate.Labels["key1"]); - Assert.Equal("value2", retrievedTemplate.Labels["key2"]); - } - } -} diff --git a/modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateWithMetadataTest.cs b/modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateWithMetadataTest.cs deleted file mode 100644 index f327180410d..00000000000 --- a/modelarmor/api/ModelArmor.Samples.Tests/CreateTemplateWithMetadataTest.cs +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 System; -using System.Linq; -using Google.Cloud.ModelArmor.V1; -using Xunit; -using Xunit.Abstractions; - -namespace ModelArmor.Samples.Tests -{ - public class CreateTemplateWithMetadataTests : IClassFixture - { - private readonly ModelArmorFixture _fixture; - private readonly CreateTemplateWithMetadataSample _sample; - - public CreateTemplateWithMetadataTests(ModelArmorFixture fixture, ITestOutputHelper output) - { - _fixture = fixture; - _sample = new CreateTemplateWithMetadataSample(); - } - - [Fact] - public void CreateTemplateWithMetadata() - { - string projectId = _fixture.ProjectId; - string locationId = _fixture.LocationId; - - TemplateName templateName = _fixture.CreateTemplateName(); - _fixture.RegisterTemplateForCleanup(templateName); - string templateId = templateName.TemplateId; - - // Run the sample. - Template createdTemplate = _sample.CreateTemplateWithMetadata( - projectId: projectId, - locationId: locationId, - templateId: templateId - ); - - // Verify the expected template metadata. - Assert.NotNull(createdTemplate.TemplateMetadata); - Assert.True(createdTemplate.TemplateMetadata.LogTemplateOperations); - Assert.True(createdTemplate.TemplateMetadata.LogSanitizeOperations); - } - } -} diff --git a/modelarmor/api/ModelArmor.Samples.Tests/QuickStartTest.cs b/modelarmor/api/ModelArmor.Samples.Tests/QuickStartTest.cs index 295920bd3a9..4316427906b 100644 --- a/modelarmor/api/ModelArmor.Samples.Tests/QuickStartTest.cs +++ b/modelarmor/api/ModelArmor.Samples.Tests/QuickStartTest.cs @@ -42,5 +42,7 @@ public void Runs() locationId: templateName.LocationId, templateId: templateName.TemplateId ); + + _fixture.RegisterTemplateForCleanup(templateName); } } diff --git a/modelarmor/api/ModelArmor.Samples/CreateTemplateWithLabels.cs b/modelarmor/api/ModelArmor.Samples/CreateTemplateWithLabels.cs deleted file mode 100644 index d43b593baf1..00000000000 --- a/modelarmor/api/ModelArmor.Samples/CreateTemplateWithLabels.cs +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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. - */ - -// [START modelarmor_create_template_with_labels] -using System; -using System.Collections.Generic; -using Google.Api.Gax.ResourceNames; -using Google.Cloud.ModelArmor.V1; -using Google.Protobuf.Collections; - -namespace ModelArmor.Samples -{ - public class CreateTemplateWithLabelsSample - { - public Template CreateTemplateWithLabels( - string projectId = "my-project", - string locationId = "us-central1", - string templateId = "my-template" - ) - { - // Construct the API endpoint URL. - ModelArmorClientBuilder clientBuilder = new ModelArmorClientBuilder - { - Endpoint = $"modelarmor.{locationId}.rep.googleapis.com", - }; - - // Create the client. - Google.Cloud.ModelArmor.V1.ModelArmorClient client = clientBuilder.Build(); - - // Build the parent resource name. - LocationName parent = LocationName.FromProjectLocation(projectId, locationId); - - // Build the Model Armor template with preferred filters. - // For more details on filters, refer to: - // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters - RaiFilterSettings raiFilterSettings = new RaiFilterSettings(); - raiFilterSettings.RaiFilters.Add( - new RaiFilterSettings.Types.RaiFilter - { - FilterType = RaiFilterType.Dangerous, - ConfidenceLevel = DetectionConfidenceLevel.High, - } - ); - raiFilterSettings.RaiFilters.Add( - new RaiFilterSettings.Types.RaiFilter - { - FilterType = RaiFilterType.HateSpeech, - ConfidenceLevel = DetectionConfidenceLevel.High, - } - ); - raiFilterSettings.RaiFilters.Add( - new RaiFilterSettings.Types.RaiFilter - { - FilterType = RaiFilterType.SexuallyExplicit, - ConfidenceLevel = DetectionConfidenceLevel.LowAndAbove, - } - ); - raiFilterSettings.RaiFilters.Add( - new RaiFilterSettings.Types.RaiFilter - { - FilterType = RaiFilterType.Harassment, - ConfidenceLevel = DetectionConfidenceLevel.MediumAndAbove, - } - ); - - FilterConfig modelArmorFilter = new FilterConfig { RaiSettings = raiFilterSettings }; - - Template template = new Template { FilterConfig = modelArmorFilter }; - - template.Labels.Add("key1", "value1"); - template.Labels.Add("key2", "value2"); - - CreateTemplateRequest request = new CreateTemplateRequest - { - ParentAsLocationName = parent, - TemplateId = templateId, - Template = template, - }; - - Template createdTemplate = client.CreateTemplate(request); - return createdTemplate; - } - } -} -// [END modelarmor_create_template_with_labels] diff --git a/modelarmor/api/ModelArmor.Samples/CreateTemplateWithMetadata.cs b/modelarmor/api/ModelArmor.Samples/CreateTemplateWithMetadata.cs deleted file mode 100644 index bd8da08fd77..00000000000 --- a/modelarmor/api/ModelArmor.Samples/CreateTemplateWithMetadata.cs +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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. - */ - -// [START modelarmor_create_template_with_metadata] -using Google.Api.Gax.ResourceNames; -using Google.Cloud.ModelArmor.V1; - -public class CreateTemplateWithMetadataSample -{ - public Template CreateTemplateWithMetadata( - string projectId = "my-project", - string locationId = "us-central1", - string templateId = "my-template" - ) - { - // Construct the API endpoint URL. - ModelArmorClientBuilder clientBuilder = new ModelArmorClientBuilder - { - Endpoint = $"modelarmor.{locationId}.rep.googleapis.com", - }; - - // Create the client. - Google.Cloud.ModelArmor.V1.ModelArmorClient client = clientBuilder.Build(); - - // Build the parent resource name. - LocationName parent = LocationName.FromProjectLocation(projectId, locationId); - - // Build the Model Armor template with preferred filters. - // For more details on filters, refer to: - // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters - RaiFilterSettings raiFilterSettings = new RaiFilterSettings(); - raiFilterSettings.RaiFilters.Add( - new RaiFilterSettings.Types.RaiFilter - { - FilterType = RaiFilterType.Dangerous, - ConfidenceLevel = DetectionConfidenceLevel.High, - } - ); - raiFilterSettings.RaiFilters.Add( - new RaiFilterSettings.Types.RaiFilter - { - FilterType = RaiFilterType.HateSpeech, - ConfidenceLevel = DetectionConfidenceLevel.High, - } - ); - raiFilterSettings.RaiFilters.Add( - new RaiFilterSettings.Types.RaiFilter - { - FilterType = RaiFilterType.SexuallyExplicit, - ConfidenceLevel = DetectionConfidenceLevel.LowAndAbove, - } - ); - raiFilterSettings.RaiFilters.Add( - new RaiFilterSettings.Types.RaiFilter - { - FilterType = RaiFilterType.Harassment, - ConfidenceLevel = DetectionConfidenceLevel.MediumAndAbove, - } - ); - - FilterConfig modelArmorFilter = new FilterConfig { RaiSettings = raiFilterSettings }; - - // For more details about metadata, refer to the following documentation: - // https://cloud.google.com/security-command-center/docs/reference/model-armor/rest/v1/projects.locations.templates#templatemetadata - Template.Types.TemplateMetadata templateMetadata = new Template.Types.TemplateMetadata - { - LogTemplateOperations = true, - LogSanitizeOperations = true, - }; - - // Create the template with filter config and metadata. - Template template = new Template - { - FilterConfig = modelArmorFilter, - TemplateMetadata = templateMetadata, - }; - - CreateTemplateRequest request = new CreateTemplateRequest - { - ParentAsLocationName = parent, - TemplateId = templateId, - Template = template, - }; - - Template createdTemplate = client.CreateTemplate(request); - System.Console.WriteLine( - $"Successfully created template with name: {createdTemplate.Name}" - ); - return createdTemplate; - } -} -// [END modelarmor_create_template_with_metadata] From 27d3e9c5b58f1302c2db79dde14388d806c52e96 Mon Sep 17 00:00:00 2001 From: Mahendra Date: Tue, 16 Sep 2025 13:21:31 +0530 Subject: [PATCH 21/24] Update README.md --- storage/api/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/storage/api/README.md b/storage/api/README.md index 32941e4b635..55210357876 100644 --- a/storage/api/README.md +++ b/storage/api/README.md @@ -31,4 +31,5 @@ The samples requires [.NET Core 3.1][net-core] or later. That means using [net-core]: https://www.microsoft.com/net/core ## Note + Tests for the Anywhere Cache samples are not included because creating an AnywhereCache can take an extremely long time, sometimes up to 48 hours. From 6755e787d2c7b2662d1a3b0f9948c0015d69574c Mon Sep 17 00:00:00 2001 From: Mahendra Date: Tue, 16 Sep 2025 13:23:07 +0530 Subject: [PATCH 22/24] Delete modelarmor/api/ModelArmor.Samples/ModelArmor.Samples.csproj --- .../api/ModelArmor.Samples/ModelArmor.Samples.csproj | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 modelarmor/api/ModelArmor.Samples/ModelArmor.Samples.csproj diff --git a/modelarmor/api/ModelArmor.Samples/ModelArmor.Samples.csproj b/modelarmor/api/ModelArmor.Samples/ModelArmor.Samples.csproj deleted file mode 100644 index 8a0a414ad19..00000000000 --- a/modelarmor/api/ModelArmor.Samples/ModelArmor.Samples.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - net8.0 - false - - - - - - From da18d89de944c7db2a1b60b680de5d4759692cca Mon Sep 17 00:00:00 2001 From: mahendra-google Date: Tue, 16 Sep 2025 01:00:22 -0700 Subject: [PATCH 23/24] samples(ModelArmer): add project file --- .../api/ModelArmor.Samples/ModelArmor.Samples.csproj | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 modelarmor/api/ModelArmor.Samples/ModelArmor.Samples.csproj diff --git a/modelarmor/api/ModelArmor.Samples/ModelArmor.Samples.csproj b/modelarmor/api/ModelArmor.Samples/ModelArmor.Samples.csproj new file mode 100644 index 00000000000..de067770500 --- /dev/null +++ b/modelarmor/api/ModelArmor.Samples/ModelArmor.Samples.csproj @@ -0,0 +1,10 @@ + + + net8.0 + false + + + + + + From 2aa5893a53962b9ee1335163d7ca013e7061bed0 Mon Sep 17 00:00:00 2001 From: Mahendra Date: Tue, 16 Sep 2025 13:32:24 +0530 Subject: [PATCH 24/24] Update ModelArmor.Samples.csproj --- modelarmor/api/ModelArmor.Samples/ModelArmor.Samples.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modelarmor/api/ModelArmor.Samples/ModelArmor.Samples.csproj b/modelarmor/api/ModelArmor.Samples/ModelArmor.Samples.csproj index de067770500..8a0a414ad19 100644 --- a/modelarmor/api/ModelArmor.Samples/ModelArmor.Samples.csproj +++ b/modelarmor/api/ModelArmor.Samples/ModelArmor.Samples.csproj @@ -5,6 +5,6 @@ - +