Get and update region for the request if needed. Signature v4 needs the region of the bucket or the request will fail with the indication of the correct region. We are trying to avoid this failure by pre-emptively getting the correct region to use, if not provided by
(self, request)
| 1662 | raise S3Error(response) |
| 1663 | |
| 1664 | def update_region_inner_request(self, request): |
| 1665 | """Get and update region for the request if needed. |
| 1666 | |
| 1667 | Signature v4 needs the region of the bucket or the request will fail |
| 1668 | with the indication of the correct region. |
| 1669 | We are trying to avoid this failure by pre-emptively getting the |
| 1670 | correct region to use, if not provided by the user. |
| 1671 | """ |
| 1672 | if request.resource.get('bucket') and not request.use_signature_v2() \ |
| 1673 | and S3Request.region_map.get( |
| 1674 | request.resource['bucket'], Config().bucket_location |
| 1675 | ) == "US": |
| 1676 | debug("===== SEND Inner request to determine the bucket region " |
| 1677 | "=====") |
| 1678 | try: |
| 1679 | s3_uri = S3Uri(u's3://' + request.resource['bucket']) |
| 1680 | # "force_us_default" should prevent infinite recursivity because |
| 1681 | # it will set the region_map dict. |
| 1682 | region = self.get_bucket_location(s3_uri, force_us_default=True) |
| 1683 | if region is not None: |
| 1684 | S3Request.region_map[request.resource['bucket']] = region |
| 1685 | debug("===== SUCCESS Inner request to determine the bucket " |
| 1686 | "region (%r) =====", region) |
| 1687 | except Exception as exc: |
| 1688 | # Ignore errors, it is just an optimisation, so nothing critical |
| 1689 | debug("getlocation inner request failure reason: %s", exc) |
| 1690 | debug("===== FAILED Inner request to determine the bucket " |
| 1691 | "region =====") |
| 1692 | |
| 1693 | def send_request(self, request, retries=None): |
| 1694 | if retries is None: |
no test coverage detected