-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(secretmanager): Add filter and cmek related samples #3292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
khilan-crest
wants to merge
12
commits into
GoogleCloudPlatform:main
Choose a base branch
from
khilan-crest:cs_filter_cmek_samples
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
62f68ac
feat(secretmanager): Adding labels and annotations sample
khilan-crest 0b20481
feat(secretmanager): Adding filter and cmek samples
khilan-crest dee8bc1
feat(secretmanager): Adding secret version filter samples
khilan-crest 5832e34
feat(secretmanager): Update labels annotations samples
khilan-crest 7b77ac3
feat(secretmanager): Update cmek filter samples
khilan-crest e4fe6a0
Merge branch 'cs_labels_annotation_samples' of https://github.com/khi…
khilan-crest cdd5217
feat(secretmanager): Updating fixture
khilan-crest 4641d03
feat(secretmanager): Reformat code
khilan-crest cdbc3c2
Merge branch 'cs_labels_annotation_samples' of https://github.com/khi…
khilan-crest 34e7a7a
feat(secretmanager): Reformat code
khilan-crest 2f0bfb5
feat(secretmanager): Reformat code
khilan-crest 7dea915
Merge branch 'cs_labels_annotation_samples' of https://github.com/khi…
khilan-crest File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
secretmanager/api/SecretManager.Samples.Tests/DeleteRegionalSecretAnnotationTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * 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 DeleteRegionalSecretAnnotationTests | ||
| { | ||
| private readonly RegionalSecretManagerFixture _fixture; | ||
| private readonly DeleteRegionalSecretAnnotationSample _sample; | ||
|
|
||
| public DeleteRegionalSecretAnnotationTests(RegionalSecretManagerFixture fixture) | ||
| { | ||
| _fixture = fixture; | ||
| _sample = new DeleteRegionalSecretAnnotationSample(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DeleteRegionalSecretAnnotation() | ||
| { | ||
| // Create a secret with annotations | ||
| Secret secret = _fixture.CreateSecret(_fixture.RandomId()); | ||
| SecretName secretName = secret.SecretName; | ||
| try | ||
| { | ||
| // Get a key from the existing annotations | ||
| string annotationKey = _fixture.AnnotationKey; | ||
|
|
||
| // Verify the secret has annotations | ||
| Assert.NotEmpty(secret.Annotations); | ||
| Assert.True(secret.Annotations.ContainsKey(annotationKey)); | ||
|
|
||
| // Run the sample code to delete the annotation | ||
| Secret result = _sample.DeleteRegionalSecretAnnotation( | ||
| projectId: secretName.ProjectId, | ||
| locationId: secretName.LocationId, | ||
| secretId: secretName.SecretId); | ||
|
|
||
| Assert.Empty(result.Annotations); | ||
| } | ||
| finally | ||
| { | ||
| // Clean the created secret. | ||
| _fixture.DeleteSecret(secretName); | ||
| } | ||
| } | ||
| } | ||
59 changes: 59 additions & 0 deletions
59
secretmanager/api/SecretManager.Samples.Tests/DeleteRegionalSecretLabelTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * 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 DeleteRegionalSecretLabelTests | ||
| { | ||
| private readonly RegionalSecretManagerFixture _fixture; | ||
| private readonly DeleteRegionalSecretLabelSample _sample; | ||
|
|
||
| public DeleteRegionalSecretLabelTests(RegionalSecretManagerFixture fixture) | ||
| { | ||
| _fixture = fixture; | ||
| _sample = new DeleteRegionalSecretLabelSample(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DeleteRegionalSecretLabel() | ||
| { | ||
| Secret secret = _fixture.CreateSecret(_fixture.RandomId()); | ||
| SecretName secretName = secret.SecretName; | ||
| try | ||
| { | ||
| // Verify the secret has labels | ||
| Assert.NotEmpty(secret.Labels); | ||
|
|
||
| // Run the sample code to delete all labels | ||
| Secret result = _sample.DeleteRegionalSecretLabel( | ||
|
|
||
| projectId: secretName.ProjectId, | ||
| locationId: secretName.LocationId, | ||
| secretId: secretName.SecretId); | ||
|
|
||
| Assert.Empty(result.Labels); | ||
| } | ||
| finally | ||
| { | ||
| // Clean the created secret. | ||
| _fixture.DeleteSecret(secretName); | ||
| } | ||
| } | ||
|
khilan-crest marked this conversation as resolved.
|
||
| } | ||
57 changes: 57 additions & 0 deletions
57
secretmanager/api/SecretManager.Samples.Tests/DeleteSecretAnnotationTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * 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(SecretManagerFixture))] | ||
| public class DeleteSecretAnnotationTests | ||
| { | ||
| private readonly SecretManagerFixture _fixture; | ||
| private readonly DeleteSecretAnnotationSample _sample; | ||
|
|
||
| public DeleteSecretAnnotationTests(SecretManagerFixture fixture) | ||
| { | ||
| _fixture = fixture; | ||
| _sample = new DeleteSecretAnnotationSample(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DeleteSecretAnnotation() | ||
| { | ||
| // Create the secret. | ||
| Secret secret = _fixture.CreateSecret(_fixture.RandomId()); | ||
| // Get the secretName from the created secret. | ||
| SecretName secretName = secret.SecretName; | ||
| try | ||
| { | ||
| Assert.NotEmpty(secret.Annotations); | ||
| // Call the code sample function to delete the annotations | ||
| Secret result = _sample.DeleteSecretAnnotation( | ||
| projectId: secretName.ProjectId, secretId: secretName.SecretId); | ||
|
|
||
| // Assert that the label is deleted. | ||
| Assert.Empty(result.Annotations); | ||
| } | ||
| finally | ||
| { | ||
| // Clean the created secret. | ||
| _fixture.DeleteSecret(secretName); | ||
| } | ||
| } | ||
|
khilan-crest marked this conversation as resolved.
|
||
| } | ||
58 changes: 58 additions & 0 deletions
58
secretmanager/api/SecretManager.Samples.Tests/DeleteSecretLabelTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * 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(SecretManagerFixture))] | ||
| public class DeleteSecretLabelTests | ||
| { | ||
| private readonly SecretManagerFixture _fixture; | ||
| private readonly DeleteSecretLabelSample _sample; | ||
|
|
||
| public DeleteSecretLabelTests(SecretManagerFixture fixture) | ||
| { | ||
| _fixture = fixture; | ||
| _sample = new DeleteSecretLabelSample(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DeleteSecretLabel() | ||
| { | ||
| // Create the secret. | ||
| Secret secret = _fixture.CreateSecret(_fixture.RandomId()); | ||
|
|
||
| // Get the secretName from the created secret. | ||
| SecretName secretName = secret.SecretName; | ||
| try | ||
| { | ||
| Assert.NotEmpty(secret.Labels); | ||
| // Call the code sample function to delete the label | ||
| Secret result = _sample.DeleteSecretLabel( | ||
| projectId: secretName.ProjectId, secretId: secretName.SecretId); | ||
|
|
||
| // Assert that the label is deleted. | ||
| Assert.Empty(result.Labels); | ||
| } | ||
| finally | ||
| { | ||
| // Clean the created secret. | ||
| _fixture.DeleteSecret(secretName); | ||
| } | ||
| } | ||
|
khilan-crest marked this conversation as resolved.
|
||
| } | ||
46 changes: 46 additions & 0 deletions
46
secretmanager/api/SecretManager.Samples.Tests/EditSecretLabelTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * 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(SecretManagerFixture))] | ||
| public class EditSecretLabelTests | ||
| { | ||
| private readonly SecretManagerFixture _fixture; | ||
| private readonly EditSecretLabelSample _sample; | ||
|
|
||
| public EditSecretLabelTests(SecretManagerFixture fixture) | ||
| { | ||
| _fixture = fixture; | ||
| _sample = new EditSecretLabelSample(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void EditSecretLabel() | ||
| { | ||
| // Get the SecretName to create Secret. | ||
| SecretName secretName = _fixture.Secret.SecretName; | ||
|
|
||
| // Call the code sample function. | ||
| Secret result = _sample.EditSecretLabel( | ||
| projectId: secretName.ProjectId, secretId: secretName.SecretId); | ||
|
|
||
| Assert.Equal("my-label-value", result.Labels["my-label-key"]); | ||
| } | ||
| } |
66 changes: 66 additions & 0 deletions
66
secretmanager/api/SecretManager.Samples.Tests/ListSecretVersionsWithFilterTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| * 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 System; | ||
| using System.IO; | ||
| using System.Collections.Generic; | ||
| using Xunit; | ||
| using Google.Cloud.SecretManager.V1; | ||
|
|
||
| [Collection(nameof(SecretManagerFixture))] | ||
| public class ListSecretVersionsWithFilterTests | ||
| { | ||
| private readonly SecretManagerFixture _fixture; | ||
| private readonly ListSecretVersionsWithFilterSample _sample; | ||
|
|
||
| public ListSecretVersionsWithFilterTests(SecretManagerFixture fixture) | ||
| { | ||
| _fixture = fixture; | ||
| _sample = new ListSecretVersionsWithFilterSample(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ListSecretVersionsWithFilter() | ||
| { | ||
| // Create the secret resource. | ||
| Secret secret = _fixture.CreateSecret(_fixture.RandomId()); | ||
|
|
||
| // Get the SecretName. | ||
| SecretName secretName = secret.SecretName; | ||
|
|
||
| // Run the code sample. | ||
| SecretVersion secretVersion = _fixture.AddSecretVersion(secret); | ||
| _fixture.DisableSecretVersion(secretVersion); | ||
|
|
||
| // Run the sample code | ||
| IList<SecretVersion> versions = _sample.ListSecretVersionsWithFilter( | ||
| projectId: secretName.ProjectId, | ||
| secretId: secretName.SecretId); | ||
|
|
||
| // Verify we got results | ||
| Assert.NotNull(versions); | ||
| Assert.NotEmpty(versions); | ||
|
|
||
| // Verify only disabled versions are returned | ||
| foreach (var version in versions) | ||
| { | ||
| Assert.Equal(SecretVersion.Types.State.Disabled, version.State); | ||
| } | ||
|
|
||
| // Clean the created secret. | ||
| _fixture.DeleteSecret(secretName); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.