Example #1
0
    def test_s3_keyname_name(self):
        # array description : 'path', 'header', 'expected_ouput'
        key_names = [
            ("/bucket/keyname", {
                "host": f"https://{LOCALHOST}:4566"
            }, "keyname"),
            ("/bucket//keyname", {
                "host": f"https://{LOCALHOST}:4566"
            }, "/keyname"),
            (
                "/keyname",
                {
                    "host": f"https://bucket.{S3_VIRTUAL_HOSTNAME}:4566"
                },
                "keyname",
            ),
            (
                "//keyname",
                {
                    "host": f"https://bucket.{S3_VIRTUAL_HOSTNAME}:4566"
                },
                "/keyname",
            ),
        ]

        for path, headers, expected_result in key_names:
            self.assertEqual(expected_result,
                             s3_utils.extract_key_name(headers, path))
Example #2
0
    def test_s3_keyname_name(self):
        # array description : 'path', 'header', 'expected_ouput'
        key_names = [
            ('/bucket/keyname', {'host': f'https://{HOSTNAME}:4566'}, 'keyname'),
            ('/bucket//keyname', {'host': f'https://{HOSTNAME}:4566'}, '/keyname'),
            ('/keyname', {'host': f'https://bucket.{S3_VIRTUAL_HOSTNAME}:4566'}, 'keyname'),
            ('//keyname', {'host': f'https://bucket.{S3_VIRTUAL_HOSTNAME}:4566'}, '/keyname'),
        ]

        for path, headers, expected_result in key_names:
            self.assertEqual(expected_result, s3_utils.extract_key_name(headers, path))
Example #3
0
def convert_s3_to_local_url(url):
    url_parsed = urlparse.urlparse(url)
    path = url_parsed.path

    headers = CaseInsensitiveDict({"Host": url_parsed.netloc})
    bucket_name = s3_utils.extract_bucket_name(headers, path)
    key_name = s3_utils.extract_key_name(headers, path)

    # note: make sure to normalize the bucket name here!
    bucket_name = s3_listener.normalize_bucket_name(bucket_name)
    local_url = "%s/%s/%s" % (config.TEST_S3_URL, bucket_name, key_name)
    return local_url
Example #4
0
def convert_s3_to_local_url(url):
    url_parsed = urlparse(url)
    path = url_parsed.path

    headers = CaseInsensitiveDict({"Host": url_parsed.netloc})
    bucket_name = s3_utils.extract_bucket_name(headers, path)
    key_name = s3_utils.extract_key_name(headers, path)

    # note: make sure to normalize the bucket name here!
    bucket_name = s3_listener.normalize_bucket_name(bucket_name)
    local_url = f"{config.service_url('s3')}/{bucket_name}/{key_name}"
    return local_url