Skip to content

Commit 0c8f299

Browse files
authored
Add a basic support for parsing urls from virtual private cloud (#49)
* Add a basic support for parsing urls from virtual private cloud * Improve comment * v1.6.2 * PR feedback * 1.6 compat
1 parent 63e4b3a commit 0c8f299

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CloudStore"
22
uuid = "3365d9ee-d53b-4a56-812d-5344d5b716d7"
33
authors = ["quinnj <[email protected]>"]
4-
version = "1.6.1"
4+
version = "1.6.2"
55

66
[deps]
77
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

src/parse.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const AWS_REGIONS = Set{String}([
1818
"ap-southeast-2",
1919
"ap-northeast-1",
2020
"ca-central-1",
21+
"ca-west-1",
2122
"eu-central-1",
2223
"eu-west-1",
2324
"eu-west-2",
@@ -26,6 +27,7 @@ const AWS_REGIONS = Set{String}([
2627
"eu-south-2",
2728
"eu-north-1",
2829
"eu-central-2",
30+
"il-central-1",
2931
"me-south-1",
3032
"me-central-1",
3133
"sa-east-1",
@@ -136,6 +138,12 @@ function parseAWSBucketRegionKey(url; parseLocal::Bool=false)
136138
# https://bucket-name.s3.amazonaws.com
137139
m = match(r"^https://(?<bucket>[^\.]+)\.s3(?<accelerate>-accelerate)?(?:\.(?<region>[^\.]+))?\.amazonaws\.com(?:/(?<key>.+))?$"i, url)
138140
m !== nothing && return _validate_aws(true, !isnothing(m[:accelerate]), nothing, m[:bucket], m[:region], m[:key])
141+
142+
### See: https://docs.aws.amazon.com/AmazonS3/latest/userguide/privatelink-interface-endpoints.html
143+
# https://bucket.vpce-1a2b3c4d-5e6f.s3.region-code.vpce.amazonaws.com/bucket-name/key-name
144+
# https://bucket.vpce-1a2b3c4d-5e6f.s3.region-code.vpce.amazonaws.com/bucket-name
145+
m = match(r"^https://bucket\.vpce[^\.]+\.s3\.(?<region>[^\.]+)\.vpce\.amazonaws\.com/(?<bucket>[^/]+)(?:/(?<key>.+))?$"i, url)
146+
m !== nothing && return _validate_aws(true, false, nothing, m[:bucket], m[:region], m[:key])
139147
# https://s3.region-code.amazonaws.com/bucket-name/key-name
140148
# https://s3.region-code.amazonaws.com/bucket-name
141149
m = match(r"^https://s3(?:\.(?<region>[^\.]+))?\.amazonaws\.com/(?<bucket>[^/]+)(?:/(?<key>.+))?$"i, url)

test/runtests.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,9 @@ end
531531
("S3://bucket-name", (true, false, nothing, "bucket-name", "", "")),
532532
("HTtp://127.0.0.1:27181/bucket-name/key-name", (true, false, "HTtp://127.0.0.1:27181", "bucket-name", "", "key-name")),
533533
("htTP://127.0.0.1:27181/bucket-name", (true, false, "htTP://127.0.0.1:27181", "bucket-name", "", "")),
534+
535+
("https://bucket.vpce-1a2b3c4d-5e6f.s3.us-west-2.vpce.amazonaws.com/bucket-name", (true, false, nothing, "bucket-name", "us-west-2", "")),
536+
("https://bucket.vpce-1a2b3c4d-5e6f.s3.us-west-2.vpce.amazonaws.com/bucket-name/key-name", (true, false, nothing, "bucket-name", "us-west-2", "key-name")),
534537
]
535538
for (url, parts) in s3
536539
ok, accelerate, host, bucket, reg, key = CloudStore.parseAWSBucketRegionKey(url; parseLocal=true)
@@ -587,6 +590,12 @@ end
587590
"httP://S3.AmAzonAws.com/bucket-name",
588591
"httP://bucket-name/key-name",
589592
"httP://bucket-name",
593+
594+
"http://bucket.vpce-1a2b3c4d-5e6f.s3.us-west-2.vpce.amazonaws.com/bucket-name",
595+
"http://bucket.vpce-1a2b3c4d-5e6f.s3.us-west-2.vpce.amazonaws.com/bucket-name/key-name",
596+
"https://bucket.vpce-1a2b3c4d-5e6f.s3.us-west-2.XvpceX.amazonaws.com/bucket-name",
597+
"https://bucket.Xvpce-1a2b3c4d-5e6f.s3.us-west-2.vpce.amazonaws.com/bucket-name",
598+
"https://XbucketX.vpce-1a2b3c4d-5e6f.s3.us-west-2.vpce.amazonaws.com/bucket-name/key-name",
590599
]
591600
for url in invalid_s3
592601
ok, accelerate, host, bucket, reg, key = CloudStore.parseAWSBucketRegionKey(url; parseLocal=true)
@@ -918,6 +927,10 @@ end
918927
@test CloudStore.validate_bucket_name("a.b-c1", false) == "a.b-c1"
919928
@test CloudStore.validate_bucket_name("a"^63, false) == "a"^63
920929
@test CloudStore.validate_bucket_name("a"^3, false) == "a"^3
930+
931+
@test_throws ArgumentError("Validation failed for `region` \"xx-xxxx-x\"") CloudStore.parseAWSBucketRegionKey("https://bucket.vpce-1a2b3c4d-5e6f.s3.xx-xxxx-x.vpce.amazonaws.com/bucket-name")
932+
@test_throws ArgumentError("Validation failed for `bucket` name \"bn\": Bucket names must be between 3 (min) and 63 (max) characters long.") CloudStore.parseAWSBucketRegionKey("https://bucket.vpce-1a2b3c4d-5e6f.s3.us-west-2.vpce.amazonaws.com/bn")
933+
@test_throws ArgumentError("Validation failed for `key` \"key-n$("a" ^ 1024)me\": The key name must be shorter than 1025 bytes.") CloudStore.parseAWSBucketRegionKey("https://bucket.vpce-1a2b3c4d-5e6f.s3.us-west-2.vpce.amazonaws.com/bucket-name/key-n$("a" ^ 1024)me")
921934
end
922935

923936
@testset "validate_container_name" begin

0 commit comments

Comments
 (0)