Skip to content

Commit a8a8b15

Browse files
authored
Add a basic support for parsing hosts from virtual private cloud (#35)
* Add a basic support for parsing hosts from virtual private cloud * v1.4.6
1 parent db6d637 commit a8a8b15

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CloudBase"
22
uuid = "85eb1798-d7c4-4918-bb13-c944d38e27ed"
33
authors = ["quinnj <[email protected]>"]
4-
version = "1.4.5"
4+
version = "1.4.6"
55

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

src/aws.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function AWSCredentials(profile::String="", load::Bool=true; expireThreshold=Dat
4040
end
4141

4242
getCredentialsFile() = get(AWS_CONFIGS, "aws_shared_credentials_file", joinpath(homedir(), ".aws", "credentials"))
43-
getConfigFile() = get(AWS_CONFIGS, "aws_config_file", joinpath(homedir(), ".aws", "config"))
43+
getConfigFile() = get(AWS_CONFIGS, "aws_config_file", joinpath(homedir(), ".aws", "config"))
4444

4545
function awsLoadConfig!(profile::String="", expireThreshold=Dates.Minute(5))
4646
# on each fresh load, we want to clear out potentially stale credential fields
@@ -76,7 +76,7 @@ function awsLoadConfig!(profile::String="", expireThreshold=Dates.Minute(5))
7676
# together as one object in AWS_CONFIGS, so we know they all came "together"
7777
exp = get(AWS_CONFIGS, "expiration", nothing)
7878
expiration = exp === nothing ? exp : DateTime(rstrip(exp, 'Z'))
79-
Figgy.load!(AWS_CONFIGS, "credentials" =>
79+
Figgy.load!(AWS_CONFIGS, "credentials" =>
8080
AWSCredentials(profile,
8181
get(AWS_CONFIGS, "aws_access_key_id", ""),
8282
get(AWS_CONFIGS, "aws_secret_access_key", ""),
@@ -237,6 +237,7 @@ const AWS_DEFAULT_REGION = "us-east-1"
237237
# "s3.amazonaws.com"
238238
# "s3.us-west-2.amazonaws.com"
239239
# "bucket.s3.us-west-2.amazonaws.com"
240+
# "bucket.vpce-1a2b3c4d-5e6f.s3.us-east-1.vpce.amazonaws.com"
240241
function urlServiceRegion(host)
241242
spl = split(host, '.')
242243
if length(spl) == 5 && !all(isdigit, spl[2]) && !all(isdigit, spl[3])
@@ -247,6 +248,10 @@ function urlServiceRegion(host)
247248
elseif length(spl) == 3 && !all(isdigit, spl[1])
248249
# just got service
249250
return (spl[1], nothing)
251+
elseif length(spl) == 7 && spl[5] == "vpce" && spl[6] == "amazonaws" && spl[7] == "com"
252+
# See virtual private cloud https://docs.aws.amazon.com/AmazonS3/latest/userguide/privatelink-interface-endpoints.html
253+
# got service & region
254+
return (spl[3], spl[4])
250255
else
251256
# no service, no region
252257
return (nothing, nothing)
@@ -399,4 +404,4 @@ function awssignv2!(request::HTTP.Request; credentials::Union{Nothing, AWSCreden
399404
request.body = params
400405
end
401406
return
402-
end
407+
end

test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,11 @@ end
226226
@test prereq_ref[] == 2
227227
end
228228
end
229+
230+
@testset "urlServiceRegion" begin
231+
@test CloudBase.urlServiceRegion("amazonaws.com") == (nothing, nothing)
232+
@test CloudBase.urlServiceRegion("s3.amazonaws.com") == ("s3", nothing)
233+
@test CloudBase.urlServiceRegion("s3.us-west-2.amazonaws.com") == ("s3", "us-west-2")
234+
@test CloudBase.urlServiceRegion("bucket.s3.us-west-2.amazonaws.com") == ("s3", "us-west-2")
235+
@test CloudBase.urlServiceRegion("bucket.vpce-1a2b3c4d-5e6f.s3.us-east-1.vpce.amazonaws.com") == ("s3", "us-east-1")
236+
end

0 commit comments

Comments
 (0)