bib-vagrant 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
  SHA1:
3
- metadata.gz: e61e6e30152c53c0beb8c47629d5ab6c02a20131
4
- data.tar.gz: 20110d8627d95de0556d45585f2fe657b2fe10d4
3
+ metadata.gz: 321c5c79c1c30f4f74a06e99065d2d3efd47ee03
4
+ data.tar.gz: 5065e81e14aa4a075bdb949ddf4ae4e3164b3756
5
5
  SHA512:
6
- metadata.gz: 4e2981e65dcd8d39210e4c71d32128e23427d987aaf170e80349266f5b415db0375f454eb59847500406e626ffd01b692cbbb6687f17ff55098af46e596e0610
7
- data.tar.gz: 0c7f5978c96ad4e529d50ccb68f40a42893eeda13820c7d8e9ba73681909c76b6867450a37f5139c9d8f4a9a26a47f6eed666b5b0fa3d2c9d6670549013b7044
6
+ metadata.gz: 81fe49a54adf89136038fb269dd716e245b28bb35b96750da69cd53d7e7b59420fbe5266d3891cbd827c84b5d17cf3389c09c9387d4e4a855d09e650a4328401
7
+ data.tar.gz: 5b0d4ed21cd034e2dc9f75948f5e04f7212062064ec61ae9f241e4adb0c31bbfb2709803b6fcc7592089bab0230a2dd2bff6cbc93687b479575dc799c81ea6f2
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .DS_Store
1
2
  *.gem
2
3
  *.rbc
3
4
  .vagrant
data/.travis.yml CHANGED
@@ -1,7 +1,6 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 1.9.3
5
4
  - 2.0.0
6
5
 
7
6
  script:
data/CONTRIBUTING.md CHANGED
@@ -8,5 +8,5 @@
8
8
 
9
9
  # publishing new release
10
10
 
11
- Use `rake release` to tag & publish a new release
11
+ Use `bundle exec rake release` to tag & publish a new release
12
12
 
data/Gemfile CHANGED
@@ -5,12 +5,11 @@ source 'https://rubygems.org'
5
5
  gemspec
6
6
 
7
7
  group :development do
8
- gem "vagrant", git: "https://github.com/mitchellh/vagrant.git"
8
+ gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
9
9
  # gem "vagrant", git: "git://github.com/mitchellh/vagrant.git", tag: "v1.7.4"
10
10
  # gem "vagrant", git: "git://github.com/mitchellh/vagrant.git", tag: "v1.3.5"
11
11
  end
12
12
 
13
13
  group :plugins do
14
- gem "bib-vagrant", path: "."
14
+ gem 'bib-vagrant', path: '.'
15
15
  end
16
-
data/README.md CHANGED
@@ -16,10 +16,11 @@ This is a work in progress - and subject to [additions and changes](CONTRIBUTING
16
16
  Install the plugin:
17
17
 
18
18
  $ vagrant plugin install bib-vagrant
19
-
19
+
20
20
  Do not use this command in a directory with a Vagrantfile which requires the plugin. Vagrant does _always_ include the Vagrantfile, and therefore will fail before installation because of the missing plugin. Just ```cd``` somewhere else and retry the command, maybe from your homedir?
21
21
 
22
22
  ## Usage
23
+
23
24
  ### Developer Settings
24
25
  The config file with all developer specific settings is currently ```~/.config/easybib/vagrantdefault.yml```. If no such file exists, the plugin will create the file with default settings.
25
26
 
@@ -30,7 +31,7 @@ The current default settings and their respective usage in our Vagrantfiles are:
30
31
  ```
31
32
 
32
33
  #Use filesystem shares over nfs
33
- nfs: false
34
+ nfs: false
34
35
 
35
36
  #Path to the cookbooks
36
37
  cookbook_path: ~/Sites/easybib/cookbooks
@@ -92,9 +93,9 @@ Vagrant.configure("2") do |config|
92
93
  chef.add_recipe "something::here"
93
94
  chef.log_level = vagrantconfig["chef_log_level"]
94
95
  end
95
-
96
- web_config.vm.provision "bib_configure_npm"
97
-
96
+
97
+ web_config.vm.provision "bib_configure_npm"
98
+
98
99
  end
99
100
  ```
100
101
 
@@ -114,6 +115,8 @@ npm_usermail: <npm or github users email address>
114
115
  npm_userpass: <npm or github authentication token>
115
116
  ```
116
117
 
118
+ NOTE: the npm_registry should be in the format of 'http[s]://host.domain.tld/' - The trailing slash is important
119
+
117
120
  ## Contributing
118
121
 
119
122
  See [Contributing](CONTRIBUTING.md)
data/Rakefile CHANGED
@@ -3,8 +3,8 @@ Coveralls.wear!
3
3
 
4
4
  ## Bundler::GemHelper.install_tasks
5
5
 
6
- require "bundler/gem_tasks"
7
- require "minitest/autorun"
6
+ require 'bundler/gem_tasks'
7
+ require 'minitest/autorun'
8
8
 
9
9
  Encoding.default_external = Encoding::UTF_8
10
10
  Encoding.default_internal = Encoding::UTF_8
data/Vagrantfile CHANGED
@@ -1,15 +1,15 @@
1
1
 
2
- Vagrant.configure("2") do |config|
3
- foo = Bib::Vagrant::Config.new()
2
+ Vagrant.configure('2') do |config|
3
+ foo = Bib::Vagrant::Config.new
4
4
  puts foo.get.inspect
5
-
5
+
6
6
  # for testing ubuntu 14.04
7
7
  config.vm.box = 'trusty-server-cloudimg-amd64-vagrant-disk1.box'
8
8
  config.vm.box_url = 'https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box'
9
9
 
10
10
  # for testing ubuntu 15.04
11
11
  # config.vm.box = 'vivid-server-cloudimg-amd64-vagrant-disk1.box'
12
- # config.vm.box_url = 'https://cloud-images.ubuntu.com/vagrant/vivid/current/vivid-server-cloudimg-amd64-vagrant-disk1.box'
12
+ # config.vm.box_url = 'https://cloud-images.ubuntu.com/vagrant/vivid/current/vivid-server-cloudimg-amd64-vagrant-disk1.box'
13
13
 
14
14
  # config.vm.provision :shell, :path => 'apt-spy-2-bootstrap.sh'
15
15
 
@@ -21,10 +21,9 @@ Vagrant.configure("2") do |config|
21
21
 
22
22
  config.vm.provision 'shell', inline: 'sudo apt-get -y install nodejs npm'
23
23
 
24
- config.vm.provision 'bib_configure_npm'
24
+ config.vm.provision 'bib_configure_npm'
25
25
 
26
26
  config.vm.provision 'shell', inline: 'npm config list'
27
27
 
28
28
  config.vm.provision 'shell', inline: 'npm --loglevel silly view test'
29
-
30
29
  end
data/bib-vagrant.gemspec CHANGED
@@ -1,31 +1,30 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'bib/vagrant/version'
4
+ require 'bib/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "bib-vagrant"
7
+ spec.name = 'bib-vagrant'
8
8
  spec.version = Bib::Vagrant::VERSION
9
- spec.authors = ["tillk", "fh", "gilleyj"]
10
- spec.email = ["till@php.net"]
9
+ spec.authors = %w('tillk', 'fh', 'gilleyj')
10
+ spec.email = ['till@php.net']
11
11
  spec.description = "A rubygem to centralize configuration and setup in every project's Vagrantfile"
12
- spec.summary = "Centralize configuration and setup"
13
- spec.homepage = "https://github.com/easybiblabs/bib-vagrant"
14
- spec.license = "New BSD License"
12
+ spec.summary = 'Centralize configuration and setup'
13
+ spec.homepage = 'https://github.com/easybiblabs/bib-vagrant'
14
+ spec.license = 'New BSD License'
15
15
 
16
- spec.files = `git ls-files`.split($/)
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'thor', '>= 0.18.1'
22
22
  spec.add_dependency 'colored', '>= 1.2'
23
23
  spec.add_dependency 'rest_client'
24
24
  spec.add_dependency 'json'
25
25
 
26
- spec.add_development_dependency "bundler", "~> 1.5"
27
- spec.add_development_dependency "rake"
28
- spec.add_development_dependency "minitest", "~> 5.0.8"
29
- spec.add_development_dependency "coveralls"
26
+ spec.add_development_dependency 'bundler', '~> 1.5'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'minitest', '~> 5.0.8'
29
+ spec.add_development_dependency 'coveralls'
30
30
  end
31
-
data/bin/bib-vagrant CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'thor'
4
- require 'bib/vagrant'
4
+ require 'bib'
5
5
  require 'colored'
6
6
 
7
7
  Encoding.default_external = Encoding::UTF_8
@@ -0,0 +1,94 @@
1
+ require 'yaml'
2
+
3
+ module Bib
4
+ module Vagrant
5
+ class Config
6
+ @@home_dir = nil
7
+ @@verbose = true
8
+
9
+ def initialize(home = '~', verbose = true)
10
+ @@home = home
11
+ @@verbose = verbose
12
+ end
13
+
14
+ def get
15
+ vagrantconfig = get_defaults
16
+
17
+ begin
18
+ localconfigfile = File.open(get_path, 'r')
19
+ vagrantconfig.merge!(YAML.load(localconfigfile.read))
20
+ rescue Errno::ENOENT
21
+ puts 'WARNING: No vagrant user-config found, using default cookbook path' if @@verbose
22
+ create(get_path, vagrantconfig)
23
+ end
24
+
25
+ vagrantconfig
26
+ end
27
+
28
+ def has?
29
+ File.exist?(get_path)
30
+ end
31
+
32
+ def get_path
33
+ File.expand_path("#{@@home}/.config/easybib/vagrantdefault.yml")
34
+ end
35
+
36
+ def validate!(config)
37
+ current_config_keys = config.keys
38
+
39
+ get_defaults.keys.each do |required_key|
40
+ fail "Missing #{required_key}!" unless current_config_keys.include?(required_key)
41
+ end
42
+
43
+ errors = []
44
+ log_level = %w(debug info warn error fatal)
45
+ bool = [TrueClass, FalseClass]
46
+
47
+ cookbook_path = File.expand_path(config['cookbook_path'])
48
+
49
+ errors << 'nfs: must be a boolean' unless bool.include?(config['nfs'].class)
50
+ errors << 'gui: must be a boolean' unless bool.include?(config['gui'].class)
51
+ errors << 'cookbook_path: does not exist' unless File.directory?(cookbook_path)
52
+ errors << "chef_log_level: must be one of #{log_level.join}" unless log_level.include?(config['chef_log_level'])
53
+
54
+ unless config['additional_json'].empty?
55
+ errors << 'additional_json: must be empty or valid json' unless is_valid_json?(config['additional_json'])
56
+ end
57
+
58
+ return true if errors.count == 0
59
+
60
+ fail "Errors: #{errors.join(', ')}"
61
+ end
62
+
63
+ private
64
+
65
+ def create(localconfigpath, vagrantconfig)
66
+ FileUtils.mkdir_p(File.dirname(localconfigpath))
67
+ File.open(localconfigpath, 'w+') do |file|
68
+ file.write(vagrantconfig.to_yaml)
69
+ puts "INFO: Created default vagrant user-config in #{localconfigpath}" if @@verbose
70
+ puts 'INFO: You probably want to fix the path to the cookbooks in this file.' if @@verbose
71
+ end
72
+ rescue
73
+ puts "WARNING: Unable to create default #{localconfigpath} - please do it manually." if @@verbose
74
+ end
75
+
76
+ def get_defaults
77
+ {
78
+ 'nfs' => false,
79
+ 'cookbook_path' => '~/Sites/easybib/cookbooks',
80
+ 'chef_log_level' => 'debug',
81
+ 'additional_json' => '{}',
82
+ 'gui' => false
83
+ }
84
+ end
85
+
86
+ def is_valid_json?(json)
87
+ JSON.parse(json)
88
+ return true
89
+ rescue JSON::ParserError
90
+ false
91
+ end
92
+ end
93
+ end
94
+ end
@@ -4,13 +4,22 @@ require 'rest_client'
4
4
  require 'json'
5
5
  require 'base64'
6
6
 
7
- # Define the plugin.
7
+ String.class_eval do
8
+ def is_valid_url?
9
+ uri = URI.parse self
10
+ uri.is_a? URI::HTTP
11
+ rescue URI::InvalidURIError
12
+ false
13
+ end
14
+ end
15
+
16
+ # Define the provisioner.
17
+ # do this outside of the bib::vagrant module for ease of calling
8
18
  class BibConfigurePlugin < Vagrant.plugin('2')
9
- name 'NPM configuration Plugin'
19
+ name 'NPM configuration Provisioner'
10
20
 
11
21
  # This plugin provides a provisioner called unix_reboot.
12
22
  provisioner 'bib_configure_npm' do
13
-
14
23
  # Create a provisioner.
15
24
  class BibConfigureProvisioner < Vagrant.plugin('2', :provisioner)
16
25
  # Initialization, define internal state. Nothing needed.
@@ -20,12 +29,12 @@ class BibConfigurePlugin < Vagrant.plugin('2')
20
29
  def initialize(machine, config)
21
30
  super(machine, config)
22
31
  end
23
-
32
+
24
33
  # Configuration changes to be done. Nothing needed here either.
25
34
  def configure(root_config)
26
35
  super(root_config)
27
36
  end
28
-
37
+
29
38
  # Run the provisioning.
30
39
  def provision
31
40
  return unless @machine.communicate.ready?
@@ -58,7 +67,7 @@ class BibConfigurePlugin < Vagrant.plugin('2')
58
67
  userpass = bib_config_values['npm_userpass'].clone
59
68
  end
60
69
 
61
- if ( registry && username && usermail && userpass)
70
+ if registry && username && usermail && userpass
62
71
  auth_hash = Base64.strict_encode64(username + ':' + userpass)
63
72
  auth_token = get_npm_token(registry, username, usermail, userpass)
64
73
  if auth_token
@@ -73,13 +82,13 @@ class BibConfigurePlugin < Vagrant.plugin('2')
73
82
  # npmrc_set('username', username)
74
83
 
75
84
  # for older npm user/pass hash authentication
76
- npmrc_set( '_auth', '"' + auth_hash + '"')
85
+ npmrc_set('_auth', '"' + auth_hash + '"')
77
86
 
78
87
  # for newer npm token authentication
79
- npmrc_set( registry_ident + ':_authToken', '"' + auth_token + '"')
80
-
88
+ npmrc_set(registry_ident + ':_authToken', '"' + auth_token + '"')
89
+
81
90
  else
82
- @machine.ui.info("npm registry token request failed. Attempting old style auth configuration.")
91
+ @machine.ui.info('npm registry token request failed. Attempting old style auth configuration.')
83
92
  npmrc_set('always-auth', 'true')
84
93
  npmrc_set('registry', registry)
85
94
  npmrc_set('email', usermail)
@@ -90,27 +99,19 @@ class BibConfigurePlugin < Vagrant.plugin('2')
90
99
  npmrc_set('_auth', auth_hash)
91
100
  end
92
101
 
93
- else
102
+ else
94
103
 
95
104
  message = ''
96
- if !registry
97
- message += " npm_registry"
98
- end
105
+ message += ' npm_registry' unless registry
99
106
 
100
- if !username
101
- message += " npm_username"
102
- end
107
+ message += ' npm_username' unless username
103
108
 
104
- if !usermail
105
- message += " npm_userpass"
106
- end
109
+ message += ' npm_userpass' unless usermail
107
110
 
108
- if !userpass
109
- message += " npm_userpass"
110
- end
111
+ message += ' npm_userpass' unless userpass
111
112
 
112
- @machine.ui.warn("WARNING: Missing " + message + " value(s) in ~/.config/easybib/vagrantdefault.yml (Your HOST OS)")
113
- @machine.ui.warn("WARNING: .npmrc not setup on guest OS")
113
+ @machine.ui.warn('WARNING: Missing ' + message + ' value(s) in ~/.config/easybib/vagrantdefault.yml (On your HOST OS)')
114
+ @machine.ui.warn('WARNING: .npmrc not setup on your guest OS')
114
115
  end
115
116
 
116
117
  # if bib_config_values.includ?('composer_github_token')
@@ -118,9 +119,9 @@ class BibConfigurePlugin < Vagrant.plugin('2')
118
119
  # else
119
120
  # @machine.ui.warn("Missing composer_github_token value in config")
120
121
  # end
121
-
122
- send_command("mkdir -p ~/.npm/_locks")
123
- send_command("sudo chown -R $USER ~/.npm")
122
+
123
+ send_command('mkdir -p ~/.npm/_locks')
124
+ send_command('sudo chown -R $USER ~/.npm')
124
125
 
125
126
  # Now the machine is up again, perform the necessary tasks.
126
127
  @machine.ui.info('bib-vagrant config complete...')
@@ -132,7 +133,7 @@ class BibConfigurePlugin < Vagrant.plugin('2')
132
133
  # end
133
134
 
134
135
  def npmrc_set(key, value)
135
- command = "npm -g config "
136
+ command = 'npm -g config '
136
137
  if value
137
138
  command << "set #{key} #{value}"
138
139
  else
@@ -156,7 +157,7 @@ class BibConfigurePlugin < Vagrant.plugin('2')
156
157
  end
157
158
  end
158
159
 
159
- def sudo_command(command)
160
+ def sudo_command(command)
160
161
  @machine.communicate.sudo(command) do |type, data|
161
162
  if type == :stderr
162
163
  @machine.ui.warn(data)
@@ -167,34 +168,47 @@ class BibConfigurePlugin < Vagrant.plugin('2')
167
168
  end
168
169
 
169
170
  # my nifty function to get an NPM token from the registry
170
- def get_npm_token(registry_url, username, usermail, userpass)
171
+ def get_npm_token(registry_url, username, usermail, userpass)
171
172
  # get the date for some reason
172
- date = Time.now;
173
- # set up the request _id ???
173
+ date = Time.now
174
+ # set up the request _id ???
174
175
  _id = 'org.couchdb.user:' + username
175
176
  # set up the registry URL to request the token from
176
177
  url = registry_url + '-/user/' + _id
177
178
  # create json object passed to the registry
178
- data = { _id: _id ,
179
- name: username,
180
- password: userpass,
181
- email: usermail,
182
- type: 'user',
183
- roles: [],
184
- date: date
179
+ data = { _id: _id,
180
+ name: username,
181
+ password: userpass,
182
+ email: usermail,
183
+ type: 'user',
184
+ roles: [],
185
+ date: date
185
186
  }
186
187
  # convert it to json
187
188
  jdata = JSON.generate(data)
188
189
  # make the request and see if we get a token
189
- response_json = RestClient.put url, jdata, {:content_type => :json}
190
- # convert the response to a hash???
191
- hash = JSON.parse response_json
192
- # check to see if the key token is there
193
- if hash.has_key?('token')
194
- # it is, so return it
195
- hash['token']
190
+ if url.is_valid_url?
191
+ begin
192
+ response_json = RestClient.put url, jdata, content_type: :json
193
+ # convert the response to a hash???
194
+ hash = JSON.parse response_json
195
+ # check to see if the key token is there
196
+ if hash.key?('token')
197
+ # it is, so return it
198
+ hash['token']
199
+ else
200
+ # it doesn't so return false
201
+ false
202
+ end
203
+ rescue => error
204
+ # not a valid connection
205
+ puts 'WARNING: could not connect to ' + url + ' to exchange tokens'
206
+ false
207
+ end
208
+
196
209
  else
197
- # it doesn't so return false
210
+ # not a valid URL
211
+ puts 'WARNING: ' + url + ' does not seem to be valid'
198
212
  false
199
213
  end
200
214
  end
@@ -207,4 +221,3 @@ class BibConfigurePlugin < Vagrant.plugin('2')
207
221
  BibConfigureProvisioner
208
222
  end
209
223
  end
210
-
data/lib/bib/plugin.rb ADDED
@@ -0,0 +1,23 @@
1
+ begin
2
+ require 'bib_vagrant'
3
+ rescue LoadError
4
+ raise 'This is a vagrant plugin, do not use standalone.'
5
+ end
6
+
7
+ fail 'This vagrant plugin needs vagrant 1.2.0+' if Vagrant::VERSION < '1.2.0'
8
+
9
+ require_relative 'version'
10
+ require_relative 'bib_vagrant'
11
+
12
+ module VagrantPlugins
13
+ module Bib
14
+ module Vagrant
15
+ class Plugin < ::Vagrant.plugin('2')
16
+ name 'bib-vagrant'
17
+ description <<-DESC
18
+ This is a null plugin to get bib::vagrant into vagrant
19
+ DESC
20
+ end
21
+ end
22
+ end
23
+ end
data/lib/bib/vagrant.rb CHANGED
@@ -1,6 +1,8 @@
1
- require "bib/vagrant/version"
2
- require "bib/vagrant/config"
3
- require "thor"
1
+ require_relative 'version'
2
+ require_relative 'bib_vagrant'
3
+ require_relative 'bib_vagrant_npm_provisioner'
4
+
5
+ require 'thor'
4
6
 
5
7
  class BibVagrant < Thor
6
8
  package_name 'bib-vagrant'
@@ -8,20 +10,16 @@ class BibVagrant < Thor
8
10
  desc 'validate', 'validate the local configuration'
9
11
  def validate
10
12
  config = get_wrapper
11
-
12
13
  vagrant_defaults = config.get
13
14
  config.validate!(vagrant_defaults)
14
-
15
15
  end
16
16
 
17
17
  desc 'show', 'show configuration settings'
18
18
  def show
19
19
  config = get_wrapper
20
-
21
20
  puts "Your configuration is located in: #{config.get_path}"
22
- puts ""
23
-
24
- config.get.each do |config_key,config_value|
21
+ puts ''
22
+ config.get.each do |config_key, config_value|
25
23
  puts "#{config_key}: #{config_value}"
26
24
  end
27
25
  end
@@ -29,17 +27,16 @@ class BibVagrant < Thor
29
27
  desc 'setup', 'setup local configuration with default values'
30
28
  def setup
31
29
  config = Bib::Vagrant::Config.new
32
- raise "Your configuration is already created: #{config.get_path}" if config.has?
33
-
30
+ fail "Your configuration is already created: #{config.get_path}" if config.has?
34
31
  config.get
35
-
36
32
  puts "Configuration created in #{config.get_path}!"
37
33
  end
38
34
 
39
35
  private
36
+
40
37
  def get_wrapper
41
38
  config = Bib::Vagrant::Config.new
42
- raise "No configuration, run `bib-vagrant setup`!" unless config.has?
39
+ fail 'No configuration, run `bib-vagrant setup`!' unless config.has?
43
40
  config
44
41
  end
45
42
  end
@@ -1,5 +1,5 @@
1
1
  module Bib
2
2
  module Vagrant
3
- VERSION = "0.1.2"
3
+ VERSION = '0.1.3'
4
4
  end
5
5
  end
data/test/config_test.rb CHANGED
@@ -1,45 +1,42 @@
1
- require 'bib/vagrant/config'
1
+ require 'bib/bib_vagrant'
2
2
 
3
3
  class ConfigTest < Minitest::Test
4
-
5
4
  @@fixture_dir = nil
6
5
 
7
6
  def setup
8
- @@fixture_dir = File.dirname(__FILE__) + "/fixtures"
7
+ @@fixture_dir = File.dirname(__FILE__) + '/fixtures'
9
8
 
10
9
  FileUtils.mkdir @@fixture_dir
11
10
  end
12
11
 
13
12
  def teardown
14
- FileUtils.rm_rf @@fixture_dir if File.exists?(@@fixture_dir)
13
+ FileUtils.rm_rf @@fixture_dir if File.exist?(@@fixture_dir)
15
14
  end
16
15
 
17
16
  def test_config
18
-
19
17
  c = Bib::Vagrant::Config.new(@@fixture_dir, false)
20
18
  assert_equal(false, c.has?)
21
19
 
22
20
  vagrant_config = c.get
23
21
 
24
- assert(File.exists?("#{@@fixture_dir}/.config/easybib/vagrantdefault.yml"))
22
+ assert(File.exist?("#{@@fixture_dir}/.config/easybib/vagrantdefault.yml"))
25
23
  assert_kind_of(Hash, vagrant_config)
26
24
 
27
- assert_equal(false, vagrant_config["nfs"])
28
- assert_equal("~/Sites/easybib/cookbooks", vagrant_config["cookbook_path"])
29
- assert_equal("debug", vagrant_config["chef_log_level"])
30
- assert_equal("{}", vagrant_config["additional_json"])
31
- assert_equal(false, vagrant_config["gui"])
32
-
25
+ assert_equal(false, vagrant_config['nfs'])
26
+ assert_equal('~/Sites/easybib/cookbooks', vagrant_config['cookbook_path'])
27
+ assert_equal('debug', vagrant_config['chef_log_level'])
28
+ assert_equal('{}', vagrant_config['additional_json'])
29
+ assert_equal(false, vagrant_config['gui'])
33
30
  end
34
31
 
35
32
  # I wish I knew how to write a data provider with minitest
36
33
  def test_validate!
37
34
  config = {
38
- "nfs" => "yes",
39
- "gui" => false,
40
- "cookbook_path" => "/this/does/not/exist",
41
- "chef_log_level" => "debug",
42
- "additional_json" => ""
35
+ 'nfs' => 'yes',
36
+ 'gui' => false,
37
+ 'cookbook_path' => '/this/does/not/exist',
38
+ 'chef_log_level' => 'debug',
39
+ 'additional_json' => ''
43
40
  }
44
41
 
45
42
  c = Bib::Vagrant::Config.new(@@fixture_dir, false)
@@ -49,17 +46,15 @@ class ConfigTest < Minitest::Test
49
46
  c.validate!(config)
50
47
  }
51
48
 
52
- config["nfs"] = false
53
- config["cookbook_path"] = '~/'
49
+ config['nfs'] = false
50
+ config['cookbook_path'] = '~/'
54
51
 
55
52
  assert(c.validate!(config))
56
53
 
57
- config["additional_json"] = "{'hello'}"
54
+ config['additional_json'] = "{'hello'}"
58
55
 
59
56
  assert_raises(RuntimeError) {
60
57
  c.validate!(config)
61
58
  }
62
-
63
59
  end
64
-
65
60
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bib-vagrant
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
- - tillk
8
- - fh
9
- - gilleyj
7
+ - '''tillk'','
8
+ - '''fh'','
9
+ - '''gilleyj'''
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-10-16 00:00:00.000000000 Z
13
+ date: 2016-01-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: thor
@@ -142,12 +142,11 @@ files:
142
142
  - Vagrantfile
143
143
  - bib-vagrant.gemspec
144
144
  - bin/bib-vagrant
145
- - lib/bib-vagrant.rb
145
+ - lib/bib/bib_vagrant.rb
146
+ - lib/bib/bib_vagrant_npm_provisioner.rb
147
+ - lib/bib/plugin.rb
146
148
  - lib/bib/vagrant.rb
147
- - lib/bib/vagrant/config.rb
148
- - lib/bib/vagrant/plugin.rb
149
- - lib/bib/vagrant/provisioner.rb
150
- - lib/bib/vagrant/version.rb
149
+ - lib/bib/version.rb
151
150
  - test/config_test.rb
152
151
  homepage: https://github.com/easybiblabs/bib-vagrant
153
152
  licenses:
@@ -175,3 +174,4 @@ specification_version: 4
175
174
  summary: Centralize configuration and setup
176
175
  test_files:
177
176
  - test/config_test.rb
177
+ has_rdoc:
data/lib/bib-vagrant.rb DELETED
@@ -1,8 +0,0 @@
1
- begin
2
- require "vagrant"
3
- rescue LoadError
4
- raise "This plugin must be run within Vagrant."
5
- end
6
-
7
- require "bib/vagrant/plugin"
8
- require "bib/vagrant/provisioner"
@@ -1,102 +0,0 @@
1
- require 'yaml'
2
-
3
- module Bib
4
- module Vagrant
5
- class Config
6
-
7
- @@home_dir = nil
8
- @@verbose = true
9
-
10
- def initialize(home = "~", verbose = true)
11
- @@home = home
12
- @@verbose = verbose
13
- end
14
-
15
- def get
16
- vagrantconfig = get_defaults
17
-
18
- begin
19
- localconfigfile = File.open(get_path, 'r')
20
- vagrantconfig.merge!(YAML.load(localconfigfile.read))
21
- rescue Errno::ENOENT
22
- puts 'WARNING: No vagrant user-config found, using default cookbook path' if @@verbose
23
- create(get_path, vagrantconfig)
24
- end
25
-
26
- vagrantconfig
27
- end
28
-
29
- def has?
30
- File.exists?(get_path)
31
- end
32
-
33
- def get_path
34
- File.expand_path("#{@@home}/.config/easybib/vagrantdefault.yml")
35
- end
36
-
37
- def validate!(config)
38
-
39
- current_config_keys = config.keys
40
-
41
- get_defaults.keys.each do |required_key|
42
- raise "Missing #{required_key}!" unless current_config_keys.include?(required_key)
43
- end
44
-
45
- errors = []
46
- log_level = ['debug', 'info', 'warn', 'error', 'fatal']
47
- bool = [TrueClass, FalseClass]
48
-
49
- cookbook_path = File.expand_path(config['cookbook_path'])
50
-
51
- errors << "nfs: must be a boolean" unless bool.include?(config['nfs'].class)
52
- errors << "gui: must be a boolean" unless bool.include?(config['gui'].class)
53
- errors << "cookbook_path: does not exist" unless File.directory?(cookbook_path)
54
- errors << "chef_log_level: must be one of #{log_level.join}" unless log_level.include?(config['chef_log_level'])
55
-
56
- if !config['additional_json'].empty?
57
- errors << "additional_json: must be empty or valid json" unless is_valid_json?(config['additional_json'])
58
- end
59
-
60
- if errors.count == 0
61
- return true
62
- end
63
-
64
- raise "Errors: #{errors.join(', ')}"
65
- end
66
-
67
- private
68
- def create(localconfigpath, vagrantconfig)
69
- begin
70
- FileUtils.mkdir_p(File.dirname(localconfigpath))
71
- File.open(localconfigpath, 'w+') do |file|
72
- file.write( vagrantconfig.to_yaml )
73
- puts "INFO: Created default vagrant user-config in #{localconfigpath}" if @@verbose
74
- puts "INFO: You probably want to fix the path to the cookbooks in this file." if @@verbose
75
- end
76
- rescue
77
- puts "WARNING: Unable to create default #{localconfigpath} - please do it manually." if @@verbose
78
- end
79
- end
80
-
81
- def get_defaults
82
- {
83
- "nfs" => false,
84
- "cookbook_path" => '~/Sites/easybib/cookbooks',
85
- "chef_log_level" => 'debug',
86
- "additional_json" => '{}',
87
- "gui" => false
88
- }
89
- end
90
-
91
- def is_valid_json?(json)
92
- begin
93
- JSON.parse(json)
94
- return true
95
- rescue JSON::ParserError
96
- false
97
- end
98
- end
99
-
100
- end
101
- end
102
- end
@@ -1,27 +0,0 @@
1
- begin
2
- require "vagrant"
3
- rescue LoadError
4
- raise "This is a vagrant plugin, do not use standalone."
5
- end
6
-
7
- if Vagrant::VERSION < "1.2.0"
8
- raise "This vagrant plugin needs vagrant 1.2.0+"
9
- end
10
-
11
- require_relative 'config'
12
- require_relative 'version'
13
-
14
- module VagrantPlugins
15
- module Bib
16
- module Vagrant
17
- class Plugin < ::Vagrant.plugin("2")
18
-
19
- name "bib-vagrant"
20
- description <<-DESC
21
- This is a fake plugin to get bib::vagrant into vagrant
22
- DESC
23
-
24
- end
25
- end
26
- end
27
- end