Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/cloud/errorreporting_v1beta1/services/error_group_service/transports/grpc.py: 43%

60 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-08 06:45 +0000

1# -*- coding: utf-8 -*- 

2# Copyright 2023 Google LLC 

3# 

4# Licensed under the Apache License, Version 2.0 (the "License"); 

5# you may not use this file except in compliance with the License. 

6# You may obtain a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

10# Unless required by applicable law or agreed to in writing, software 

11# distributed under the License is distributed on an "AS IS" BASIS, 

12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

13# See the License for the specific language governing permissions and 

14# limitations under the License. 

15# 

16import warnings 

17from typing import Callable, Dict, Optional, Sequence, Tuple, Union 

18 

19from google.api_core import grpc_helpers 

20from google.api_core import gapic_v1 

21import google.auth # type: ignore 

22from google.auth import credentials as ga_credentials # type: ignore 

23from google.auth.transport.grpc import SslCredentials # type: ignore 

24 

25import grpc # type: ignore 

26 

27from google.cloud.errorreporting_v1beta1.types import common 

28from google.cloud.errorreporting_v1beta1.types import error_group_service 

29from .base import ErrorGroupServiceTransport, DEFAULT_CLIENT_INFO 

30 

31 

32class ErrorGroupServiceGrpcTransport(ErrorGroupServiceTransport): 

33 """gRPC backend transport for ErrorGroupService. 

34 

35 Service for retrieving and updating individual error groups. 

36 

37 This class defines the same methods as the primary client, so the 

38 primary client can load the underlying transport implementation 

39 and call it. 

40 

41 It sends protocol buffers over the wire using gRPC (which is built on 

42 top of HTTP/2); the ``grpcio`` package must be installed. 

43 """ 

44 

45 _stubs: Dict[str, Callable] 

46 

47 def __init__( 

48 self, 

49 *, 

50 host: str = "clouderrorreporting.googleapis.com", 

51 credentials: Optional[ga_credentials.Credentials] = None, 

52 credentials_file: Optional[str] = None, 

53 scopes: Optional[Sequence[str]] = None, 

54 channel: Optional[grpc.Channel] = None, 

55 api_mtls_endpoint: Optional[str] = None, 

56 client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, 

57 ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, 

58 client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, 

59 quota_project_id: Optional[str] = None, 

60 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

61 always_use_jwt_access: Optional[bool] = False, 

62 api_audience: Optional[str] = None, 

63 ) -> None: 

64 """Instantiate the transport. 

65 

66 Args: 

67 host (Optional[str]): 

68 The hostname to connect to. 

69 credentials (Optional[google.auth.credentials.Credentials]): The 

70 authorization credentials to attach to requests. These 

71 credentials identify the application to the service; if none 

72 are specified, the client will attempt to ascertain the 

73 credentials from the environment. 

74 This argument is ignored if ``channel`` is provided. 

75 credentials_file (Optional[str]): A file with credentials that can 

76 be loaded with :func:`google.auth.load_credentials_from_file`. 

77 This argument is ignored if ``channel`` is provided. 

78 scopes (Optional(Sequence[str])): A list of scopes. This argument is 

79 ignored if ``channel`` is provided. 

80 channel (Optional[grpc.Channel]): A ``Channel`` instance through 

81 which to make calls. 

82 api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. 

83 If provided, it overrides the ``host`` argument and tries to create 

84 a mutual TLS channel with client SSL credentials from 

85 ``client_cert_source`` or application default SSL credentials. 

86 client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): 

87 Deprecated. A callback to provide client SSL certificate bytes and 

88 private key bytes, both in PEM format. It is ignored if 

89 ``api_mtls_endpoint`` is None. 

90 ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials 

91 for the grpc channel. It is ignored if ``channel`` is provided. 

92 client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): 

93 A callback to provide client certificate bytes and private key bytes, 

94 both in PEM format. It is used to configure a mutual TLS channel. It is 

95 ignored if ``channel`` or ``ssl_channel_credentials`` is provided. 

96 quota_project_id (Optional[str]): An optional project to use for billing 

97 and quota. 

98 client_info (google.api_core.gapic_v1.client_info.ClientInfo): 

99 The client info used to send a user-agent string along with 

100 API requests. If ``None``, then default info will be used. 

101 Generally, you only need to set this if you're developing 

102 your own client library. 

103 always_use_jwt_access (Optional[bool]): Whether self signed JWT should 

104 be used for service account credentials. 

105 

106 Raises: 

107 google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport 

108 creation failed for any reason. 

109 google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` 

110 and ``credentials_file`` are passed. 

111 """ 

112 self._grpc_channel = None 

113 self._ssl_channel_credentials = ssl_channel_credentials 

114 self._stubs: Dict[str, Callable] = {} 

115 

116 if api_mtls_endpoint: 

117 warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) 

118 if client_cert_source: 

119 warnings.warn("client_cert_source is deprecated", DeprecationWarning) 

120 

121 if channel: 

122 # Ignore credentials if a channel was passed. 

123 credentials = False 

124 # If a channel was explicitly provided, set it. 

125 self._grpc_channel = channel 

126 self._ssl_channel_credentials = None 

127 

128 else: 

129 if api_mtls_endpoint: 

130 host = api_mtls_endpoint 

131 

132 # Create SSL credentials with client_cert_source or application 

133 # default SSL credentials. 

134 if client_cert_source: 

135 cert, key = client_cert_source() 

136 self._ssl_channel_credentials = grpc.ssl_channel_credentials( 

137 certificate_chain=cert, private_key=key 

138 ) 

139 else: 

140 self._ssl_channel_credentials = SslCredentials().ssl_credentials 

141 

142 else: 

143 if client_cert_source_for_mtls and not ssl_channel_credentials: 

144 cert, key = client_cert_source_for_mtls() 

145 self._ssl_channel_credentials = grpc.ssl_channel_credentials( 

146 certificate_chain=cert, private_key=key 

147 ) 

148 

149 # The base transport sets the host, credentials and scopes 

150 super().__init__( 

151 host=host, 

152 credentials=credentials, 

153 credentials_file=credentials_file, 

154 scopes=scopes, 

155 quota_project_id=quota_project_id, 

156 client_info=client_info, 

157 always_use_jwt_access=always_use_jwt_access, 

158 api_audience=api_audience, 

159 ) 

160 

161 if not self._grpc_channel: 

162 self._grpc_channel = type(self).create_channel( 

163 self._host, 

164 # use the credentials which are saved 

165 credentials=self._credentials, 

166 # Set ``credentials_file`` to ``None`` here as 

167 # the credentials that we saved earlier should be used. 

168 credentials_file=None, 

169 scopes=self._scopes, 

170 ssl_credentials=self._ssl_channel_credentials, 

171 quota_project_id=quota_project_id, 

172 options=[ 

173 ("grpc.max_send_message_length", -1), 

174 ("grpc.max_receive_message_length", -1), 

175 ], 

176 ) 

177 

178 # Wrap messages. This must be done after self._grpc_channel exists 

179 self._prep_wrapped_messages(client_info) 

180 

181 @classmethod 

182 def create_channel( 

183 cls, 

184 host: str = "clouderrorreporting.googleapis.com", 

185 credentials: Optional[ga_credentials.Credentials] = None, 

186 credentials_file: Optional[str] = None, 

187 scopes: Optional[Sequence[str]] = None, 

188 quota_project_id: Optional[str] = None, 

189 **kwargs, 

190 ) -> grpc.Channel: 

191 """Create and return a gRPC channel object. 

192 Args: 

193 host (Optional[str]): The host for the channel to use. 

194 credentials (Optional[~.Credentials]): The 

195 authorization credentials to attach to requests. These 

196 credentials identify this application to the service. If 

197 none are specified, the client will attempt to ascertain 

198 the credentials from the environment. 

199 credentials_file (Optional[str]): A file with credentials that can 

200 be loaded with :func:`google.auth.load_credentials_from_file`. 

201 This argument is mutually exclusive with credentials. 

202 scopes (Optional[Sequence[str]]): A optional list of scopes needed for this 

203 service. These are only used when credentials are not specified and 

204 are passed to :func:`google.auth.default`. 

205 quota_project_id (Optional[str]): An optional project to use for billing 

206 and quota. 

207 kwargs (Optional[dict]): Keyword arguments, which are passed to the 

208 channel creation. 

209 Returns: 

210 grpc.Channel: A gRPC channel object. 

211 

212 Raises: 

213 google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` 

214 and ``credentials_file`` are passed. 

215 """ 

216 

217 return grpc_helpers.create_channel( 

218 host, 

219 credentials=credentials, 

220 credentials_file=credentials_file, 

221 quota_project_id=quota_project_id, 

222 default_scopes=cls.AUTH_SCOPES, 

223 scopes=scopes, 

224 default_host=cls.DEFAULT_HOST, 

225 **kwargs, 

226 ) 

227 

228 @property 

229 def grpc_channel(self) -> grpc.Channel: 

230 """Return the channel designed to connect to this service.""" 

231 return self._grpc_channel 

232 

233 @property 

234 def get_group( 

235 self, 

236 ) -> Callable[[error_group_service.GetGroupRequest], common.ErrorGroup]: 

237 r"""Return a callable for the get group method over gRPC. 

238 

239 Get the specified group. 

240 

241 Returns: 

242 Callable[[~.GetGroupRequest], 

243 ~.ErrorGroup]: 

244 A function that, when called, will call the underlying RPC 

245 on the server. 

246 """ 

247 # Generate a "stub function" on-the-fly which will actually make 

248 # the request. 

249 # gRPC handles serialization and deserialization, so we just need 

250 # to pass in the functions for each. 

251 if "get_group" not in self._stubs: 

252 self._stubs["get_group"] = self.grpc_channel.unary_unary( 

253 "/google.devtools.clouderrorreporting.v1beta1.ErrorGroupService/GetGroup", 

254 request_serializer=error_group_service.GetGroupRequest.serialize, 

255 response_deserializer=common.ErrorGroup.deserialize, 

256 ) 

257 return self._stubs["get_group"] 

258 

259 @property 

260 def update_group( 

261 self, 

262 ) -> Callable[[error_group_service.UpdateGroupRequest], common.ErrorGroup]: 

263 r"""Return a callable for the update group method over gRPC. 

264 

265 Replace the data for the specified group. 

266 Fails if the group does not exist. 

267 

268 Returns: 

269 Callable[[~.UpdateGroupRequest], 

270 ~.ErrorGroup]: 

271 A function that, when called, will call the underlying RPC 

272 on the server. 

273 """ 

274 # Generate a "stub function" on-the-fly which will actually make 

275 # the request. 

276 # gRPC handles serialization and deserialization, so we just need 

277 # to pass in the functions for each. 

278 if "update_group" not in self._stubs: 

279 self._stubs["update_group"] = self.grpc_channel.unary_unary( 

280 "/google.devtools.clouderrorreporting.v1beta1.ErrorGroupService/UpdateGroup", 

281 request_serializer=error_group_service.UpdateGroupRequest.serialize, 

282 response_deserializer=common.ErrorGroup.deserialize, 

283 ) 

284 return self._stubs["update_group"] 

285 

286 def close(self): 

287 self.grpc_channel.close() 

288 

289 @property 

290 def kind(self) -> str: 

291 return "grpc" 

292 

293 

294__all__ = ("ErrorGroupServiceGrpcTransport",)