|
9 | 9 | from mypy_boto3_ssm import SSMClient |
10 | 10 |
|
11 | 11 | from awspub import exceptions |
| 12 | +from awspub.common import _split_partition |
12 | 13 | from awspub.context import Context |
13 | 14 | from awspub.image_marketplace import ImageMarketplace |
14 | 15 | from awspub.s3 import S3 |
@@ -159,16 +160,34 @@ def _tags(self): |
159 | 160 | tags.append({"Key": name, "Value": value}) |
160 | 161 | return tags |
161 | 162 |
|
| 163 | + def _share_list_filtered(self, share_conf: List[str]) -> List[Dict[str, str]]: |
| 164 | + """ |
| 165 | + Get a filtered list of share configurations based on the current partition |
| 166 | + :param share_conf: the share configuration |
| 167 | + :type share_conf: List[str] |
| 168 | + :return: a List of share configurations that is usable by modify_image_attribute() |
| 169 | + :rtype: List[Dict[str, str]] |
| 170 | + """ |
| 171 | + # the current partition |
| 172 | + partition_current = boto3.client("ec2").meta.partition |
| 173 | + |
| 174 | + share_list: List[Dict[str, str]] = [] |
| 175 | + for share in share_conf: |
| 176 | + partition, account_id = _split_partition(share) |
| 177 | + if partition == partition_current: |
| 178 | + share_list.append({"UserId": account_id}) |
| 179 | + return share_list |
| 180 | + |
162 | 181 | def _share(self, share_conf: List[str], images: Dict[str, _ImageInfo]): |
163 | 182 | """ |
164 | 183 | Share images with accounts |
165 | 184 |
|
166 | | - :param share_conf: the share configuration. eg. self.conf["share_create"] |
| 185 | + :param share_conf: the share configuration containing list |
167 | 186 | :type share_conf: List[str] |
168 | 187 | :param images: a Dict with region names as keys and _ImageInfo objects as values |
169 | 188 | :type images: Dict[str, _ImageInfo] |
170 | 189 | """ |
171 | | - share_list: List[Dict[str, str]] = [{"UserId": user_id} for user_id in share_conf] |
| 190 | + share_list = self._share_list_filtered(share_conf) |
172 | 191 |
|
173 | 192 | for region, image_info in images.items(): |
174 | 193 | ec2client: EC2Client = boto3.client("ec2", region_name=region) |
|
0 commit comments