vagrant-fog-box-storage 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
@@ -0,0 +1,7 @@
1
+ # 0.0.2
2
+
3
+ Um...fix require paths.
4
+
5
+ # 0.0.1
6
+
7
+ Iniitial release
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem "protest", "~> 0.4.0"
7
+ gem "mocha", "~> 0.9.8"
8
+ end
@@ -0,0 +1,58 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vagrant-fog-box-storage (0.0.1)
5
+ fog (~> 1.0)
6
+ vagrant (~> 1.0.6)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ archive-tar-minitar (0.5.2)
12
+ builder (3.2.0)
13
+ childprocess (0.3.9)
14
+ ffi (~> 1.0, >= 1.0.11)
15
+ erubis (2.7.0)
16
+ excon (0.19.5)
17
+ ffi (1.4.0)
18
+ fog (1.9.0)
19
+ builder
20
+ excon (~> 0.14)
21
+ formatador (~> 0.2.0)
22
+ mime-types
23
+ multi_json (~> 1.0)
24
+ net-scp (~> 1.0.4)
25
+ net-ssh (>= 2.1.3)
26
+ nokogiri (~> 1.5.0)
27
+ ruby-hmac
28
+ formatador (0.2.4)
29
+ i18n (0.6.4)
30
+ json (1.5.5)
31
+ log4r (1.1.10)
32
+ mime-types (1.21)
33
+ mocha (0.9.12)
34
+ multi_json (1.6.1)
35
+ net-scp (1.0.4)
36
+ net-ssh (>= 1.99.1)
37
+ net-ssh (2.2.2)
38
+ nokogiri (1.5.6)
39
+ protest (0.4.2)
40
+ ruby-hmac (0.4.0)
41
+ vagrant (1.0.6)
42
+ archive-tar-minitar (= 0.5.2)
43
+ childprocess (~> 0.3.1)
44
+ erubis (~> 2.7.0)
45
+ i18n (~> 0.6.0)
46
+ json (~> 1.5.1)
47
+ log4r (~> 1.1.9)
48
+ net-scp (~> 1.0.4)
49
+ net-ssh (~> 2.2.2)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ bundler (>= 1.0.0)
56
+ mocha (~> 0.9.8)
57
+ protest (~> 0.4.0)
58
+ vagrant-fog-box-storage!
@@ -0,0 +1,43 @@
1
+ # vagrant-fog-box-storage
2
+
3
+ Use the [fog](http://fog.io/) gem to get the authenticated url of a box to download from your favorite
4
+ cloud storage jawn.
5
+
6
+ The use case is if you have a vagrant box, stored on S3 (or another storage
7
+ provider supported by fog) that you don't want to be downloadable publicly that
8
+ you need to authenticate somehow to get at.
9
+
10
+ Note that this doesn't actually add an additional vagrant downloader class, but instead
11
+ grabs the authenticated url and uses ```Vagrant::Downloaders::HTTP``` to fetch
12
+ the box.
13
+
14
+ Example:
15
+
16
+ ```ruby
17
+ require 'vagrant-fog-box-storage'
18
+
19
+ Vagrant::Config.run do |config|
20
+ config.vm.define :app do |app_config|
21
+ app_config.fog_box_storage.provider = 'AWS'
22
+ app_config.fog_box_storage.access_key_id = "AAAAAAAAAAAAAAA"
23
+ app_config.fog_box_storage.secret_access_key = "XXXXXXXXXXXXXXXXXXXXXXXXX"
24
+ app_config.fog_box_storage.bucket_name = "awesome-secret-bukkit"
25
+ app_config.fog_box_storage.box_file_name = "secret-linux.box"
26
+
27
+ app_config.vm.box_url = app_config.fog_box_storage.box_url
28
+
29
+ app_config.vm.box = "secret-linux"
30
+ end
31
+ end
32
+
33
+ ```
34
+
35
+ ## TODO
36
+
37
+ Not sure if there's a way to reach in and set ```vm.box_url``` from within the
38
+ plugin instead of having to call the ```#box_url``` method from the plugin from
39
+ the Vagrantfile.
40
+
41
+ ## What else?
42
+
43
+ I've only used this with S3.
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'bundler/setup'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ task :default => :test
7
+
8
+ desc "Run the test suite."
9
+ task :test do
10
+ $:.unshift File.expand_path("../test", __FILE__)
11
+
12
+ Dir["test/**/*_test.rb"].each do |f|
13
+ load f
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ require 'fog'
2
+ require File.join(File.dirname(__FILE__), 'vagrant-fog-box-storage', 'version')
3
+ require File.join(File.dirname(__FILE__), 'vagrant-fog-box-storage', 'config')
@@ -0,0 +1,82 @@
1
+ require 'vagrant/config'
2
+
3
+
4
+ module VagrantFogBoxStorage
5
+
6
+ class CloudStorageBoxNotFound < Exception ; end
7
+ class CloudStorageBucketNotFound < Exception ; end
8
+
9
+ class Config < Vagrant::Config::Base
10
+ def self.key_names
11
+ [
12
+ :provider,
13
+ :access_key_id,
14
+ :secret_access_key,
15
+ :bucket_name,
16
+ :box_file_name
17
+ ]
18
+ end
19
+
20
+ self.key_names.each do |name|
21
+ attr_accessor name
22
+ end
23
+
24
+ def is_used?
25
+ self.class.key_names.any? do |name|
26
+ !self.send(name).nil?
27
+ end
28
+ end
29
+
30
+ def cloud_storage
31
+ if is_used?
32
+ provider_name = self.provider.to_s.downcase
33
+
34
+ @cloud_storage ||= Fog::Storage.new({
35
+ :provider => self.provider,
36
+ :"#{provider_name}_access_key_id" => self.access_key_id,
37
+ :"#{provider_name}_secret_access_key" => self.secret_access_key
38
+ })
39
+ end
40
+ end
41
+
42
+ def cloud_directories
43
+ cloud_storage.directories
44
+ end
45
+
46
+ def box_directory
47
+ directory = cloud_directories.get(self.bucket_name)
48
+
49
+ raise CloudStorageBucketNotFound.new("#{self.bucket_name} does not exist") if !directory
50
+
51
+ directory
52
+ end
53
+
54
+ def directory_files
55
+ directory = box_directory()
56
+
57
+ directory.files
58
+ end
59
+
60
+ def expiry_time
61
+ Time.now + 3600
62
+ end
63
+
64
+ def box_url
65
+ files = directory_files()
66
+
67
+ url = files.get_https_url(self.box_file_name, expiry_time)
68
+
69
+ url
70
+ end
71
+
72
+ def validate(env, errors)
73
+ if is_used?
74
+ errors.add('missing provider') if !self.provider
75
+ errors.add('missing access_key_id') if !self.access_key_id
76
+ errors.add('missing secret_access_key') if !self.secret_access_key
77
+ errors.add('missing bucket_name') if !self.bucket_name
78
+ errors.add('missing box_file_name') if !self.box_file_name
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,3 @@
1
+ module VagrantFogBoxStorage
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,6 @@
1
+ # This file is automatically loaded by Vagrant to load any
2
+ # plugins. This file kicks off this plugin.
3
+
4
+ require 'vagrant-fog-box-storage'
5
+
6
+ Vagrant.config_keys.register(:fog_box_storage) { VagrantFogBoxStorage::Config }
@@ -0,0 +1,36 @@
1
+ require 'vagrant'
2
+ require "test/unit/assertions"
3
+ require "protest"
4
+ require "mocha"
5
+ require "vagrant-fog-box-storage"
6
+
7
+ class Protest::TestCase
8
+ include Test::Unit::Assertions
9
+ include Mocha::API
10
+ include Vagrant::TestHelpers
11
+
12
+ # Get Mocha integrated properly into the tests
13
+ alias :original_run :run
14
+ def run(report)
15
+ original_run(report)
16
+ mocha_verify
17
+ ensure
18
+ mocha_teardown
19
+ end
20
+
21
+ # Helper to silence streams, courtesy of Ruby Facets library.
22
+ def silence_stream(*streams) #:yeild:
23
+ on_hold = streams.collect{ |stream| stream.dup }
24
+ streams.each do |stream|
25
+ stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
26
+ stream.sync = true
27
+ end
28
+ yield
29
+ ensure
30
+ streams.each_with_index do |stream, i|
31
+ stream.reopen(on_hold[i])
32
+ end
33
+ end
34
+ end
35
+
36
+ Protest.report_with(:documentation)
@@ -0,0 +1,69 @@
1
+ require "test_helper"
2
+
3
+ Protest.describe("Configuration class") do
4
+ setup do
5
+ Fog.mock!
6
+
7
+ @klass = VagrantFogBoxStorage::Config
8
+ @instance = @klass.new
9
+ @errors = Vagrant::Config::ErrorRecorder.new
10
+ @env = mock('Vagrant::Environment')
11
+ end
12
+
13
+ should "be valid by default" do
14
+ @instance.validate(@env, @errors)
15
+ assert @errors.errors.empty?
16
+ end
17
+
18
+ should "be invalid if any one key is set and another is not" do
19
+ @instance.provider = :aws
20
+ @instance.validate(@env, @errors)
21
+
22
+ assert !@errors.errors.empty?
23
+ end
24
+
25
+ should "be is_used? if all keys are set" do
26
+ @instance.provider = :aws
27
+ @instance.access_key_id = "1Z"
28
+ @instance.secret_access_key = "1Z"
29
+ @instance.bucket_name = "bukkit"
30
+ @instance.box_file_name = "awesome.box"
31
+ end
32
+
33
+ context 'with all keys set' do
34
+ setup do
35
+ @instance.provider = :aws
36
+ @instance.access_key_id = "1Z"
37
+ @instance.secret_access_key = "1Z"
38
+ @instance.bucket_name = "bukkit"
39
+ @instance.box_file_name = "awesome.box"
40
+ end
41
+
42
+ context "#box_directory" do
43
+ should "get the directory using bucket_name" do
44
+ @instance.stubs(:cloud_directories).returns(dirs = [])
45
+ dirs.expects(:get).with('bukkit').returns(mock('FogDirectory'))
46
+
47
+ @instance.box_directory()
48
+ end
49
+ end
50
+
51
+ context "#box_url" do
52
+ context "when box is found" do
53
+ setup do
54
+ @instance.stubs(:directory_files).returns(@files = mock('Files'))
55
+ @instance.stubs(:expiry_time).returns(@expires = Time.now)
56
+ end
57
+
58
+ should "return url for box" do
59
+ @files.expects(:get_https_url).with(@instance.box_file_name, @expires).
60
+ returns("http://example.com/files.gz")
61
+
62
+
63
+ assert_equal "http://example.com/files.gz", @instance.box_url
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/vagrant-fog-box-storage/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "vagrant-fog-box-storage"
6
+ s.version = VagrantFogBoxStorage::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Nat Lownes"]
9
+ s.email = ["nat.lownes@gmail.com"]
10
+ s.homepage = "https://github.com/natlownes/vagrant-fog-box-storage"
11
+ s.summary = "The use case is if you have a vagrant box, stored on S3 (or another storage provider supported by fog) that you don't want to be downloadable publicly that you need to authenticate somehow to get at."
12
+ s.description = ""
13
+
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+
16
+ s.add_dependency "vagrant" , "~> 1.0.6"
17
+ s.add_dependency "fog" , "~> 1.0"
18
+
19
+ s.add_development_dependency "protest" , "~> 0.4.0"
20
+ s.add_development_dependency "mocha" , "~> 0.9.8"
21
+ s.add_development_dependency "bundler" , ">= 1.0.0"
22
+
23
+ s.files = `git ls-files`.split("\n")
24
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
25
+ s.require_path = 'lib'
26
+ end
@@ -0,0 +1,3 @@
1
+ require 'vagrant'
2
+ require 'vagrant/config'
3
+ require File.join(File.dirname(__FILE__), 'lib', 'vagrant-fog-box-storage')
metadata CHANGED
@@ -1,103 +1,141 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: vagrant-fog-box-storage
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - Nat Lownes
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2013-03-06 00:00:00 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
12
+ date: 2013-03-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
15
  name: vagrant
16
- prerelease: false
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- requirements:
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
19
  - - ~>
20
- - !ruby/object:Gem::Version
20
+ - !ruby/object:Gem::Version
21
21
  version: 1.0.6
22
22
  type: :runtime
23
- version_requirements: *id001
24
- - !ruby/object:Gem::Dependency
25
- name: fog
26
23
  prerelease: false
27
- requirement: &id002 !ruby/object:Gem::Requirement
28
- requirements:
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.6
30
+ - !ruby/object:Gem::Dependency
31
+ name: fog
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
29
35
  - - ~>
30
- - !ruby/object:Gem::Version
31
- version: "1.0"
36
+ - !ruby/object:Gem::Version
37
+ version: '1.0'
32
38
  type: :runtime
33
- version_requirements: *id002
34
- - !ruby/object:Gem::Dependency
35
- name: protest
36
39
  prerelease: false
37
- requirement: &id003 !ruby/object:Gem::Requirement
38
- requirements:
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: protest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
39
51
  - - ~>
40
- - !ruby/object:Gem::Version
52
+ - !ruby/object:Gem::Version
41
53
  version: 0.4.0
42
54
  type: :development
43
- version_requirements: *id003
44
- - !ruby/object:Gem::Dependency
45
- name: mocha
46
55
  prerelease: false
47
- requirement: &id004 !ruby/object:Gem::Requirement
48
- requirements:
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
49
59
  - - ~>
50
- - !ruby/object:Gem::Version
60
+ - !ruby/object:Gem::Version
61
+ version: 0.4.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: mocha
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
51
69
  version: 0.9.8
52
70
  type: :development
53
- version_requirements: *id004
54
- - !ruby/object:Gem::Dependency
55
- name: bundler
56
71
  prerelease: false
57
- requirement: &id005 !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.9.8
78
+ - !ruby/object:Gem::Dependency
79
+ name: bundler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
61
85
  version: 1.0.0
62
86
  type: :development
63
- version_requirements: *id005
64
- description: ""
65
- email:
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 1.0.0
94
+ description: ''
95
+ email:
66
96
  - nat.lownes@gmail.com
67
97
  executables: []
68
-
69
98
  extensions: []
70
-
71
99
  extra_rdoc_files: []
72
-
73
- files: []
74
-
75
- homepage: ""
100
+ files:
101
+ - .gitignore
102
+ - CHANGELOG.md
103
+ - Gemfile
104
+ - Gemfile.lock
105
+ - README.md
106
+ - Rakefile
107
+ - lib/vagrant-fog-box-storage.rb
108
+ - lib/vagrant-fog-box-storage/config.rb
109
+ - lib/vagrant-fog-box-storage/version.rb
110
+ - lib/vagrant_init.rb
111
+ - test/test_helper.rb
112
+ - test/vagrant-fog-box-storage/config_test.rb
113
+ - vagrant-fog-box-storage.gemspec
114
+ - vagrant-fog-box-storage.rb
115
+ homepage: https://github.com/natlownes/vagrant-fog-box-storage
76
116
  licenses: []
77
-
78
- metadata: {}
79
-
80
117
  post_install_message:
81
118
  rdoc_options: []
82
-
83
- require_paths:
119
+ require_paths:
84
120
  - lib
85
- required_ruby_version: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: "0"
90
- required_rubygems_version: !ruby/object:Gem::Requirement
91
- requirements:
92
- - - ">="
93
- - !ruby/object:Gem::Version
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
94
132
  version: 1.3.6
95
133
  requirements: []
96
-
97
134
  rubyforge_project:
98
- rubygems_version: 2.0.2
135
+ rubygems_version: 1.8.25
99
136
  signing_key:
100
- specification_version: 4
101
- summary: ""
137
+ specification_version: 3
138
+ summary: The use case is if you have a vagrant box, stored on S3 (or another storage
139
+ provider supported by fog) that you don't want to be downloadable publicly that
140
+ you need to authenticate somehow to get at.
102
141
  test_files: []
103
-
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA512:
3
- metadata.gz: 8cc3d8717f76f33f7b55dfed6e327eadfffcab97f6ab0334e4797a06796eea11c77a8fa979aa016ec9ab30981b8bc21fa49a58e1551707796261624e8b369a8d
4
- data.tar.gz: c17469a29ccc9be165acbc9f608513c7be13ffc3130b556ee3df44fc0e7796f502a5d701cc740d4568ec4d7e841235362e48d88c2f790c2ad003a24da5219e6a
5
- SHA1:
6
- metadata.gz: 2a8eb0a161234ae4b5aea7ad29640c5cc1a7dd6b
7
- data.tar.gz: 01bf75f6ca5f109de13b5f074d650db109a26298