nugrant 2.0.0.rc1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +29 -11
- data/lib/nugrant/config.rb +27 -3
- data/lib/nugrant/vagrant/v2/command/parameters.rb +2 -2
- data/lib/nugrant/vagrant/v2/command/restricted_keys.rb +5 -5
- data/lib/nugrant/vagrant/v2/config/user.rb +1 -2
- data/lib/nugrant/vagrant/v2/helper.rb +95 -0
- data/lib/nugrant/vagrant/v2/plugin.rb +3 -0
- data/lib/nugrant/version.rb +1 -1
- data/locales/en.yml +2 -2
- data/locales/fr.yml +24 -0
- data/test/lib/nugrant/test_config.rb +22 -0
- metadata +6 -5
- data/lib/nugrant/vagrant/v2/command/helper.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89aef5f2cae21cfe30f4fd15204955cd83ee5fd7
|
4
|
+
data.tar.gz: 85aff126d8c8cb3719d5f4a75ace5a95ce4460df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9fb53dbf9edcb2cf22060430ea36fe6a54c07002fe4601e374f98e5d8a001243f1ff0550b07d8a3a576729d69c3b9da5478f8f7f6fd08485cd07b05f0641597
|
7
|
+
data.tar.gz: 0ee9ef8856832546e5048f614a42ca6ad166387b905d3cfa119bce4a8d2ffd185c9814ea26f15ef714bad9c36fa50e4b807f6c3d23493fbf58bf992b5888919d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# 2.0.0 (In progress)
|
2
2
|
|
3
|
+
* Fixed retrieval of current directory for `.vagrantuser`. The directory
|
4
|
+
is now that same as the one of the `Vagrantfile`. Rules have been
|
5
|
+
copied for Vagrant's one, hence, the behavior should be the same.
|
6
|
+
|
3
7
|
* Fixed bad implementation of config class `::Vagrant.plugin("2", :config)`
|
4
8
|
where `merge` was not implemented and was causing errors. Now, all objects
|
5
9
|
(i.e. `Config`, `Bag` and `Parameters` implements `merge` and `merge!`
|
data/README.md
CHANGED
@@ -30,8 +30,8 @@ Let's start with an example. You need to distribute among your enterprise a
|
|
30
30
|
The `aws_access_key` and `aws_secret_key` should be configurable depending on the user
|
31
31
|
running `vagrant up`.
|
32
32
|
|
33
|
-
To achieve this, simply create a file named `.vagrantuser` in the
|
34
|
-
|
33
|
+
To achieve this, simply create a file named `.vagrantuser` that resides in the directory
|
34
|
+
as your `Vagrantfile`:
|
35
35
|
|
36
36
|
aws:
|
37
37
|
access_key: "123456"
|
@@ -60,16 +60,32 @@ must be filled in, something like:
|
|
60
60
|
access_key: "<ACCESS_KEY_HERE>"
|
61
61
|
secret_key: "<SECRET_KEY_HERE>"
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
To find where your project `.vagrantuser` is located, Nugrant uses the directory
|
64
|
+
where the `Vagrantfile` is located. It achieves this using the same set of
|
65
|
+
rules as Vagrant meaning you can be in a nested directory and parameters
|
66
|
+
will still be fetched correctly.
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
in your hierarchy.
|
68
|
+
Moreover, like other similar system, there is a hierarchy of `.vagrantuser` files
|
69
|
+
that you can leverage:
|
71
70
|
|
72
|
-
|
71
|
+
| Name | Location | Priority | Overrides |
|
72
|
+
| ---------|-----------------------------------------|:---------:|--------------------------|
|
73
|
+
| Defaults | [config.user.defaults](#default-values) | 4 | - |
|
74
|
+
| System | $SYSTEM/.vagrantuser | 3 | Defaults |
|
75
|
+
| User | ~/.vagrantuser | 2 | Defaults & System |
|
76
|
+
| Project | .vagrantuser | 1 | Defaults & System & User |
|
77
|
+
|
78
|
+
The project level directory is always the same as the directory where your
|
79
|
+
`Vagrantfile` resides and same rules as Vagrant are used to find it.
|
80
|
+
The `~` is the user's home directory and `$SYSTEM` is the platform dependent
|
81
|
+
folder where system global can be put. Check [Hierarchy](#hierarchy) section
|
82
|
+
for where `$SYSTEM` maps exactly.
|
83
|
+
|
84
|
+
You can use the command `vagrant user parameters` to see the final merged
|
85
|
+
hierarchy seen by Nugrant. This command also prints [restricted keys](#restricted-keys)
|
86
|
+
defined in your hierarchy.
|
87
|
+
|
88
|
+
Accessing parameters in your `Vagrantfile` can be done either by method access
|
73
89
|
(i.e. `config.user.<key>`) or by array access (i.e. `config.user[<key>]`).
|
74
90
|
This support is working for any deepness, only `config.user` is different
|
75
91
|
because provided directly by `Vagrant` and not by this plugin.
|
@@ -230,6 +246,8 @@ That would be equivalent to:
|
|
230
246
|
config.vm.synced_folder "/home/user/personal/git", "/personal"
|
231
247
|
end
|
232
248
|
|
249
|
+
#### Hierarchy
|
250
|
+
|
233
251
|
As you can see, the parameters defined in the second `.vagrantuser` file
|
234
252
|
(the current one) overrides settings defined in the `.vagrantuser` found
|
235
253
|
in the home directory (the user one).
|
@@ -239,7 +257,7 @@ Here the list of locations where Nugrant looks for parameters:
|
|
239
257
|
1. Defaults (via `config.user.defaults` in `Vagrantfile`)
|
240
258
|
2. System (`/etc/.vagrantuser` on Unix, `%PROGRAMDATA%/.vagrantuser` or `%ALLUSERSPROFILE%/.vagrantuser` on Windows)
|
241
259
|
3. Home (`~/.vagrantuser`)
|
242
|
-
4.
|
260
|
+
4. Project (`.vagrantuser` within the same folder as the `Vagrantfile`)
|
243
261
|
|
244
262
|
#### Paths
|
245
263
|
|
data/lib/nugrant/config.rb
CHANGED
@@ -44,6 +44,30 @@ module Nugrant
|
|
44
44
|
"/etc"
|
45
45
|
end
|
46
46
|
|
47
|
+
##
|
48
|
+
# Method to fix-up a received path. The fix-up do the follows
|
49
|
+
# the following rules:
|
50
|
+
#
|
51
|
+
# 1. If the path is callable, call it to get the value.
|
52
|
+
# 2. If value is nil, return default value.
|
53
|
+
# 3. If value is a directory, return path + params_filename to it.
|
54
|
+
# 4. Otherwise, return value
|
55
|
+
#
|
56
|
+
# @param path The path parameter received.
|
57
|
+
# @param default The default path to use, can be a directory.
|
58
|
+
# @param params_filename The params filename to append if path is a directory
|
59
|
+
#
|
60
|
+
# @return The fix-up path following rules defined above.
|
61
|
+
#
|
62
|
+
def self.fixup_path(path, default, params_filename)
|
63
|
+
path = path.call if path.respond_to?(:call)
|
64
|
+
|
65
|
+
path = File.expand_path(path || default)
|
66
|
+
path = "#{path}/#{params_filename}" if ::File.directory?(path)
|
67
|
+
|
68
|
+
path
|
69
|
+
end
|
70
|
+
|
47
71
|
def self.supported_array_merge_strategy(strategy)
|
48
72
|
SUPPORTED_ARRAY_MERGE_STRATEGIES.include?(strategy)
|
49
73
|
end
|
@@ -108,9 +132,9 @@ module Nugrant
|
|
108
132
|
@params_filename = options[:params_filename] || DEFAULT_PARAMS_FILENAME
|
109
133
|
@params_format = options[:params_format] || DEFAULT_PARAMS_FORMAT
|
110
134
|
|
111
|
-
@current_path =
|
112
|
-
@user_path =
|
113
|
-
@system_path =
|
135
|
+
@current_path = Config.fixup_path(options[:current_path], ".", @params_filename)
|
136
|
+
@user_path = Config.fixup_path(options[:user_path], Config.default_user_path(), @params_filename)
|
137
|
+
@system_path = Config.fixup_path(options[:system_path], Config.default_system_path(), @params_filename)
|
114
138
|
|
115
139
|
@array_merge_strategy = options[:array_merge_strategy] || :replace
|
116
140
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'nugrant'
|
2
2
|
require 'nugrant/helper/yaml'
|
3
|
-
require 'nugrant/vagrant/v2/
|
3
|
+
require 'nugrant/vagrant/v2/helper'
|
4
4
|
|
5
5
|
module Nugrant
|
6
6
|
module Vagrant
|
@@ -101,7 +101,7 @@ module Nugrant
|
|
101
101
|
end
|
102
102
|
|
103
103
|
def project(parameters)
|
104
|
-
print_bag("Project", parameters.
|
104
|
+
print_bag("Project", parameters.__current)
|
105
105
|
end
|
106
106
|
|
107
107
|
def all(parameters)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'nugrant'
|
2
|
-
require 'nugrant/vagrant/v2/
|
2
|
+
require 'nugrant/vagrant/v2/helper'
|
3
3
|
|
4
4
|
module Nugrant
|
5
5
|
module Vagrant
|
@@ -30,8 +30,8 @@ module Nugrant
|
|
30
30
|
|
31
31
|
parser.separator ""
|
32
32
|
parser.separator "Prints keys that cannot be accessed using the method access syntax\n" +
|
33
|
-
"(`config.user
|
34
|
-
"if you really want to use of the restricted keys
|
33
|
+
"(`config.user.<key>`). Use array access syntax (`config.user['<key>']`)\n" +
|
34
|
+
"if you really want to use of the restricted keys.\n"
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -41,9 +41,9 @@ module Nugrant
|
|
41
41
|
|
42
42
|
return help(parser) if @show_help
|
43
43
|
|
44
|
-
@env.ui.info("The following keys are restricted, i.e. that method access (`config.user
|
44
|
+
@env.ui.info("The following keys are restricted, i.e. that method access (`config.user.<key>`)", :prefix => false)
|
45
45
|
@env.ui.info("will not work. If you really want to use a restricted key, use array access ", :prefix => false)
|
46
|
-
@env.ui.info("instead (`config.user['
|
46
|
+
@env.ui.info("instead (`config.user['<key>']`).", :prefix => false)
|
47
47
|
@env.ui.info("", :prefix => false)
|
48
48
|
|
49
49
|
@env.ui.info("You can run `vagrant user parameters` to check if your config currently defines", :prefix => false)
|
@@ -12,6 +12,7 @@ module Nugrant
|
|
12
12
|
def initialize(defaults = {}, config = {})
|
13
13
|
setup!(defaults,
|
14
14
|
:params_filename => ".vagrantuser",
|
15
|
+
:current_path => Helper.find_project_path(),
|
15
16
|
:key_error => Proc.new do |key|
|
16
17
|
raise Errors::ParameterNotFoundError, :key => key.to_s
|
17
18
|
end,
|
@@ -20,8 +21,6 @@ module Nugrant
|
|
20
21
|
end
|
21
22
|
)
|
22
23
|
end
|
23
|
-
|
24
|
-
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
require 'nugrant'
|
4
|
+
require 'nugrant/bag'
|
5
|
+
require 'nugrant/vagrant/v2/config/user'
|
6
|
+
|
7
|
+
module Nugrant
|
8
|
+
module Vagrant
|
9
|
+
module V2
|
10
|
+
class Helper
|
11
|
+
|
12
|
+
##
|
13
|
+
# The project path is the path where the top-most (loaded last)
|
14
|
+
# Vagrantfile resides. It can be considered the project root for
|
15
|
+
# this environment.
|
16
|
+
#
|
17
|
+
# Copied from `lib\vagrant\environment.rb#532` (tag: v1.6.2)
|
18
|
+
#
|
19
|
+
# @return [String] The project path to use.
|
20
|
+
#
|
21
|
+
def self.find_project_path()
|
22
|
+
vagrantfile_name = ENV["VAGRANT_VAGRANTFILE"]
|
23
|
+
|
24
|
+
root_finder = lambda do |path|
|
25
|
+
vagrantfile = find_vagrantfile(path, vagrantfile_name)
|
26
|
+
|
27
|
+
return path if vagrantfile
|
28
|
+
return nil if path.root? || !File.exist?(path)
|
29
|
+
|
30
|
+
root_finder.call(path.parent)
|
31
|
+
end
|
32
|
+
|
33
|
+
root_finder.call(get_vagrant_working_directory())
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Finds the Vagrantfile in the given directory.
|
38
|
+
#
|
39
|
+
# Copied from `lib\vagrant\environment.rb#732` (tag: v1.6.2)
|
40
|
+
#
|
41
|
+
# @param [Pathname] path Path to search in.
|
42
|
+
# @return [Pathname]
|
43
|
+
#
|
44
|
+
def self.find_vagrantfile(search_path, filenames = nil)
|
45
|
+
filenames ||= ["Vagrantfile", "vagrantfile"]
|
46
|
+
filenames.each do |vagrantfile|
|
47
|
+
current_path = search_path.join(vagrantfile)
|
48
|
+
return current_path if current_path.file?
|
49
|
+
end
|
50
|
+
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# Returns Vagrant working directory to use.
|
56
|
+
#
|
57
|
+
# Copied from `lib\vagrant\environment.rb#80` (tag: v1.6.2)
|
58
|
+
#
|
59
|
+
# @return [Pathname] The working directory to start search in.
|
60
|
+
#
|
61
|
+
def self.get_vagrant_working_directory()
|
62
|
+
cwd = nil
|
63
|
+
|
64
|
+
# Set the default working directory to look for the vagrantfile
|
65
|
+
cwd ||= ENV["VAGRANT_CWD"] if ENV.has_key?("VAGRANT_CWD")
|
66
|
+
cwd ||= Dir.pwd
|
67
|
+
cwd = Pathname.new(cwd)
|
68
|
+
|
69
|
+
if !cwd.directory?
|
70
|
+
raise Errors::EnvironmentNonExistentCWD, cwd: cwd.to_s
|
71
|
+
end
|
72
|
+
|
73
|
+
cwd = cwd.expand_path
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.get_restricted_keys()
|
77
|
+
bag_methods = Nugrant::Bag.instance_methods
|
78
|
+
parameters_methods = V2::Config::User.instance_methods
|
79
|
+
|
80
|
+
(bag_methods | parameters_methods).map(&:to_s)
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.get_used_restricted_keys(hash, restricted_keys)
|
84
|
+
keys = []
|
85
|
+
hash.each do |key, value|
|
86
|
+
keys << key if restricted_keys.include?(key)
|
87
|
+
keys += get_used_restricted_keys(value, restricted_keys) if value.kind_of?(Hash)
|
88
|
+
end
|
89
|
+
|
90
|
+
keys.uniq
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -4,6 +4,9 @@ module Nugrant
|
|
4
4
|
module V2
|
5
5
|
class Plugin < ::Vagrant.plugin("2")
|
6
6
|
name "Nugrant"
|
7
|
+
description <<-DESC
|
8
|
+
Plugin to define and use user specific parameters from various location inside your Vagrantfile.
|
9
|
+
DESC
|
7
10
|
|
8
11
|
command "user" do
|
9
12
|
require_relative "command/root"
|
data/lib/nugrant/version.rb
CHANGED
data/locales/en.yml
CHANGED
@@ -9,8 +9,8 @@ en:
|
|
9
9
|
|
10
10
|
%{context}
|
11
11
|
|
12
|
-
If you think
|
13
|
-
issue @ https://github.com/maoueh/nugrant/issues.
|
12
|
+
If you think the parameter '%{key}' should have been found, don't
|
13
|
+
hesitate to fill an issue @ https://github.com/maoueh/nugrant/issues.
|
14
14
|
|
15
15
|
parse_error: |-
|
16
16
|
Nugrant: Vagrant user file could not be parsed correctly,
|
data/locales/fr.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
en:
|
2
|
+
nugrant:
|
3
|
+
vagrant:
|
4
|
+
errors:
|
5
|
+
parameter_not_found: |-
|
6
|
+
Nugrant: Le paramètre '%{key}' n'a pu être trouvé, est-il définie
|
7
|
+
dans votre fichier .vagrantuser ? Voici où nous pensons que l'erreur
|
8
|
+
se trouve dans votre fichier Vagrantfile:
|
9
|
+
|
10
|
+
%{context}
|
11
|
+
|
12
|
+
Si vous croyez que le paramètre '%{key}' devrait être trouvé, n'hésitez
|
13
|
+
pas à rapporter le problème @ https://github.com/maoueh/nugrant/issues.
|
14
|
+
|
15
|
+
parse_error: |-
|
16
|
+
Nugrant: Le fichier de paramètres Vagrant n'a pu être lu correctement,
|
17
|
+
le fichier contient probablement une erreur de syntaxe.
|
18
|
+
|
19
|
+
File: %{filename}
|
20
|
+
Error: %{error}
|
21
|
+
|
22
|
+
Si vous croyez que ceci est un bug, n'hésitez pas à rapporter le
|
23
|
+
problème @ https://github.com/maoueh/nugrant/issues.
|
24
|
+
|
@@ -54,6 +54,28 @@ module Nugrant
|
|
54
54
|
assert_equal("#{@user_dir}/.currentcustomparams", config.current_path())
|
55
55
|
end
|
56
56
|
|
57
|
+
def test_custom_current_path_without_filename
|
58
|
+
config = Nugrant::Config.new({
|
59
|
+
:params_filename => ".customparams",
|
60
|
+
:current_path => "#{@user_dir}"
|
61
|
+
})
|
62
|
+
|
63
|
+
assert_equal(".customparams", config.params_filename())
|
64
|
+
assert_equal("#{@user_dir}/.customparams", config.current_path())
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_custom_current_path_using_callable
|
68
|
+
config = Nugrant::Config.new({
|
69
|
+
:params_filename => ".customparams",
|
70
|
+
:current_path => lambda do ||
|
71
|
+
"#{@user_dir}/"
|
72
|
+
end
|
73
|
+
})
|
74
|
+
|
75
|
+
assert_equal(".customparams", config.params_filename())
|
76
|
+
assert_equal("#{@user_dir}/.customparams", config.current_path())
|
77
|
+
end
|
78
|
+
|
57
79
|
def test_custom_user_path
|
58
80
|
config = Nugrant::Config.new({
|
59
81
|
:params_filename => ".customparams",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nugrant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthieu Vachon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -64,14 +64,15 @@ files:
|
|
64
64
|
- lib/nugrant/parameters.rb
|
65
65
|
- lib/nugrant/vagrant/errors.rb
|
66
66
|
- lib/nugrant/vagrant/v2/command/env.rb
|
67
|
-
- lib/nugrant/vagrant/v2/command/helper.rb
|
68
67
|
- lib/nugrant/vagrant/v2/command/parameters.rb
|
69
68
|
- lib/nugrant/vagrant/v2/command/restricted_keys.rb
|
70
69
|
- lib/nugrant/vagrant/v2/command/root.rb
|
71
70
|
- lib/nugrant/vagrant/v2/config/user.rb
|
71
|
+
- lib/nugrant/vagrant/v2/helper.rb
|
72
72
|
- lib/nugrant/vagrant/v2/plugin.rb
|
73
73
|
- lib/nugrant/version.rb
|
74
74
|
- locales/en.yml
|
75
|
+
- locales/fr.yml
|
75
76
|
- nugrant.gemspec
|
76
77
|
- test/lib/nugrant/helper/env/test_exporter.rb
|
77
78
|
- test/lib/nugrant/helper/test_bag.rb
|
@@ -139,9 +140,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
140
|
version: '0'
|
140
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
142
|
requirements:
|
142
|
-
- - '
|
143
|
+
- - '>='
|
143
144
|
- !ruby/object:Gem::Version
|
144
|
-
version:
|
145
|
+
version: '0'
|
145
146
|
requirements: []
|
146
147
|
rubyforge_project:
|
147
148
|
rubygems_version: 2.2.2
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'nugrant'
|
2
|
-
require 'nugrant/bag'
|
3
|
-
require 'nugrant/vagrant/v2/config/user'
|
4
|
-
|
5
|
-
module Nugrant
|
6
|
-
module Vagrant
|
7
|
-
module V2
|
8
|
-
module Command
|
9
|
-
class Helper
|
10
|
-
def self.get_restricted_keys()
|
11
|
-
bag_methods = Nugrant::Bag.instance_methods
|
12
|
-
parameters_methods = V2::Config::User.instance_methods
|
13
|
-
|
14
|
-
(bag_methods | parameters_methods).map(&:to_s)
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.get_used_restricted_keys(hash, restricted_keys)
|
18
|
-
keys = []
|
19
|
-
hash.each do |key, value|
|
20
|
-
keys << key if restricted_keys.include?(key)
|
21
|
-
keys += get_used_restricted_keys(value, restricted_keys) if value.kind_of?(Hash)
|
22
|
-
end
|
23
|
-
|
24
|
-
keys.uniq
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|