|
10 | 10 |
|
11 | 11 | import logging
|
12 | 12 | from pathlib import Path
|
13 |
| -from typing import TYPE_CHECKING, Dict, List, Optional, Union |
| 13 | +from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union |
14 | 14 |
|
15 | 15 | from aibs_informatics_core.utils.decorators import retry
|
16 | 16 | from aibs_informatics_core.utils.tools.dicttools import remove_null_values
|
@@ -144,35 +144,36 @@ def list_efs_access_points(
|
144 | 144 | """
|
145 | 145 | efs = get_efs_client()
|
146 | 146 |
|
147 |
| - file_system_ids: List[Optional[str]] = [] |
| 147 | + file_system_ids: List[str] = [] |
148 | 148 | if file_system_id:
|
149 | 149 | file_system_ids.append(file_system_id)
|
150 | 150 | elif file_system_name or file_system_tags:
|
151 | 151 | file_systems = list_efs_file_systems(
|
152 | 152 | file_system_id=file_system_id, name=file_system_name, tags=file_system_tags
|
153 | 153 | )
|
154 | 154 | file_system_ids.extend(map(lambda _: _["FileSystemId"], file_systems))
|
155 |
| - else: |
156 |
| - file_system_ids.append(None) |
157 | 155 |
|
158 | 156 | access_points: List[AccessPointDescriptionTypeDef] = []
|
159 | 157 |
|
160 |
| - for fs_id in file_system_ids: |
| 158 | + if access_point_id or not file_system_ids: |
161 | 159 | response = efs.describe_access_points(
|
162 |
| - **remove_null_values(dict(AccessPointId=access_point_id, FileSystemId=fs_id)) # type: ignore |
| 160 | + **remove_null_values(dict(AccessPointId=access_point_id)) # type: ignore |
163 | 161 | )
|
164 |
| - access_points.extend(response["AccessPoints"]) |
165 |
| - while response.get("NextToken"): |
166 |
| - response = efs.describe_access_points( |
167 |
| - **remove_null_values( # type: ignore |
168 |
| - dict( |
169 |
| - AccessPointId=access_point_id, |
170 |
| - FileSystemId=fs_id, |
171 |
| - NextToken=response["NextToken"], |
172 |
| - ) |
173 |
| - ) |
174 |
| - ) |
| 162 | + # If file_system_ids is empty, we want to include all access points. Otherwise, |
| 163 | + # we only want to include access points that belong to the file systems |
| 164 | + # in file_system_ids. |
| 165 | + for access_point in response["AccessPoints"]: |
| 166 | + if not file_system_ids or access_point.get("FileSystemId") in file_system_ids: |
| 167 | + access_points.append(access_point) |
| 168 | + else: |
| 169 | + for fs_id in file_system_ids: |
| 170 | + response = efs.describe_access_points(FileSystemId=fs_id) |
175 | 171 | access_points.extend(response["AccessPoints"])
|
| 172 | + while response.get("NextToken"): |
| 173 | + response = efs.describe_access_points( |
| 174 | + FileSystemId=fs_id, NextToken=response["NextToken"] |
| 175 | + ) |
| 176 | + access_points.extend(response["AccessPoints"]) |
176 | 177 |
|
177 | 178 | filtered_access_points: List[AccessPointDescriptionTypeDef] = []
|
178 | 179 |
|
@@ -227,13 +228,13 @@ def get_efs_access_point(
|
227 | 228 | if len(access_points) > 1:
|
228 | 229 | raise ValueError(
|
229 | 230 | f"Found more than one access points ({len(access_points)}) "
|
230 |
| - f"based on access point filters (id={access_point_id}, name={access_point_id}, tags={access_point_tags}) " |
| 231 | + f"based on access point filters (id={access_point_id}, name={access_point_name}, tags={access_point_tags}) " |
231 | 232 | f"and on file system filters (id={file_system_id}, name={file_system_name}, tags={file_system_tags}) "
|
232 | 233 | )
|
233 | 234 | elif len(access_points) == 0:
|
234 | 235 | raise ValueError(
|
235 | 236 | f"Found no access points "
|
236 |
| - f"based on access point filters (id={access_point_id}, name={access_point_id}, tags={access_point_tags}) " |
| 237 | + f"based on access point filters (id={access_point_id}, name={access_point_name}, tags={access_point_tags}) " |
237 | 238 | f"and on file system filters (id={file_system_id}, name={file_system_name}, tags={file_system_tags}) "
|
238 | 239 | )
|
239 | 240 | return access_points[0]
|
0 commit comments