Skip to content

Commit 47c827a

Browse files
authored
chore(storage): Migrate to google-cloud-pubsub v3.x (googleapis#30773)
1 parent 0af0b42 commit 47c827a

4 files changed

Lines changed: 59 additions & 25 deletions

File tree

google-cloud-storage/OVERVIEW.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -531,14 +531,23 @@ created and owns the topic.)
531531
require "google/cloud/pubsub"
532532
require "google/cloud/storage"
533533

534-
pubsub = Google::Cloud::Pubsub.new
534+
pubsub = Google::Cloud::PubSub.new
535535
storage = Google::Cloud::Storage.new
536536

537-
topic = pubsub.create_topic "my-topic"
538-
topic.policy do |p|
539-
p.add "roles/pubsub.publisher",
540-
"serviceAccount:#{storage.service_account_email}"
541-
end
537+
topic_admin = pubsub.topic_admin
538+
topic_path = pubsub.topic_path "my-topic"
539+
topic = topic_admin.create_topic name: topic_path
540+
541+
policy = {
542+
bindings: [
543+
{
544+
role: "roles/pubsub.publisher",
545+
members: ["serviceAccount:#{storage.service_account_email}"]
546+
}
547+
]
548+
}
549+
550+
pubsub.iam.set_iam_policy resource: topic_path, policy: policy
542551

543552
bucket = storage.bucket "my-bucket"
544553

google-cloud-storage/acceptance/storage/bucket_notification_test.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,21 @@
2929
let(:payload) { "NONE" }
3030

3131
it "creates a Pub/Sub subscription notification" do
32+
pubsub = Google::Cloud::PubSub.new
33+
topic_admin = pubsub.topic_admin
34+
topic = nil
3235
begin
33-
topic = Google::Cloud.pubsub.create_topic topic_name
34-
topic.policy do |p|
35-
p.add "roles/pubsub.publisher", project_email
36-
end
36+
topic = topic_admin.create_topic name: pubsub.topic_path(topic_name)
37+
38+
policy = {
39+
bindings: [
40+
{
41+
role: "roles/pubsub.publisher",
42+
members: [project_email]
43+
}
44+
]
45+
}
46+
pubsub.iam.set_iam_policy resource: topic.name, policy: policy
3747

3848
notification = bucket.create_notification topic.name, custom_attrs: custom_attrs,
3949
event_types: event_types,
@@ -63,8 +73,7 @@
6373
fresh_notification.delete
6474
ensure
6575
bucket.notifications.map(&:delete)
66-
post_topic = Google::Cloud.pubsub.topic "#{prefix}_bucket_notification_topic"
67-
post_topic.delete if post_topic # Assume no subscriptions to clean up.
76+
topic_admin.delete_topic topic: topic.name if topic
6877
end
6978
end
7079
end

google-cloud-storage/acceptance/storage/bucket_requester_pays_test.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,21 @@
122122
end
123123

124124
it "creates a Pub/Sub subscription notification" do
125+
pubsub = Google::Cloud::PubSub.new
126+
topic_admin = pubsub.topic_admin
127+
topic = nil
125128
begin
126-
topic = Google::Cloud.pubsub.create_topic topic_name
127-
topic.policy do |p|
128-
p.add "roles/pubsub.publisher", project_email
129-
end
129+
topic = topic_admin.create_topic name: pubsub.topic_path(topic_name)
130+
131+
policy = {
132+
bindings: [
133+
{
134+
role: "roles/pubsub.publisher",
135+
members: [project_email]
136+
}
137+
]
138+
}
139+
pubsub.iam.set_iam_policy resource: topic.name, policy: policy
130140

131141
notification = bucket.create_notification topic.name, custom_attrs: custom_attrs,
132142
event_types: event_types,
@@ -156,8 +166,7 @@
156166
fresh_notification.delete
157167
ensure
158168
bucket.notifications.map(&:delete)
159-
post_topic = Google::Cloud.pubsub.topic "#{prefix}_bucket_notification_topic"
160-
post_topic.delete if post_topic # Assume no subscriptions to clean up.
169+
topic_admin.delete_topic topic: topic.name if topic
161170
end
162171
end
163172

google-cloud-storage/samples/acceptance/notification_test.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,24 @@
2626

2727
before :all do
2828
@bucket = create_bucket_helper random_bucket_name
29-
pubsub = Google::Cloud::Pubsub.new
30-
@topic = pubsub.create_topic random_topic_name
31-
topic.policy do |p|
32-
p.add "roles/pubsub.publisher",
33-
"serviceAccount:#{storage_client.service_account_email}"
34-
end
29+
pubsub = Google::Cloud::PubSub.new
30+
@topic_admin = pubsub.topic_admin
31+
@topic = @topic_admin.create_topic name: pubsub.topic_path(random_topic_name)
32+
33+
policy = {
34+
bindings: [
35+
{
36+
role: "roles/pubsub.publisher",
37+
members: ["serviceAccount:#{storage_client.service_account_email}"]
38+
}
39+
]
40+
}
41+
pubsub.iam.set_iam_policy resource: @topic.name, policy: policy
3542
end
3643

3744
after :all do
3845
delete_bucket_helper @bucket.name
39-
topic.delete
46+
@topic_admin.delete_topic topic: @topic.name if @topic
4047
end
4148

4249
describe "Notification Lifecycle" do

0 commit comments

Comments
 (0)