|
12 | 12 | from __future__ import annotations
|
13 | 13 |
|
14 | 14 | __all__ = (
|
15 |
| - "clean_test_environment", |
16 | 15 | "getS3Client",
|
17 | 16 | "s3CheckFileExists",
|
18 | 17 | "bucketExists",
|
19 |
| - "setAwsEnvCredentials", |
20 |
| - "unsetAwsEnvCredentials", |
21 | 18 | "backoff",
|
22 | 19 | "all_retryable_errors",
|
23 | 20 | "max_retry_time",
|
|
35 | 32 | from contextlib import contextmanager
|
36 | 33 | from http.client import HTTPException, ImproperConnectionState
|
37 | 34 | from types import ModuleType
|
38 |
| -from typing import TYPE_CHECKING, Any, NamedTuple, cast |
| 35 | +from typing import Any, NamedTuple, cast |
39 | 36 | from unittest.mock import patch
|
40 | 37 |
|
41 | 38 | from botocore.exceptions import ClientError
|
42 | 39 | from botocore.handlers import validate_bucket_name
|
43 |
| -from deprecated.sphinx import deprecated |
44 | 40 | from urllib3.exceptions import HTTPError, RequestError
|
45 | 41 | from urllib3.util import Url, parse_url
|
46 | 42 |
|
47 |
| -if TYPE_CHECKING: |
48 |
| - from unittest import TestCase |
49 |
| - |
50 |
| - |
51 | 43 | try:
|
52 | 44 | import boto3
|
53 | 45 | except ImportError:
|
@@ -124,33 +116,6 @@ class _TooManyRequestsError(Exception):
|
124 | 116 | max_retry_time = 60
|
125 | 117 |
|
126 | 118 |
|
127 |
| -@deprecated( |
128 |
| - reason="This has been replaced by a new function, clean_test_environment_for_s3()." |
129 |
| - " Will be removed after v26.2023.5000", |
130 |
| - version="26.2023.5000", |
131 |
| - category=FutureWarning, |
132 |
| -) |
133 |
| -def clean_test_environment(testcase: TestCase) -> None: |
134 |
| - """Clear S3_ENDPOINT_URL then restore it at the end of a test. |
135 |
| -
|
136 |
| - Parameters |
137 |
| - ---------- |
138 |
| - testcase : `unittest.TestCase` |
139 |
| - Reference to the test being run; used to add a cleanup function. |
140 |
| - """ |
141 |
| - endpoint = os.environ.get("S3_ENDPOINT_URL") |
142 |
| - |
143 |
| - if not endpoint: |
144 |
| - return |
145 |
| - os.environ["S3_ENDPOINT_URL"] = "" |
146 |
| - |
147 |
| - def cleanup() -> None: |
148 |
| - if endpoint is not None: |
149 |
| - os.environ["S3_ENDPOINT_URL"] = endpoint |
150 |
| - |
151 |
| - testcase.addCleanup(cleanup) |
152 |
| - |
153 |
| - |
154 | 119 | @contextmanager
|
155 | 120 | def clean_test_environment_for_s3() -> Iterator[None]:
|
156 | 121 | """Reset S3 environment to ensure that unit tests with a mock S3 can't
|
@@ -446,62 +411,6 @@ def bucketExists(bucketName: str, client: boto3.client | None = None) -> bool:
|
446 | 411 | return False
|
447 | 412 |
|
448 | 413 |
|
449 |
| -@deprecated( |
450 |
| - reason="This function could accidentally leave real credentials in the environment during testing." |
451 |
| - " A new function, clean_test_environment_for_s3(), can be used to set up mock credentials." |
452 |
| - " Will be removed after v26.2023.5000", |
453 |
| - version="26.2023.5000", |
454 |
| - category=FutureWarning, |
455 |
| -) |
456 |
| -def setAwsEnvCredentials( |
457 |
| - accessKeyId: str = "dummyAccessKeyId", secretAccessKey: str = "dummySecretAccessKey" |
458 |
| -) -> bool: |
459 |
| - """Set AWS credentials environmental variables. |
460 |
| -
|
461 |
| - Parameters |
462 |
| - ---------- |
463 |
| - accessKeyId : `str` |
464 |
| - Value given to AWS_ACCESS_KEY_ID environmental variable. Defaults to |
465 |
| - `dummyAccessKeyId`. |
466 |
| - secretAccessKey : `str` |
467 |
| - Value given to AWS_SECRET_ACCESS_KEY environmental variable. Defaults |
468 |
| - to `dummySecretAccessKey`. |
469 |
| -
|
470 |
| - Returns |
471 |
| - ------- |
472 |
| - setEnvCredentials : `bool` |
473 |
| - True when environmental variables were set, False otherwise. |
474 |
| -
|
475 |
| - Notes |
476 |
| - ----- |
477 |
| - If either AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY are not set, both |
478 |
| - values are overwritten to ensure that the values are consistent. |
479 |
| - """ |
480 |
| - if "AWS_ACCESS_KEY_ID" not in os.environ or "AWS_SECRET_ACCESS_KEY" not in os.environ: |
481 |
| - os.environ["AWS_ACCESS_KEY_ID"] = accessKeyId |
482 |
| - os.environ["AWS_SECRET_ACCESS_KEY"] = secretAccessKey |
483 |
| - return True |
484 |
| - return False |
485 |
| - |
486 |
| - |
487 |
| -@deprecated( |
488 |
| - reason="This has been replaced by a new function, clean_test_environment_for_s3()." |
489 |
| - " Will be removed after v26.2023.5000", |
490 |
| - version="26.2023.5000", |
491 |
| - category=FutureWarning, |
492 |
| -) |
493 |
| -def unsetAwsEnvCredentials() -> None: |
494 |
| - """Unset AWS credential environment variables. |
495 |
| -
|
496 |
| - Unsets the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environmental |
497 |
| - variables. |
498 |
| - """ |
499 |
| - if "AWS_ACCESS_KEY_ID" in os.environ: |
500 |
| - del os.environ["AWS_ACCESS_KEY_ID"] |
501 |
| - if "AWS_SECRET_ACCESS_KEY" in os.environ: |
502 |
| - del os.environ["AWS_SECRET_ACCESS_KEY"] |
503 |
| - |
504 |
| - |
505 | 414 | def translate_client_error(err: ClientError, uri: ResourcePath) -> None:
|
506 | 415 | """Translate a ClientError into a specialist error if relevant.
|
507 | 416 |
|
|
0 commit comments