-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add regional code samples for Secret Manager (#28115)
- Loading branch information
1 parent
2ad551c
commit 409ca00
Showing
51 changed files
with
3,499 additions
and
1 deletion.
There are no files selected for viewing
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
27 changes: 27 additions & 0 deletions
27
google-cloud-secret_manager/samples/acceptance/access_regional_secret_version_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,27 @@ | ||
# Copyright 2022 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 "#access_regional_secret_version", :regional_secret_manager_snippet do | ||
it "accesses the regional secret version" do | ||
sample = SampleLoader.load "access_regional_secret_version.rb" | ||
|
||
assert_output(/Plaintext: hello world!/) do | ||
sample.run project_id: project_id, location_id: location_id, secret_id: secret_id, version_id: version_id | ||
end | ||
end | ||
end |
35 changes: 35 additions & 0 deletions
35
google-cloud-secret_manager/samples/acceptance/add_regional_secret_version_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,35 @@ | ||
# Copyright 2022 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 "#add_regional_secret_version", :regional_secret_manager_snippet do | ||
it "adds a secret version" do | ||
sample = SampleLoader.load "add_regional_secret_version.rb" | ||
|
||
o_list = client.list_secret_versions(parent: secret.name).to_a | ||
assert_empty o_list | ||
|
||
out, _err = capture_io do | ||
sample.run project_id: project_id, location_id: location_id, secret_id: secret_id | ||
end | ||
assert_match(/Added regional secret version: \S+/, out) | ||
version = /Added regional secret version: (\S+)/.match(out)[1] | ||
|
||
n_list = client.list_secret_versions(parent: secret.name).to_a | ||
assert_includes n_list.map(&:name), version | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
google-cloud-secret_manager/samples/acceptance/create_regional_secret_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 2022 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", :regional_secret_manager_snippet do | ||
it "creates a regional secret" do | ||
sample = SampleLoader.load "create_regional_secret.rb" | ||
|
||
out, _err = capture_io do | ||
sample.run project_id: project_id, location_id: location_id, secret_id: secret_id | ||
end | ||
secret_id_regex = Regexp.escape secret_id | ||
assert_match %r{Created regional secret: projects/\S+locations/\S+/secrets/#{secret_id_regex}}, out | ||
end | ||
end |
34 changes: 34 additions & 0 deletions
34
google-cloud-secret_manager/samples/acceptance/delete_regional_secret_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,34 @@ | ||
# Copyright 2022 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 "#delete_regional_secret", :regional_secret_manager_snippet do | ||
it "deletes the secret" do | ||
sample = SampleLoader.load "delete_regional_secret.rb" | ||
|
||
refute_nil secret | ||
client.get_secret name: secret_name | ||
|
||
assert_output(/Deleted regional secret/) do | ||
sample.run project_id: project_id, location_id: location_id, secret_id: secret_id | ||
end | ||
|
||
assert_raises Google::Cloud::NotFoundError do | ||
client.get_secret name: secret_name | ||
end | ||
end | ||
end |
36 changes: 36 additions & 0 deletions
36
google-cloud-secret_manager/samples/acceptance/delete_regional_secret_with_etag_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,36 @@ | ||
# Copyright 2022 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 "#delete_regional_secret_with_etag", :regional_secret_manager_snippet do | ||
it "deletes the regional secret" do | ||
sample = SampleLoader.load "delete_regional_secret_with_etag.rb" | ||
|
||
refute_nil secret | ||
get_secret_reponse = client.get_secret name: secret_name | ||
|
||
updated_etag = get_secret_reponse.etag | ||
|
||
assert_output(/Deleted regional secret/) do | ||
sample.run project_id: project_id, location_id: location_id, secret_id: secret_id, etag: updated_etag | ||
end | ||
|
||
assert_raises Google::Cloud::NotFoundError do | ||
client.get_secret name: secret_name | ||
end | ||
end | ||
end |
33 changes: 33 additions & 0 deletions
33
google-cloud-secret_manager/samples/acceptance/destroy_regional_secret_version_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,33 @@ | ||
# Copyright 2022 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 "#destroy_regional_secret_version", :regional_secret_manager_snippet do | ||
it "destroys the secret version" do | ||
sample = SampleLoader.load "destroy_regional_secret_version.rb" | ||
|
||
refute_nil secret_version | ||
|
||
assert_output(/Destroyed regional secret version/) do | ||
sample.run project_id: project_id, location_id: location_id, secret_id: secret_id, version_id: version_id | ||
end | ||
|
||
n_version = client.get_secret_version name: version_name | ||
refute_nil n_version | ||
assert_equal "destroyed", n_version.state.to_s.downcase | ||
end | ||
end |
33 changes: 33 additions & 0 deletions
33
...cloud-secret_manager/samples/acceptance/destroy_regional_secret_version_with_etag_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,33 @@ | ||
# Copyright 2022 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 "#destroy_regional_secret_version_with_etag", :regional_secret_manager_snippet do | ||
it "destroys the regional secret version with etag" do | ||
sample = SampleLoader.load "destroy_regional_secret_version_with_etag.rb" | ||
|
||
refute_nil secret_version | ||
|
||
assert_output(/Destroyed regional secret version/) do | ||
sample.run project_id: project_id, location_id: location_id, secret_id: secret_id, version_id: version_id, etag: etag | ||
end | ||
|
||
n_version = client.get_secret_version name: version_name | ||
refute_nil n_version | ||
assert_equal "destroyed", n_version.state.to_s.downcase | ||
end | ||
end |
33 changes: 33 additions & 0 deletions
33
google-cloud-secret_manager/samples/acceptance/disable_regional_secret_version_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,33 @@ | ||
# Copyright 2022 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 "#disable_regional_secret_version", :regional_secret_manager_snippet do | ||
it "disables the secret version" do | ||
sample = SampleLoader.load "disable_regional_secret_version.rb" | ||
|
||
refute_nil secret_version | ||
|
||
assert_output(/Disabled regional secret version/) do | ||
sample.run project_id: project_id, location_id: location_id, secret_id: secret_id, version_id: version_id | ||
end | ||
|
||
n_version = client.get_secret_version name: version_name | ||
refute_nil n_version | ||
assert_equal "disabled", n_version.state.to_s.downcase | ||
end | ||
end |
33 changes: 33 additions & 0 deletions
33
...cloud-secret_manager/samples/acceptance/disable_regional_secret_version_with_etag_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,33 @@ | ||
# Copyright 2022 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 "#disable_regional_secret_version_with_etag", :regional_secret_manager_snippet do | ||
it "disables the regional secret version with the etag" do | ||
sample = SampleLoader.load "disable_regional_secret_version_with_etag.rb" | ||
|
||
refute_nil secret_version | ||
|
||
assert_output(/Disabled regional secret version/) do | ||
sample.run project_id: project_id, location_id: location_id, secret_id: secret_id, version_id: version_id, etag: etag | ||
end | ||
|
||
n_version = client.get_secret_version name: version_name | ||
refute_nil n_version | ||
assert_equal "disabled", n_version.state.to_s.downcase | ||
end | ||
end |
Oops, something went wrong.