Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ca82d74
samples(storage control): add samples for anywhere cache
harshnasitcrest Jul 29, 2025
cbd60f6
samples(storage): modify sample to create anywhere cache
mahendra-google Aug 6, 2025
36bb43b
samples(storage): modify default bucket name
Aug 6, 2025
b435193
samples(storage): add samples to update anyhere cache
mahendra-google Aug 13, 2025
9356839
samples(storage): Remove unused assembly reference
mahendra-google Aug 13, 2025
966586a
samples(storage): add test to list anywhere cache
mahendra-google Sep 4, 2025
963ed6c
samples(storage); add tests for anywhere cache
mahendra-google Sep 4, 2025
bbbdfc7
samples(storage): remove unused namespace
mahendra-google Sep 4, 2025
20e8e08
Revert test Code
mahendra-google Sep 8, 2025
311d8e1
Revert "samples(storage): add test to list anywhere cache"
mahendra-google Sep 8, 2025
5f00e7d
Update README.md
mahendra-google Sep 8, 2025
0a1272e
Update storage/api/README.md
mahendra-google Sep 8, 2025
18f2f68
samples(storage control): modify parameter name in sample methods
mahendra-google Sep 9, 2025
d9c95d7
Update storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs
mahendra-google Sep 9, 2025
a1753a1
Update README.md
mahendra-google Sep 10, 2025
352f782
samples(storagecontrol): remove trailing whitespaces from google gemi…
mahendra-google Sep 10, 2025
6d27cf4
samples(storagecontrol): modify zoneName default parameter value in S…
mahendra-google Sep 11, 2025
07b9318
samples(storagecontrol): modify parameter name for samples
mahendra-google Sep 12, 2025
a07f19d
samples(storagecontrol): modify parameter description of anywherecach…
mahendra-google Sep 15, 2025
46de3ed
samples(storagecontrol): undo changes
mahendra-google Sep 15, 2025
27d3e9c
Update README.md
mahendra-google Sep 16, 2025
6755e78
Delete modelarmor/api/ModelArmor.Samples/ModelArmor.Samples.csproj
mahendra-google Sep 16, 2025
da18d89
samples(ModelArmer): add project file
mahendra-google Sep 16, 2025
2aa5893
Update ModelArmor.Samples.csproj
mahendra-google Sep 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
Expand Down
6 changes: 5 additions & 1 deletion storage/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ 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
[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.
Comment thread
mahendra-google marked this conversation as resolved.
56 changes: 56 additions & 0 deletions storage/api/Storage.Samples/StorageControlCreateAnywhereCache.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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;

public class StorageControlCreateAnywhereCacheSample
{
/// <summary>Creates an anywhere cache instance in the specified bucket.</summary>
/// <param name="bucketName">The name of the bucket.</param>
/// <param name="zoneName">The name of the zone in which the cache instance will run.</param>
public Operation<AnywhereCache, CreateAnywhereCacheMetadata> StorageControlCreateAnywhereCache(string bucketName = "your-unique-bucket-name",
string zoneName = "us-east1-a")
{
StorageControlClient storageControlClient = StorageControlClient.Create();

// Set project to "_" to signify globally scoped bucket.
string parent = $"projects/_/buckets/{bucketName}";

AnywhereCache anywhereCache = new AnywhereCache
{
Zone = zoneName
};

var request = new CreateAnywhereCacheRequest
{
AnywhereCache = anywhereCache,
Parent = parent
};

// Start a long-running operation (LRO).
Operation<AnywhereCache, CreateAnywhereCacheMetadata> createdCacheOperation = storageControlClient.CreateAnywhereCache(request);

// Await the LROs completion.
var createdCache = createdCacheOperation.PollUntilCompleted();

Console.WriteLine($"Created Anywhere Cache Instance: {createdCache.Result.AnywhereCacheName}");
Comment thread
mahendra-google marked this conversation as resolved.

return createdCache;
}
}
// [END storage_control_create_anywhere_cache]
45 changes: 45 additions & 0 deletions storage/api/Storage.Samples/StorageControlDisableAnywhereCache.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>Disables the anywhere cache instance in the specified bucket.</summary>
/// <param name="bucketName">The name of the bucket that owns the anywhere cache instance.</param>
/// <param name="anywhereCacheId">The unique identifier of the cache instance to disable.</param>
public AnywhereCache StorageControlDisableAnywhereCache(string bucketName = "your-unique-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]
45 changes: 45 additions & 0 deletions storage/api/Storage.Samples/StorageControlGetAnywhereCache.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>Gets an anywhere cache instance for the specified bucket.</summary>
/// <param name="bucketName">The name of the bucket that owns the anywhere cache instance.</param>
/// <param name="anywhereCacheId">The unique identifier of the cache instance.</param>
public AnywhereCache StorageControlGetAnywhereCache(string bucketName = "your-unique-bucket-name",
string anywhereCacheId = "us-east1-a")
Comment thread
mahendra-google marked this conversation as resolved.
{
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]
50 changes: 50 additions & 0 deletions storage/api/Storage.Samples/StorageControlListAnywhereCaches.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>Lists all anywhere cache instances for the specified bucket.</summary>
/// <param name="bucketName">The name of the bucket that owns the anywhere cache instance.</param>
public IEnumerable<AnywhereCache> StorageControlListAnywhereCaches(string bucketName = "your-unique-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<ListAnywhereCachesResponse, AnywhereCache> 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]
45 changes: 45 additions & 0 deletions storage/api/Storage.Samples/StorageControlPauseAnywhereCache.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>Pauses an anywhere cache instance in the specified bucket.</summary>
/// <param name="bucketName">The name of the bucket that owns the anywhere cache instance.</param>
/// <param name="anywhereCacheId">The unique identifier of the cache instance to pause.</param>
public AnywhereCache StorageControlPauseAnywhereCache(string bucketName = "your-unique-bucket-name",
string anywhereCacheId = "us-east1-a")
Comment thread
mahendra-google marked this conversation as resolved.
{
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]
45 changes: 45 additions & 0 deletions storage/api/Storage.Samples/StorageControlResumeAnywhereCache.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>Resumes the disabled or paused anywhere cache instance in the specified bucket.</summary>
/// <param name="bucketName">The name of the bucket that owns the anywhere cache instance.</param>
/// <param name="anywhereCacheId">The unique identifier of the cache instance to resume.</param>
public AnywhereCache StorageControlResumeAnywhereCache(string bucketName = "your-unique-bucket-name",
string anywhereCacheId = "us-east1-a")
Comment thread
mahendra-google marked this conversation as resolved.
{
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]
61 changes: 61 additions & 0 deletions storage/api/Storage.Samples/StorageControlUpdateAnywhereCache.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// 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;

public class StorageControlUpdateAnywhereCacheSample
{
/// <summary>Updates the running anywhere cache instance for the specified bucket.</summary>
/// <param name="bucketName">The name of the bucket that owns the anywhere cache instance.</param>
/// <param name="anywhereCacheId">The unique identifier of the cache instance to update.</param>
/// <param name="admissionPolicy"> 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.</param>
public Operation<AnywhereCache, UpdateAnywhereCacheMetadata> 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<AnywhereCache, UpdateAnywhereCacheMetadata> 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]