Skip to content
This repository was archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
expand S3 shorthand urls in authenticate_box_url hook
Browse files Browse the repository at this point in the history
Vagrant 1.8 only supports HTTP metadata boxes. Expand s3:// shorthand
URLs in the authenticate_box_url hook so that Vagrant's metadata check
sees HTTP URLs. This method should also be compatibile with Vagrant
1.5+.

Fix #27.
  • Loading branch information
benesch committed Jan 19, 2016
1 parent ce1d686 commit 84ec86a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: ruby
rvm:
- 2.1
- 2.2.3

before_install:
# Install Bats, the Bash testing framework
Expand Down Expand Up @@ -34,7 +34,8 @@ env:
- VAGRANT_S3AUTH_BOX_BASE=minimal
matrix:
- VAGRANT_VERSION=master
- VAGRANT_VERSION=v1.7.1
- VAGRANT_VERSION=v1.8.1
- VAGRANT_VERSION=v1.7.4
- VAGRANT_VERSION=v1.6.5
- VAGRANT_VERSION=v1.5.1

Expand Down
28 changes: 28 additions & 0 deletions lib/vagrant-s3auth/middleware/expand_s3_urls.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'uri'

module VagrantPlugins
module S3Auth
class ExpandS3Urls
def initialize(app, _)
@app = app
end

def call(env)
env[:box_urls].map! do |url_string|
url = URI(url_string)

if url.scheme == 's3'
bucket = url.host
key = url.path[1..-1]
raise Errors::MalformedShorthandURLError, url: url unless bucket && key
next "http://s3.amazonaws.com/#{bucket}/#{key}"
end

url_string
end

@app.call(env)
end
end
end
end
5 changes: 5 additions & 0 deletions lib/vagrant-s3auth/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class Plugin < Vagrant.plugin('2')
description <<-DESC
Use versioned Vagrant boxes with S3 authentication.
DESC

action_hook(:s3_urls, :authenticate_box_url) do |hook|
require_relative 'middleware/expand_s3_urls'
hook.prepend(ExpandS3Urls)
end
end
end
end

0 comments on commit 84ec86a

Please sign in to comment.