Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/cloud/resourcemanager_v3/services/tag_bindings/transports/base.py: 58%

59 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-06 06:03 +0000

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

2# Copyright 2022 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 

19import google.api_core 

20from google.api_core import exceptions as core_exceptions 

21from google.api_core import gapic_v1, operations_v1 

22from google.api_core import retry as retries 

23import google.auth # type: ignore 

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

25from google.longrunning import operations_pb2 # type: ignore 

26from google.oauth2 import service_account # type: ignore 

27 

28from google.cloud.resourcemanager_v3 import gapic_version as package_version 

29from google.cloud.resourcemanager_v3.types import tag_bindings 

30 

31DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

32 gapic_version=package_version.__version__ 

33) 

34 

35 

36class TagBindingsTransport(abc.ABC): 

37 """Abstract transport class for TagBindings.""" 

38 

39 AUTH_SCOPES = ( 

40 "https://www.googleapis.com/auth/cloud-platform", 

41 "https://www.googleapis.com/auth/cloud-platform.read-only", 

42 ) 

43 

44 DEFAULT_HOST: str = "cloudresourcemanager.googleapis.com" 

45 

46 def __init__( 

47 self, 

48 *, 

49 host: str = DEFAULT_HOST, 

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

51 credentials_file: Optional[str] = None, 

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

53 quota_project_id: Optional[str] = None, 

54 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

55 always_use_jwt_access: Optional[bool] = False, 

56 api_audience: Optional[str] = None, 

57 **kwargs, 

58 ) -> None: 

59 """Instantiate the transport. 

60 

61 Args: 

62 host (Optional[str]): 

63 The hostname to connect to. 

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

65 authorization credentials to attach to requests. These 

66 credentials identify the application to the service; if none 

67 are specified, the client will attempt to ascertain the 

68 credentials from the environment. 

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

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

71 This argument is mutually exclusive with credentials. 

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

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

74 and quota. 

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

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

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

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

79 your own client library. 

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

81 be used for service account credentials. 

82 """ 

83 

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

85 

86 # Save the scopes. 

87 self._scopes = scopes 

88 

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

90 # defaults. 

91 if credentials and credentials_file: 

92 raise core_exceptions.DuplicateCredentialArgs( 

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

94 ) 

95 

96 if credentials_file is not None: 

97 credentials, _ = google.auth.load_credentials_from_file( 

98 credentials_file, **scopes_kwargs, quota_project_id=quota_project_id 

99 ) 

100 elif credentials is None: 

101 credentials, _ = google.auth.default( 

102 **scopes_kwargs, quota_project_id=quota_project_id 

103 ) 

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

105 if hasattr(credentials, "with_gdch_audience"): 

106 credentials = credentials.with_gdch_audience( 

107 api_audience if api_audience else host 

108 ) 

109 

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

111 if ( 

112 always_use_jwt_access 

113 and isinstance(credentials, service_account.Credentials) 

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

115 ): 

116 credentials = credentials.with_always_use_jwt_access(True) 

117 

118 # Save the credentials. 

119 self._credentials = credentials 

120 

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

122 if ":" not in host: 

123 host += ":443" 

124 self._host = host 

125 

126 def _prep_wrapped_messages(self, client_info): 

127 # Precompute the wrapped methods. 

128 self._wrapped_methods = { 

129 self.list_tag_bindings: gapic_v1.method.wrap_method( 

130 self.list_tag_bindings, 

131 default_retry=retries.Retry( 

132 initial=0.1, 

133 maximum=60.0, 

134 multiplier=1.3, 

135 predicate=retries.if_exception_type( 

136 core_exceptions.ServiceUnavailable, 

137 ), 

138 deadline=60.0, 

139 ), 

140 default_timeout=60.0, 

141 client_info=client_info, 

142 ), 

143 self.create_tag_binding: gapic_v1.method.wrap_method( 

144 self.create_tag_binding, 

145 default_timeout=60.0, 

146 client_info=client_info, 

147 ), 

148 self.delete_tag_binding: gapic_v1.method.wrap_method( 

149 self.delete_tag_binding, 

150 default_timeout=60.0, 

151 client_info=client_info, 

152 ), 

153 self.list_effective_tags: gapic_v1.method.wrap_method( 

154 self.list_effective_tags, 

155 default_timeout=None, 

156 client_info=client_info, 

157 ), 

158 } 

159 

160 def close(self): 

161 """Closes resources associated with the transport. 

162 

163 .. warning:: 

164 Only call this method if the transport is NOT shared 

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

166 """ 

167 raise NotImplementedError() 

168 

169 @property 

170 def operations_client(self): 

171 """Return the client designed to process long-running operations.""" 

172 raise NotImplementedError() 

173 

174 @property 

175 def list_tag_bindings( 

176 self, 

177 ) -> Callable[ 

178 [tag_bindings.ListTagBindingsRequest], 

179 Union[ 

180 tag_bindings.ListTagBindingsResponse, 

181 Awaitable[tag_bindings.ListTagBindingsResponse], 

182 ], 

183 ]: 

184 raise NotImplementedError() 

185 

186 @property 

187 def create_tag_binding( 

188 self, 

189 ) -> Callable[ 

190 [tag_bindings.CreateTagBindingRequest], 

191 Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], 

192 ]: 

193 raise NotImplementedError() 

194 

195 @property 

196 def delete_tag_binding( 

197 self, 

198 ) -> Callable[ 

199 [tag_bindings.DeleteTagBindingRequest], 

200 Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], 

201 ]: 

202 raise NotImplementedError() 

203 

204 @property 

205 def list_effective_tags( 

206 self, 

207 ) -> Callable[ 

208 [tag_bindings.ListEffectiveTagsRequest], 

209 Union[ 

210 tag_bindings.ListEffectiveTagsResponse, 

211 Awaitable[tag_bindings.ListEffectiveTagsResponse], 

212 ], 

213 ]: 

214 raise NotImplementedError() 

215 

216 @property 

217 def get_operation( 

218 self, 

219 ) -> Callable[ 

220 [operations_pb2.GetOperationRequest], 

221 Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], 

222 ]: 

223 raise NotImplementedError() 

224 

225 @property 

226 def kind(self) -> str: 

227 raise NotImplementedError() 

228 

229 

230__all__ = ("TagBindingsTransport",)