google-cloud-service_directory-v1 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab1fbade1121d7ff11ec6d117b7704fb12a4e9f072d536e1b0a2b808e7a97751
4
- data.tar.gz: 33b6307a1c1f9e3f7533967a9f7c5c29e5b0356d3931279c284e47cdc54e4a85
3
+ metadata.gz: 97920ef46aee3ce9b4f8026675c2a133fa971b81015866c817a271836a474d0e
4
+ data.tar.gz: 6e598e169bc9d94c08faf3e6205fbd1dd002ea64ef61f00f40ddeeabd6449f19
5
5
  SHA512:
6
- metadata.gz: be3b3394f637725fbf65d5aaf9817f53f15618a6298b2881d4bdbe3042ab30fa0f09c856aeaa3f90c27d92d503c071e7aca8b90df341a92bae069c496ecde2aa
7
- data.tar.gz: 1f3679112b69ad1b7984ec34cad1410c9cf0be6f8f986635c0c5fed34f67dfcbfdc7d746be73cb8782e2c8111ada5d2a555898cc8d62b7c894256baeedc781b1
6
+ metadata.gz: 734c7ed575781fa89ad1c95abeb09cf6d49e6b72df414497f54d32e42a1f201d15a8b881ecd177dcb3a247c79020ee4a2f8e842383ee8ffffed1f56791547b42
7
+ data.tar.gz: e429bfc055569afeb7b1d715e0358141dffc4791359afd1a94175106dc2d3e963565f73e7335d378264a19eada011a330289e0c5a334cde23868d7a699b2249e
data/README.md CHANGED
@@ -43,33 +43,43 @@ for class and method documentation.
43
43
  See also the [Product Documentation](https://cloud.google.com/service-directory)
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/service_directory/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::ServiceDirectory::V1::LookupService::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).
@@ -163,14 +163,26 @@ module Google
163
163
  universe_domain: @config.universe_domain,
164
164
  channel_args: @config.channel_args,
165
165
  interceptors: @config.interceptors,
166
- channel_pool_config: @config.channel_pool
166
+ channel_pool_config: @config.channel_pool,
167
+ logger: @config.logger
167
168
  )
168
169
 
170
+ @lookup_service_stub.stub_logger&.info do |entry|
171
+ entry.set_system_name
172
+ entry.set_service
173
+ entry.message = "Created client for #{entry.service}"
174
+ entry.set_credentials_fields credentials
175
+ entry.set "customEndpoint", @config.endpoint if @config.endpoint
176
+ entry.set "defaultTimeout", @config.timeout if @config.timeout
177
+ entry.set "quotaProject", @quota_project_id if @quota_project_id
178
+ end
179
+
169
180
  @location_client = Google::Cloud::Location::Locations::Client.new do |config|
170
181
  config.credentials = credentials
171
182
  config.quota_project = @quota_project_id
172
183
  config.endpoint = @lookup_service_stub.endpoint
173
184
  config.universe_domain = @lookup_service_stub.universe_domain
185
+ config.logger = @lookup_service_stub.logger if config.respond_to? :logger=
174
186
  end
175
187
  end
176
188
 
@@ -181,6 +193,15 @@ module Google
181
193
  #
182
194
  attr_reader :location_client
183
195
 
196
+ ##
197
+ # The logger used for request/response debug logging.
198
+ #
199
+ # @return [Logger]
200
+ #
201
+ def logger
202
+ @lookup_service_stub.logger
203
+ end
204
+
184
205
  # Service calls
185
206
 
186
207
  ##
@@ -306,7 +327,6 @@ module Google
306
327
 
307
328
  @lookup_service_stub.call_rpc :resolve_service, request, options: options do |response, operation|
308
329
  yield response, operation if block_given?
309
- return response
310
330
  end
311
331
  rescue ::GRPC::BadStatus => e
312
332
  raise ::Google::Cloud::Error.from_error(e)
@@ -395,6 +415,11 @@ module Google
395
415
  # default endpoint URL. The default value of nil uses the environment
396
416
  # universe (usually the default "googleapis.com" universe).
397
417
  # @return [::String,nil]
418
+ # @!attribute [rw] logger
419
+ # A custom logger to use for request/response debug logging, or the value
420
+ # `:default` (the default) to construct a default logger, or `nil` to
421
+ # explicitly disable logging.
422
+ # @return [::Logger,:default,nil]
398
423
  #
399
424
  class Configuration
400
425
  extend ::Gapic::Config
@@ -419,6 +444,7 @@ module Google
419
444
  config_attr :retry_policy, nil, ::Hash, ::Proc, nil
420
445
  config_attr :quota_project, nil, ::String, nil
421
446
  config_attr :universe_domain, nil, ::String, nil
447
+ config_attr :logger, :default, ::Logger, nil, :default
422
448
 
423
449
  # @private
424
450
  def initialize parent_config = nil
@@ -156,15 +156,27 @@ module Google
156
156
  endpoint: @config.endpoint,
157
157
  endpoint_template: DEFAULT_ENDPOINT_TEMPLATE,
158
158
  universe_domain: @config.universe_domain,
159
- credentials: credentials
159
+ credentials: credentials,
160
+ logger: @config.logger
160
161
  )
161
162
 
163
+ @lookup_service_stub.logger(stub: true)&.info do |entry|
164
+ entry.set_system_name
165
+ entry.set_service
166
+ entry.message = "Created client for #{entry.service}"
167
+ entry.set_credentials_fields credentials
168
+ entry.set "customEndpoint", @config.endpoint if @config.endpoint
169
+ entry.set "defaultTimeout", @config.timeout if @config.timeout
170
+ entry.set "quotaProject", @quota_project_id if @quota_project_id
171
+ end
172
+
162
173
  @location_client = Google::Cloud::Location::Locations::Rest::Client.new do |config|
163
174
  config.credentials = credentials
164
175
  config.quota_project = @quota_project_id
165
176
  config.endpoint = @lookup_service_stub.endpoint
166
177
  config.universe_domain = @lookup_service_stub.universe_domain
167
178
  config.bindings_override = @config.bindings_override
179
+ config.logger = @lookup_service_stub.logger if config.respond_to? :logger=
168
180
  end
169
181
  end
170
182
 
@@ -175,6 +187,15 @@ module Google
175
187
  #
176
188
  attr_reader :location_client
177
189
 
190
+ ##
191
+ # The logger used for request/response debug logging.
192
+ #
193
+ # @return [Logger]
194
+ #
195
+ def logger
196
+ @lookup_service_stub.logger
197
+ end
198
+
178
199
  # Service calls
179
200
 
180
201
  ##
@@ -293,7 +314,6 @@ module Google
293
314
 
294
315
  @lookup_service_stub.resolve_service request, options do |result, operation|
295
316
  yield result, operation if block_given?
296
- return result
297
317
  end
298
318
  rescue ::Gapic::Rest::Error => e
299
319
  raise ::Google::Cloud::Error.from_error(e)
@@ -373,6 +393,11 @@ module Google
373
393
  # default endpoint URL. The default value of nil uses the environment
374
394
  # universe (usually the default "googleapis.com" universe).
375
395
  # @return [::String,nil]
396
+ # @!attribute [rw] logger
397
+ # A custom logger to use for request/response debug logging, or the value
398
+ # `:default` (the default) to construct a default logger, or `nil` to
399
+ # explicitly disable logging.
400
+ # @return [::Logger,:default,nil]
376
401
  #
377
402
  class Configuration
378
403
  extend ::Gapic::Config
@@ -401,6 +426,7 @@ module Google
401
426
  # by the host service.
402
427
  # @return [::Hash{::Symbol=>::Array<::Gapic::Rest::GrpcTranscoder::HttpBinding>}]
403
428
  config_attr :bindings_override, {}, ::Hash, nil
429
+ config_attr :logger, :default, ::Logger, nil, :default
404
430
 
405
431
  # @private
406
432
  def initialize parent_config = nil
@@ -30,7 +30,8 @@ module Google
30
30
  # including transcoding, making the REST call, and deserialing the response.
31
31
  #
32
32
  class ServiceStub
33
- def initialize endpoint:, endpoint_template:, universe_domain:, credentials:
33
+ # @private
34
+ def initialize endpoint:, endpoint_template:, universe_domain:, credentials:, logger:
34
35
  # These require statements are intentionally placed here to initialize
35
36
  # the REST modules only when it's required.
36
37
  require "gapic/rest"
@@ -40,7 +41,9 @@ module Google
40
41
  universe_domain: universe_domain,
41
42
  credentials: credentials,
42
43
  numeric_enums: true,
43
- raise_faraday_errors: false
44
+ service_name: self.class,
45
+ raise_faraday_errors: false,
46
+ logger: logger
44
47
  end
45
48
 
46
49
  ##
@@ -61,6 +64,15 @@ module Google
61
64
  @client_stub.endpoint
62
65
  end
63
66
 
67
+ ##
68
+ # The logger used for request/response debug logging.
69
+ #
70
+ # @return [Logger]
71
+ #
72
+ def logger stub: false
73
+ stub ? @client_stub.stub_logger : @client_stub.logger
74
+ end
75
+
64
76
  ##
65
77
  # Baseline implementation for the resolve_service REST call
66
78
  #
@@ -87,16 +99,18 @@ module Google
87
99
 
88
100
  response = @client_stub.make_http_request(
89
101
  verb,
90
- uri: uri,
91
- body: body || "",
92
- params: query_string_params,
102
+ uri: uri,
103
+ body: body || "",
104
+ params: query_string_params,
105
+ method_name: "resolve_service",
93
106
  options: options
94
107
  )
95
108
  operation = ::Gapic::Rest::TransportOperation.new response
96
109
  result = ::Google::Cloud::ServiceDirectory::V1::ResolveServiceResponse.decode_json response.body, ignore_unknown_fields: true
97
-
98
- yield result, operation if block_given?
99
- result
110
+ catch :response do
111
+ yield result, operation if block_given?
112
+ result
113
+ end
100
114
  end
101
115
 
102
116
  ##
@@ -177,14 +177,26 @@ module Google
177
177
  universe_domain: @config.universe_domain,
178
178
  channel_args: @config.channel_args,
179
179
  interceptors: @config.interceptors,
180
- channel_pool_config: @config.channel_pool
180
+ channel_pool_config: @config.channel_pool,
181
+ logger: @config.logger
181
182
  )
182
183
 
184
+ @registration_service_stub.stub_logger&.info do |entry|
185
+ entry.set_system_name
186
+ entry.set_service
187
+ entry.message = "Created client for #{entry.service}"
188
+ entry.set_credentials_fields credentials
189
+ entry.set "customEndpoint", @config.endpoint if @config.endpoint
190
+ entry.set "defaultTimeout", @config.timeout if @config.timeout
191
+ entry.set "quotaProject", @quota_project_id if @quota_project_id
192
+ end
193
+
183
194
  @location_client = Google::Cloud::Location::Locations::Client.new do |config|
184
195
  config.credentials = credentials
185
196
  config.quota_project = @quota_project_id
186
197
  config.endpoint = @registration_service_stub.endpoint
187
198
  config.universe_domain = @registration_service_stub.universe_domain
199
+ config.logger = @registration_service_stub.logger if config.respond_to? :logger=
188
200
  end
189
201
  end
190
202
 
@@ -195,6 +207,15 @@ module Google
195
207
  #
196
208
  attr_reader :location_client
197
209
 
210
+ ##
211
+ # The logger used for request/response debug logging.
212
+ #
213
+ # @return [Logger]
214
+ #
215
+ def logger
216
+ @registration_service_stub.logger
217
+ end
218
+
198
219
  # Service calls
199
220
 
200
221
  ##
@@ -288,7 +309,6 @@ module Google
288
309
 
289
310
  @registration_service_stub.call_rpc :create_namespace, request, options: options do |response, operation|
290
311
  yield response, operation if block_given?
291
- return response
292
312
  end
293
313
  rescue ::GRPC::BadStatus => e
294
314
  raise ::Google::Cloud::Error.from_error(e)
@@ -425,7 +445,7 @@ module Google
425
445
  @registration_service_stub.call_rpc :list_namespaces, request, options: options do |response, operation|
426
446
  response = ::Gapic::PagedEnumerable.new @registration_service_stub, :list_namespaces, request, response, operation, options
427
447
  yield response, operation if block_given?
428
- return response
448
+ throw :response, response
429
449
  end
430
450
  rescue ::GRPC::BadStatus => e
431
451
  raise ::Google::Cloud::Error.from_error(e)
@@ -511,7 +531,6 @@ module Google
511
531
 
512
532
  @registration_service_stub.call_rpc :get_namespace, request, options: options do |response, operation|
513
533
  yield response, operation if block_given?
514
- return response
515
534
  end
516
535
  rescue ::GRPC::BadStatus => e
517
536
  raise ::Google::Cloud::Error.from_error(e)
@@ -599,7 +618,6 @@ module Google
599
618
 
600
619
  @registration_service_stub.call_rpc :update_namespace, request, options: options do |response, operation|
601
620
  yield response, operation if block_given?
602
- return response
603
621
  end
604
622
  rescue ::GRPC::BadStatus => e
605
623
  raise ::Google::Cloud::Error.from_error(e)
@@ -686,7 +704,6 @@ module Google
686
704
 
687
705
  @registration_service_stub.call_rpc :delete_namespace, request, options: options do |response, operation|
688
706
  yield response, operation if block_given?
689
- return response
690
707
  end
691
708
  rescue ::GRPC::BadStatus => e
692
709
  raise ::Google::Cloud::Error.from_error(e)
@@ -782,7 +799,6 @@ module Google
782
799
 
783
800
  @registration_service_stub.call_rpc :create_service, request, options: options do |response, operation|
784
801
  yield response, operation if block_given?
785
- return response
786
802
  end
787
803
  rescue ::GRPC::BadStatus => e
788
804
  raise ::Google::Cloud::Error.from_error(e)
@@ -921,7 +937,7 @@ module Google
921
937
  @registration_service_stub.call_rpc :list_services, request, options: options do |response, operation|
922
938
  response = ::Gapic::PagedEnumerable.new @registration_service_stub, :list_services, request, response, operation, options
923
939
  yield response, operation if block_given?
924
- return response
940
+ throw :response, response
925
941
  end
926
942
  rescue ::GRPC::BadStatus => e
927
943
  raise ::Google::Cloud::Error.from_error(e)
@@ -1007,7 +1023,6 @@ module Google
1007
1023
 
1008
1024
  @registration_service_stub.call_rpc :get_service, request, options: options do |response, operation|
1009
1025
  yield response, operation if block_given?
1010
- return response
1011
1026
  end
1012
1027
  rescue ::GRPC::BadStatus => e
1013
1028
  raise ::Google::Cloud::Error.from_error(e)
@@ -1095,7 +1110,6 @@ module Google
1095
1110
 
1096
1111
  @registration_service_stub.call_rpc :update_service, request, options: options do |response, operation|
1097
1112
  yield response, operation if block_given?
1098
- return response
1099
1113
  end
1100
1114
  rescue ::GRPC::BadStatus => e
1101
1115
  raise ::Google::Cloud::Error.from_error(e)
@@ -1182,7 +1196,6 @@ module Google
1182
1196
 
1183
1197
  @registration_service_stub.call_rpc :delete_service, request, options: options do |response, operation|
1184
1198
  yield response, operation if block_given?
1185
- return response
1186
1199
  end
1187
1200
  rescue ::GRPC::BadStatus => e
1188
1201
  raise ::Google::Cloud::Error.from_error(e)
@@ -1278,7 +1291,6 @@ module Google
1278
1291
 
1279
1292
  @registration_service_stub.call_rpc :create_endpoint, request, options: options do |response, operation|
1280
1293
  yield response, operation if block_given?
1281
- return response
1282
1294
  end
1283
1295
  rescue ::GRPC::BadStatus => e
1284
1296
  raise ::Google::Cloud::Error.from_error(e)
@@ -1420,7 +1432,7 @@ module Google
1420
1432
  @registration_service_stub.call_rpc :list_endpoints, request, options: options do |response, operation|
1421
1433
  response = ::Gapic::PagedEnumerable.new @registration_service_stub, :list_endpoints, request, response, operation, options
1422
1434
  yield response, operation if block_given?
1423
- return response
1435
+ throw :response, response
1424
1436
  end
1425
1437
  rescue ::GRPC::BadStatus => e
1426
1438
  raise ::Google::Cloud::Error.from_error(e)
@@ -1506,7 +1518,6 @@ module Google
1506
1518
 
1507
1519
  @registration_service_stub.call_rpc :get_endpoint, request, options: options do |response, operation|
1508
1520
  yield response, operation if block_given?
1509
- return response
1510
1521
  end
1511
1522
  rescue ::GRPC::BadStatus => e
1512
1523
  raise ::Google::Cloud::Error.from_error(e)
@@ -1594,7 +1605,6 @@ module Google
1594
1605
 
1595
1606
  @registration_service_stub.call_rpc :update_endpoint, request, options: options do |response, operation|
1596
1607
  yield response, operation if block_given?
1597
- return response
1598
1608
  end
1599
1609
  rescue ::GRPC::BadStatus => e
1600
1610
  raise ::Google::Cloud::Error.from_error(e)
@@ -1680,7 +1690,6 @@ module Google
1680
1690
 
1681
1691
  @registration_service_stub.call_rpc :delete_endpoint, request, options: options do |response, operation|
1682
1692
  yield response, operation if block_given?
1683
- return response
1684
1693
  end
1685
1694
  rescue ::GRPC::BadStatus => e
1686
1695
  raise ::Google::Cloud::Error.from_error(e)
@@ -1770,7 +1779,6 @@ module Google
1770
1779
 
1771
1780
  @registration_service_stub.call_rpc :get_iam_policy, request, options: options do |response, operation|
1772
1781
  yield response, operation if block_given?
1773
- return response
1774
1782
  end
1775
1783
  rescue ::GRPC::BadStatus => e
1776
1784
  raise ::Google::Cloud::Error.from_error(e)
@@ -1868,7 +1876,6 @@ module Google
1868
1876
 
1869
1877
  @registration_service_stub.call_rpc :set_iam_policy, request, options: options do |response, operation|
1870
1878
  yield response, operation if block_given?
1871
- return response
1872
1879
  end
1873
1880
  rescue ::GRPC::BadStatus => e
1874
1881
  raise ::Google::Cloud::Error.from_error(e)
@@ -1960,7 +1967,6 @@ module Google
1960
1967
 
1961
1968
  @registration_service_stub.call_rpc :test_iam_permissions, request, options: options do |response, operation|
1962
1969
  yield response, operation if block_given?
1963
- return response
1964
1970
  end
1965
1971
  rescue ::GRPC::BadStatus => e
1966
1972
  raise ::Google::Cloud::Error.from_error(e)
@@ -2049,6 +2055,11 @@ module Google
2049
2055
  # default endpoint URL. The default value of nil uses the environment
2050
2056
  # universe (usually the default "googleapis.com" universe).
2051
2057
  # @return [::String,nil]
2058
+ # @!attribute [rw] logger
2059
+ # A custom logger to use for request/response debug logging, or the value
2060
+ # `:default` (the default) to construct a default logger, or `nil` to
2061
+ # explicitly disable logging.
2062
+ # @return [::Logger,:default,nil]
2052
2063
  #
2053
2064
  class Configuration
2054
2065
  extend ::Gapic::Config
@@ -2073,6 +2084,7 @@ module Google
2073
2084
  config_attr :retry_policy, nil, ::Hash, ::Proc, nil
2074
2085
  config_attr :quota_project, nil, ::String, nil
2075
2086
  config_attr :universe_domain, nil, ::String, nil
2087
+ config_attr :logger, :default, ::Logger, nil, :default
2076
2088
 
2077
2089
  # @private
2078
2090
  def initialize parent_config = nil