|
18 | 18 | """ # pylint: disable=pointless-string-statement |
19 | 19 |
|
20 | 20 |
|
21 | | -def _list_all_files(bucket: str, prefix: str, s3_client=None) -> List[str]: |
| 21 | +def _list_all_files(bucket: str, prefix: str, s3_client=None, anon=False) -> List[str]: |
22 | 22 | """ |
23 | 23 | Get list of all files from an s3 bucket matching a certain prefix |
24 | 24 | """ |
25 | 25 | import boto3 # pylint: disable=import-outside-toplevel |
| 26 | + from botocore import UNSIGNED # pylint: disable=import-outside-toplevel |
| 27 | + from botocore.client import Config # pylint: disable=import-outside-toplevel |
26 | 28 |
|
27 | 29 | if s3_client is None: |
28 | | - s3_client = boto3.client("s3") |
| 30 | + if anon: |
| 31 | + s3_client = boto3.client("s3", config=Config(signature_version=UNSIGNED)) |
| 32 | + else: |
| 33 | + s3_client = boto3.client("s3") |
| 34 | + |
29 | 35 | paginator = s3_client.get_paginator("list_objects") |
30 | 36 | all_files = [] |
31 | 37 | for page in paginator.paginate(Bucket=bucket, Prefix=prefix): |
@@ -78,12 +84,12 @@ def __init__( |
78 | 84 | ): |
79 | 85 | self.s3_bucket = s3_bucket |
80 | 86 | self.s3_prefix = s3_prefix |
81 | | - self.all_files = _list_all_files(s3_bucket, s3_prefix) |
| 87 | + self.anon = anon |
| 88 | + self.all_files = _list_all_files(s3_bucket, s3_prefix, anon) |
82 | 89 | self.classes = sorted({self._get_class(x) for x in self.all_files}) |
83 | 90 | self.class_to_idx = {k: idx for idx, k in enumerate(self.classes)} |
84 | 91 | self.transform = transform |
85 | 92 | self.target_transform = target_transform |
86 | | - self.anon = anon |
87 | 93 |
|
88 | 94 | @classmethod |
89 | 95 | def _get_class(cls, path): |
|
0 commit comments