google-cloud-pubsub 3.0.2 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c47519bfe64a6b8c705b8f6d0f3d89453cabf39bec693e5031fca85fd406c5f1
4
- data.tar.gz: 438769cf4b54c421b353436f9c1f89fb8c6621bb0dfcb02fe02f9fe7b3f4e239
3
+ metadata.gz: 0b807c188d7948862efc100d1d0c2bd06eb7495fe9031719e5c80f395093b491
4
+ data.tar.gz: 955a2d3cd3b3777a938a58e933c6aa8714a62ad21949daf8b7fd7efdfbd64091
5
5
  SHA512:
6
- metadata.gz: 863a808c566bf8c2667387915ab89643f1e587bf6acf572d8ca2ecd4670a2adc9f47ed4fc2de633f91f345abce0ae03b3f7fe9ddaf11bfb9152b0bc556d61d7a
7
- data.tar.gz: 67ccab46b9cdb3c52065e6585f870f49cc0e6892205bde6ec76a314a6570cd00c847d628764e86dbf5088cb4320f5c1ed4bfe68b2f5f6c21938766d410d0f1dc
6
+ metadata.gz: 7f953960c1f7d30b5de38591d3f5c7c6ad27404ca99b93593ce8e41b772c3a5043731c861a9283bc7c15f1210ccb0aa3be8f50a94e46a73db5b835ab23402f59
7
+ data.tar.gz: 8e227ff927d181ef32dbcc85fe8dffcb9d66aa80fcc203d13fec166b83a05b92066c10423805269b40f7fd4a05530b1c30163560f4a955678fd704f00ea83f7f
data/AUTHENTICATION.md CHANGED
@@ -46,6 +46,12 @@ code.
46
46
 
47
47
  **Credentials** are discovered in the following order:
48
48
 
49
+ > [!WARNING]
50
+ > If you accept a credential configuration (JSON file or Hash) from an
51
+ > external source for authentication to Google Cloud, you must validate it before
52
+ > providing it to a Google API client library. Providing an unvalidated credential
53
+ > configuration to Google APIs can compromise the security of your systems and data.
54
+
49
55
  1. Specify credentials in method arguments
50
56
  2. Specify credentials in configuration
51
57
  3. Discover credentials path in environment variables
@@ -100,11 +106,16 @@ The **Project ID** and the path to the **Credentials JSON** file can be configur
100
106
  instead of placing them in environment variables or providing them as arguments.
101
107
 
102
108
  ```ruby
109
+ require "googleauth"
103
110
  require "google/cloud/pubsub"
104
111
 
112
+ credentials = ::Google::Auth::ServiceAccountCredentials.make_creds(
113
+ json_key_io: ::File.open("/path/to/keyfile.json")
114
+ )
115
+
105
116
  Google::Cloud::PubSub.configure do |config|
106
117
  config.project_id = "my-project-id"
107
- config.credentials = "path/to/keyfile.json"
118
+ config.credentials = credentials
108
119
  end
109
120
 
110
121
  client = Google::Cloud::PubSub.new
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Release History
2
2
 
3
+ ### 3.1.0 (2025-12-12)
4
+
5
+ #### Features
6
+
7
+ * Add skip_lookup to Project#publisher to enable lazy loading ([#32263](https://github.com/googleapis/google-cloud-ruby/issues/32263))
8
+ #### Documentation
9
+
10
+ * Fix overview documentation URL
11
+
12
+ ### 3.0.3 (2025-11-04)
13
+
14
+ #### Documentation
15
+
16
+ * add warning about loading unvalidated credentials ([#32121](https://github.com/googleapis/google-cloud-ruby/issues/32121))
17
+
3
18
  ### 3.0.2 (2025-08-12)
4
19
 
5
20
  #### Bug Fixes
data/OVERVIEW.md CHANGED
@@ -36,7 +36,7 @@ into Admin Operations and Data Plane Operations.
36
36
  * **Data Plane Operations**: For the core functionality of publishing and receiving messages.
37
37
 
38
38
  To learn more about Pub/Sub, read the [Google Cloud Pub/Sub Overview
39
- ](https://cloud.google.com/pubsub/overview).
39
+ ](https://docs.cloud.google.com/pubsub/docs/overview).
40
40
 
41
41
  ## Admin Operations
42
42
 
@@ -133,12 +133,17 @@ module Google
133
133
  # @param [Hash] async A hash of values to configure the topic's
134
134
  # {AsyncPublisher} that is created when {Publisher#publish_async}
135
135
  # is called. Optional.
136
+ # @param [Boolean] skip_lookup Optionally create a {Publisher} object
137
+ # without verifying the topic resource exists on the Pub/Sub
138
+ # service. Calls made on this object will raise errors if the service
139
+ # resource does not exist. Default is `false`.
136
140
  #
137
141
  # @return [Google::Cloud::PubSub::Publisher]
138
142
  #
139
- def publisher topic_name, project: nil, async: nil
143
+ def publisher topic_name, project: nil, async: nil, skip_lookup: nil
140
144
  ensure_service!
141
145
  options = { project: project, async: async }
146
+ return Publisher.from_name topic_name, service, options if skip_lookup
142
147
  grpc = topic_admin.get_topic topic: service.topic_path(topic_name, options)
143
148
  Publisher.from_grpc grpc, service, async: async
144
149
  end
@@ -87,9 +87,56 @@ module Google
87
87
  # `projects/{project_id}/topics/{topic_id}`.
88
88
  #
89
89
  def name
90
+ return @resource_name if reference?
90
91
  @grpc.name
91
92
  end
92
93
 
94
+ ##
95
+ # Determines whether the publisher object was created with a resource
96
+ # representation from the Pub/Sub service.
97
+ #
98
+ # @return [Boolean] `true` when the publisher was created with a resource
99
+ # representation, `false` otherwise.
100
+ #
101
+ def reference?
102
+ @grpc.nil?
103
+ end
104
+
105
+ ##
106
+ # Determines whether the publisher object was created with a resource
107
+ # representation from the Pub/Sub service.
108
+ #
109
+ # @return [Boolean] `true` when the publisher was created with a resource
110
+ # representation, `false` otherwise.
111
+ #
112
+ def resource?
113
+ !@grpc.nil?
114
+ end
115
+
116
+
117
+ ##
118
+ # Reloads the publisher with current data from the Pub/Sub service.
119
+ #
120
+ # @return [Google::Cloud::PubSub::Publisher] Returns the reloaded
121
+ # publisher
122
+ #
123
+ # @example
124
+ # require "google/cloud/pubsub"
125
+ #
126
+ # pubsub = Google::Cloud::PubSub.new
127
+ #
128
+ # publisher = pubsub.publisher "my-topic", skip_lookup: true
129
+ #
130
+ # publisher.reload!
131
+ #
132
+ def reload!
133
+ ensure_service!
134
+ topic_path = service.topic_path name
135
+ @grpc = service.topic_admin.get_topic topic: topic_path
136
+ @resource_name = nil
137
+ self
138
+ end
139
+
93
140
  ##
94
141
  # Publishes one or more messages to the publisher.
95
142
  #
@@ -166,7 +213,7 @@ module Google
166
213
  #
167
214
  def publish data = nil, attributes = nil, ordering_key: nil, compress: nil, compression_bytes_threshold: nil,
168
215
  **extra_attrs, &block
169
- ensure_service!
216
+ ensure_grpc!
170
217
  batch = BatchPublisher.new data,
171
218
  attributes,
172
219
  ordering_key,
@@ -290,8 +337,7 @@ module Google
290
337
  # publisher.async_publisher.stop!
291
338
  #
292
339
  def publish_async data = nil, attributes = nil, ordering_key: nil, **extra_attrs, &callback
293
- ensure_service!
294
-
340
+ ensure_grpc!
295
341
  @async_publisher ||= AsyncPublisher.new name, service, **@async_opts
296
342
  @async_publisher.publish data, attributes, ordering_key: ordering_key, **extra_attrs, &callback
297
343
  end
@@ -351,6 +397,16 @@ module Google
351
397
  end
352
398
  end
353
399
 
400
+ ##
401
+ # @private New reference {Publisher} from a topic name without making
402
+ # a HTTP request.
403
+ def self.from_name name, service, options = {}
404
+ name = service.topic_path name, options
405
+ from_grpc(nil, service, async: options[:async]).tap do |t|
406
+ t.instance_variable_set :@resource_name, name
407
+ end
408
+ end
409
+
354
410
  protected
355
411
 
356
412
  ##
@@ -364,6 +420,7 @@ module Google
364
420
  # Ensures a Google::Cloud::PubSub::V1::Topic object exists.
365
421
  def ensure_grpc!
366
422
  ensure_service!
423
+ reload! if reference?
367
424
  end
368
425
  end
369
426
  end
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module PubSub
19
- VERSION = "3.0.2".freeze
19
+ VERSION = "3.1.0".freeze
20
20
  end
21
21
 
22
22
  Pubsub = PubSub unless const_defined? :Pubsub
@@ -43,9 +43,24 @@ module Google
43
43
  # @param [String] project_id Project identifier for the Pub/Sub service
44
44
  # you are connecting to. If not present, the default project for the
45
45
  # credentials is used.
46
- # @param [String, Hash, Google::Auth::Credentials] credentials The path to
47
- # the keyfile as a String, the contents of the keyfile as a Hash, or a
48
- # Google::Auth::Credentials object. (See {PubSub::Credentials})
46
+ # @param [Google::Auth::Credentials] credentials A Google::Auth::Credentials
47
+ # object. (See {PubSub::Credentials})
48
+ # @note Warning: Passing a `String` to a keyfile path or a `Hash` of credentials
49
+ # is deprecated. Providing an unvalidated credential configuration to
50
+ # Google APIs can compromise the security of your systems and data.
51
+ #
52
+ # @example
53
+ #
54
+ # # The recommended way to provide credentials is to use the `make_creds` method
55
+ # # on the appropriate credentials class for your environment.
56
+ #
57
+ # require "googleauth"
58
+ #
59
+ # credentials = ::Google::Auth::ServiceAccountCredentials.make_creds(
60
+ # json_key_io: ::File.open("/path/to/keyfile.json")
61
+ # )
62
+ #
63
+ # pubsub = Google::Cloud::Pubsub.new project_id: "my-project", credentials: credentials
49
64
  # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling
50
65
  # the set of resources and operations that the connection can access.
51
66
  # See [Using OAuth 2.0 to Access Google
@@ -76,10 +76,24 @@ module Google
76
76
  # @param [String] project_id Project identifier for the Pub/Sub service you
77
77
  # are connecting to. If not present, the default project for the
78
78
  # credentials is used.
79
- # @param [String, Hash, Google::Auth::Credentials] credentials The path to
80
- # the keyfile as a String, the contents of the keyfile as a Hash, or a
81
- # Google::Auth::Credentials object.
82
- # (See {Google::Cloud::PubSub::Credentials})
79
+ # @param [Google::Auth::Credentials] credentials A Google::Auth::Credentials
80
+ # object. (See {Google::Cloud::PubSub::Credentials})
81
+ # @note Warning: Passing a `String` to a keyfile path or a `Hash` of credentials
82
+ # is deprecated. Providing an unvalidated credential configuration to
83
+ # Google APIs can compromise the security of your systems and data.
84
+ #
85
+ # @example
86
+ #
87
+ # # The recommended way to provide credentials is to use the `make_creds` method
88
+ # # on the appropriate credentials class for your environment.
89
+ #
90
+ # require "googleauth"
91
+ #
92
+ # credentials = ::Google::Auth::ServiceAccountCredentials.make_creds(
93
+ # json_key_io: ::File.open("/path/to/keyfile.json")
94
+ # )
95
+ #
96
+ # pubsub = Google::Cloud::Pubsub.new project_id: "my-project", credentials: credentials
83
97
  # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
84
98
  # set of resources and operations that the connection can access. See
85
99
  # [Using OAuth 2.0 to Access Google
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-pubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore