|
19 | 19 | _print_invalid_config_error, |
20 | 20 | deprecated |
21 | 21 | ) |
| 22 | +from ..core.connection import _instantiate_s3_session |
| 23 | +from ..core.config import _retrieve_s3_access_details |
22 | 24 |
|
23 | 25 | logger = setup_logger(__name__) |
24 | 26 |
|
25 | 27 |
|
26 | | -def _instantiate_s3_session(s3Endpoint: str, s3AccessKeyId: str, s3SecretAccessKey: str, s3VerifySSLCert: bool, s3CACertBundle: str, print_output: bool = False): |
27 | | - # Instantiate session |
28 | | - session = boto3.session.Session(aws_access_key_id=s3AccessKeyId, aws_secret_access_key=s3SecretAccessKey) |
29 | | - config = BotoConfig(signature_version='s3v4') |
30 | | - |
31 | | - if s3VerifySSLCert: |
32 | | - if s3CACertBundle: |
33 | | - s3 = session.resource(service_name='s3', endpoint_url=s3Endpoint, verify=s3CACertBundle, config=config) |
34 | | - else: |
35 | | - s3 = session.resource(service_name='s3', endpoint_url=s3Endpoint, config=config) |
36 | | - else: |
37 | | - s3 = session.resource(service_name='s3', endpoint_url=s3Endpoint, verify=False, config=config) |
38 | | - |
39 | | - return s3 |
40 | | - |
41 | | - |
42 | | -def _retrieve_s3_access_details(print_output: bool = False) -> Tuple[str, str, str, bool, str]: |
43 | | - try: |
44 | | - config = _retrieve_config(print_output=print_output) |
45 | | - except InvalidConfigError: |
46 | | - raise |
47 | | - try: |
48 | | - s3Endpoint = config["s3Endpoint"] |
49 | | - s3AccessKeyId = config["s3AccessKeyId"] |
50 | | - s3SecretAccessKeyBase64 = config["s3SecretAccessKey"] |
51 | | - s3VerifySSLCert = config["s3VerifySSLCert"] |
52 | | - s3CACertBundle = config["s3CACertBundle"] |
53 | | - except KeyError: |
54 | | - if print_output: |
55 | | - _print_invalid_config_error() |
56 | | - raise InvalidConfigError() |
57 | | - |
58 | | - s3SecretAccessKeyBase64Bytes = s3SecretAccessKeyBase64.encode("ascii") |
59 | | - s3SecretAccessKeyBytes = base64.b64decode(s3SecretAccessKeyBase64Bytes) |
60 | | - s3SecretAccessKey = s3SecretAccessKeyBytes.decode("ascii") |
61 | | - |
62 | | - return s3Endpoint, s3AccessKeyId, s3SecretAccessKey, s3VerifySSLCert, s3CACertBundle |
63 | | - |
64 | | - |
65 | 28 | def _download_from_s3(s3Endpoint: str, s3AccessKeyId: str, s3SecretAccessKey: str, s3VerifySSLCert: bool, |
66 | 29 | s3CACertBundle: str, s3Bucket: str, s3ObjectKey: str, localFile: str, print_output: bool = False): |
67 | 30 | # Instantiate S3 session |
|
0 commit comments