vagrant-box-s3 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +9 -4
- data/lib/vagrant-box-s3/downloader.rb +5 -1
- data/lib/vagrant-box-s3/utils.rb +55 -24
- data/lib/vagrant-box-s3/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 857a4297cb7c77e6fc882a495a81de46e19ec48481e69394450349f4d2ab1462
|
4
|
+
data.tar.gz: 54fbc90963cefabf0318fadf73ef4e2370c4438862c75a00041fa727fd4f0780
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15d7d800c9636bdcc0fbcab656b46d041f57ee018ac20220689135952289603d9dece21ef7b5c7b8700ca9672ba4e7c4231e09d25b1eade790cc7fdd05e7b39b
|
7
|
+
data.tar.gz: 141d2ca407dfda8c5fa8516732dbbafea8c19a15d9c451645a817b14f177a68362797fb22b57726472acbf9a352758440fc376e2f82b08c97031d6e9be8b6296
|
data/README.md
CHANGED
@@ -40,14 +40,14 @@ You can also use your credentials file to create a profile. Select the appropria
|
|
40
40
|
|
41
41
|
#### ~/.aws/credentials
|
42
42
|
|
43
|
-
[vagrant-
|
43
|
+
[vagrant-box-s3]
|
44
44
|
aws_access_key_id = AKIA...
|
45
45
|
aws_secret_access_key = ...
|
46
46
|
|
47
47
|
#### Vagrantfile
|
48
48
|
|
49
49
|
ENV.delete_if { |name| name.start_with?('AWS_') } # Filter out rogue env vars.
|
50
|
-
ENV['AWS_PROFILE'] = 'vagrant-
|
50
|
+
ENV['AWS_PROFILE'] = 'vagrant-box-s3'
|
51
51
|
|
52
52
|
Vagrant.configure("2") { |config| ... }
|
53
53
|
|
@@ -60,10 +60,11 @@ You can use any valid HTTP(S) URL for your box URL:
|
|
60
60
|
Specify the bucket name in the path of the URL. AWS has deprecated path-style URLs, but they might still be seen or used in legacy systems.
|
61
61
|
|
62
62
|
- Format: https://s3.Region.amazonaws.com/bucket-name/key-name
|
63
|
-
|
63
|
+
- Example: https://s3.eu-west-1.amazonaws.com/mybucket/mybox.box
|
64
|
+
|
64
65
|
|
65
66
|
- Format: https://s3-Region.amazonaws.com/bucket-name/keyname
|
66
|
-
|
67
|
+
- Example: https://s3-eu-west-1.amazonaws.com/bucket-name/mybox.box
|
67
68
|
|
68
69
|
#### Virtual-Hosted-Style URLs
|
69
70
|
Virtual-hosted-style URLs use the bucket name as a subdomain. This is the recommended and most commonly used format.
|
@@ -124,6 +125,10 @@ Update the current version in `lib/vagrant-box-s3/version.rb`.
|
|
124
125
|
|
125
126
|
To build the plugin, use `rake build`, this will create a file with the current version number, e.g. `pkg/vagrant-box-s3-0.1.2.gem`.
|
126
127
|
|
128
|
+
Remove the old version:
|
129
|
+
|
130
|
+
vagrant plugin uninstall vagrant-box-s3
|
131
|
+
|
127
132
|
Testing the plugin requires installing into vagrant from the build:
|
128
133
|
|
129
134
|
vagrant plugin install ../vagrant-box-s3/pkg/vagrant-box-s3-0.1.2.gem
|
@@ -20,10 +20,14 @@ module Vagrant
|
|
20
20
|
# Call original execute_curl (aliased).
|
21
21
|
execute_curl_without_aws_auth(options, subprocess_options, &data_proc)
|
22
22
|
|
23
|
+
rescue Aws::Errors::MissingCredentialsError, Aws::Sigv4::Errors::MissingCredentialsError => e
|
24
|
+
message = "Missing AWS credentials: #{e.message}"
|
25
|
+
@logger.error(message) if defined?(@logger)
|
26
|
+
raise Errors::DownloaderError, message: message
|
23
27
|
rescue Aws::S3::Errors::Forbidden => e
|
24
28
|
message = "403 Forbidden: #{e.message}"
|
25
29
|
raise Errors::DownloaderError, message: message
|
26
|
-
rescue
|
30
|
+
rescue => e
|
27
31
|
raise Errors::DownloaderError, message: e
|
28
32
|
end
|
29
33
|
|
data/lib/vagrant-box-s3/utils.rb
CHANGED
@@ -15,15 +15,15 @@ module VagrantPlugins
|
|
15
15
|
S3_URL_PATH_REGEX = %r{^https?://s3[-\.]([\w\-]+)\.amazonaws\.com/([^/]+)/([^?]+)}
|
16
16
|
|
17
17
|
# Parse an s3 URL.
|
18
|
-
def self.parse_s3_url(
|
18
|
+
def self.parse_s3_url(url)
|
19
19
|
region = bucket = key = nil
|
20
|
-
if
|
21
|
-
match = S3_URL_HOST_REGEX.match(
|
20
|
+
if url =~ S3_URL_HOST_REGEX
|
21
|
+
match = S3_URL_HOST_REGEX.match(url)
|
22
22
|
region = match[2]
|
23
23
|
bucket = match[1]
|
24
24
|
key = match[3]
|
25
|
-
elsif
|
26
|
-
match = S3_URL_PATH_REGEX.match(
|
25
|
+
elsif url =~ S3_URL_PATH_REGEX
|
26
|
+
match = S3_URL_PATH_REGEX.match(url)
|
27
27
|
region = match[1]
|
28
28
|
bucket = match[2]
|
29
29
|
key = match[3]
|
@@ -32,33 +32,64 @@ module VagrantPlugins
|
|
32
32
|
return region, bucket, key
|
33
33
|
end
|
34
34
|
|
35
|
+
# Remove presigned URL params from box URL.
|
36
|
+
# We do this as URLs can be cached and do not want to want
|
37
|
+
# to include previously presigned URL parameters.
|
38
|
+
def self.remove_presigned_params(url)
|
39
|
+
# Parse the URL
|
40
|
+
uri = URI.parse(url)
|
41
|
+
|
42
|
+
# Split the query string into parameters
|
43
|
+
query_params = URI.decode_www_form(uri.query || '').to_h
|
44
|
+
|
45
|
+
# Remove any parameters that start with 'X-Amz-'
|
46
|
+
query_params.reject! { |k, _| k.start_with?('X-Amz-') }
|
47
|
+
|
48
|
+
# Check if there are any query parameters left
|
49
|
+
if query_params.empty?
|
50
|
+
# If no query parameters left, set uri.query to nil to remove the '?'
|
51
|
+
uri.query = nil
|
52
|
+
else
|
53
|
+
# Reconstruct the query string without AWS presigned parameters
|
54
|
+
uri.query = URI.encode_www_form(query_params)
|
55
|
+
end
|
56
|
+
|
57
|
+
return uri.to_s
|
58
|
+
end
|
59
|
+
|
35
60
|
# Pre-sign an s3 URL, with given method.
|
36
61
|
def self.presign_url(method, url, logger)
|
37
|
-
logger.info("BoxS3: Generating signed URL for #{method.upcase}")
|
38
|
-
logger.info("BoxS3: Discovered S3 URL: #{url}")
|
39
62
|
|
40
|
-
|
63
|
+
url = remove_presigned_params(url)
|
64
|
+
|
65
|
+
logger.info("BoxS3: Generating signed URL for #{method.upcase}")
|
66
|
+
logger.info("BoxS3: Discovered S3 URL: #{url}")
|
67
|
+
|
68
|
+
region, bucket, key = parse_s3_url(url)
|
69
|
+
|
70
|
+
profile = ENV['AWS_PROFILE']
|
41
71
|
|
42
|
-
|
43
|
-
|
44
|
-
|
72
|
+
logger.debug("BoxS3: Region: #{region}")
|
73
|
+
logger.debug("BoxS3: Bucket: #{bucket}")
|
74
|
+
logger.debug("BoxS3: Key: #{key}")
|
75
|
+
logger.debug("BoxS3: Profile: #{profile}")
|
45
76
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
77
|
+
client = Aws::S3::Client.new(
|
78
|
+
profile: profile,
|
79
|
+
region: region
|
80
|
+
)
|
81
|
+
presigner = Aws::S3::Presigner.new(client: client)
|
51
82
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
83
|
+
presigned_url = presigner.presigned_url(
|
84
|
+
method,
|
85
|
+
bucket: bucket,
|
86
|
+
key: key,
|
87
|
+
expires_in: 3600
|
88
|
+
).to_s
|
58
89
|
|
59
|
-
|
90
|
+
logger.debug("BoxS3: Pre-signed URL: #{presigned_url}")
|
60
91
|
|
61
|
-
|
92
|
+
return presigned_url
|
62
93
|
end
|
63
94
|
|
64
95
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-box-s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Whiteley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-s3
|
@@ -68,7 +68,9 @@ files:
|
|
68
68
|
homepage: https://github.com/memiah/vagrant-box-s3
|
69
69
|
licenses:
|
70
70
|
- MIT
|
71
|
-
metadata:
|
71
|
+
metadata:
|
72
|
+
source_code_uri: https://github.com/memiah/vagrant-box-s3
|
73
|
+
bug_tracker_uri: https://github.com/memiah/vagrant-box-s3/issues
|
72
74
|
post_install_message:
|
73
75
|
rdoc_options: []
|
74
76
|
require_paths:
|