1+ # -*- coding: utf-8 -*-
2+ #
13# Copyright 2018 Google LLC
24#
35# Licensed under the Apache License, Version 2.0 (the "License");
1416"""Accesses the google.devtools.clouderrorreporting.v1beta1 ErrorGroupService API."""
1517
1618import pkg_resources
19+ import warnings
1720
21+ from google .oauth2 import service_account
1822import google .api_core .gapic_v1 .client_info
1923import google .api_core .gapic_v1 .config
2024import google .api_core .gapic_v1 .method
2125import google .api_core .grpc_helpers
2226import google .api_core .path_template
27+ import grpc
2328
2429from google .cloud .errorreporting_v1beta1 .gapic import enums
2530from google .cloud .errorreporting_v1beta1 .gapic import error_group_service_client_config
31+ from google .cloud .errorreporting_v1beta1 .gapic .transports import error_group_service_grpc_transport
2632from google .cloud .errorreporting_v1beta1 .proto import common_pb2
2733from google .cloud .errorreporting_v1beta1 .proto import error_group_service_pb2
34+ from google .cloud .errorreporting_v1beta1 .proto import error_group_service_pb2_grpc
2835
2936_GAPIC_LIBRARY_VERSION = pkg_resources .get_distribution (
3037 'google-cloud-error-reporting' , ).version
@@ -36,14 +43,31 @@ class ErrorGroupServiceClient(object):
3643 SERVICE_ADDRESS = 'clouderrorreporting.googleapis.com:443'
3744 """The default address of the service."""
3845
39- # The scopes needed to make gRPC calls to all of the methods defined in
40- # this service
41- _DEFAULT_SCOPES = ('https://www.googleapis.com/auth/cloud-platform' , )
42-
43- # The name of the interface for this client. This is the key used to find
44- # method configuration in the client_config dictionary.
46+ # The name of the interface for this client. This is the key used to
47+ # find the method configuration in the client_config dictionary.
4548 _INTERFACE_NAME = 'google.devtools.clouderrorreporting.v1beta1.ErrorGroupService'
4649
50+ @classmethod
51+ def from_service_account_file (cls , filename , * args , ** kwargs ):
52+ """Creates an instance of this client using the provided credentials
53+ file.
54+
55+ Args:
56+ filename (str): The path to the service account private key json
57+ file.
58+ args: Additional arguments to pass to the constructor.
59+ kwargs: Additional arguments to pass to the constructor.
60+
61+ Returns:
62+ ErrorGroupServiceClient: The constructed client.
63+ """
64+ credentials = service_account .Credentials .from_service_account_file (
65+ filename )
66+ kwargs ['credentials' ] = credentials
67+ return cls (* args , ** kwargs )
68+
69+ from_service_account_json = from_service_account_file
70+
4771 @classmethod
4872 def group_path (cls , project , group ):
4973 """Return a fully-qualified group string."""
@@ -54,76 +78,91 @@ def group_path(cls, project, group):
5478 )
5579
5680 def __init__ (self ,
81+ transport = None ,
5782 channel = None ,
5883 credentials = None ,
5984 client_config = error_group_service_client_config .config ,
6085 client_info = None ):
6186 """Constructor.
6287
6388 Args:
64- channel (grpc.Channel): A ``Channel`` instance through
65- which to make calls. This argument is mutually exclusive
89+ transport (Union[~.ErrorGroupServiceGrpcTransport,
90+ Callable[[~.Credentials, type], ~.ErrorGroupServiceGrpcTransport]): A transport
91+ instance, responsible for actually making the API calls.
92+ The default transport uses the gRPC protocol.
93+ This argument may also be a callable which returns a
94+ transport instance. Callables will be sent the credentials
95+ as the first argument and the default transport class as
96+ the second argument.
97+ channel (grpc.Channel): DEPRECATED. A ``Channel`` instance
98+ through which to make calls. This argument is mutually exclusive
6699 with ``credentials``; providing both will raise an exception.
67100 credentials (google.auth.credentials.Credentials): The
68101 authorization credentials to attach to requests. These
69102 credentials identify this application to the service. If none
70103 are specified, the client will attempt to ascertain the
71104 credentials from the environment.
72- client_config (dict): A dictionary of call options for each
73- method. If not specified, the default configuration is used.
105+ This argument is mutually exclusive with providing a
106+ transport instance to ``transport``; doing so will raise
107+ an exception.
108+ client_config (dict): DEPRECATED. A dictionary of call options for
109+ each method. If not specified, the default configuration is used.
74110 client_info (google.api_core.gapic_v1.client_info.ClientInfo):
75111 The client info used to send a user-agent string along with
76112 API requests. If ``None``, then default info will be used.
77113 Generally, you only need to set this if you're developing
78114 your own client library.
79115 """
80- # If both `channel` and `credentials` are specified, raise an
81- # exception (channels come with credentials baked in already).
82- if channel is not None and credentials is not None :
83- raise ValueError (
84- 'The `channel` and `credentials` arguments to {} are mutually '
85- 'exclusive.' .format (self .__class__ .__name__ ), )
86-
87- # Create the channel.
88- if channel is None :
89- channel = google .api_core .grpc_helpers .create_channel (
90- self .SERVICE_ADDRESS ,
116+ # Raise deprecation warnings for things we want to go away.
117+ if client_config :
118+ warnings .warn ('The `client_config` argument is deprecated.' ,
119+ PendingDeprecationWarning )
120+ if channel :
121+ warnings .warn (
122+ 'The `channel` argument is deprecated; use '
123+ '`transport` instead.' , PendingDeprecationWarning )
124+
125+ # Instantiate the transport.
126+ # The transport is responsible for handling serialization and
127+ # deserialization and actually sending data to the service.
128+ if transport :
129+ if callable (transport ):
130+ self .transport = transport (
131+ credentials = credentials ,
132+ default_class = error_group_service_grpc_transport .
133+ ErrorGroupServiceGrpcTransport ,
134+ )
135+ else :
136+ if credentials :
137+ raise ValueError (
138+ 'Received both a transport instance and '
139+ 'credentials; these are mutually exclusive.' )
140+ self .transport = transport
141+ else :
142+ self .transport = error_group_service_grpc_transport .ErrorGroupServiceGrpcTransport (
143+ address = self .SERVICE_ADDRESS ,
144+ channel = channel ,
91145 credentials = credentials ,
92- scopes = self ._DEFAULT_SCOPES ,
93146 )
94147
95- # Create the gRPC stubs.
96- self .error_group_service_stub = (
97- error_group_service_pb2 .ErrorGroupServiceStub (channel ))
98-
99148 if client_info is None :
100149 client_info = (
101150 google .api_core .gapic_v1 .client_info .DEFAULT_CLIENT_INFO )
102151 client_info .gapic_version = _GAPIC_LIBRARY_VERSION
152+ self ._client_info = client_info
103153
104154 # Parse out the default settings for retry and timeout for each RPC
105155 # from the client configuration.
106156 # (Ordinarily, these are the defaults specified in the `*_config.py`
107157 # file next to this one.)
108- method_configs = google .api_core .gapic_v1 .config .parse_method_configs (
158+ self . _method_configs = google .api_core .gapic_v1 .config .parse_method_configs (
109159 client_config ['interfaces' ][self ._INTERFACE_NAME ], )
110160
111- # Write the "inner API call" methods to the class.
112- # These are wrapped versions of the gRPC stub methods, with retry and
113- # timeout configuration applied, called by the public methods on
114- # this class.
115- self ._get_group = google .api_core .gapic_v1 .method .wrap_method (
116- self .error_group_service_stub .GetGroup ,
117- default_retry = method_configs ['GetGroup' ].retry ,
118- default_timeout = method_configs ['GetGroup' ].timeout ,
119- client_info = client_info ,
120- )
121- self ._update_group = google .api_core .gapic_v1 .method .wrap_method (
122- self .error_group_service_stub .UpdateGroup ,
123- default_retry = method_configs ['UpdateGroup' ].retry ,
124- default_timeout = method_configs ['UpdateGroup' ].timeout ,
125- client_info = client_info ,
126- )
161+ # Save a dictionary of cached API call functions.
162+ # These are the actual callables which invoke the proper
163+ # transport methods, wrapped with `wrap_method` to add retry,
164+ # timeout, and the like.
165+ self ._inner_api_calls = {}
127166
128167 # Service calls
129168 def get_group (self ,
@@ -171,12 +210,19 @@ def get_group(self,
171210 to a retryable error and retry attempts failed.
172211 ValueError: If the parameters are invalid.
173212 """
174- if metadata is None :
175- metadata = []
176- metadata = list (metadata )
213+ # Wrap the transport method to add retry and timeout logic.
214+ if 'get_group' not in self ._inner_api_calls :
215+ self ._inner_api_calls [
216+ 'get_group' ] = google .api_core .gapic_v1 .method .wrap_method (
217+ self .transport .get_group ,
218+ default_retry = self ._method_configs ['GetGroup' ].retry ,
219+ default_timeout = self ._method_configs ['GetGroup' ].timeout ,
220+ client_info = self ._client_info ,
221+ )
222+
177223 request = error_group_service_pb2 .GetGroupRequest (
178224 group_name = group_name , )
179- return self ._get_group (
225+ return self ._inner_api_calls [ 'get_group' ] (
180226 request , retry = retry , timeout = timeout , metadata = metadata )
181227
182228 def update_group (self ,
@@ -193,6 +239,7 @@ def update_group(self,
193239 >>>
194240 >>> client = errorreporting_v1beta1.ErrorGroupServiceClient()
195241 >>>
242+ >>> # TODO: Initialize ``group``:
196243 >>> group = {}
197244 >>>
198245 >>> response = client.update_group(group)
@@ -220,9 +267,17 @@ def update_group(self,
220267 to a retryable error and retry attempts failed.
221268 ValueError: If the parameters are invalid.
222269 """
223- if metadata is None :
224- metadata = []
225- metadata = list (metadata )
270+ # Wrap the transport method to add retry and timeout logic.
271+ if 'update_group' not in self ._inner_api_calls :
272+ self ._inner_api_calls [
273+ 'update_group' ] = google .api_core .gapic_v1 .method .wrap_method (
274+ self .transport .update_group ,
275+ default_retry = self ._method_configs ['UpdateGroup' ].retry ,
276+ default_timeout = self ._method_configs ['UpdateGroup' ].
277+ timeout ,
278+ client_info = self ._client_info ,
279+ )
280+
226281 request = error_group_service_pb2 .UpdateGroupRequest (group = group , )
227- return self ._update_group (
282+ return self ._inner_api_calls [ 'update_group' ] (
228283 request , retry = retry , timeout = timeout , metadata = metadata )
0 commit comments