Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/base.py: 55%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

55 statements  

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

2# Copyright 2025 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 abc 

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

18 

19from google.cloud.errorreporting_v1beta1 import gapic_version as package_version 

20 

21import google.auth # type: ignore 

22import google.api_core 

23from google.api_core import exceptions as core_exceptions 

24from google.api_core import gapic_v1 

25from google.api_core import retry as retries 

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

27from google.oauth2 import service_account # type: ignore 

28import google.protobuf 

29 

30from google.cloud.errorreporting_v1beta1.types import error_stats_service 

31 

32DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

33 gapic_version=package_version.__version__ 

34) 

35 

36if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER 

37 DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ 

38 

39 

40class ErrorStatsServiceTransport(abc.ABC): 

41 """Abstract transport class for ErrorStatsService.""" 

42 

43 AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) 

44 

45 DEFAULT_HOST: str = "clouderrorreporting.googleapis.com" 

46 

47 def __init__( 

48 self, 

49 *, 

50 host: str = DEFAULT_HOST, 

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

52 credentials_file: Optional[str] = None, 

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

54 quota_project_id: Optional[str] = None, 

55 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

56 always_use_jwt_access: Optional[bool] = False, 

57 api_audience: Optional[str] = None, 

58 **kwargs, 

59 ) -> None: 

60 """Instantiate the transport. 

61 

62 Args: 

63 host (Optional[str]): 

64 The hostname to connect to (default: 'clouderrorreporting.googleapis.com'). 

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

66 authorization credentials to attach to requests. These 

67 credentials identify the application to the service; if none 

68 are specified, the client will attempt to ascertain the 

69 credentials from the environment. 

70 credentials_file (Optional[str]): Deprecated. A file with credentials that can 

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

72 This argument is mutually exclusive with credentials. This argument will be 

73 removed in the next major version of this library. 

74 scopes (Optional[Sequence[str]]): A list of scopes. 

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

76 and quota. 

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

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

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

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

81 your own client library. 

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

83 be used for service account credentials. 

84 """ 

85 

86 # Save the scopes. 

87 self._scopes = scopes 

88 if not hasattr(self, "_ignore_credentials"): 

89 self._ignore_credentials: bool = False 

90 

91 # If no credentials are provided, then determine the appropriate 

92 # defaults. 

93 if credentials and credentials_file: 

94 raise core_exceptions.DuplicateCredentialArgs( 

95 "'credentials_file' and 'credentials' are mutually exclusive" 

96 ) 

97 

98 if credentials_file is not None: 

99 credentials, _ = google.auth.load_credentials_from_file( 

100 credentials_file, 

101 scopes=scopes, 

102 quota_project_id=quota_project_id, 

103 default_scopes=self.AUTH_SCOPES, 

104 ) 

105 elif credentials is None and not self._ignore_credentials: 

106 credentials, _ = google.auth.default( 

107 scopes=scopes, 

108 quota_project_id=quota_project_id, 

109 default_scopes=self.AUTH_SCOPES, 

110 ) 

111 # Don't apply audience if the credentials file passed from user. 

112 if hasattr(credentials, "with_gdch_audience"): 

113 credentials = credentials.with_gdch_audience( 

114 api_audience if api_audience else host 

115 ) 

116 

117 # If the credentials are service account credentials, then always try to use self signed JWT. 

118 if ( 

119 always_use_jwt_access 

120 and isinstance(credentials, service_account.Credentials) 

121 and hasattr(service_account.Credentials, "with_always_use_jwt_access") 

122 ): 

123 credentials = credentials.with_always_use_jwt_access(True) 

124 

125 # Save the credentials. 

126 self._credentials = credentials 

127 

128 # Save the hostname. Default to port 443 (HTTPS) if none is specified. 

129 if ":" not in host: 

130 host += ":443" 

131 self._host = host 

132 

133 @property 

134 def host(self): 

135 return self._host 

136 

137 def _prep_wrapped_messages(self, client_info): 

138 # Precompute the wrapped methods. 

139 self._wrapped_methods = { 

140 self.list_group_stats: gapic_v1.method.wrap_method( 

141 self.list_group_stats, 

142 default_timeout=None, 

143 client_info=client_info, 

144 ), 

145 self.list_events: gapic_v1.method.wrap_method( 

146 self.list_events, 

147 default_timeout=None, 

148 client_info=client_info, 

149 ), 

150 self.delete_events: gapic_v1.method.wrap_method( 

151 self.delete_events, 

152 default_timeout=None, 

153 client_info=client_info, 

154 ), 

155 } 

156 

157 def close(self): 

158 """Closes resources associated with the transport. 

159 

160 .. warning:: 

161 Only call this method if the transport is NOT shared 

162 with other clients - this may cause errors in other clients! 

163 """ 

164 raise NotImplementedError() 

165 

166 @property 

167 def list_group_stats( 

168 self, 

169 ) -> Callable[ 

170 [error_stats_service.ListGroupStatsRequest], 

171 Union[ 

172 error_stats_service.ListGroupStatsResponse, 

173 Awaitable[error_stats_service.ListGroupStatsResponse], 

174 ], 

175 ]: 

176 raise NotImplementedError() 

177 

178 @property 

179 def list_events( 

180 self, 

181 ) -> Callable[ 

182 [error_stats_service.ListEventsRequest], 

183 Union[ 

184 error_stats_service.ListEventsResponse, 

185 Awaitable[error_stats_service.ListEventsResponse], 

186 ], 

187 ]: 

188 raise NotImplementedError() 

189 

190 @property 

191 def delete_events( 

192 self, 

193 ) -> Callable[ 

194 [error_stats_service.DeleteEventsRequest], 

195 Union[ 

196 error_stats_service.DeleteEventsResponse, 

197 Awaitable[error_stats_service.DeleteEventsResponse], 

198 ], 

199 ]: 

200 raise NotImplementedError() 

201 

202 @property 

203 def kind(self) -> str: 

204 raise NotImplementedError() 

205 

206 

207__all__ = ("ErrorStatsServiceTransport",)