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

82 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.iam.v1 import iam_policy_pb2 # type: ignore 

26from google.iam.v1 import policy_pb2 # type: ignore 

27from google.longrunning import operations_pb2 # type: ignore 

28from google.oauth2 import service_account # type: ignore 

29 

30from google.cloud.resourcemanager_v3 import gapic_version as package_version 

31from google.cloud.resourcemanager_v3.types import folders 

32 

33DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

34 gapic_version=package_version.__version__ 

35) 

36 

37 

38class FoldersTransport(abc.ABC): 

39 """Abstract transport class for Folders.""" 

40 

41 AUTH_SCOPES = ( 

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

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

44 ) 

45 

46 DEFAULT_HOST: str = "cloudresourcemanager.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. 

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]): 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. 

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 scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} 

87 

88 # Save the scopes. 

89 self._scopes = scopes 

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, **scopes_kwargs, quota_project_id=quota_project_id 

101 ) 

102 elif credentials is None: 

103 credentials, _ = google.auth.default( 

104 **scopes_kwargs, quota_project_id=quota_project_id 

105 ) 

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

107 if hasattr(credentials, "with_gdch_audience"): 

108 credentials = credentials.with_gdch_audience( 

109 api_audience if api_audience else host 

110 ) 

111 

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

113 if ( 

114 always_use_jwt_access 

115 and isinstance(credentials, service_account.Credentials) 

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

117 ): 

118 credentials = credentials.with_always_use_jwt_access(True) 

119 

120 # Save the credentials. 

121 self._credentials = credentials 

122 

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

124 if ":" not in host: 

125 host += ":443" 

126 self._host = host 

127 

128 def _prep_wrapped_messages(self, client_info): 

129 # Precompute the wrapped methods. 

130 self._wrapped_methods = { 

131 self.get_folder: gapic_v1.method.wrap_method( 

132 self.get_folder, 

133 default_retry=retries.Retry( 

134 initial=0.1, 

135 maximum=60.0, 

136 multiplier=1.3, 

137 predicate=retries.if_exception_type( 

138 core_exceptions.ServiceUnavailable, 

139 ), 

140 deadline=60.0, 

141 ), 

142 default_timeout=60.0, 

143 client_info=client_info, 

144 ), 

145 self.list_folders: gapic_v1.method.wrap_method( 

146 self.list_folders, 

147 default_retry=retries.Retry( 

148 initial=0.1, 

149 maximum=60.0, 

150 multiplier=1.3, 

151 predicate=retries.if_exception_type( 

152 core_exceptions.ServiceUnavailable, 

153 ), 

154 deadline=60.0, 

155 ), 

156 default_timeout=60.0, 

157 client_info=client_info, 

158 ), 

159 self.search_folders: gapic_v1.method.wrap_method( 

160 self.search_folders, 

161 default_timeout=60.0, 

162 client_info=client_info, 

163 ), 

164 self.create_folder: gapic_v1.method.wrap_method( 

165 self.create_folder, 

166 default_timeout=60.0, 

167 client_info=client_info, 

168 ), 

169 self.update_folder: gapic_v1.method.wrap_method( 

170 self.update_folder, 

171 default_timeout=60.0, 

172 client_info=client_info, 

173 ), 

174 self.move_folder: gapic_v1.method.wrap_method( 

175 self.move_folder, 

176 default_timeout=60.0, 

177 client_info=client_info, 

178 ), 

179 self.delete_folder: gapic_v1.method.wrap_method( 

180 self.delete_folder, 

181 default_timeout=60.0, 

182 client_info=client_info, 

183 ), 

184 self.undelete_folder: gapic_v1.method.wrap_method( 

185 self.undelete_folder, 

186 default_timeout=60.0, 

187 client_info=client_info, 

188 ), 

189 self.get_iam_policy: gapic_v1.method.wrap_method( 

190 self.get_iam_policy, 

191 default_retry=retries.Retry( 

192 initial=0.1, 

193 maximum=60.0, 

194 multiplier=1.3, 

195 predicate=retries.if_exception_type( 

196 core_exceptions.ServiceUnavailable, 

197 ), 

198 deadline=60.0, 

199 ), 

200 default_timeout=60.0, 

201 client_info=client_info, 

202 ), 

203 self.set_iam_policy: gapic_v1.method.wrap_method( 

204 self.set_iam_policy, 

205 default_timeout=60.0, 

206 client_info=client_info, 

207 ), 

208 self.test_iam_permissions: gapic_v1.method.wrap_method( 

209 self.test_iam_permissions, 

210 default_timeout=None, 

211 client_info=client_info, 

212 ), 

213 } 

214 

215 def close(self): 

216 """Closes resources associated with the transport. 

217 

218 .. warning:: 

219 Only call this method if the transport is NOT shared 

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

221 """ 

222 raise NotImplementedError() 

223 

224 @property 

225 def operations_client(self): 

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

227 raise NotImplementedError() 

228 

229 @property 

230 def get_folder( 

231 self, 

232 ) -> Callable[ 

233 [folders.GetFolderRequest], Union[folders.Folder, Awaitable[folders.Folder]] 

234 ]: 

235 raise NotImplementedError() 

236 

237 @property 

238 def list_folders( 

239 self, 

240 ) -> Callable[ 

241 [folders.ListFoldersRequest], 

242 Union[folders.ListFoldersResponse, Awaitable[folders.ListFoldersResponse]], 

243 ]: 

244 raise NotImplementedError() 

245 

246 @property 

247 def search_folders( 

248 self, 

249 ) -> Callable[ 

250 [folders.SearchFoldersRequest], 

251 Union[folders.SearchFoldersResponse, Awaitable[folders.SearchFoldersResponse]], 

252 ]: 

253 raise NotImplementedError() 

254 

255 @property 

256 def create_folder( 

257 self, 

258 ) -> Callable[ 

259 [folders.CreateFolderRequest], 

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

261 ]: 

262 raise NotImplementedError() 

263 

264 @property 

265 def update_folder( 

266 self, 

267 ) -> Callable[ 

268 [folders.UpdateFolderRequest], 

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

270 ]: 

271 raise NotImplementedError() 

272 

273 @property 

274 def move_folder( 

275 self, 

276 ) -> Callable[ 

277 [folders.MoveFolderRequest], 

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

279 ]: 

280 raise NotImplementedError() 

281 

282 @property 

283 def delete_folder( 

284 self, 

285 ) -> Callable[ 

286 [folders.DeleteFolderRequest], 

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

288 ]: 

289 raise NotImplementedError() 

290 

291 @property 

292 def undelete_folder( 

293 self, 

294 ) -> Callable[ 

295 [folders.UndeleteFolderRequest], 

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

297 ]: 

298 raise NotImplementedError() 

299 

300 @property 

301 def get_iam_policy( 

302 self, 

303 ) -> Callable[ 

304 [iam_policy_pb2.GetIamPolicyRequest], 

305 Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], 

306 ]: 

307 raise NotImplementedError() 

308 

309 @property 

310 def set_iam_policy( 

311 self, 

312 ) -> Callable[ 

313 [iam_policy_pb2.SetIamPolicyRequest], 

314 Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], 

315 ]: 

316 raise NotImplementedError() 

317 

318 @property 

319 def test_iam_permissions( 

320 self, 

321 ) -> Callable[ 

322 [iam_policy_pb2.TestIamPermissionsRequest], 

323 Union[ 

324 iam_policy_pb2.TestIamPermissionsResponse, 

325 Awaitable[iam_policy_pb2.TestIamPermissionsResponse], 

326 ], 

327 ]: 

328 raise NotImplementedError() 

329 

330 @property 

331 def get_operation( 

332 self, 

333 ) -> Callable[ 

334 [operations_pb2.GetOperationRequest], 

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

336 ]: 

337 raise NotImplementedError() 

338 

339 @property 

340 def kind(self) -> str: 

341 raise NotImplementedError() 

342 

343 

344__all__ = ("FoldersTransport",)