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

49 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 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 

28 

29from google.cloud.errorreporting_v1beta1.types import error_stats_service 

30 

31DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

32 gapic_version=package_version.__version__ 

33) 

34 

35 

36class ErrorStatsServiceTransport(abc.ABC): 

37 """Abstract transport class for ErrorStatsService.""" 

38 

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

40 

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

42 

43 def __init__( 

44 self, 

45 *, 

46 host: str = DEFAULT_HOST, 

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

48 credentials_file: Optional[str] = None, 

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

50 quota_project_id: Optional[str] = None, 

51 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

52 always_use_jwt_access: Optional[bool] = False, 

53 api_audience: Optional[str] = None, 

54 **kwargs, 

55 ) -> None: 

56 """Instantiate the transport. 

57 

58 Args: 

59 host (Optional[str]): 

60 The hostname to connect to. 

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

62 authorization credentials to attach to requests. These 

63 credentials identify the application to the service; if none 

64 are specified, the client will attempt to ascertain the 

65 credentials from the environment. 

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

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

68 This argument is mutually exclusive with credentials. 

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

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

71 and quota. 

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

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

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

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

76 your own client library. 

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

78 be used for service account credentials. 

79 """ 

80 

81 scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} 

82 

83 # Save the scopes. 

84 self._scopes = scopes 

85 

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

87 # defaults. 

88 if credentials and credentials_file: 

89 raise core_exceptions.DuplicateCredentialArgs( 

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

91 ) 

92 

93 if credentials_file is not None: 

94 credentials, _ = google.auth.load_credentials_from_file( 

95 credentials_file, **scopes_kwargs, quota_project_id=quota_project_id 

96 ) 

97 elif credentials is None: 

98 credentials, _ = google.auth.default( 

99 **scopes_kwargs, quota_project_id=quota_project_id 

100 ) 

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

102 if hasattr(credentials, "with_gdch_audience"): 

103 credentials = credentials.with_gdch_audience( 

104 api_audience if api_audience else host 

105 ) 

106 

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

108 if ( 

109 always_use_jwt_access 

110 and isinstance(credentials, service_account.Credentials) 

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

112 ): 

113 credentials = credentials.with_always_use_jwt_access(True) 

114 

115 # Save the credentials. 

116 self._credentials = credentials 

117 

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

119 if ":" not in host: 

120 host += ":443" 

121 self._host = host 

122 

123 def _prep_wrapped_messages(self, client_info): 

124 # Precompute the wrapped methods. 

125 self._wrapped_methods = { 

126 self.list_group_stats: gapic_v1.method.wrap_method( 

127 self.list_group_stats, 

128 default_timeout=None, 

129 client_info=client_info, 

130 ), 

131 self.list_events: gapic_v1.method.wrap_method( 

132 self.list_events, 

133 default_timeout=None, 

134 client_info=client_info, 

135 ), 

136 self.delete_events: gapic_v1.method.wrap_method( 

137 self.delete_events, 

138 default_timeout=None, 

139 client_info=client_info, 

140 ), 

141 } 

142 

143 def close(self): 

144 """Closes resources associated with the transport. 

145 

146 .. warning:: 

147 Only call this method if the transport is NOT shared 

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

149 """ 

150 raise NotImplementedError() 

151 

152 @property 

153 def list_group_stats( 

154 self, 

155 ) -> Callable[ 

156 [error_stats_service.ListGroupStatsRequest], 

157 Union[ 

158 error_stats_service.ListGroupStatsResponse, 

159 Awaitable[error_stats_service.ListGroupStatsResponse], 

160 ], 

161 ]: 

162 raise NotImplementedError() 

163 

164 @property 

165 def list_events( 

166 self, 

167 ) -> Callable[ 

168 [error_stats_service.ListEventsRequest], 

169 Union[ 

170 error_stats_service.ListEventsResponse, 

171 Awaitable[error_stats_service.ListEventsResponse], 

172 ], 

173 ]: 

174 raise NotImplementedError() 

175 

176 @property 

177 def delete_events( 

178 self, 

179 ) -> Callable[ 

180 [error_stats_service.DeleteEventsRequest], 

181 Union[ 

182 error_stats_service.DeleteEventsResponse, 

183 Awaitable[error_stats_service.DeleteEventsResponse], 

184 ], 

185 ]: 

186 raise NotImplementedError() 

187 

188 @property 

189 def kind(self) -> str: 

190 raise NotImplementedError() 

191 

192 

193__all__ = ("ErrorStatsServiceTransport",)