Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
62f68ac
feat(secretmanager): Adding labels and annotations sample
khilan-crest Jan 22, 2026
0b20481
feat(secretmanager): Adding filter and cmek samples
khilan-crest Jan 22, 2026
dee8bc1
feat(secretmanager): Adding secret version filter samples
khilan-crest Jan 22, 2026
a888e11
feat(secretmanager): Adding secrets tags samples
khilan-crest Jan 27, 2026
d21d2a7
feat(secretmanager): Adding secrets expiration samples
khilan-crest Jan 27, 2026
5832e34
feat(secretmanager): Update labels annotations samples
khilan-crest Jan 27, 2026
7b77ac3
feat(secretmanager): Update cmek filter samples
khilan-crest Jan 27, 2026
e4fe6a0
Merge branch 'cs_labels_annotation_samples' of https://github.com/khi…
khilan-crest Jan 27, 2026
43f47dd
Merge branch 'cs_filter_cmek_samples' of https://github.com/khilan-cr…
khilan-crest Jan 27, 2026
922ff50
feat(secretmanager): Update expiration samples
khilan-crest Jan 27, 2026
e02e8ed
Merge branch 'cs_expiretime_samples' of https://github.com/khilan-cre…
khilan-crest Jan 27, 2026
68b3c11
feat(secretmanager): Update tags samples
khilan-crest Jan 27, 2026
d410f73
feat(secretmanager): Add secret rotation samples
khilan-crest Jan 28, 2026
cdd5217
feat(secretmanager): Updating fixture
khilan-crest Jan 28, 2026
3933710
Merge branch 'cs_filter_cmek_samples' of https://github.com/khilan-cr…
khilan-crest Jan 28, 2026
2b756f1
feat(secretmanager): Updating fixture
khilan-crest Jan 28, 2026
1d82a7d
Merge branch 'cs_expiretime_samples' of https://github.com/khilan-cre…
khilan-crest Jan 28, 2026
02390e8
Merge branch 'cs_tag_samples' of https://github.com/khilan-crest/dotn…
khilan-crest Jan 28, 2026
d2cfa81
feat(secretmanager): Updating fixture
khilan-crest Jan 28, 2026
4641d03
feat(secretmanager): Reformat code
khilan-crest Jan 28, 2026
cdbc3c2
Merge branch 'cs_labels_annotation_samples' of https://github.com/khi…
khilan-crest Jan 28, 2026
34e7a7a
feat(secretmanager): Reformat code
khilan-crest Jan 28, 2026
32295a4
Merge branch 'cs_filter_cmek_samples' of https://github.com/khilan-cr…
khilan-crest Jan 28, 2026
5a4e75a
feat(secretmanager): Reformat code
khilan-crest Jan 28, 2026
2f0bfb5
feat(secretmanager): Reformat code
khilan-crest Jan 28, 2026
7dea915
Merge branch 'cs_labels_annotation_samples' of https://github.com/khi…
khilan-crest Jan 28, 2026
a24afb7
Merge branch 'cs_filter_cmek_samples' of https://github.com/khilan-cr…
khilan-crest Jan 28, 2026
033b2a6
feat(secretmanager): Reformat code
khilan-crest Jan 28, 2026
2c1de99
feat(secretmanager): Reformat code
khilan-crest Jan 28, 2026
9e8e2f4
Merge branch 'cs_expiretime_samples' of https://github.com/khilan-cre…
khilan-crest Jan 28, 2026
8c8e8b4
Merge branch 'cs_tag_samples' of https://github.com/khilan-crest/dotn…
khilan-crest Jan 28, 2026
26f4e0e
feat(secretmanager): Reformat code
khilan-crest Jan 29, 2026
c2015d4
Merge branch 'cs_tag_samples' of https://github.com/khilan-crest/dotn…
khilan-crest Jan 29, 2026
4f00ed3
feat(secretmanager): Reformat code
khilan-crest Jan 29, 2026
5bea92e
feat(secretmanager): Reformat code
khilan-crest Jan 29, 2026
eced0ba
feat(secretmanager): Reformat code
khilan-crest Jan 29, 2026
61a4496
Merge branch 'cs_tag_samples' of https://github.com/khilan-crest/dotn…
khilan-crest Jan 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* Copyright 2026 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.ResourceManager.V3;
using Google.Cloud.SecretManager.V1;
using System;
using System.IO;
using System.Threading.Tasks;
using Xunit;

[Collection(nameof(RegionalSecretManagerFixture))]
public class BindTagsToRegionalSecretTests
{
private readonly RegionalSecretManagerFixture _fixture;
private readonly BindTagsToRegionalSecretSample _sample;
private readonly TagKeysClient _tagKeysClient;
private readonly TagValuesClient _tagValuesClient;
private readonly TagBindingsClient _tagBindingsClient;
private string _tagKeyName;
private string _tagValueName;

public BindTagsToRegionalSecretTests(RegionalSecretManagerFixture fixture)
{
_fixture = fixture;
_sample = new BindTagsToRegionalSecretSample();
_tagKeysClient = TagKeysClient.Create();
_tagValuesClient = TagValuesClient.Create();
_tagBindingsClient = TagBindingsClient.Create();
}

private void CreateTagKeyAndValue(string projectId)
{
// Generate unique names for tag key and value
string tagKeyShortName = $"test-key-{_fixture.RandomId()}";
string tagValueShortName = $"test-value-{_fixture.RandomId()}";

var createKeyRequest = new CreateTagKeyRequest
{
TagKey = new TagKey
{
Parent = $"projects/{projectId}",
ShortName = tagKeyShortName,
}
};

try
{
var createKeyOperation = _tagKeysClient.CreateTagKey(createKeyRequest);
TagKey tagKey = createKeyOperation.PollUntilCompleted().Result;
_tagKeyName = tagKey.Name;
}
catch (Exception e)
{
throw new Exception("Error creating tag key: " + e.Message, e);
}

var createValueRequest = new CreateTagValueRequest
{
TagValue = new TagValue
{
Parent = _tagKeyName,
ShortName = tagValueShortName,
}
};

try
{
var createValueOperation = _tagValuesClient.CreateTagValue(createValueRequest);
TagValue tagValue = createValueOperation.PollUntilCompleted().Result;
_tagValueName = tagValue.Name;
}
catch (Exception e)
{
throw new Exception("Error creating tag value: " + e.Message, e);
}
}

private void CleanupResources()
{
// Delete the tag value if it exists
if (!string.IsNullOrEmpty(_tagValueName))
{
try
{
var deleteValueRequest = new DeleteTagValueRequest { Name = _tagValueName };
_tagValuesClient.DeleteTagValue(deleteValueRequest).PollUntilCompleted();
}
catch (Exception e)
{
Console.WriteLine($"Error deleting tag value: {e.GetType().Name}: {e.Message}");
}
}

// Delete the tag key if it exists
if (!string.IsNullOrEmpty(_tagKeyName))
{
try
{
var deleteKeyRequest = new DeleteTagKeyRequest { Name = _tagKeyName };
_tagKeysClient.DeleteTagKey(deleteKeyRequest).PollUntilCompleted();
}
catch (Exception e)
{
Console.WriteLine($"Error deleting tag key: {e.GetType().Name}: {e.Message}");
}
}
}

[Fact]
public async Task BindsTagToRegionalSecretAsync()
{
// Create a tag key and value for testing
CreateTagKeyAndValue(_fixture.ProjectId);

SecretName secretName = SecretName.FromProjectLocationSecret(_fixture.ProjectId, _fixture.LocationId, _fixture.RandomId());

// Call the method being tested
TagBinding tagBinding = await _sample.BindTagsToRegionalSecretAsync(
projectId: secretName.ProjectId,
locationId: secretName.LocationId,
secretId: secretName.SecretId,
tagValue: _tagValueName);

Assert.Equal(_tagValueName, tagBinding.TagValue);
// Clean up all resources
_fixture.DeleteSecret(secretName);
CleanupResources();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
* Copyright 2026 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.ResourceManager.V3;
using Google.Cloud.SecretManager.V1;
using System;
using System.IO;
using System.Threading.Tasks;
using Xunit;

[Collection(nameof(SecretManagerFixture))]
public class BindTagsToSecretTests
{
private readonly SecretManagerFixture _fixture;
private readonly BindTagsToSecretSample _sample;
private readonly TagKeysClient _tagKeysClient;
private readonly TagValuesClient _tagValuesClient;
private readonly TagBindingsClient _tagBindingsClient;
private string _tagKeyName;
private string _tagValueName;

public BindTagsToSecretTests(SecretManagerFixture fixture)
{
_fixture = fixture;
_sample = new BindTagsToSecretSample();
_tagKeysClient = TagKeysClient.Create();
_tagValuesClient = TagValuesClient.Create();
_tagBindingsClient = TagBindingsClient.Create();
}

private void CreateTagKeyAndValue(string projectId)
{
// Generate unique names for tag key and value
string tagKeyShortName = $"test-key-{_fixture.RandomId()}";
string tagValueShortName = $"test-value-{_fixture.RandomId()}";

var createKeyRequest = new CreateTagKeyRequest
{
TagKey = new TagKey
{
Parent = $"projects/{projectId}",
ShortName = tagKeyShortName,
}
};

try
{
var createKeyOperation = _tagKeysClient.CreateTagKey(createKeyRequest);
TagKey tagKey = createKeyOperation.PollUntilCompleted().Result;
_tagKeyName = tagKey.Name;
}
catch (Exception e)
{
throw new Exception("Error creating tag key: " + e.Message, e);
}

var createValueRequest = new CreateTagValueRequest
{
TagValue = new TagValue
{
Parent = _tagKeyName,
ShortName = tagValueShortName,
}
};

try
{
var createValueOperation = _tagValuesClient.CreateTagValue(createValueRequest);
TagValue tagValue = createValueOperation.PollUntilCompleted().Result;
_tagValueName = tagValue.Name;
}
catch (Exception e)
{
throw new Exception("Error creating tag value: " + e.Message, e);
}
}

private void CleanupResources()
{

// Delete the tag value if it exists
if (!string.IsNullOrEmpty(_tagValueName))
{
try
{
var deleteValueRequest = new DeleteTagValueRequest { Name = _tagValueName };
_tagValuesClient.DeleteTagValue(deleteValueRequest).PollUntilCompleted();
}
catch (Exception e)
{
Console.WriteLine($"Error deleting tag value: {e.GetType().Name}: {e.Message}");
}
}

// Delete the tag key if it exists
if (!string.IsNullOrEmpty(_tagKeyName))
{
try
{
var deleteKeyRequest = new DeleteTagKeyRequest { Name = _tagKeyName };
_tagKeysClient.DeleteTagKey(deleteKeyRequest).PollUntilCompleted();
}
catch (Exception e)
{
Console.WriteLine($"Error deleting tag key: {e.GetType().Name}: {e.Message}");
}
}
}

[Fact]
public async Task BindsTagToSecretAsync()
{
// Create a tag key and value for testing
CreateTagKeyAndValue(_fixture.ProjectId);

// Generate a unique secret ID
SecretName secretName = new SecretName(_fixture.ProjectId, _fixture.RandomId());
// string secretId = _fixture.RandomId();

TagBinding tagBinding = await _sample.BindTagsToSecretAsync(
projectId: secretName.ProjectId,
secretId: secretName.SecretId,
tagValue: _tagValueName);

Assert.Equal(_tagValueName, tagBinding.TagValue);

_fixture.DeleteSecret(secretName);
CleanupResources();

}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2026 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.SecretManager.V1;
using System;
using System.IO;
using Xunit;

[Collection(nameof(RegionalSecretManagerFixture))]
public class CreateRegionalSecretWithExpireTimeTests
{
private readonly RegionalSecretManagerFixture _fixture;
private readonly CreateRegionalSecretWithExpireTimeSample _sample;

public CreateRegionalSecretWithExpireTimeTests(RegionalSecretManagerFixture fixture)
{
_fixture = fixture;
_sample = new CreateRegionalSecretWithExpireTimeSample();
}

[Fact]
public void CreatesRegionalSecretWithExpireTime()
{
// Get the SecretName from the set ProjectId & LocationId.
SecretName secretName = SecretName.FromProjectLocationSecret(
_fixture.ProjectId, _fixture.LocationId, _fixture.RandomId());
try
{
// Run the code sample.
Secret result = _sample.CreateRegionalSecretWithExpireTime(
projectId: secretName.ProjectId,
secretId: secretName.SecretId,
locationId: secretName.LocationId);

Assert.NotNull(result.ExpireTime);
}
finally
{
// Clean the created secret.
_fixture.DeleteSecret(secretName);
}
}
}
Loading