Skip to content

Commit

Permalink
Add a basic support for parsing hosts from virtual private cloud (#35)
Browse files Browse the repository at this point in the history
* Add a basic support for parsing hosts from virtual private cloud

* v1.4.6
  • Loading branch information
Drvi authored Jan 24, 2024
1 parent db6d637 commit a8a8b15
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CloudBase"
uuid = "85eb1798-d7c4-4918-bb13-c944d38e27ed"
authors = ["quinnj <quinn.jacobd@gmail.com>"]
version = "1.4.5"
version = "1.4.6"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
11 changes: 8 additions & 3 deletions src/aws.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function AWSCredentials(profile::String="", load::Bool=true; expireThreshold=Dat
end

getCredentialsFile() = get(AWS_CONFIGS, "aws_shared_credentials_file", joinpath(homedir(), ".aws", "credentials"))
getConfigFile() = get(AWS_CONFIGS, "aws_config_file", joinpath(homedir(), ".aws", "config"))
getConfigFile() = get(AWS_CONFIGS, "aws_config_file", joinpath(homedir(), ".aws", "config"))

function awsLoadConfig!(profile::String="", expireThreshold=Dates.Minute(5))
# on each fresh load, we want to clear out potentially stale credential fields
Expand Down Expand Up @@ -76,7 +76,7 @@ function awsLoadConfig!(profile::String="", expireThreshold=Dates.Minute(5))
# together as one object in AWS_CONFIGS, so we know they all came "together"
exp = get(AWS_CONFIGS, "expiration", nothing)
expiration = exp === nothing ? exp : DateTime(rstrip(exp, 'Z'))
Figgy.load!(AWS_CONFIGS, "credentials" =>
Figgy.load!(AWS_CONFIGS, "credentials" =>
AWSCredentials(profile,
get(AWS_CONFIGS, "aws_access_key_id", ""),
get(AWS_CONFIGS, "aws_secret_access_key", ""),
Expand Down Expand Up @@ -237,6 +237,7 @@ const AWS_DEFAULT_REGION = "us-east-1"
# "s3.amazonaws.com"
# "s3.us-west-2.amazonaws.com"
# "bucket.s3.us-west-2.amazonaws.com"
# "bucket.vpce-1a2b3c4d-5e6f.s3.us-east-1.vpce.amazonaws.com"
function urlServiceRegion(host)
spl = split(host, '.')
if length(spl) == 5 && !all(isdigit, spl[2]) && !all(isdigit, spl[3])
Expand All @@ -247,6 +248,10 @@ function urlServiceRegion(host)
elseif length(spl) == 3 && !all(isdigit, spl[1])
# just got service
return (spl[1], nothing)
elseif length(spl) == 7 && spl[5] == "vpce" && spl[6] == "amazonaws" && spl[7] == "com"
# See virtual private cloud https://docs.aws.amazon.com/AmazonS3/latest/userguide/privatelink-interface-endpoints.html
# got service & region
return (spl[3], spl[4])
else
# no service, no region
return (nothing, nothing)
Expand Down Expand Up @@ -399,4 +404,4 @@ function awssignv2!(request::HTTP.Request; credentials::Union{Nothing, AWSCreden
request.body = params
end
return
end
end
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,11 @@ end
@test prereq_ref[] == 2
end
end

@testset "urlServiceRegion" begin
@test CloudBase.urlServiceRegion("amazonaws.com") == (nothing, nothing)
@test CloudBase.urlServiceRegion("s3.amazonaws.com") == ("s3", nothing)
@test CloudBase.urlServiceRegion("s3.us-west-2.amazonaws.com") == ("s3", "us-west-2")
@test CloudBase.urlServiceRegion("bucket.s3.us-west-2.amazonaws.com") == ("s3", "us-west-2")
@test CloudBase.urlServiceRegion("bucket.vpce-1a2b3c4d-5e6f.s3.us-east-1.vpce.amazonaws.com") == ("s3", "us-east-1")
end

2 comments on commit a8a8b15

@Drvi
Copy link
Member Author

@Drvi Drvi commented on a8a8b15 Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/99435

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.4.6 -m "<description of version>" a8a8b151a6776353f288fd97939d45a45a85e8ba
git push origin v1.4.6

Please sign in to comment.