-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples(secret_manager): add annotation and label samples (#28817)
- Loading branch information
1 parent
cbfec8f
commit 45da8e0
Showing
26 changed files
with
1,548 additions
and
39 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
...e-cloud-secret_manager/samples/acceptance/create_regional_secret_with_annotations_test.rb
This file contains 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,29 @@ | ||
# Copyright 2025 Google, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
require "uri" | ||
|
||
require_relative "regional_helper" | ||
|
||
describe "#create_regional_secret_with_annotations", :regional_secret_manager_snippet do | ||
it "creates a regional secret with annotations" do | ||
sample = SampleLoader.load "create_regional_secret_with_annotations.rb" | ||
|
||
out, _err = capture_io do | ||
sample.run project_id: project_id, location_id: location_id, secret_id: secret_id, annotation_key: annotation_key, annotation_value: annotation_value | ||
end | ||
secret_id_regex = Regexp.escape secret_id | ||
assert_match %r{Created regional secret with annotations: projects/\S+locations/\S+/secrets/#{secret_id_regex}}, out | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
google-cloud-secret_manager/samples/acceptance/create_regional_secret_with_labels_test.rb
This file contains 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,29 @@ | ||
# Copyright 2025 Google, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
require "uri" | ||
|
||
require_relative "regional_helper" | ||
|
||
describe "#create_regional_secret_with_labels", :regional_secret_manager_snippet do | ||
it "creates a regional secret with labels" do | ||
sample = SampleLoader.load "create_regional_secret_with_labels.rb" | ||
|
||
out, _err = capture_io do | ||
sample.run project_id: project_id, location_id: location_id, secret_id: secret_id, label_key: label_key, label_value: label_value | ||
end | ||
secret_id_regex = Regexp.escape secret_id | ||
assert_match %r{Created regional secret with labels: projects/\S+locations/\S+/secrets/#{secret_id_regex}}, out | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
google-cloud-secret_manager/samples/acceptance/create_secret_with_annotations_test.rb
This file contains 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,29 @@ | ||
# Copyright 2025 Google, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
require "uri" | ||
|
||
require_relative "helper" | ||
|
||
describe "#create_secret_with_annotations", :secret_manager_snippet do | ||
it "creates a secret with annotations" do | ||
sample = SampleLoader.load "create_secret_with_annotations.rb" | ||
|
||
out, _err = capture_io do | ||
sample.run project_id: project_id, secret_id: secret_id, annotation_key: annotation_key, annotation_value: annotation_value | ||
end | ||
secret_id_regex = Regexp.escape secret_id | ||
assert_match %r{Created secret: projects/\S+/secrets/#{secret_id_regex}}, out | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
google-cloud-secret_manager/samples/acceptance/create_secret_with_labels_test.rb
This file contains 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,29 @@ | ||
# Copyright 2025 Google, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
require "uri" | ||
|
||
require_relative "helper" | ||
|
||
describe "#create_secret_with_labels", :secret_manager_snippet do | ||
it "creates a secret with labels" do | ||
sample = SampleLoader.load "create_secret_with_labels.rb" | ||
|
||
out, _err = capture_io do | ||
sample.run project_id: project_id, secret_id: secret_id, label_key: label_key, label_value: label_value | ||
end | ||
secret_id_regex = Regexp.escape secret_id | ||
assert_match %r{Created secret with label: projects/\S+/secrets/#{secret_id_regex}}, out | ||
end | ||
end |
32 changes: 32 additions & 0 deletions
32
google-cloud-secret_manager/samples/acceptance/edit_regional_secret_annotations_test.rb
This file contains 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,32 @@ | ||
# Copyright 2025 Google, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
require "uri" | ||
|
||
require_relative "regional_helper" | ||
|
||
describe "#edit_regional_secret_annotations", :regional_secret_manager_snippet do | ||
it "edits a regional secret annotations" do | ||
sample = SampleLoader.load "edit_regional_secret_annotations.rb" | ||
|
||
refute_nil secret | ||
|
||
out, _err = capture_io do | ||
sample.run project_id: project_id, location_id: location_id, secret_id: secret_id, annotation_key: updated_annotation_key, annotation_value: updated_annotation_value | ||
end | ||
|
||
assert_match(/Updated regional secret/, out) | ||
assert_match(/New updated annotations/, out) | ||
end | ||
end |
32 changes: 32 additions & 0 deletions
32
google-cloud-secret_manager/samples/acceptance/edit_secret_annotations_test.rb
This file contains 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,32 @@ | ||
# Copyright 2025 Google, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
require "uri" | ||
|
||
require_relative "helper" | ||
|
||
describe "#edit_secret_annotations", :secret_manager_snippet do | ||
it "edits the secret annotations" do | ||
sample = SampleLoader.load "edit_secret_annotations.rb" | ||
|
||
refute_nil secret | ||
|
||
out, _err = capture_io do | ||
sample.run project_id: project_id, secret_id: secret_id, annotation_key: updated_annotation_key, annotation_value: updated_annotation_value | ||
end | ||
|
||
assert_match(/Updated secret/, out) | ||
assert_match(/New updated annotations/, out) | ||
end | ||
end |
This file contains 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 |
---|---|---|
|
@@ -29,13 +29,28 @@ class SecretManagerSnippetSpec < Minitest::Spec | |
|
||
let(:iam_user) { "user:[email protected]" } | ||
|
||
let(:annotation_key) { "annotation-key" } | ||
let(:annotation_value) { "annotation-value" } | ||
|
||
let(:updated_annotation_key) { "updated-annotation-key" } | ||
let(:updated_annotation_value) { "updated-annotation-value" } | ||
|
||
let(:label_key) { "label-key" } | ||
let(:label_value) { "label-value" } | ||
|
||
let :secret do | ||
client.create_secret( | ||
parent: "projects/#{project_id}", | ||
secret_id: secret_id, | ||
secret: { | ||
replication: { | ||
automatic: {} | ||
}, | ||
annotations: { | ||
annotation_key => annotation_value | ||
}, | ||
labels: { | ||
label_key => label_value | ||
} | ||
} | ||
) | ||
|
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -33,11 +33,27 @@ | |
let(:secret_name) { "projects/#{project_id}/locations/#{location_id}/secrets/#{secret_id}" } | ||
let(:iam_user) { "user:[email protected]" } | ||
|
||
let(:annotation_key) { "annotation-key" } | ||
let(:annotation_value) { "annotation-value" } | ||
|
||
let(:updated_annotation_key) { "updated-annotation-key" } | ||
let(:updated_annotation_value) { "updated-annotation-value" } | ||
|
||
let(:label_key) { "label-key" } | ||
let(:label_value) { "label-value" } | ||
|
||
let :secret do | ||
client.create_secret( | ||
parent: "projects/#{project_id}/locations/#{location_id}", | ||
secret_id: secret_id, | ||
secret: {} | ||
secret: { | ||
annotations: { | ||
annotation_key => annotation_value | ||
}, | ||
labels: { | ||
label_key => label_value | ||
} | ||
} | ||
) | ||
end | ||
|
||
|
@@ -466,4 +482,94 @@ | |
}.must_output(/Updated regional secret/) | ||
end | ||
end | ||
|
||
describe "#create_regional_secret_with_annotations" do | ||
it "create regional secret with annotations" do | ||
expect { | ||
secret = create_regional_secret_with_annotations( | ||
project_id: project_id, | ||
location_id: location_id, | ||
secret_id: secret_id, | ||
annotation_key: annotation_key, | ||
annotation_value: annotation_value | ||
) | ||
|
||
expect(secret).wont_be_nil | ||
expect(secret.name).must_include(secret_id) | ||
expect(secret.annotations[annotation_key]).must_equal(annotation_value) | ||
}.must_output(/Created regional secret/) | ||
end | ||
end | ||
|
||
describe "#create_regional_secret_with_labels" do | ||
it "create regional secret with labels" do | ||
expect { | ||
secret = create_regional_secret_with_labels( | ||
project_id: project_id, | ||
location_id: location_id, | ||
secret_id: secret_id, | ||
label_key: label_key, | ||
label_value: label_value | ||
) | ||
|
||
expect(secret).wont_be_nil | ||
expect(secret.name).must_include(secret_id) | ||
expect(secret.labels[label_key]).must_equal(label_value) | ||
}.must_output(/Created regional secret with label/) | ||
end | ||
end | ||
|
||
describe "#edit_regional_secret_annotations" do | ||
it "edit regional secret annotations" do | ||
expect(secret).wont_be_nil | ||
|
||
expect { | ||
n_secret = edit_regional_secret_annotations( | ||
project_id: project_id, | ||
location_id: location_id, | ||
secret_id: secret_id, | ||
annotation_key: updated_annotation_key, | ||
annotation_value: updated_annotation_value | ||
) | ||
|
||
expect(n_secret).wont_be_nil | ||
expect(n_secret.name).must_include(secret_id) | ||
expect(n_secret.annotations[updated_annotation_key]).must_equal(updated_annotation_value) | ||
}.must_output(/Updated regional secret/) | ||
end | ||
end | ||
|
||
describe "#view_regional_secret_annotations" do | ||
it "view regional secret annotations" do | ||
expect(secret).wont_be_nil | ||
|
||
expect { | ||
secret_annotations = view_regional_secret_annotations( | ||
project_id: project_id, | ||
location_id: location_id, | ||
secret_id: secret_id | ||
) | ||
|
||
expect(secret_annotations).wont_be_nil | ||
expect(secret_annotations[annotation_key]).must_equal(annotation_value) | ||
}.must_output(/Annotation Key: #{annotation_key}, Annotation Value: #{annotation_value}/) | ||
end | ||
end | ||
|
||
describe "#view_regional_secret_labels" do | ||
it "view regional secret labels" do | ||
expect(secret).wont_be_nil | ||
|
||
expect { | ||
secret_labels = view_regional_secret_labels( | ||
project_id: project_id, | ||
location_id: location_id, | ||
secret_id: secret_id | ||
) | ||
|
||
expect(secret_labels).wont_be_nil | ||
expect(secret_labels[label_key]).must_equal(label_value) | ||
}.must_output(/Label Key: #{label_key}, Label Value: #{label_value}/) | ||
end | ||
end | ||
end |
Oops, something went wrong.