nugrant 2.0.0.dev2 → 2.0.0.pre1
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 +6 -14
- data/.gitignore +2 -1
- data/.travis.yml +2 -2
- data/CHANGELOG.md +148 -3
- data/Gemfile +8 -20
- data/README.md +266 -72
- data/Rakefile +1 -0
- data/lib/nugrant.rb +14 -6
- data/lib/nugrant/bag.rb +116 -62
- data/lib/nugrant/helper/bag.rb +19 -19
- data/lib/nugrant/helper/env/exporter.rb +208 -0
- data/lib/nugrant/helper/env/namer.rb +47 -0
- data/lib/nugrant/helper/parameters.rb +12 -0
- data/lib/nugrant/helper/stack.rb +86 -0
- data/lib/nugrant/mixin/parameters.rb +98 -0
- data/lib/nugrant/parameters.rb +14 -68
- data/lib/nugrant/vagrant/errors.rb +27 -0
- data/lib/nugrant/vagrant/v2/command/env.rb +101 -0
- data/lib/nugrant/vagrant/v2/command/helper.rb +30 -0
- data/lib/nugrant/vagrant/v2/command/parameters.rb +16 -4
- data/lib/nugrant/vagrant/v2/command/restricted_keys.rb +60 -0
- data/lib/nugrant/vagrant/v2/command/root.rb +12 -2
- data/lib/nugrant/vagrant/v2/config/user.rb +9 -21
- data/lib/nugrant/vagrant/v2/plugin.rb +0 -1
- data/lib/nugrant/version.rb +1 -1
- data/locales/en.yml +13 -0
- data/nugrant.gemspec +3 -7
- data/test/lib/nugrant/helper/env/test_exporter.rb +238 -0
- data/test/lib/nugrant/helper/test_bag.rb +16 -0
- data/test/lib/nugrant/helper/test_parameters.rb +17 -0
- data/test/lib/nugrant/helper/test_stack.rb +152 -0
- data/test/lib/nugrant/test_bag.rb +132 -22
- data/test/lib/nugrant/test_config.rb +95 -92
- data/test/lib/nugrant/test_parameters.rb +232 -177
- data/test/lib/test_helper.rb +3 -0
- data/test/resources/json/params_user_nil_values.json +9 -0
- data/test/resources/vagrantfiles/v2.defaults_mixed_string_symbols +18 -0
- data/test/resources/vagrantfiles/v2.defaults_null_values_in_vagrantuser +23 -0
- data/test/resources/vagrantfiles/v2.defaults_using_string +18 -0
- data/test/resources/vagrantfiles/v2.defaults_using_symbol +18 -0
- data/test/resources/{Vagrantfile.v2.empty → vagrantfiles/v2.empty} +0 -2
- data/test/resources/{Vagrantfile.v2.fake → vagrantfiles/v2.fake} +4 -3
- data/test/resources/vagrantfiles/v2.missing_parameter +3 -0
- data/test/resources/{Vagrantfile.v2.real → vagrantfiles/v2.real} +0 -2
- data/test/resources/yaml/params_user_nil_values.yml +5 -0
- metadata +55 -88
- data/lib/nugrant/vagrant/v1/command/parameters.rb +0 -134
- data/lib/nugrant/vagrant/v1/command/root.rb +0 -81
- data/lib/nugrant/vagrant/v1/config/user.rb +0 -37
- data/lib/nugrant/vagrant/v1/plugin.rb +0 -6
- data/lib/vagrant_init.rb +0 -2
- data/test/resources/Vagrantfile.v1.empty +0 -2
- data/test/resources/Vagrantfile.v1.fake +0 -10
- data/test/resources/Vagrantfile.v1.real +0 -19
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
OTc5ZDY1N2IzZGYwN2M5Y2IxOWEzYmMxODFjYjlkMmY0ODEzNWIzMTA3MGY2
|
10
|
-
YzYyZGIxOWRlYjc0N2E0MGYyNjdhZDZlNzg5YzlkMzM5NGJlYjg4OTljYTM1
|
11
|
-
NjhkZDYzODJiYjA0MGE3MWQ0MTcyOThmYTMzYzUwMTU5YjY0ODE=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZjQyNzc2M2Q2YjdlZTc0YzE1ZDFlNjFlMzY1M2UwOTQzZjU2ZWM5ZGQ5ZDc4
|
14
|
-
ZDVlZmQwZjEwMDk5Yzk1YjlhNjgxNjlmZWU0NDQyYmZjNjc4MjQxMDA3NmRj
|
15
|
-
MTlmYWQ4NjFiYjJjNWI5YTRmYzNmM2RiYTQ2NmFhZDg2YWUxMzY=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9f14bf2a70810293d967c9e9d24b60408880e5b0
|
4
|
+
data.tar.gz: 1d24d5cfa15fde530b4daab7743adb9b29bf74a4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4ade947b4d55e761d3ec22065b34b680cac998f9544fa98e30a309ce9c65d4f2a76bde76233633e9eb630725c0fc622ea6c8b163332af8401347af8d0dd409d9
|
7
|
+
data.tar.gz: 20d4f38d519f1e15f487d0bdecd6d74246a8b748d4933f98285504587360c24cd5936c111fb85dfb578079abb9a28a47e7f8dccf7b22655510aa77a87a91725b
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,146 @@
|
|
1
|
-
#
|
1
|
+
# 2.0.0 (In progress)
|
2
|
+
|
3
|
+
* It is now possible to customize key error handling by passing
|
4
|
+
an options hash with key `:key_error` and a `Proc` value.
|
5
|
+
|
6
|
+
* Improved command `vagrant user parameters`. The command now checks if
|
7
|
+
restricted keys are used and prints a warning when it's the case.
|
8
|
+
|
9
|
+
* Added a new command `vagrant user restricted-keys` that prints the keys that
|
10
|
+
are restricted, i.e. that cannot be accessed using method access
|
11
|
+
syntax.
|
12
|
+
|
13
|
+
* Added possibility to specify merge strategy to use when merging
|
14
|
+
two arrays together.
|
15
|
+
|
16
|
+
### Backward Incompatibilities
|
17
|
+
|
18
|
+
* Removed deprecated `--script` argument from `vagrant user env` command.
|
19
|
+
|
20
|
+
* Support for Ruby <= 1.9.2 has been dropped. This is not a problem when using
|
21
|
+
Nugrant as a Vagrant plugin. Use branch `1.x` if you can't upgrade to
|
22
|
+
Ruby >= 1.9.3.
|
23
|
+
|
24
|
+
* Support for Vagrant 0.x has been dropped. This means that Nugrant 2.x will not
|
25
|
+
load if installed in a Vagrant 0.x environment. Use branch `1.x` if you can't
|
26
|
+
upgrade to Vagrant 1.x.
|
27
|
+
|
28
|
+
* `Bag` and `Parameters` and Vagrant configuration object `config.user` are now
|
29
|
+
[Enumerable](http://ruby-doc.org/core-2.0.0/Enumerable.html).
|
30
|
+
|
31
|
+
This change has implications on the resolving process of the variables
|
32
|
+
that are stored in the `Bag` when using the dot syntax `(config.user.email)`
|
33
|
+
in your code and `Vagrantfiles`. By using this syntax with version 2.0, some keys
|
34
|
+
will collapse with the internal object's methods. In fact, it was already the
|
35
|
+
case before but to a much smaller scope because object were not enumerable.
|
36
|
+
|
37
|
+
The number of conflicts should be rather low because the restricted keys
|
38
|
+
are not commonly used as parameter name. The list of the restricted keys
|
39
|
+
is the following:
|
40
|
+
|
41
|
+
!, !=, !~, <=>, ==, ===, =~, [], __all, __current, __defaults,
|
42
|
+
__id__, __send__, __system, __user, _detected_errors, _finalize!,
|
43
|
+
all?, any?, chunk, class, clear!, clone, collect, collect_concat,
|
44
|
+
compute_all!, compute_bags!, count, cycle, defaults, defaults=,
|
45
|
+
define_singleton_method, detect, display, drop, drop_while, dup,
|
46
|
+
each, each_cons, each_entry, each_slice, each_with_index,
|
47
|
+
each_with_object, empty?, entries, enum_for, eql?, equal?, extend,
|
48
|
+
finalize!, find, find_all, find_index, first, flat_map, freeze,
|
49
|
+
frozen?, gem, grep, group_by, has?, hash, include?, inject,
|
50
|
+
inspect, instance_eval, instance_exec, instance_of?,
|
51
|
+
instance_variable_defined?, instance_variable_get,
|
52
|
+
instance_variable_set, instance_variables, instance_variables_hash,
|
53
|
+
is_a?, kind_of?, lazy, map, max, max_by, member?, merge, merge!,
|
54
|
+
method, method_missing, methods, min, min_by, minmax, minmax_by,
|
55
|
+
nil?, none?, object_id, one?, partition, private_methods,
|
56
|
+
protected_methods, psych_to_yaml, public_method, public_methods,
|
57
|
+
public_send, reduce, reject, remove_instance_variable, respond_to?,
|
58
|
+
reverse_each, select, send, set_options, singleton_class,
|
59
|
+
singleton_methods, slice_before, sort, sort_by, suppress_warnings,
|
60
|
+
taint, tainted?, take, take_while, tap, to_a, to_enum, to_hash,
|
61
|
+
to_json, to_s, to_set, to_yaml, to_yaml_properties, trust, untaint,
|
62
|
+
untrust, untrusted?, validate, zip
|
63
|
+
|
64
|
+
* The `Parameter` class has a new API.
|
65
|
+
|
66
|
+
* The `Bag` class has a new API.
|
67
|
+
|
68
|
+
# 1.4.3 (In progess)
|
69
|
+
|
70
|
+
# 1.4.2 (January 11th, 2014)
|
71
|
+
|
72
|
+
* Fixed Vagrant `user` config class to make the `has?` method
|
73
|
+
available to people using Vagrant. This considered has a bug
|
74
|
+
fix because using `has?` was not working anyway before.
|
75
|
+
|
76
|
+
# 1.4.1 (December 15th, 2013)
|
77
|
+
|
78
|
+
* Fixed a superfluous warning message when using ruby >= 2.0.0 which is now the
|
79
|
+
default when installing Vagrant >= 1.4.0 (at least on Windows).
|
80
|
+
|
81
|
+
# 1.4.0 (November 28th, 2013)
|
82
|
+
|
83
|
+
* Adding support to export to an [autoenv](https://github.com/kennethreitz/autoenv)
|
84
|
+
file. See [GH-13](https://github.com/maoueh/nugrant/issues/13).
|
85
|
+
|
86
|
+
* Deprecated usage of `-s, --script` option for command
|
87
|
+
`vagrant user env`. This was replaced by the more generic
|
88
|
+
and extensible `-f, --format FORMAT` option. The
|
89
|
+
`-s, --script` option will be removed in 2.0.
|
90
|
+
|
91
|
+
# 1.3.0 (November 19th, 2013)
|
92
|
+
|
93
|
+
* Now using [minitest](https://github.com/seattlerb/minitest) as our
|
94
|
+
testing library.
|
95
|
+
|
96
|
+
* Added a new command that can be used either standalone or via
|
97
|
+
a small bash script to easily export environment variables
|
98
|
+
from your currently set parameters. See
|
99
|
+
[GH-13](https://github.com/maoueh/nugrant/issues/13).
|
100
|
+
|
101
|
+
* Keys associated to a null value are considered as being missing
|
102
|
+
by the merge process. It is still possible to define a null
|
103
|
+
parameter, but it will be overridden by any parameter and will not
|
104
|
+
override any. See [GH-12](https://github.com/maoueh/nugrant/issues/12).
|
105
|
+
|
106
|
+
* Fixed output of command `vagrant user parameters`, the keys were
|
107
|
+
serialized as symbol instead of string.
|
108
|
+
|
109
|
+
# 1.2.0 (October 24th, 2013)
|
110
|
+
|
111
|
+
* Now showing better error message to the end-user when a parameter
|
112
|
+
cannot be found. The message displays which key could not be found.
|
113
|
+
Moreover, we show the context within the Vagrantfile where we think
|
114
|
+
the error occurred:
|
115
|
+
|
116
|
+
```
|
117
|
+
Nugrant: Parameter 'param' was not found, is it defined in
|
118
|
+
your .vagrantuser file? Here where we think the error
|
119
|
+
could be in your Vagrantfile:
|
120
|
+
|
121
|
+
1: Vagrant.configure("2") do |config|
|
122
|
+
2:>> puts config.user.param
|
123
|
+
3: end
|
124
|
+
```
|
125
|
+
|
126
|
+
See [GH-8] (https://github.com/maoueh/nugrant/issues/8).
|
127
|
+
|
128
|
+
* Ensured that keys used within a `Bag` are always symbol. This make
|
129
|
+
sure that it is possible to retrieve a value with any access method.
|
130
|
+
See [GH-9](https://github.com/maoueh/nugrant/issues/9).
|
131
|
+
|
132
|
+
* Now using [multi_json](https://rubygems.org/gems/multi_json)
|
133
|
+
for JSON handling.
|
2
134
|
|
3
135
|
# 1.1.0 (May 17th, 2013)
|
4
136
|
|
5
137
|
* Rewrite completely classes `Parameters` and `Bag`.
|
6
138
|
* Reduced chances to have a parameter name collapsing with an
|
7
139
|
implementation method.
|
140
|
+
|
8
141
|
* Removed dependency on `deep_merge`. We do now perform
|
9
142
|
our own merge.
|
143
|
+
|
10
144
|
* Added possibility to iterate through keys by using
|
11
145
|
`.each`:
|
12
146
|
|
@@ -19,6 +153,7 @@
|
|
19
153
|
### Backward Incompatibilities
|
20
154
|
|
21
155
|
* `Parameters` is not extending the `Bag` class anymore.
|
156
|
+
|
22
157
|
* `Parameters` and `Bag` attributes and methods are now almost
|
23
158
|
all prefixed with __ to reduce clashes to a minimum when
|
24
159
|
accessing parameters with method-like syntax
|
@@ -27,7 +162,8 @@
|
|
27
162
|
# 1.0.1 (April 9th, 2013)
|
28
163
|
|
29
164
|
* Fixed a crash when `user` config value is `nil` preventing `vagrant user parameters`
|
30
|
-
from working as expected. [GH-4](https://github.com/maoueh/nugrant/issues/4)
|
165
|
+
from working as expected. See [GH-4](https://github.com/maoueh/nugrant/issues/4).
|
166
|
+
|
31
167
|
* Fixed a bug preventing the version from being printed when doing `vagrant user -v`.
|
32
168
|
|
33
169
|
# 1.0.0 (March 21th, 2013)
|
@@ -39,6 +175,7 @@
|
|
39
175
|
# 0.0.14
|
40
176
|
|
41
177
|
* Renamed `ParameterBag` to `Bag`
|
178
|
+
|
42
179
|
* Cleanup `Bag` api
|
43
180
|
* Renamed method `has_param?` to `has_key?` in `Bag`
|
44
181
|
* Removed method `get_params` from `Bag`
|
@@ -48,6 +185,7 @@
|
|
48
185
|
* Cleanup `Parameters` and `ParameterBag` interface
|
49
186
|
* The method `defaults` has been removed from the bag
|
50
187
|
* Setting defaults on `Parameters` now recompute the final bag
|
188
|
+
|
51
189
|
* Improved `vagrant user parameters` command
|
52
190
|
* Now using the exact config as seen by Vagrant, this includes defaults parameters
|
53
191
|
* An option has been added to only see defaults parameters
|
@@ -55,8 +193,11 @@
|
|
55
193
|
# 0.0.12
|
56
194
|
|
57
195
|
* Added travis configuration file
|
196
|
+
|
58
197
|
* Added travis build status icon to readme
|
198
|
+
|
59
199
|
* Fixed a bug when `.vagrantuser` file is empty or not a hash type
|
200
|
+
|
60
201
|
* Improved parameters command
|
61
202
|
* The parameters command is now a proper subcommand
|
62
203
|
* An option has been added to see system parameters
|
@@ -70,6 +211,7 @@
|
|
70
211
|
# 0.0.10
|
71
212
|
|
72
213
|
* Added a subcommand `parameters` for vagrant command `user`
|
214
|
+
|
73
215
|
* Added a vagrant command `vagrant user subcommand [options]`
|
74
216
|
|
75
217
|
# 0.0.9
|
@@ -79,7 +221,9 @@
|
|
79
221
|
# 0.0.8
|
80
222
|
|
81
223
|
* Introduced possibility to set default values
|
82
|
-
|
224
|
+
|
225
|
+
* Introduced restricted keys (For now, restricted keys are [`defaults`]).
|
226
|
+
|
83
227
|
* Fixed a bug with system-wide parameters
|
84
228
|
|
85
229
|
# 0.0.7
|
@@ -97,4 +241,5 @@
|
|
97
241
|
# 0.0.4
|
98
242
|
|
99
243
|
* JSON is now the default file format for parameters (due to problem with YAML)
|
244
|
+
|
100
245
|
* It is now possible to store parameters in the JSON format
|
data/Gemfile
CHANGED
@@ -1,27 +1,15 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gemspec
|
4
|
-
|
5
3
|
group :development do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
'gem' => Proc.new do
|
10
|
-
gem "vagrant", "~> 1.0.7"
|
11
|
-
end,
|
12
|
-
},
|
13
|
-
'v2' => {
|
14
|
-
'home' => "~/.vagrant.d",
|
15
|
-
'gem' => Proc.new do
|
16
|
-
gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
|
17
|
-
end,
|
18
|
-
},
|
19
|
-
}
|
4
|
+
gem "rake", "~> 10.1"
|
5
|
+
gem "minitest", "~> 5.2"
|
6
|
+
gem "minitest-reporters", "~> 1.0"
|
20
7
|
|
21
|
-
|
22
|
-
vagrant_dependency = vagrant_dependencies[vagrant_plugin_version]
|
8
|
+
gem "win32console", :platforms => ['mswin', 'mingw', :'x64_mingw']
|
23
9
|
|
24
|
-
|
10
|
+
gem "vagrant", :git => "https://github.com/mitchellh/vagrant.git", :tag => "v1.5.1"
|
11
|
+
end
|
25
12
|
|
26
|
-
|
13
|
+
group :plugins do
|
14
|
+
gem "nugrant", path: "."
|
27
15
|
end
|
data/README.md
CHANGED
@@ -1,80 +1,113 @@
|
|
1
|
-
# Nugrant
|
1
|
+
# Nugrant
|
2
|
+
|
3
|
+
[][gem]
|
4
|
+
[][travis]
|
5
|
+
[][gemnasium]
|
6
|
+
[][codeclimate]
|
7
|
+
|
8
|
+
[gem]: https://rubygems.org/gems/nugrant
|
9
|
+
[travis]: http://travis-ci.org/maoueh/nugrant
|
10
|
+
[gemnasium]: https://gemnasium.com/maoueh/nugrant
|
11
|
+
[codeclimate]: https://codeclimate.com/github/maoueh/nugrant
|
2
12
|
|
3
13
|
Nugrant is a library to easily handle parameters that need to be
|
4
14
|
injected into an application via different sources (system, user,
|
5
|
-
current, defaults).
|
15
|
+
current, defaults). But foremost, a Vagrant plug-in that will enhance
|
16
|
+
Vagrantfile to allow user specific configuration values.
|
6
17
|
|
7
|
-
|
8
|
-
Vagrantfile to allow user specific configuration values. The plugin
|
9
|
-
will let users define a `.vagrantuser` file at different locations. This
|
10
|
-
file will contain parameters that will be injected into the Vagrantfile.
|
18
|
+
Supported platforms:
|
11
19
|
|
12
|
-
|
20
|
+
* Vagrant 1.x
|
21
|
+
* Ruby 1.9.3+
|
13
22
|
|
14
|
-
|
23
|
+
## Overview
|
15
24
|
|
16
|
-
|
17
|
-
|
18
|
-
your `Gemfile` or your `.gemspec` file.
|
25
|
+
Using Nugrant as a plug-in provides an easy and hierarchical system to manage
|
26
|
+
machine and user specific parameters.
|
19
27
|
|
20
|
-
|
28
|
+
Let's start with an example. You need to distribute among your enterprise a
|
29
|
+
`Vagrantfile` to start and provision an AWS EC2 instance (or for an open-source project).
|
30
|
+
The `aws_access_key` and `aws_secret_key` should be configurable depending on the user
|
31
|
+
running `vagrant up`.
|
21
32
|
|
22
|
-
|
33
|
+
To achieve this, simply create a file named `.vagrantuser` in the project directory with
|
34
|
+
the following content:
|
35
|
+
|
36
|
+
aws:
|
37
|
+
access_key: "123456"
|
38
|
+
secret_key: "abcdef"
|
39
|
+
|
40
|
+
In your `Vagrantfile`, `Nugrant` will let you access the parameters via the
|
41
|
+
`config.user` object:
|
42
|
+
|
43
|
+
Vagrant.configure("2") do |config|
|
44
|
+
...
|
23
45
|
|
24
|
-
|
25
|
-
|
26
|
-
|
46
|
+
config.vm.provider :aws do |aws, override|
|
47
|
+
aws.access_key_id = config.user.aws.access_key
|
48
|
+
aws.secret_access_key = config.user.aws.secret_key
|
27
49
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
50
|
+
...
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
You then ignore the `.vagrantuser` file in your revision control, so each developer
|
55
|
+
as a specific one with their own values. People often commit a `.vagrantuser.example`
|
56
|
+
file in project's repository as an easy startup for the various parameters that
|
57
|
+
must be filled in, something like:
|
58
|
+
|
59
|
+
aws:
|
60
|
+
access_key: "<ACCESS_KEY_HERE>"
|
61
|
+
secret_key: "<SECRET_KEY_HERE>"
|
32
62
|
|
33
|
-
|
34
|
-
|
63
|
+
Moreover, there is a hierarchy of `.vagrantuser` files that you can leverage.
|
64
|
+
The order is project `.vagrantuser` overrides `$HOME/.vagrantuser` overrides
|
65
|
+
`$SYSTEM/.vagrantuser` where `$HOME` is the user's home directory and `$SYSTEM`
|
66
|
+
is the platform dependent folder where system global parameters are set.
|
35
67
|
|
36
|
-
|
68
|
+
We use it in our team to specify the various parameters required for
|
69
|
+
Vagrant `chef-solo` provisioner by putting the a `.vagrantuser` in our
|
70
|
+
home directory under a key `chef`. It gets merged with the project's
|
71
|
+
`.vagrantuser` file (if it exists), so it they can be overridden there.
|
72
|
+
|
73
|
+
Please refer to section [Usage](#usage) for all details and explanations
|
74
|
+
needed to fully use and understand Nugrant.
|
75
|
+
|
76
|
+
## Installation
|
37
77
|
|
38
|
-
|
39
|
-
You can install it via Vagrant or directly via the system gem
|
40
|
-
container.
|
78
|
+
### Vagrant
|
41
79
|
|
42
|
-
|
43
|
-
|
44
|
-
chance for this gem's dependencies, even if they are minimal,
|
45
|
-
to clash with gems already installed on your system. This is the
|
46
|
-
recommended installation method. To install, simply run in
|
47
|
-
a terminal:
|
80
|
+
Vagrant's plug-in system is very well done and Nugrant supports
|
81
|
+
the following plug-in API versions:
|
48
82
|
|
49
|
-
|
83
|
+
* V2 => Vagrant 1.x
|
50
84
|
|
51
|
-
|
52
|
-
|
85
|
+
To install the Nugrant as a Vagrant plug-in, simply type the following
|
86
|
+
command in a terminal:
|
53
87
|
|
54
|
-
|
88
|
+
vagrant plugin install nugrant
|
55
89
|
|
56
|
-
####
|
90
|
+
#### Vagrant 0.x
|
57
91
|
|
58
|
-
|
59
|
-
|
60
|
-
environment.
|
92
|
+
Vagrant 0.x is not supported anymore. If you still need support for
|
93
|
+
Vagrant 0.x, please use release line `1.x` (branch [1.x](https://github.com/maoueh/nugrant/tree/1.x)).
|
61
94
|
|
62
|
-
|
63
|
-
terminal:
|
95
|
+
### Library
|
64
96
|
|
65
|
-
|
97
|
+
If you would like to use Nugrant as a library, simply reference
|
98
|
+
it as a dependency of your application. Probably by adding it to
|
99
|
+
your `Gemfile` or your `.gemspec` file.
|
66
100
|
|
67
|
-
|
68
|
-
versions, it is not possible anymore to make the plugin available
|
69
|
-
within Vagrant when installing Nugrant in the system
|
70
|
-
gem container.
|
101
|
+
"nugrant", "~> 2.0"
|
71
102
|
|
72
103
|
## Usage
|
73
104
|
|
74
|
-
Whether used as a library or a Vagrant
|
105
|
+
Whether used as a library or a Vagrant plug-in, Nugrant has some
|
75
106
|
common concepts that apply to both usages. The most important
|
76
107
|
one is the parameters hierarchy.
|
77
108
|
|
109
|
+
### Common
|
110
|
+
|
78
111
|
Nugrant can read parameters from various locations and will merge
|
79
112
|
them all together in a single set. Merging is done in a fairly
|
80
113
|
standard fashion.
|
@@ -93,20 +126,10 @@ In text, this means that current parameters overrides user
|
|
93
126
|
parameters, user parameters overrides system parameters and
|
94
127
|
finally system parameters overrides defaults parameters.
|
95
128
|
|
96
|
-
### Library
|
97
|
-
|
98
|
-
Using Nugrant as a library to handle parameters from various
|
99
|
-
location is really easy. Two main classes need to be handled.
|
100
|
-
|
101
|
-
First, you need to create a `Nugrant::Config` object. This
|
102
|
-
configuration holds the values that needs to be customized
|
103
|
-
by your own application. This includes the different parameters paths
|
104
|
-
and the format of the parameters file.
|
105
|
-
|
106
129
|
### Vagrant
|
107
130
|
|
108
131
|
All examples shown here are for Vagrant 1.1+. They have
|
109
|
-
been tested with Vagrant 1.
|
132
|
+
been tested with Vagrant 1.4.0. Keep this in mind when
|
110
133
|
copying examples.
|
111
134
|
|
112
135
|
Let start with a small use case. Say the git repository you want
|
@@ -123,14 +146,14 @@ Your `Vagrantfile` would look like this:
|
|
123
146
|
|
124
147
|
However, what happens when multiple developers
|
125
148
|
need to share the same `Vagrantfile`? This is the main
|
126
|
-
use case this
|
149
|
+
use case this plug-in try to address.
|
127
150
|
|
128
|
-
When Vagrant starts, it loads all vagrant
|
129
|
-
about. If you installed the
|
151
|
+
When Vagrant starts, it loads all vagrant plug-ins it knows
|
152
|
+
about. If you installed the plug-in with one of the two
|
130
153
|
methods we listed above, Vagrant will know about Nugrant
|
131
154
|
and will load it correctly.
|
132
155
|
|
133
|
-
To use the
|
156
|
+
To use the plug-in, first create a YAML file named
|
134
157
|
`.vagrantuser` in the same folder where your `Vagrantfile` is
|
135
158
|
located. The file must be a valid YAML file:
|
136
159
|
|
@@ -201,10 +224,10 @@ Here the list of locations where Nugrant looks for parameters:
|
|
201
224
|
3. Home (`~/.vagrantuser`)
|
202
225
|
4. current (`.vagrantuser` within the same folder as the `Vagrantfile`)
|
203
226
|
|
204
|
-
|
227
|
+
#### Paths
|
205
228
|
|
206
229
|
When you want to specify paths on, specially on Windows, it's probably
|
207
|
-
better to only use
|
230
|
+
better to only use forward slash (`/`). The main reason for this is because
|
208
231
|
Ruby, which will be used at the end by Vagrant is able to deal with forward
|
209
232
|
slash even on Windows. This is great because with this, you can avoid
|
210
233
|
values escaping in YAML file. If you need to use backward slash (`\`), don't
|
@@ -213,7 +236,19 @@ forget to properly escape it!
|
|
213
236
|
value: "C:/Users/user/work/git"
|
214
237
|
value: "C:\\Users\\user\\work\\git"
|
215
238
|
|
216
|
-
|
239
|
+
Moreover, it is preferable that paths are specified in full
|
240
|
+
(i.e. no `~` for HOME directory for example). Normally, they
|
241
|
+
should be handled by `Vagrant` but it may happen that it's not
|
242
|
+
the case. If your have an error with a specific parameter,
|
243
|
+
either expand it in your config:
|
244
|
+
|
245
|
+
project: "/home/joe/work/ruby/git"
|
246
|
+
|
247
|
+
Of expand it in the `Vagrantfile`:
|
248
|
+
|
249
|
+
config.vm.synced_folder File.expand_path(config.user.repository.project), "/git"
|
250
|
+
|
251
|
+
#### Parameters access
|
217
252
|
|
218
253
|
Parameters in the `Vagrantfile` can be retrieved via method call
|
219
254
|
of array access.
|
@@ -229,9 +264,35 @@ it since its always better to be consistent:
|
|
229
264
|
|
230
265
|
Only the root key, i.e. `config.user`, cannot be access with
|
231
266
|
both syntax, only the method syntax can be used since this
|
232
|
-
is not provided by this
|
267
|
+
is not provided by this plug-in but by Vagrant itself.
|
268
|
+
|
269
|
+
##### Tips
|
270
|
+
|
271
|
+
Each non-final parameter (i.e a parameter that contains other parameters and
|
272
|
+
not a scalar value) is in fact a [Bag](/lib/nugrant/bag.rb)
|
273
|
+
object. You can call any defined methods on it. Since this object is also
|
274
|
+
[Enumerable](http://ruby-doc.org/core-2.0/Enumerable.html), you can do neat things
|
275
|
+
like iterating over your values or filtering them.
|
276
|
+
|
277
|
+
##### Restricted keys
|
278
|
+
|
279
|
+
Method access has the neat advantage of being beautiful to the
|
280
|
+
eye. However, the drawback of using this retrieval syntax is
|
281
|
+
that not all keys are permitted. As explained in the [Tips](#tips)
|
282
|
+
section, the object you are calling when using method access
|
283
|
+
is in fact of type [Bag](/lib/nugrant/bag.rb). Hence, if you
|
284
|
+
are using a key which collapse with ones of Bag's keys, it will
|
285
|
+
call the method instead of given you the value of you parameter.
|
286
|
+
At best, you will get a weird behavior and at worst a stack
|
287
|
+
trace when trying to access the parameter.
|
233
288
|
|
234
|
-
|
289
|
+
If you really want to use one of the restricted keys, simply
|
290
|
+
ensure to always use array access method.
|
291
|
+
|
292
|
+
The list of restricted keys can be accessed using command
|
293
|
+
`vagrant user restricted-keys`.
|
294
|
+
|
295
|
+
#### Default values
|
235
296
|
|
236
297
|
When using parameters, it is often needed so set default values
|
237
298
|
for certain parameters so if the user does not define one, the
|
@@ -262,12 +323,12 @@ If the user decides to change it, he just has to set it in his
|
|
262
323
|
own `.vagrantuser` and it will override the default value defined
|
263
324
|
in the Vagrantfile.
|
264
325
|
|
265
|
-
|
326
|
+
#### Commands
|
266
327
|
|
267
328
|
In this section, we describe the various vagrant commands defined
|
268
|
-
by this
|
329
|
+
by this plug-in that can be used to interact with it.
|
269
330
|
|
270
|
-
|
331
|
+
##### Parameters
|
271
332
|
|
272
333
|
This command will print the currently defined parameters at the
|
273
334
|
given location. All rules are respected when using this command.
|
@@ -285,6 +346,139 @@ Usage:
|
|
285
346
|
nodes_path: /Users/Chef/kitchen/nodes
|
286
347
|
roles_path: /Users/Chef/kitchen/roles
|
287
348
|
|
349
|
+
Add flag `-h` (or `--help`) for description of the command and a
|
350
|
+
list of available options.
|
351
|
+
|
352
|
+
##### Restricted Keys
|
353
|
+
|
354
|
+
This command will print the keys that cannot be accessed using
|
355
|
+
the method access syntax.
|
356
|
+
|
357
|
+
Usage:
|
358
|
+
|
359
|
+
> vagrant user restricted-keys
|
360
|
+
|
361
|
+
##### Env
|
362
|
+
|
363
|
+
Sometimes, you would like to have acces to the different values
|
364
|
+
stored in your `.vagrantuser` from environment variables. This
|
365
|
+
command is meant is exactly for this.
|
366
|
+
|
367
|
+
By using one of the three methods below, you will be able to export
|
368
|
+
(but also unset) environment variables from your current
|
369
|
+
parameters as seen by Nugrant.
|
370
|
+
|
371
|
+
You can see the commands that will be executed by simply
|
372
|
+
calling the method:
|
373
|
+
|
374
|
+
vagrant user env
|
375
|
+
|
376
|
+
The name of the environment will be upper cased and full path of
|
377
|
+
the key, without the `config.user` prefix, separated
|
378
|
+
with `_`. For example, the key accessible using
|
379
|
+
`config.user.db.user` and with value `root` would generate the
|
380
|
+
export command:
|
381
|
+
|
382
|
+
export DB_USER=root
|
383
|
+
|
384
|
+
And the unset command:
|
385
|
+
|
386
|
+
unset DB_USER
|
387
|
+
|
388
|
+
The value are escaped so it is possible to define value containing
|
389
|
+
spaces for example.
|
390
|
+
|
391
|
+
A last note about generate commands is that pre-existing environment
|
392
|
+
variable are not taking in consideration by this command. So if
|
393
|
+
an environment variable with name `DB_USER` already exist, it
|
394
|
+
would be overwritten by an export command.
|
395
|
+
|
396
|
+
Add flag `-h` (or `--help`) for description of the command and a
|
397
|
+
list of available options.
|
398
|
+
|
399
|
+
###### Method #1
|
400
|
+
|
401
|
+
If you plan to use frequently this feature, our best suggestion
|
402
|
+
is to create a little bash script that will simply delegates
|
403
|
+
to the real command. By having a bash script that calls the
|
404
|
+
command, you will be able to easily export environment variables
|
405
|
+
by sourcing the script.
|
406
|
+
|
407
|
+
Create a file named `nugrant2env` somewhere accessible from
|
408
|
+
the `$PATH` variable with the following content:
|
409
|
+
|
410
|
+
#!/bin/env sh
|
411
|
+
|
412
|
+
$(vagrant user env "$@")
|
413
|
+
|
414
|
+
This script will simply delegates to the `vagrant user env`
|
415
|
+
command and pass all arguments it receives to it. The
|
416
|
+
magic happens because the command `vagrant user env` outputs
|
417
|
+
the various export commands to the standard output.
|
418
|
+
|
419
|
+
By sourcing the simple delegating bash script, the parameters
|
420
|
+
seen by Nugrant will be available in your environment:
|
421
|
+
|
422
|
+
. nugrant2env
|
423
|
+
|
424
|
+
By default, export commands are generated. But you can pass
|
425
|
+
some options to the `nugrant2env` script, For example, to
|
426
|
+
generate the unset ones, add `--unset` (or simply `-u`).
|
427
|
+
|
428
|
+
. nugrant2env --unset
|
429
|
+
|
430
|
+
For a list of options, see the help of the command delegated
|
431
|
+
to:
|
432
|
+
|
433
|
+
vagrant user env -h
|
434
|
+
|
435
|
+
###### Method #2
|
436
|
+
|
437
|
+
Use the command to generate a base script in the current
|
438
|
+
directory that you will then source:
|
439
|
+
|
440
|
+
vagrant user env --format script
|
441
|
+
|
442
|
+
This will generate a script called `nugrant2env.sh` into the
|
443
|
+
current directory. You then simply source this script:
|
444
|
+
|
445
|
+
. nugrant2env.sh
|
446
|
+
|
447
|
+
Using `vagrant user env -u --format script` will instead generate the bash
|
448
|
+
script that will unset the environment variables. Don't forget
|
449
|
+
to source it to unset variables.
|
450
|
+
|
451
|
+
###### Method #3
|
452
|
+
|
453
|
+
Use the command to generate an [autoenv](https://github.com/kennethreitz/autoenv)
|
454
|
+
file in the current directory. By using the [autoenv] project, anytime you
|
455
|
+
will enter the project directory via the `cd` command, variables
|
456
|
+
exported found in the `.env` file generated will be exported to
|
457
|
+
your environment.
|
458
|
+
|
459
|
+
vagrant user env --format autoenv
|
460
|
+
|
461
|
+
This will generate a file called `.env` in the
|
462
|
+
current directory. You then simply change to the directory
|
463
|
+
where the `.env` file was generated to made exported variables
|
464
|
+
available in your environment.
|
465
|
+
|
466
|
+
cd ..
|
467
|
+
cd <project_dir>
|
468
|
+
|
469
|
+
Using `vagrant user env -u --format autoenv` will instead generate
|
470
|
+
the autoenv file that will unset the environment variables.
|
471
|
+
|
472
|
+
### Library
|
473
|
+
|
474
|
+
Using Nugrant as a library to handle parameters from various
|
475
|
+
location is really easy. Two main classes need to be handled.
|
476
|
+
|
477
|
+
First, you need to create a `Nugrant::Config` object. This
|
478
|
+
configuration holds the values that needs to be customized
|
479
|
+
by your own application. This includes the different parameters paths
|
480
|
+
and the format of the parameters file.
|
481
|
+
|
288
482
|
## Contributing
|
289
483
|
|
290
484
|
You can contribute by filling issues when something goes
|
@@ -293,5 +487,5 @@ to fix the issue either in the code or in the documentation,
|
|
293
487
|
where applicable.
|
294
488
|
|
295
489
|
You can also send pull requests for any feature or improvement
|
296
|
-
you think should be included in this
|
490
|
+
you think should be included in this plug-in. I will evaluate
|
297
491
|
each of them and merge them as fast as possible.
|