|
88 | 88 | FilterDef, |
89 | 89 | apply_filter, |
90 | 90 | merge_filters, |
| 91 | + split_arn, |
91 | 92 | valid_preferred_maintenance_window, |
92 | 93 | validate_filters, |
93 | 94 | ) |
@@ -2478,8 +2479,7 @@ def get_snapshot( |
2478 | 2479 | ) -> DBSnapshot | DBClusterSnapshot: |
2479 | 2480 | region = self.region_name |
2480 | 2481 | if identifier.startswith("arn"): |
2481 | | - region = identifier.split(":")[3] |
2482 | | - identifier = identifier.split(":")[-1] |
| 2482 | + region, _, _, identifier = split_arn(identifier) |
2483 | 2483 | backend = self.get_backend("rds", region=region) |
2484 | 2484 | snapshots = backend.resource_map[resource_type] |
2485 | 2485 | if identifier not in snapshots: |
@@ -2758,8 +2758,7 @@ def reboot_db_instance(self, db_instance_identifier: str) -> DBInstance: |
2758 | 2758 | return self.describe_db_instances(db_instance_identifier)[0] |
2759 | 2759 |
|
2760 | 2760 | def extract_snapshot_name_from_arn(self, snapshot_arn: str) -> str: |
2761 | | - arn_breakdown = snapshot_arn.split(":") |
2762 | | - region_name, account_id, resource_type, snapshot_name = arn_breakdown[3:7] |
| 2761 | + _, _, resource_type, snapshot_name = split_arn(snapshot_arn) |
2763 | 2762 | if resource_type != "snapshot": |
2764 | 2763 | raise InvalidParameterValue( |
2765 | 2764 | "The parameter SourceDBSnapshotIdentifier is not a valid identifier. " |
@@ -3710,8 +3709,7 @@ def stop_db_cluster(self, cluster_identifier: str) -> DBCluster: |
3710 | 3709 | def start_export_task(self, kwargs: dict[str, Any]) -> ExportTask: |
3711 | 3710 | export_task_id = kwargs["export_task_identifier"] |
3712 | 3711 | source_arn = kwargs["source_arn"] |
3713 | | - snapshot_id = source_arn.split(":")[-1] |
3714 | | - snapshot_type = source_arn.split(":")[-2] |
| 3712 | + _, _, snapshot_type, snapshot_id = split_arn(source_arn) |
3715 | 3713 |
|
3716 | 3714 | if export_task_id in self.export_tasks: |
3717 | 3715 | raise ExportTaskAlreadyExistsError(export_task_id) |
@@ -3797,15 +3795,8 @@ def _find_resource(self, resource_type: str, resource_name: str) -> Any: |
3797 | 3795 |
|
3798 | 3796 | def _get_resource_for_tagging(self, arn: str) -> Any: |
3799 | 3797 | if self.arn_regex.match(arn): |
3800 | | - arn_breakdown = arn.split(":") |
3801 | | - resource_type = arn_breakdown[len(arn_breakdown) - 2] |
3802 | | - resource_name = arn_breakdown[len(arn_breakdown) - 1] |
3803 | | - # FIXME: HACK for automated snapshots |
3804 | | - if resource_type == "rds": |
3805 | | - resource_type = arn_breakdown[-3] |
3806 | | - resource_name = arn_breakdown[-2] + ":" + arn_breakdown[-1] |
3807 | | - resource = self._find_resource(resource_type, resource_name) |
3808 | | - return resource |
| 3798 | + _, _, resource_type, resource_name = split_arn(arn) |
| 3799 | + return self._find_resource(resource_type, resource_name) |
3809 | 3800 | raise RDSClientError("InvalidParameterValue", f"Invalid resource name: {arn}") |
3810 | 3801 |
|
3811 | 3802 | def list_tags_for_resource(self, arn: str) -> list[dict[str, str]]: |
|
0 commit comments