google-cloud-vision-v1 1.0.1 → 1.2.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: db3d3509433114ebd96e031223ff0a925f02120b93d6af5feca8096215cc20b7
4
- data.tar.gz: 1d7f82c7a858cee064cea7cab74a2584583926a049f84adcb9c761525002abdd
3
+ metadata.gz: 2fbc4b262873b57c433c84d9821a93d359d771a90fe78d1ea7f22e37a15b5391
4
+ data.tar.gz: b143f4b97aa0bbc01d62c7adf92636aee65fda1bc29b07ec587fa9f2218c64f9
5
5
  SHA512:
6
- metadata.gz: 8bf372d03a982220b376f4f5a9b514ef541dbfe70ba9302ee338cd1641adf602ba6359270d0b44d779353c418f57ed80e252ebe1d6cf304156f330c753ea7a09
7
- data.tar.gz: 3f5c6fa63c0e0399b237263d72b9526e39f5395d0c2cfdc097ce11f7e887eec890560f56eda49d6bd1de4045c1e4cb7423fe286b6bf4d42a3b9f064040311968
6
+ metadata.gz: 86abfa7d15ab34f6deed11ddb6935350d597f0a5b35c434a3915bd1938f7ff4b2853dc24e63cd5c0ef49b6931fabf0c57d2cc9f631eefae39e4fc8debce07d85
7
+ data.tar.gz: e7e309733064c98b6e4eafed41d8cf16a7944a67e8fed5a52895fd2e58c363a021f293056922a35937c6453412b3c4acad8577bbd051df5d1e8b14cca1780a05
data/README.md CHANGED
@@ -43,40 +43,50 @@ for class and method documentation.
43
43
  See also the [Product Documentation](https://cloud.google.com/vision)
44
44
  for general usage information.
45
45
 
46
- ## Enabling Logging
47
-
48
- To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library.
49
- The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/current/stdlibs/logger/Logger.html) as shown below,
50
- or a [`Google::Cloud::Logging::Logger`](https://cloud.google.com/ruby/docs/reference/google-cloud-logging/latest)
51
- that will write logs to [Cloud Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb)
52
- and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information.
53
-
54
- Configuring a Ruby stdlib logger:
46
+ ## Debug Logging
47
+
48
+ This library comes with opt-in Debug Logging that can help you troubleshoot
49
+ your application's integration with the API. When logging is activated, key
50
+ events such as requests and responses, along with data payloads and metadata
51
+ such as headers and client configuration, are logged to the standard error
52
+ stream.
53
+
54
+ **WARNING:** Client Library Debug Logging includes your data payloads in
55
+ plaintext, which could include sensitive data such as PII for yourself or your
56
+ customers, private keys, or other security data that could be compromising if
57
+ leaked. Always practice good data hygiene with your application logs, and follow
58
+ the principle of least access. Google also recommends that Client Library Debug
59
+ Logging be enabled only temporarily during active debugging, and not used
60
+ permanently in production.
61
+
62
+ To enable logging, set the environment variable `GOOGLE_SDK_RUBY_LOGGING_GEMS`
63
+ to the value `all`. Alternatively, you can set the value to a comma-delimited
64
+ list of client library gem names. This will select the default logging behavior,
65
+ which writes logs to the standard error stream. On a local workstation, this may
66
+ result in logs appearing on the console. When running on a Google Cloud hosting
67
+ service such as [Google Cloud Run](https://cloud.google.com/run), this generally
68
+ results in logs appearing alongside your application logs in the
69
+ [Google Cloud Logging](https://cloud.google.com/logging/) service.
70
+
71
+ You can customize logging by modifying the `logger` configuration when
72
+ constructing a client object. For example:
55
73
 
56
74
  ```ruby
75
+ require "google/cloud/vision/v1"
57
76
  require "logger"
58
77
 
59
- module MyLogger
60
- LOGGER = Logger.new $stderr, level: Logger::WARN
61
- def logger
62
- LOGGER
63
- end
64
- end
65
-
66
- # Define a gRPC module-level logger method before grpc/logconfig.rb loads.
67
- module GRPC
68
- extend MyLogger
78
+ client = ::Google::Cloud::Vision::V1::ProductSearch::Client.new do |config|
79
+ config.logger = Logger.new "my-app.log"
69
80
  end
70
81
  ```
71
82
 
72
-
73
83
  ## Google Cloud Samples
74
84
 
75
85
  To browse ready to use code samples check [Google Cloud Samples](https://cloud.google.com/docs/samples).
76
86
 
77
87
  ## Supported Ruby Versions
78
88
 
79
- This library is supported on Ruby 2.7+.
89
+ This library is supported on Ruby 3.0+.
80
90
 
81
91
  Google provides official support for Ruby versions that are actively supported
82
92
  by Ruby Core—that is, Ruby versions that are either in normal maintenance or
@@ -186,8 +186,19 @@ module Google
186
186
  universe_domain: @config.universe_domain,
187
187
  channel_args: @config.channel_args,
188
188
  interceptors: @config.interceptors,
189
- channel_pool_config: @config.channel_pool
189
+ channel_pool_config: @config.channel_pool,
190
+ logger: @config.logger
190
191
  )
192
+
193
+ @image_annotator_stub.stub_logger&.info do |entry|
194
+ entry.set_system_name
195
+ entry.set_service
196
+ entry.message = "Created client for #{entry.service}"
197
+ entry.set_credentials_fields credentials
198
+ entry.set "customEndpoint", @config.endpoint if @config.endpoint
199
+ entry.set "defaultTimeout", @config.timeout if @config.timeout
200
+ entry.set "quotaProject", @quota_project_id if @quota_project_id
201
+ end
191
202
  end
192
203
 
193
204
  ##
@@ -197,6 +208,15 @@ module Google
197
208
  #
198
209
  attr_reader :operations_client
199
210
 
211
+ ##
212
+ # The logger used for request/response debug logging.
213
+ #
214
+ # @return [Logger]
215
+ #
216
+ def logger
217
+ @image_annotator_stub.logger
218
+ end
219
+
200
220
  # Service calls
201
221
 
202
222
  ##
@@ -291,7 +311,6 @@ module Google
291
311
 
292
312
  @image_annotator_stub.call_rpc :batch_annotate_images, request, options: options do |response, operation|
293
313
  yield response, operation if block_given?
294
- return response
295
314
  end
296
315
  rescue ::GRPC::BadStatus => e
297
316
  raise ::Google::Cloud::Error.from_error(e)
@@ -396,7 +415,6 @@ module Google
396
415
 
397
416
  @image_annotator_stub.call_rpc :batch_annotate_files, request, options: options do |response, operation|
398
417
  yield response, operation if block_given?
399
- return response
400
418
  end
401
419
  rescue ::GRPC::BadStatus => e
402
420
  raise ::Google::Cloud::Error.from_error(e)
@@ -512,7 +530,7 @@ module Google
512
530
  @image_annotator_stub.call_rpc :async_batch_annotate_images, request, options: options do |response, operation|
513
531
  response = ::Gapic::Operation.new response, @operations_client, options: options
514
532
  yield response, operation if block_given?
515
- return response
533
+ throw :response, response
516
534
  end
517
535
  rescue ::GRPC::BadStatus => e
518
536
  raise ::Google::Cloud::Error.from_error(e)
@@ -623,7 +641,7 @@ module Google
623
641
  @image_annotator_stub.call_rpc :async_batch_annotate_files, request, options: options do |response, operation|
624
642
  response = ::Gapic::Operation.new response, @operations_client, options: options
625
643
  yield response, operation if block_given?
626
- return response
644
+ throw :response, response
627
645
  end
628
646
  rescue ::GRPC::BadStatus => e
629
647
  raise ::Google::Cloud::Error.from_error(e)
@@ -673,6 +691,13 @@ module Google
673
691
  # * (`GRPC::Core::Channel`) a gRPC channel with included credentials
674
692
  # * (`GRPC::Core::ChannelCredentials`) a gRPC credentails object
675
693
  # * (`nil`) indicating no credentials
694
+ #
695
+ # Warning: If you accept a credential configuration (JSON file or Hash) from an
696
+ # external source for authentication to Google Cloud, you must validate it before
697
+ # providing it to a Google API client library. Providing an unvalidated credential
698
+ # configuration to Google APIs can compromise the security of your systems and data.
699
+ # For more information, refer to [Validate credential configurations from external
700
+ # sources](https://cloud.google.com/docs/authentication/external/externally-sourced-credentials).
676
701
  # @return [::Object]
677
702
  # @!attribute [rw] scope
678
703
  # The OAuth scopes
@@ -712,6 +737,11 @@ module Google
712
737
  # default endpoint URL. The default value of nil uses the environment
713
738
  # universe (usually the default "googleapis.com" universe).
714
739
  # @return [::String,nil]
740
+ # @!attribute [rw] logger
741
+ # A custom logger to use for request/response debug logging, or the value
742
+ # `:default` (the default) to construct a default logger, or `nil` to
743
+ # explicitly disable logging.
744
+ # @return [::Logger,:default,nil]
715
745
  #
716
746
  class Configuration
717
747
  extend ::Gapic::Config
@@ -736,6 +766,7 @@ module Google
736
766
  config_attr :retry_policy, nil, ::Hash, ::Proc, nil
737
767
  config_attr :quota_project, nil, ::String, nil
738
768
  config_attr :universe_domain, nil, ::String, nil
769
+ config_attr :logger, :default, ::Logger, nil, :default
739
770
 
740
771
  # @private
741
772
  def initialize parent_config = nil
@@ -81,7 +81,6 @@ module Google
81
81
  destination: nil,
82
82
  image_context: nil,
83
83
  &block
84
-
85
84
  feature = { type: :CROP_HINTS, max_results: max_results }
86
85
  images << image if image
87
86
  formatted_images = images.map do |img|
@@ -179,7 +178,6 @@ module Google
179
178
  destination: nil,
180
179
  image_context: nil,
181
180
  &block
182
-
183
181
  feature = { type: :DOCUMENT_TEXT_DETECTION, max_results: max_results }
184
182
  images << image if image
185
183
  formatted_images = images.map do |img|
@@ -277,7 +275,6 @@ module Google
277
275
  destination: nil,
278
276
  image_context: nil,
279
277
  &block
280
-
281
278
  feature = { type: :FACE_DETECTION, max_results: max_results }
282
279
  images << image if image
283
280
  formatted_images = images.map do |img|
@@ -375,7 +372,6 @@ module Google
375
372
  destination: nil,
376
373
  image_context: nil,
377
374
  &block
378
-
379
375
  feature = { type: :IMAGE_PROPERTIES, max_results: max_results }
380
376
  images << image if image
381
377
  formatted_images = images.map do |img|
@@ -473,7 +469,6 @@ module Google
473
469
  destination: nil,
474
470
  image_context: nil,
475
471
  &block
476
-
477
472
  feature = { type: :LABEL_DETECTION, max_results: max_results }
478
473
  images << image if image
479
474
  formatted_images = images.map do |img|
@@ -571,7 +566,6 @@ module Google
571
566
  destination: nil,
572
567
  image_context: nil,
573
568
  &block
574
-
575
569
  feature = { type: :LANDMARK_DETECTION, max_results: max_results }
576
570
  images << image if image
577
571
  formatted_images = images.map do |img|
@@ -669,7 +663,6 @@ module Google
669
663
  destination: nil,
670
664
  image_context: nil,
671
665
  &block
672
-
673
666
  feature = { type: :LOGO_DETECTION, max_results: max_results }
674
667
  images << image if image
675
668
  formatted_images = images.map do |img|
@@ -767,7 +760,6 @@ module Google
767
760
  destination: nil,
768
761
  image_context: nil,
769
762
  &block
770
-
771
763
  feature = { type: :OBJECT_LOCALIZATION, max_results: max_results }
772
764
  images << image if image
773
765
  formatted_images = images.map do |img|
@@ -865,7 +857,6 @@ module Google
865
857
  destination: nil,
866
858
  image_context: nil,
867
859
  &block
868
-
869
860
  feature = { type: :PRODUCT_SEARCH, max_results: max_results }
870
861
  images << image if image
871
862
  formatted_images = images.map do |img|
@@ -963,7 +954,6 @@ module Google
963
954
  destination: nil,
964
955
  image_context: nil,
965
956
  &block
966
-
967
957
  feature = { type: :SAFE_SEARCH_DETECTION, max_results: max_results }
968
958
  images << image if image
969
959
  formatted_images = images.map do |img|
@@ -1061,7 +1051,6 @@ module Google
1061
1051
  destination: nil,
1062
1052
  image_context: nil,
1063
1053
  &block
1064
-
1065
1054
  feature = { type: :TEXT_DETECTION, max_results: max_results }
1066
1055
  images << image if image
1067
1056
  formatted_images = images.map do |img|
@@ -1159,7 +1148,6 @@ module Google
1159
1148
  destination: nil,
1160
1149
  image_context: nil,
1161
1150
  &block
1162
-
1163
1151
  feature = { type: :WEB_DETECTION, max_results: max_results }
1164
1152
  images << image if image
1165
1153
  formatted_images = images.map do |img|
@@ -124,14 +124,6 @@ module Google
124
124
  # Lists operations that match the specified filter in the request. If the
125
125
  # server doesn't support this method, it returns `UNIMPLEMENTED`.
126
126
  #
127
- # NOTE: the `name` binding allows API services to override the binding
128
- # to use different resource name schemes, such as `users/*/operations`. To
129
- # override the binding, API services can add a binding such as
130
- # `"/v1/{name=users/*}/operations"` to their service configuration.
131
- # For backwards compatibility, the default name includes the operations
132
- # collection id, however overriding users must ensure the name binding
133
- # is the parent resource, without the operations collection id.
134
- #
135
127
  # @overload list_operations(request, options = nil)
136
128
  # Pass arguments to `list_operations` via a request object, either of type
137
129
  # {::Google::Longrunning::ListOperationsRequest} or an equivalent Hash.
@@ -221,7 +213,7 @@ module Google
221
213
  wrap_lro_operation = ->(op_response) { ::Gapic::Operation.new op_response, @operations_client }
222
214
  response = ::Gapic::PagedEnumerable.new @operations_stub, :list_operations, request, response, operation, options, format_resource: wrap_lro_operation
223
215
  yield response, operation if block_given?
224
- return response
216
+ throw :response, response
225
217
  end
226
218
  rescue ::GRPC::BadStatus => e
227
219
  raise ::Google::Cloud::Error.from_error(e)
@@ -317,7 +309,7 @@ module Google
317
309
  @operations_stub.call_rpc :get_operation, request, options: options do |response, operation|
318
310
  response = ::Gapic::Operation.new response, @operations_client, options: options
319
311
  yield response, operation if block_given?
320
- return response
312
+ throw :response, response
321
313
  end
322
314
  rescue ::GRPC::BadStatus => e
323
315
  raise ::Google::Cloud::Error.from_error(e)
@@ -406,7 +398,6 @@ module Google
406
398
 
407
399
  @operations_stub.call_rpc :delete_operation, request, options: options do |response, operation|
408
400
  yield response, operation if block_given?
409
- return response
410
401
  end
411
402
  rescue ::GRPC::BadStatus => e
412
403
  raise ::Google::Cloud::Error.from_error(e)
@@ -421,8 +412,9 @@ module Google
421
412
  # other methods to check whether the cancellation succeeded or whether the
422
413
  # operation completed despite cancellation. On successful cancellation,
423
414
  # the operation is not deleted; instead, it becomes an operation with
424
- # an {::Google::Longrunning::Operation#error Operation.error} value with a {::Google::Rpc::Status#code google.rpc.Status.code} of 1,
425
- # corresponding to `Code.CANCELLED`.
415
+ # an {::Google::Longrunning::Operation#error Operation.error} value with a
416
+ # {::Google::Rpc::Status#code google.rpc.Status.code} of `1`, corresponding to
417
+ # `Code.CANCELLED`.
426
418
  #
427
419
  # @overload cancel_operation(request, options = nil)
428
420
  # Pass arguments to `cancel_operation` via a request object, either of type
@@ -501,7 +493,6 @@ module Google
501
493
 
502
494
  @operations_stub.call_rpc :cancel_operation, request, options: options do |response, operation|
503
495
  yield response, operation if block_given?
504
- return response
505
496
  end
506
497
  rescue ::GRPC::BadStatus => e
507
498
  raise ::Google::Cloud::Error.from_error(e)
@@ -599,7 +590,7 @@ module Google
599
590
  @operations_stub.call_rpc :wait_operation, request, options: options do |response, operation|
600
591
  response = ::Gapic::Operation.new response, @operations_client, options: options
601
592
  yield response, operation if block_given?
602
- return response
593
+ throw :response, response
603
594
  end
604
595
  rescue ::GRPC::BadStatus => e
605
596
  raise ::Google::Cloud::Error.from_error(e)
@@ -649,6 +640,13 @@ module Google
649
640
  # * (`GRPC::Core::Channel`) a gRPC channel with included credentials
650
641
  # * (`GRPC::Core::ChannelCredentials`) a gRPC credentails object
651
642
  # * (`nil`) indicating no credentials
643
+ #
644
+ # Warning: If you accept a credential configuration (JSON file or Hash) from an
645
+ # external source for authentication to Google Cloud, you must validate it before
646
+ # providing it to a Google API client library. Providing an unvalidated credential
647
+ # configuration to Google APIs can compromise the security of your systems and data.
648
+ # For more information, refer to [Validate credential configurations from external
649
+ # sources](https://cloud.google.com/docs/authentication/external/externally-sourced-credentials).
652
650
  # @return [::Object]
653
651
  # @!attribute [rw] scope
654
652
  # The OAuth scopes
@@ -688,6 +686,11 @@ module Google
688
686
  # default endpoint URL. The default value of nil uses the environment
689
687
  # universe (usually the default "googleapis.com" universe).
690
688
  # @return [::String,nil]
689
+ # @!attribute [rw] logger
690
+ # A custom logger to use for request/response debug logging, or the value
691
+ # `:default` (the default) to construct a default logger, or `nil` to
692
+ # explicitly disable logging.
693
+ # @return [::Logger,:default,nil]
691
694
  #
692
695
  class Configuration
693
696
  extend ::Gapic::Config
@@ -712,6 +715,7 @@ module Google
712
715
  config_attr :retry_policy, nil, ::Hash, ::Proc, nil
713
716
  config_attr :quota_project, nil, ::String, nil
714
717
  config_attr :universe_domain, nil, ::String, nil
718
+ config_attr :logger, :default, ::Logger, nil, :default
715
719
 
716
720
  # @private
717
721
  def initialize parent_config = nil
@@ -179,8 +179,19 @@ module Google
179
179
  endpoint: @config.endpoint,
180
180
  endpoint_template: DEFAULT_ENDPOINT_TEMPLATE,
181
181
  universe_domain: @config.universe_domain,
182
- credentials: credentials
182
+ credentials: credentials,
183
+ logger: @config.logger
183
184
  )
185
+
186
+ @image_annotator_stub.logger(stub: true)&.info do |entry|
187
+ entry.set_system_name
188
+ entry.set_service
189
+ entry.message = "Created client for #{entry.service}"
190
+ entry.set_credentials_fields credentials
191
+ entry.set "customEndpoint", @config.endpoint if @config.endpoint
192
+ entry.set "defaultTimeout", @config.timeout if @config.timeout
193
+ entry.set "quotaProject", @quota_project_id if @quota_project_id
194
+ end
184
195
  end
185
196
 
186
197
  ##
@@ -190,6 +201,15 @@ module Google
190
201
  #
191
202
  attr_reader :operations_client
192
203
 
204
+ ##
205
+ # The logger used for request/response debug logging.
206
+ #
207
+ # @return [Logger]
208
+ #
209
+ def logger
210
+ @image_annotator_stub.logger
211
+ end
212
+
193
213
  # Service calls
194
214
 
195
215
  ##
@@ -285,7 +305,6 @@ module Google
285
305
 
286
306
  @image_annotator_stub.batch_annotate_images request, options do |result, operation|
287
307
  yield result, operation if block_given?
288
- return result
289
308
  end
290
309
  rescue ::Gapic::Rest::Error => e
291
310
  raise ::Google::Cloud::Error.from_error(e)
@@ -391,7 +410,6 @@ module Google
391
410
 
392
411
  @image_annotator_stub.batch_annotate_files request, options do |result, operation|
393
412
  yield result, operation if block_given?
394
- return result
395
413
  end
396
414
  rescue ::Gapic::Rest::Error => e
397
415
  raise ::Google::Cloud::Error.from_error(e)
@@ -508,7 +526,7 @@ module Google
508
526
  @image_annotator_stub.async_batch_annotate_images request, options do |result, operation|
509
527
  result = ::Gapic::Operation.new result, @operations_client, options: options
510
528
  yield result, operation if block_given?
511
- return result
529
+ throw :response, result
512
530
  end
513
531
  rescue ::Gapic::Rest::Error => e
514
532
  raise ::Google::Cloud::Error.from_error(e)
@@ -620,7 +638,7 @@ module Google
620
638
  @image_annotator_stub.async_batch_annotate_files request, options do |result, operation|
621
639
  result = ::Gapic::Operation.new result, @operations_client, options: options
622
640
  yield result, operation if block_given?
623
- return result
641
+ throw :response, result
624
642
  end
625
643
  rescue ::Gapic::Rest::Error => e
626
644
  raise ::Google::Cloud::Error.from_error(e)
@@ -668,6 +686,13 @@ module Google
668
686
  # * (`Signet::OAuth2::Client`) A signet oauth2 client object
669
687
  # (see the [signet docs](https://rubydoc.info/gems/signet/Signet/OAuth2/Client))
670
688
  # * (`nil`) indicating no credentials
689
+ #
690
+ # Warning: If you accept a credential configuration (JSON file or Hash) from an
691
+ # external source for authentication to Google Cloud, you must validate it before
692
+ # providing it to a Google API client library. Providing an unvalidated credential
693
+ # configuration to Google APIs can compromise the security of your systems and data.
694
+ # For more information, refer to [Validate credential configurations from external
695
+ # sources](https://cloud.google.com/docs/authentication/external/externally-sourced-credentials).
671
696
  # @return [::Object]
672
697
  # @!attribute [rw] scope
673
698
  # The OAuth scopes
@@ -700,6 +725,11 @@ module Google
700
725
  # default endpoint URL. The default value of nil uses the environment
701
726
  # universe (usually the default "googleapis.com" universe).
702
727
  # @return [::String,nil]
728
+ # @!attribute [rw] logger
729
+ # A custom logger to use for request/response debug logging, or the value
730
+ # `:default` (the default) to construct a default logger, or `nil` to
731
+ # explicitly disable logging.
732
+ # @return [::Logger,:default,nil]
703
733
  #
704
734
  class Configuration
705
735
  extend ::Gapic::Config
@@ -721,6 +751,7 @@ module Google
721
751
  config_attr :retry_policy, nil, ::Hash, ::Proc, nil
722
752
  config_attr :quota_project, nil, ::String, nil
723
753
  config_attr :universe_domain, nil, ::String, nil
754
+ config_attr :logger, :default, ::Logger, nil, :default
724
755
 
725
756
  # @private
726
757
  def initialize parent_config = nil