vagrant-s3auth-mfa 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ test/box/minimal.box
data/test/cleanup.rb ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'aws-sdk'
5
+
6
+ require_relative 'support'
7
+
8
+ [REGION_STANDARD, REGION_NONSTANDARD].each do |region|
9
+ s3 = Aws::S3::Resource.new(region: region)
10
+
11
+ buckets = if ARGV.include?('--all')
12
+ s3.buckets.select do |b|
13
+ b.name.include?('vagrant-s3auth.com') && b.name.include?(region)
14
+ end
15
+ else
16
+ [s3.bucket("#{region}.#{BUCKET}")]
17
+ end
18
+
19
+ buckets.each { |b| b.delete! if b.exists? }
20
+ end
21
+
22
+ atlas = Atlas.new(ATLAS_TOKEN, ATLAS_USERNAME)
23
+ atlas.delete_box(ATLAS_BOX_NAME)
data/test/run.bats ADDED
@@ -0,0 +1,147 @@
1
+ #!/usr/bin/env bats
2
+
3
+ missing_vars=()
4
+
5
+ require_var() {
6
+ [[ "${!1}" ]] || missing_vars+=("$1")
7
+ }
8
+
9
+ require_var AWS_ACCESS_KEY_ID
10
+ require_var AWS_SECRET_ACCESS_KEY
11
+ require_var ATLAS_TOKEN
12
+ require_var ATLAS_USERNAME
13
+ require_var VAGRANT_S3AUTH_BUCKET
14
+ require_var VAGRANT_S3AUTH_BOX_BASE
15
+ require_var VAGRANT_S3AUTH_ATLAS_BOX_NAME
16
+ require_var VAGRANT_S3AUTH_REGION_NONSTANDARD
17
+
18
+ if [[ ${#missing_vars[*]} -gt 0 ]]; then
19
+ echo "Missing required environment variables:"
20
+ printf ' %s\n' "${missing_vars[@]}"
21
+ exit 1
22
+ fi
23
+
24
+ teardown() {
25
+ bundle exec vagrant box remove "$VAGRANT_S3AUTH_BOX_BASE" > /dev/null 2>&1 || true
26
+ bundle exec vagrant box remove "public-$VAGRANT_S3AUTH_BOX_BASE" > /dev/null 2>&1 || true
27
+ bundle exec vagrant box remove "vagrant-s3auth/$VAGRANT_S3AUTH_BOX_BASE" > /dev/null 2>&1 || true
28
+ bundle exec vagrant box remove "vagrant-s3auth/public-$VAGRANT_S3AUTH_BOX_BASE" > /dev/null 2>&1 || true
29
+ bundle exec vagrant box remove "$ATLAS_USERNAME/$VAGRANT_S3AUTH_ATLAS_BOX_NAME" > /dev/null 2>&1 || true
30
+ }
31
+
32
+ @test "vagrant cloud" {
33
+ bundle exec vagrant box add "$ATLAS_USERNAME/$VAGRANT_S3AUTH_ATLAS_BOX_NAME"
34
+ }
35
+
36
+ @test "simple box with full path standard url" {
37
+ bundle exec vagrant box add \
38
+ --name "$VAGRANT_S3AUTH_BOX_BASE" \
39
+ "https://s3.amazonaws.com/us-east-1.$VAGRANT_S3AUTH_BUCKET/$VAGRANT_S3AUTH_BOX_BASE.box"
40
+ }
41
+
42
+ @test "public simple box with full path standard url without credentials" {
43
+ AWS_ACCESS_KEY_ID= \
44
+ bundle exec vagrant box add \
45
+ --name "$VAGRANT_S3AUTH_BOX_BASE" \
46
+ "https://s3.amazonaws.com/us-east-1.$VAGRANT_S3AUTH_BUCKET/public-$VAGRANT_S3AUTH_BOX_BASE.box"
47
+ }
48
+
49
+ @test "simple box with full host standard url" {
50
+ bundle exec vagrant box add \
51
+ --name "$VAGRANT_S3AUTH_BOX_BASE" \
52
+ "https://us-east-1.$VAGRANT_S3AUTH_BUCKET.s3.amazonaws.com/$VAGRANT_S3AUTH_BOX_BASE.box"
53
+ }
54
+
55
+ @test "simple box with shorthand standard url" {
56
+ bundle exec vagrant box add \
57
+ --name "$VAGRANT_S3AUTH_BOX_BASE" \
58
+ "s3://us-east-1.$VAGRANT_S3AUTH_BUCKET/$VAGRANT_S3AUTH_BOX_BASE.box"
59
+ }
60
+
61
+ @test "simple box with full path nonstandard url" {
62
+ bundle exec vagrant box add \
63
+ --name "$VAGRANT_S3AUTH_BOX_BASE" \
64
+ "https://s3-$VAGRANT_S3AUTH_REGION_NONSTANDARD.amazonaws.com/$VAGRANT_S3AUTH_REGION_NONSTANDARD.$VAGRANT_S3AUTH_BUCKET/$VAGRANT_S3AUTH_BOX_BASE.box"
65
+ }
66
+
67
+ @test "public simple box with full path nonstandard url without credentials" {
68
+ AWS_ACCESS_KEY_ID= \
69
+ bundle exec vagrant box add \
70
+ --name "$VAGRANT_S3AUTH_BOX_BASE" \
71
+ "https://s3-$VAGRANT_S3AUTH_REGION_NONSTANDARD.amazonaws.com/$VAGRANT_S3AUTH_REGION_NONSTANDARD.$VAGRANT_S3AUTH_BUCKET/public-$VAGRANT_S3AUTH_BOX_BASE.box"
72
+ }
73
+
74
+ @test "simple box with full host nonstandard url" {
75
+ bundle exec vagrant box add \
76
+ --name "$VAGRANT_S3AUTH_BOX_BASE" \
77
+ "https://$VAGRANT_S3AUTH_REGION_NONSTANDARD.$VAGRANT_S3AUTH_BUCKET.s3-$VAGRANT_S3AUTH_REGION_NONSTANDARD.amazonaws.com/$VAGRANT_S3AUTH_BOX_BASE.box"
78
+ }
79
+
80
+ @test "simple box with shorthand nonstandard url" {
81
+ bundle exec vagrant box add \
82
+ --name "$VAGRANT_S3AUTH_BOX_BASE" \
83
+ "s3://$VAGRANT_S3AUTH_REGION_NONSTANDARD.$VAGRANT_S3AUTH_BUCKET/$VAGRANT_S3AUTH_BOX_BASE.box"
84
+ }
85
+
86
+ @test "metadata box with full path standard url" {
87
+ bundle exec vagrant box add \
88
+ --name "vagrant-s3auth/$VAGRANT_S3AUTH_BOX_BASE" \
89
+ "https://s3.amazonaws.com/us-east-1.$VAGRANT_S3AUTH_BUCKET/$VAGRANT_S3AUTH_BOX_BASE"
90
+ }
91
+
92
+ @test "public metadata box with full path standard url without credentials" {
93
+ AWS_ACCESS_KEY_ID= \
94
+ bundle exec vagrant box add \
95
+ --name "vagrant-s3auth/public-$VAGRANT_S3AUTH_BOX_BASE" \
96
+ "https://s3.amazonaws.com/us-east-1.$VAGRANT_S3AUTH_BUCKET/public-$VAGRANT_S3AUTH_BOX_BASE"
97
+ }
98
+
99
+ @test "metadata box with full host standard url" {
100
+ bundle exec vagrant box add \
101
+ --name "vagrant-s3auth/$VAGRANT_S3AUTH_BOX_BASE" \
102
+ "https://us-east-1.$VAGRANT_S3AUTH_BUCKET.s3.amazonaws.com/$VAGRANT_S3AUTH_BOX_BASE"
103
+ }
104
+
105
+ @test "metadata box with shorthand standard url" {
106
+ bundle exec vagrant box add \
107
+ --name "vagrant-s3auth/$VAGRANT_S3AUTH_BOX_BASE" \
108
+ "s3://us-east-1.$VAGRANT_S3AUTH_BUCKET/$VAGRANT_S3AUTH_BOX_BASE"
109
+ }
110
+
111
+ @test "metadata box with full path nonstandard url" {
112
+ bundle exec vagrant box add \
113
+ --name "vagrant-s3auth/$VAGRANT_S3AUTH_BOX_BASE" \
114
+ "https://s3-$VAGRANT_S3AUTH_REGION_NONSTANDARD.amazonaws.com/$VAGRANT_S3AUTH_REGION_NONSTANDARD.$VAGRANT_S3AUTH_BUCKET/$VAGRANT_S3AUTH_BOX_BASE"
115
+ }
116
+
117
+ @test "public metadata box with full path nonstandard url without credentials" {
118
+ AWS_ACCESS_KEY_ID= \
119
+ bundle exec vagrant box add \
120
+ --name "vagrant-s3auth/public-$VAGRANT_S3AUTH_BOX_BASE" \
121
+ "https://s3-$VAGRANT_S3AUTH_REGION_NONSTANDARD.amazonaws.com/$VAGRANT_S3AUTH_REGION_NONSTANDARD.$VAGRANT_S3AUTH_BUCKET/public-$VAGRANT_S3AUTH_BOX_BASE"
122
+ }
123
+
124
+
125
+ @test "metadata box with full host nonstandard url" {
126
+ bundle exec vagrant box add \
127
+ --name "vagrant-s3auth/$VAGRANT_S3AUTH_BOX_BASE" \
128
+ "https://$VAGRANT_S3AUTH_REGION_NONSTANDARD.$VAGRANT_S3AUTH_BUCKET.s3-$VAGRANT_S3AUTH_REGION_NONSTANDARD.amazonaws.com/$VAGRANT_S3AUTH_BOX_BASE"
129
+ }
130
+
131
+ @test "metadata box with shorthand nonstandard url" {
132
+ bundle exec vagrant box add \
133
+ --name "vagrant-s3auth/$VAGRANT_S3AUTH_BOX_BASE" \
134
+ "s3://$VAGRANT_S3AUTH_REGION_NONSTANDARD.$VAGRANT_S3AUTH_BUCKET/$VAGRANT_S3AUTH_BOX_BASE"
135
+ }
136
+
137
+ @test "garbage shorthand url" {
138
+ run bundle exec vagrant box add --name "$VAGRANT_S3AUTH_BOX_BASE" s3://smoogedydoop
139
+ [[ "$status" -eq 1 ]]
140
+ [[ "$output" == *"Malformed shorthand S3 box URL"* ]]
141
+ }
142
+
143
+ @test "garbage full url" {
144
+ run bundle exec vagrant box add --name "$VAGRANT_S3AUTH_BOX_BASE" https://smoogedydoop
145
+ [[ "$status" -eq 1 ]]
146
+ [[ "$output" == *"error occurred while downloading the remote file"* ]]
147
+ }
data/test/setup.rb ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'aws-sdk'
5
+
6
+ require_relative 'support'
7
+
8
+ ROOT = Pathname.new(File.dirname(__FILE__))
9
+
10
+ box_urls = [REGION_STANDARD, REGION_NONSTANDARD].flat_map do |region|
11
+ s3 = Aws::S3::Resource.new(region: region)
12
+ bucket = s3.create_bucket(bucket: "#{region}.#{BUCKET}")
13
+
14
+ [BOX_BASE, 'public-' + BOX_BASE].flat_map do |box_name|
15
+ box = bucket.object("#{box_name}.box")
16
+ box.upload_file(ROOT + Pathname.new("box/#{box_name}.box"))
17
+ box.acl.put(acl: 'public-read') if box_name.start_with?('public')
18
+
19
+ metadata_string = format(File.read(ROOT + Pathname.new("box/#{box_name}")),
20
+ box_url: box.public_url)
21
+
22
+ metadata = bucket.object(box_name)
23
+ metadata.put(body: metadata_string, content_type: 'application/json')
24
+ metadata.acl.put(acl: 'public-read') if box_name.start_with?('public')
25
+
26
+ box.public_url
27
+ end
28
+ end
29
+
30
+ atlas = Atlas.new(ATLAS_TOKEN, ATLAS_USERNAME)
31
+ atlas.create_box(ATLAS_BOX_NAME)
32
+ atlas.create_version(ATLAS_BOX_NAME, '1.0.1')
33
+ atlas.create_provider(ATLAS_BOX_NAME, '1.0.1', box_urls.sample)
34
+ atlas.release_version(ATLAS_BOX_NAME, '1.0.1')
data/test/support.rb ADDED
@@ -0,0 +1,82 @@
1
+ require 'http'
2
+
3
+ BOX_BASE = ENV['VAGRANT_S3AUTH_BOX_BASE'].freeze
4
+ BUCKET = ENV['VAGRANT_S3AUTH_BUCKET'].freeze
5
+ REGION_STANDARD = 'us-east-1'.freeze
6
+ REGION_NONSTANDARD = ENV['VAGRANT_S3AUTH_REGION_NONSTANDARD'].freeze
7
+
8
+ ATLAS_TOKEN = ENV['ATLAS_TOKEN'].freeze
9
+ ATLAS_USERNAME = ENV['ATLAS_USERNAME'].freeze
10
+ ATLAS_BOX_NAME = ENV['VAGRANT_S3AUTH_ATLAS_BOX_NAME'].freeze
11
+
12
+ class Atlas
13
+ BASE_URL = 'https://app.vagrantup.com/api/v1'.freeze
14
+
15
+ BOX_CREATE_URL = "#{BASE_URL}/boxes".freeze
16
+ BOX_RESOURCE_URL = "#{BASE_URL}/box/%<username>s/%<box_name>s".freeze
17
+
18
+ VERSION_CREATE_URL = "#{BOX_RESOURCE_URL}/versions".freeze
19
+ VERSION_RESOURCE_URL = "#{BOX_RESOURCE_URL}/version/%<version>s".freeze
20
+ VERSION_RELEASE_URL = "#{VERSION_RESOURCE_URL}/release".freeze
21
+
22
+ PROVIDER_CREATE_URL = "#{VERSION_RESOURCE_URL}/providers".freeze
23
+ PROVIDER_RESOURCE_URL = "#{VERSION_RESOURCE_URL}/provider/%<provider_name>s".freeze
24
+
25
+ attr_accessor :provider
26
+
27
+ def initialize(token, username)
28
+ raise if !token || token.empty?
29
+ raise if !username || username.empty?
30
+
31
+ @token = token
32
+ @username = username
33
+ @provider = 'virtualbox'
34
+ end
35
+
36
+ def create_box(box_name)
37
+ post(BOX_CREATE_URL, data: { box: { name: box_name, is_private: false } })
38
+ end
39
+
40
+ def delete_box(box_name)
41
+ url_params = { box_name: box_name }
42
+ delete(BOX_RESOURCE_URL, url_params: url_params)
43
+ end
44
+
45
+ def create_version(box_name, version)
46
+ post(VERSION_CREATE_URL,
47
+ data: { version: { version: version } },
48
+ url_params: { box_name: box_name })
49
+ end
50
+
51
+ def release_version(box_name, version)
52
+ put(VERSION_RELEASE_URL,
53
+ url_params: { box_name: box_name, version: version })
54
+ end
55
+
56
+ def create_provider(box_name, version, url)
57
+ post(PROVIDER_CREATE_URL,
58
+ data: { provider: { name: @provider, url: url } },
59
+ url_params: { box_name: box_name, version: version })
60
+ end
61
+
62
+ def request(method, url, options)
63
+ url_params = (options[:url_params] || {}).merge(username: @username)
64
+ data = (options[:data] || {})
65
+
66
+ url = (url % url_params) + "?access_token=#{@token}"
67
+ response = HTTP.request(method, url, json: data)
68
+ raise response unless response.code >= 200 && response.code < 400
69
+ end
70
+
71
+ def post(url, options)
72
+ request(:post, url, options)
73
+ end
74
+
75
+ def put(url, options)
76
+ request(:put, url, options)
77
+ end
78
+
79
+ def delete(url, options)
80
+ request(:delete, url, options)
81
+ end
82
+ end
@@ -0,0 +1,25 @@
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
+
3
+ require 'vagrant-s3auth/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'vagrant-s3auth-mfa'
7
+ spec.version = VagrantPlugins::S3Auth::VERSION
8
+ spec.authors = ['Nikhil Benesch']
9
+ spec.email = ['benesch@whoop.com']
10
+ spec.summary = '[Forked by VRTDev] Private, versioned Vagrant boxes hosted on Amazon S3.'
11
+ spec.homepage = 'https://github.com/WhoopInc/vagrant-s3auth'
12
+ spec.license = 'MIT'
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.test_files = spec.files.grep(/spec/)
16
+ spec.require_paths = ['lib']
17
+
18
+ spec.add_dependency 'aws-sdk', '~> 2.6.44'
19
+ spec.add_dependency 'aws_config', '~> 0.1.0'
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.5'
22
+ spec.add_development_dependency 'http', '~> 1.0.2'
23
+ spec.add_development_dependency 'rake', '~> 12.0'
24
+ spec.add_development_dependency 'rubocop', '~> 0.46'
25
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-s3auth-mfa
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Nikhil Benesch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.6.44
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.6.44
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws_config
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: http
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '12.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '12.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.46'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.46'
97
+ description:
98
+ email:
99
+ - benesch@whoop.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rubocop.yml"
106
+ - ".ruby-version"
107
+ - ".travis.yml"
108
+ - CHANGELOG.md
109
+ - CONTRIBUTING.md
110
+ - Gemfile
111
+ - LICENSE
112
+ - README.md
113
+ - Rakefile
114
+ - TESTING.md
115
+ - lib/vagrant-s3auth.rb
116
+ - lib/vagrant-s3auth/errors.rb
117
+ - lib/vagrant-s3auth/extension/downloader.rb
118
+ - lib/vagrant-s3auth/middleware/expand_s3_urls.rb
119
+ - lib/vagrant-s3auth/plugin.rb
120
+ - lib/vagrant-s3auth/util.rb
121
+ - lib/vagrant-s3auth/version.rb
122
+ - locales/en.yml
123
+ - test/box/minimal
124
+ - test/box/minimal.box
125
+ - test/box/public-minimal
126
+ - test/box/public-minimal.box
127
+ - test/cleanup.rb
128
+ - test/run.bats
129
+ - test/setup.rb
130
+ - test/support.rb
131
+ - vagrant-s3auth.gemspec
132
+ homepage: https://github.com/WhoopInc/vagrant-s3auth
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.7.7
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: "[Forked by VRTDev] Private, versioned Vagrant boxes hosted on Amazon S3."
156
+ test_files:
157
+ - vagrant-s3auth.gemspec