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

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

54 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 common 

31from google.cloud.errorreporting_v1beta1.types import error_group_service 

32 

33DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

34 gapic_version=package_version.__version__ 

35) 

36 

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

38 DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ 

39 

40 

41class ErrorGroupServiceTransport(abc.ABC): 

42 """Abstract transport class for ErrorGroupService.""" 

43 

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

45 

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

47 

48 def __init__( 

49 self, 

50 *, 

51 host: str = DEFAULT_HOST, 

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

53 credentials_file: Optional[str] = None, 

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

55 quota_project_id: Optional[str] = None, 

56 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

57 always_use_jwt_access: Optional[bool] = False, 

58 api_audience: Optional[str] = None, 

59 **kwargs, 

60 ) -> None: 

61 """Instantiate the transport. 

62 

63 Args: 

64 host (Optional[str]): 

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

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

67 authorization credentials to attach to requests. These 

68 credentials identify the application to the service; if none 

69 are specified, the client will attempt to ascertain the 

70 credentials from the environment. 

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

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

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

74 removed in the next major version of this library. 

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

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

77 and quota. 

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

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

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

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

82 your own client library. 

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

84 be used for service account credentials. 

85 """ 

86 

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

88 

89 # Save the scopes. 

90 self._scopes = scopes 

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

92 self._ignore_credentials: bool = False 

93 

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

95 # defaults. 

96 if credentials and credentials_file: 

97 raise core_exceptions.DuplicateCredentialArgs( 

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

99 ) 

100 

101 if credentials_file is not None: 

102 credentials, _ = google.auth.load_credentials_from_file( 

103 credentials_file, **scopes_kwargs, quota_project_id=quota_project_id 

104 ) 

105 elif credentials is None and not self._ignore_credentials: 

106 credentials, _ = google.auth.default( 

107 **scopes_kwargs, quota_project_id=quota_project_id 

108 ) 

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

110 if hasattr(credentials, "with_gdch_audience"): 

111 credentials = credentials.with_gdch_audience( 

112 api_audience if api_audience else host 

113 ) 

114 

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

116 if ( 

117 always_use_jwt_access 

118 and isinstance(credentials, service_account.Credentials) 

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

120 ): 

121 credentials = credentials.with_always_use_jwt_access(True) 

122 

123 # Save the credentials. 

124 self._credentials = credentials 

125 

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

127 if ":" not in host: 

128 host += ":443" 

129 self._host = host 

130 

131 @property 

132 def host(self): 

133 return self._host 

134 

135 def _prep_wrapped_messages(self, client_info): 

136 # Precompute the wrapped methods. 

137 self._wrapped_methods = { 

138 self.get_group: gapic_v1.method.wrap_method( 

139 self.get_group, 

140 default_timeout=None, 

141 client_info=client_info, 

142 ), 

143 self.update_group: gapic_v1.method.wrap_method( 

144 self.update_group, 

145 default_timeout=None, 

146 client_info=client_info, 

147 ), 

148 } 

149 

150 def close(self): 

151 """Closes resources associated with the transport. 

152 

153 .. warning:: 

154 Only call this method if the transport is NOT shared 

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

156 """ 

157 raise NotImplementedError() 

158 

159 @property 

160 def get_group( 

161 self, 

162 ) -> Callable[ 

163 [error_group_service.GetGroupRequest], 

164 Union[common.ErrorGroup, Awaitable[common.ErrorGroup]], 

165 ]: 

166 raise NotImplementedError() 

167 

168 @property 

169 def update_group( 

170 self, 

171 ) -> Callable[ 

172 [error_group_service.UpdateGroupRequest], 

173 Union[common.ErrorGroup, Awaitable[common.ErrorGroup]], 

174 ]: 

175 raise NotImplementedError() 

176 

177 @property 

178 def kind(self) -> str: 

179 raise NotImplementedError() 

180 

181 

182__all__ = ("ErrorGroupServiceTransport",)