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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1643e17f9a726431fd44b34c7a87fe44e73070328d4c7bb261c2f12935c74834
4
- data.tar.gz: 2f1e60867c1016ab3e349873b293b69d30142db898301b912e16bfdf8cbd95ed
3
+ metadata.gz: 857a4297cb7c77e6fc882a495a81de46e19ec48481e69394450349f4d2ab1462
4
+ data.tar.gz: 54fbc90963cefabf0318fadf73ef4e2370c4438862c75a00041fa727fd4f0780
5
5
  SHA512:
6
- metadata.gz: 8d2c9963853012e0091c2c8fe8678c77d171c56d5662e28d670d728ee9d97e0123a25056bcb6d5cf9398983e0ad3541d3486cf635a00e4fb8af8ebeecfb9fe2c
7
- data.tar.gz: dff68c70631396e84fd058e488583fce8c56e70fbc735981575f018ad91e0b710222e7cf7de721ad0c69f16a1e56da94444429c1d13e5764adb2f53e6fd85a36
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-s3auth]
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-s3auth'
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
- Example: https://s3.eu-west-1.amazonaws.com/mybucket/mybox.box
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
- Example: https://s3-eu-west-1.amazonaws.com/bucket-name/mybox.box
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 Seahorse::Client::NetworkingError => e
30
+ rescue => e
27
31
  raise Errors::DownloaderError, message: e
28
32
  end
29
33
 
@@ -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(s3_url)
18
+ def self.parse_s3_url(url)
19
19
  region = bucket = key = nil
20
- if s3_url =~ S3_URL_HOST_REGEX
21
- match = S3_URL_HOST_REGEX.match(s3_url)
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 s3_url =~ S3_URL_PATH_REGEX
26
- match = S3_URL_PATH_REGEX.match(s3_url)
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
- region, bucket, key = parse_s3_url(url)
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
- logger.debug("BoxS3: Region: #{region}")
43
- logger.debug("BoxS3: Bucket: #{bucket}")
44
- logger.debug("BoxS3: Key: #{key}")
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
- client = Aws::S3::Client.new(
47
- profile: ENV['AWS_PROFILE'],
48
- region: region
49
- )
50
- presigner = Aws::S3::Presigner.new(client: client)
77
+ client = Aws::S3::Client.new(
78
+ profile: profile,
79
+ region: region
80
+ )
81
+ presigner = Aws::S3::Presigner.new(client: client)
51
82
 
52
- presigned_url = presigner.presigned_url(
53
- method,
54
- bucket: bucket,
55
- key: key,
56
- expires_in: 3600
57
- ).to_s
83
+ presigned_url = presigner.presigned_url(
84
+ method,
85
+ bucket: bucket,
86
+ key: key,
87
+ expires_in: 3600
88
+ ).to_s
58
89
 
59
- logger.debug("BoxS3: Pre-signed URL: #{presigned_url}")
90
+ logger.debug("BoxS3: Pre-signed URL: #{presigned_url}")
60
91
 
61
- return presigned_url
92
+ return presigned_url
62
93
  end
63
94
 
64
95
  end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module BoxS3
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.3'
4
4
  end
5
5
  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.2
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-13 00:00:00.000000000 Z
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: