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

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

30from google.cloud.errorreporting_v1beta1.types import error_group_service 

31 

32DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

33 gapic_version=package_version.__version__ 

34) 

35 

36 

37class ErrorGroupServiceTransport(abc.ABC): 

38 """Abstract transport class for ErrorGroupService.""" 

39 

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

41 

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

43 

44 def __init__( 

45 self, 

46 *, 

47 host: str = DEFAULT_HOST, 

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

49 credentials_file: Optional[str] = None, 

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

51 quota_project_id: Optional[str] = None, 

52 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

53 always_use_jwt_access: Optional[bool] = False, 

54 api_audience: Optional[str] = None, 

55 **kwargs, 

56 ) -> None: 

57 """Instantiate the transport. 

58 

59 Args: 

60 host (Optional[str]): 

61 The hostname to connect to. 

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

63 authorization credentials to attach to requests. These 

64 credentials identify the application to the service; if none 

65 are specified, the client will attempt to ascertain the 

66 credentials from the environment. 

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

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

69 This argument is mutually exclusive with credentials. 

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

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

72 and quota. 

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

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

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

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

77 your own client library. 

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

79 be used for service account credentials. 

80 """ 

81 

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

83 

84 # Save the scopes. 

85 self._scopes = scopes 

86 

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

88 # defaults. 

89 if credentials and credentials_file: 

90 raise core_exceptions.DuplicateCredentialArgs( 

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

92 ) 

93 

94 if credentials_file is not None: 

95 credentials, _ = google.auth.load_credentials_from_file( 

96 credentials_file, **scopes_kwargs, quota_project_id=quota_project_id 

97 ) 

98 elif credentials is None: 

99 credentials, _ = google.auth.default( 

100 **scopes_kwargs, quota_project_id=quota_project_id 

101 ) 

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

103 if hasattr(credentials, "with_gdch_audience"): 

104 credentials = credentials.with_gdch_audience( 

105 api_audience if api_audience else host 

106 ) 

107 

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

109 if ( 

110 always_use_jwt_access 

111 and isinstance(credentials, service_account.Credentials) 

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

113 ): 

114 credentials = credentials.with_always_use_jwt_access(True) 

115 

116 # Save the credentials. 

117 self._credentials = credentials 

118 

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

120 if ":" not in host: 

121 host += ":443" 

122 self._host = host 

123 

124 def _prep_wrapped_messages(self, client_info): 

125 # Precompute the wrapped methods. 

126 self._wrapped_methods = { 

127 self.get_group: gapic_v1.method.wrap_method( 

128 self.get_group, 

129 default_timeout=None, 

130 client_info=client_info, 

131 ), 

132 self.update_group: gapic_v1.method.wrap_method( 

133 self.update_group, 

134 default_timeout=None, 

135 client_info=client_info, 

136 ), 

137 } 

138 

139 def close(self): 

140 """Closes resources associated with the transport. 

141 

142 .. warning:: 

143 Only call this method if the transport is NOT shared 

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

145 """ 

146 raise NotImplementedError() 

147 

148 @property 

149 def get_group( 

150 self, 

151 ) -> Callable[ 

152 [error_group_service.GetGroupRequest], 

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

154 ]: 

155 raise NotImplementedError() 

156 

157 @property 

158 def update_group( 

159 self, 

160 ) -> Callable[ 

161 [error_group_service.UpdateGroupRequest], 

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

163 ]: 

164 raise NotImplementedError() 

165 

166 @property 

167 def kind(self) -> str: 

168 raise NotImplementedError() 

169 

170 

171__all__ = ("ErrorGroupServiceTransport",)