nugrant 2.1.2 → 2.1.4
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 +5 -5
- data/.gitignore +23 -23
- data/.travis.yml +15 -10
- data/CHANGELOG.md +347 -338
- data/CONTRIBUTORS.md +7 -5
- data/Gemfile +13 -13
- data/README.md +601 -601
- data/lib/nugrant/bag.rb +264 -264
- data/lib/nugrant/config.rb +201 -201
- data/lib/nugrant/helper/bag.rb +38 -38
- data/lib/nugrant/helper/env/exporter.rb +195 -195
- data/lib/nugrant/helper/env/namer.rb +47 -47
- data/lib/nugrant/helper/parameters.rb +12 -12
- data/lib/nugrant/helper/stack.rb +86 -86
- data/lib/nugrant/mixin/parameters.rb +178 -178
- data/lib/nugrant/parameters.rb +29 -29
- data/lib/nugrant/vagrant/errors.rb +35 -35
- data/lib/nugrant/vagrant/v2/action/auto_export.rb +45 -45
- data/lib/nugrant/vagrant/v2/action.rb +17 -17
- data/lib/nugrant/vagrant/v2/command/env.rb +118 -118
- data/lib/nugrant/vagrant/v2/command/parameters.rb +153 -153
- data/lib/nugrant/vagrant/v2/command/restricted_keys.rb +64 -64
- data/lib/nugrant/vagrant/v2/command/root.rb +95 -95
- data/lib/nugrant/vagrant/v2/config/user.rb +29 -29
- data/lib/nugrant/vagrant/v2/helper.rb +96 -96
- data/lib/nugrant/vagrant/v2/plugin.rb +34 -34
- data/lib/nugrant/version.rb +3 -3
- data/lib/nugrant.rb +31 -31
- data/locales/en.yml +24 -24
- data/locales/fr.yml +24 -24
- data/nugrant.gemspec +32 -32
- data/test/lib/nugrant/helper/env/test_exporter.rb +238 -238
- data/test/lib/nugrant/helper/test_bag.rb +16 -16
- data/test/lib/nugrant/helper/test_parameters.rb +17 -17
- data/test/lib/nugrant/helper/test_stack.rb +152 -152
- data/test/lib/nugrant/test_bag.rb +450 -450
- data/test/lib/nugrant/test_config.rb +201 -201
- data/test/lib/nugrant/test_parameters.rb +438 -438
- data/test/lib/test_helper.rb +3 -3
- data/test/resources/README.md +52 -52
- data/test/resources/json/params_current_1.json +6 -6
- data/test/resources/json/params_current_2.json +29 -29
- data/test/resources/json/params_user_nil_values.json +9 -9
- data/test/resources/vagrantfiles/v2.auto_export +13 -13
- data/test/resources/vagrantfiles/v2.bag_inside_array +15 -15
- data/test/resources/vagrantfiles/v2.defaults_mixed_string_symbols +18 -18
- data/test/resources/vagrantfiles/v2.defaults_null_values_in_vagrantuser +23 -23
- data/test/resources/vagrantfiles/v2.defaults_using_string +18 -18
- data/test/resources/vagrantfiles/v2.defaults_using_symbol +18 -18
- data/test/resources/vagrantfiles/v2.empty +2 -2
- data/test/resources/vagrantfiles/v2.fake +29 -29
- data/test/resources/vagrantfiles/v2.missing_parameter +3 -3
- data/test/resources/vagrantfiles/v2.real +22 -22
- data/test/resources/yaml/params_array.yml +5 -5
- data/test/resources/yaml/params_boolean.yml +1 -1
- data/test/resources/yaml/params_combinations.yml +72 -72
- data/test/resources/yaml/params_current_1.yml +4 -4
- data/test/resources/yaml/params_current_2.yml +23 -23
- data/test/resources/yaml/params_defaults_at_root.yml +1 -1
- data/test/resources/yaml/params_defaults_not_at_root.yml +2 -2
- data/test/resources/yaml/params_list.yml +2 -2
- data/test/resources/yaml/params_numeric_key.yml +3 -3
- data/test/resources/yaml/params_simple.yml +1 -1
- data/test/resources/yaml/params_system_1.yml +4 -4
- data/test/resources/yaml/params_system_2.yml +25 -25
- data/test/resources/yaml/params_unix_eol.yml +3 -3
- data/test/resources/yaml/params_user_1.yml +4 -4
- data/test/resources/yaml/params_user_2.yml +23 -23
- data/test/resources/yaml/params_user_nil_values.yml +5 -5
- data/test/resources/yaml/params_windows_eol.yml +3 -3
- metadata +12 -13
@@ -1,64 +1,64 @@
|
|
1
|
-
require 'nugrant'
|
2
|
-
require 'nugrant/vagrant/v2/helper'
|
3
|
-
|
4
|
-
module Nugrant
|
5
|
-
module Vagrant
|
6
|
-
module V2
|
7
|
-
module Command
|
8
|
-
class RestrictedKeys < ::Vagrant.plugin("2", :command)
|
9
|
-
def self.synopsis
|
10
|
-
"prints list of restricted keys for method access"
|
11
|
-
end
|
12
|
-
|
13
|
-
def initialize(arguments, environment)
|
14
|
-
super(arguments, environment)
|
15
|
-
|
16
|
-
@show_help = false
|
17
|
-
end
|
18
|
-
|
19
|
-
def create_parser()
|
20
|
-
return OptionParser.new do |parser|
|
21
|
-
parser.banner = "Usage: vagrant user restricted-keys"
|
22
|
-
parser.separator ""
|
23
|
-
|
24
|
-
parser.separator "Available options:"
|
25
|
-
parser.separator ""
|
26
|
-
|
27
|
-
parser.on("-h", "--help", "Prints this help") do
|
28
|
-
@show_help = true
|
29
|
-
end
|
30
|
-
|
31
|
-
parser.separator ""
|
32
|
-
parser.separator "Prints keys that cannot be accessed using the method access syntax\n" +
|
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
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def execute
|
39
|
-
parser = create_parser()
|
40
|
-
arguments = parse_options(parser)
|
41
|
-
|
42
|
-
return help(parser) if @show_help
|
43
|
-
|
44
|
-
@env.ui.info("The following keys are restricted, i.e. that method access (`config.user.<key>`)", :prefix => false)
|
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['<key>']`).", :prefix => false)
|
47
|
-
@env.ui.info("", :prefix => false)
|
48
|
-
|
49
|
-
@env.ui.info("You can run `vagrant user parameters` to check if your config currently defines", :prefix => false)
|
50
|
-
@env.ui.info("one or more restricted keys shown below.", :prefix => false)
|
51
|
-
@env.ui.info("", :prefix => false)
|
52
|
-
|
53
|
-
restricted_keys = Helper::get_restricted_keys()
|
54
|
-
@env.ui.info(restricted_keys.sort().join(", "), :prefix => false)
|
55
|
-
end
|
56
|
-
|
57
|
-
def help(parser)
|
58
|
-
@env.ui.info(parser.help, :prefix => false)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
1
|
+
require 'nugrant'
|
2
|
+
require 'nugrant/vagrant/v2/helper'
|
3
|
+
|
4
|
+
module Nugrant
|
5
|
+
module Vagrant
|
6
|
+
module V2
|
7
|
+
module Command
|
8
|
+
class RestrictedKeys < ::Vagrant.plugin("2", :command)
|
9
|
+
def self.synopsis
|
10
|
+
"prints list of restricted keys for method access"
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(arguments, environment)
|
14
|
+
super(arguments, environment)
|
15
|
+
|
16
|
+
@show_help = false
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_parser()
|
20
|
+
return OptionParser.new do |parser|
|
21
|
+
parser.banner = "Usage: vagrant user restricted-keys"
|
22
|
+
parser.separator ""
|
23
|
+
|
24
|
+
parser.separator "Available options:"
|
25
|
+
parser.separator ""
|
26
|
+
|
27
|
+
parser.on("-h", "--help", "Prints this help") do
|
28
|
+
@show_help = true
|
29
|
+
end
|
30
|
+
|
31
|
+
parser.separator ""
|
32
|
+
parser.separator "Prints keys that cannot be accessed using the method access syntax\n" +
|
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
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def execute
|
39
|
+
parser = create_parser()
|
40
|
+
arguments = parse_options(parser)
|
41
|
+
|
42
|
+
return help(parser) if @show_help
|
43
|
+
|
44
|
+
@env.ui.info("The following keys are restricted, i.e. that method access (`config.user.<key>`)", :prefix => false)
|
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['<key>']`).", :prefix => false)
|
47
|
+
@env.ui.info("", :prefix => false)
|
48
|
+
|
49
|
+
@env.ui.info("You can run `vagrant user parameters` to check if your config currently defines", :prefix => false)
|
50
|
+
@env.ui.info("one or more restricted keys shown below.", :prefix => false)
|
51
|
+
@env.ui.info("", :prefix => false)
|
52
|
+
|
53
|
+
restricted_keys = Helper::get_restricted_keys()
|
54
|
+
@env.ui.info(restricted_keys.sort().join(", "), :prefix => false)
|
55
|
+
end
|
56
|
+
|
57
|
+
def help(parser)
|
58
|
+
@env.ui.info(parser.help, :prefix => false)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -1,95 +1,95 @@
|
|
1
|
-
require 'nugrant'
|
2
|
-
require 'nugrant/vagrant/v2/command/env'
|
3
|
-
require 'nugrant/vagrant/v2/command/parameters'
|
4
|
-
require 'nugrant/vagrant/v2/command/restricted_keys'
|
5
|
-
require 'nugrant/version'
|
6
|
-
|
7
|
-
module Nugrant
|
8
|
-
module Vagrant
|
9
|
-
module V2
|
10
|
-
module Command
|
11
|
-
class Root < ::Vagrant.plugin("2", :command)
|
12
|
-
def self.synopsis
|
13
|
-
"manage Nugrant user defined parameters (config.user)"
|
14
|
-
end
|
15
|
-
|
16
|
-
def initialize(arguments, environment)
|
17
|
-
super(arguments, environment)
|
18
|
-
|
19
|
-
@arguments, @subcommand, @subarguments = split_main_and_subcommand(arguments)
|
20
|
-
|
21
|
-
# Change super class available arguments to main ones only
|
22
|
-
@argv = @arguments
|
23
|
-
|
24
|
-
@subcommands = ::Vagrant::Registry.new()
|
25
|
-
@subcommands.register(:env) do
|
26
|
-
Command::Env
|
27
|
-
end
|
28
|
-
|
29
|
-
@subcommands.register(:parameters) do
|
30
|
-
Command::Parameters
|
31
|
-
end
|
32
|
-
|
33
|
-
@subcommands.register(:'restricted-keys') do
|
34
|
-
Command::RestrictedKeys
|
35
|
-
end
|
36
|
-
|
37
|
-
@show_help = false
|
38
|
-
@show_version = false
|
39
|
-
end
|
40
|
-
|
41
|
-
def create_parser()
|
42
|
-
return OptionParser.new do |parser|
|
43
|
-
parser.banner = "Usage: vagrant user [-h] [-v] <subcommand> [<args>]"
|
44
|
-
|
45
|
-
parser.separator ""
|
46
|
-
parser.on("-h", "--help", "Prints this help") do
|
47
|
-
@show_help = true
|
48
|
-
end
|
49
|
-
|
50
|
-
parser.on("-v", "--version", "Prints plugin version and exit.") do
|
51
|
-
@show_version = true
|
52
|
-
end
|
53
|
-
|
54
|
-
parser.separator ""
|
55
|
-
parser.separator "Available subcommands:"
|
56
|
-
|
57
|
-
keys = []
|
58
|
-
@subcommands.each { |key, value| keys << key.to_s }
|
59
|
-
|
60
|
-
keys.sort.each do |key|
|
61
|
-
parser.separator " #{key}"
|
62
|
-
end
|
63
|
-
|
64
|
-
parser.separator ""
|
65
|
-
parser.separator "For help on any individual command run `vagrant user <subcommand> -h`"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def execute
|
70
|
-
parser = create_parser()
|
71
|
-
arguments = parse_options(parser)
|
72
|
-
|
73
|
-
return version() if @show_version
|
74
|
-
return help(parser) if @show_help
|
75
|
-
|
76
|
-
command_class = @subcommands.get(@subcommand.to_sym) if @subcommand
|
77
|
-
return help(parser) if !command_class || !@subcommand
|
78
|
-
|
79
|
-
@logger.debug("Invoking nugrant command class: #{command_class} #{@subarguments.inspect}")
|
80
|
-
|
81
|
-
command_class.new(@subarguments, @env).execute
|
82
|
-
end
|
83
|
-
|
84
|
-
def help(parser)
|
85
|
-
@env.ui.info(parser.help, :prefix => false)
|
86
|
-
end
|
87
|
-
|
88
|
-
def version()
|
89
|
-
@env.ui.info("Nugrant version #{Nugrant::VERSION}", :prefix => false)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
1
|
+
require 'nugrant'
|
2
|
+
require 'nugrant/vagrant/v2/command/env'
|
3
|
+
require 'nugrant/vagrant/v2/command/parameters'
|
4
|
+
require 'nugrant/vagrant/v2/command/restricted_keys'
|
5
|
+
require 'nugrant/version'
|
6
|
+
|
7
|
+
module Nugrant
|
8
|
+
module Vagrant
|
9
|
+
module V2
|
10
|
+
module Command
|
11
|
+
class Root < ::Vagrant.plugin("2", :command)
|
12
|
+
def self.synopsis
|
13
|
+
"manage Nugrant user defined parameters (config.user)"
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(arguments, environment)
|
17
|
+
super(arguments, environment)
|
18
|
+
|
19
|
+
@arguments, @subcommand, @subarguments = split_main_and_subcommand(arguments)
|
20
|
+
|
21
|
+
# Change super class available arguments to main ones only
|
22
|
+
@argv = @arguments
|
23
|
+
|
24
|
+
@subcommands = ::Vagrant::Registry.new()
|
25
|
+
@subcommands.register(:env) do
|
26
|
+
Command::Env
|
27
|
+
end
|
28
|
+
|
29
|
+
@subcommands.register(:parameters) do
|
30
|
+
Command::Parameters
|
31
|
+
end
|
32
|
+
|
33
|
+
@subcommands.register(:'restricted-keys') do
|
34
|
+
Command::RestrictedKeys
|
35
|
+
end
|
36
|
+
|
37
|
+
@show_help = false
|
38
|
+
@show_version = false
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_parser()
|
42
|
+
return OptionParser.new do |parser|
|
43
|
+
parser.banner = "Usage: vagrant user [-h] [-v] <subcommand> [<args>]"
|
44
|
+
|
45
|
+
parser.separator ""
|
46
|
+
parser.on("-h", "--help", "Prints this help") do
|
47
|
+
@show_help = true
|
48
|
+
end
|
49
|
+
|
50
|
+
parser.on("-v", "--version", "Prints plugin version and exit.") do
|
51
|
+
@show_version = true
|
52
|
+
end
|
53
|
+
|
54
|
+
parser.separator ""
|
55
|
+
parser.separator "Available subcommands:"
|
56
|
+
|
57
|
+
keys = []
|
58
|
+
@subcommands.each { |key, value| keys << key.to_s }
|
59
|
+
|
60
|
+
keys.sort.each do |key|
|
61
|
+
parser.separator " #{key}"
|
62
|
+
end
|
63
|
+
|
64
|
+
parser.separator ""
|
65
|
+
parser.separator "For help on any individual command run `vagrant user <subcommand> -h`"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def execute
|
70
|
+
parser = create_parser()
|
71
|
+
arguments = parse_options(parser)
|
72
|
+
|
73
|
+
return version() if @show_version
|
74
|
+
return help(parser) if @show_help
|
75
|
+
|
76
|
+
command_class = @subcommands.get(@subcommand.to_sym) if @subcommand
|
77
|
+
return help(parser) if !command_class || !@subcommand
|
78
|
+
|
79
|
+
@logger.debug("Invoking nugrant command class: #{command_class} #{@subarguments.inspect}")
|
80
|
+
|
81
|
+
command_class.new(@subarguments, @env).execute
|
82
|
+
end
|
83
|
+
|
84
|
+
def help(parser)
|
85
|
+
@env.ui.info(parser.help, :prefix => false)
|
86
|
+
end
|
87
|
+
|
88
|
+
def version()
|
89
|
+
@env.ui.info("Nugrant version #{Nugrant::VERSION}", :prefix => false)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -1,29 +1,29 @@
|
|
1
|
-
require 'nugrant/mixin/parameters'
|
2
|
-
require 'nugrant/vagrant/errors'
|
3
|
-
require 'nugrant/vagrant/v2/helper'
|
4
|
-
|
5
|
-
module Nugrant
|
6
|
-
module Vagrant
|
7
|
-
module V2
|
8
|
-
module Config
|
9
|
-
class User < ::Vagrant.plugin("2", :config)
|
10
|
-
|
11
|
-
include Mixin::Parameters
|
12
|
-
|
13
|
-
def initialize(defaults = {}, config = {})
|
14
|
-
setup!(defaults,
|
15
|
-
:params_filename => ".vagrantuser",
|
16
|
-
:current_path => Helper.find_project_path(),
|
17
|
-
:key_error => Proc.new do |key|
|
18
|
-
raise Errors::ParameterNotFoundError, :key => key.to_s
|
19
|
-
end,
|
20
|
-
:parse_error => Proc.new do |filename, error|
|
21
|
-
raise Errors::VagrantUserParseError, :filename => filename.to_s, :error => error
|
22
|
-
end
|
23
|
-
)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
1
|
+
require 'nugrant/mixin/parameters'
|
2
|
+
require 'nugrant/vagrant/errors'
|
3
|
+
require 'nugrant/vagrant/v2/helper'
|
4
|
+
|
5
|
+
module Nugrant
|
6
|
+
module Vagrant
|
7
|
+
module V2
|
8
|
+
module Config
|
9
|
+
class User < ::Vagrant.plugin("2", :config)
|
10
|
+
|
11
|
+
include Mixin::Parameters
|
12
|
+
|
13
|
+
def initialize(defaults = {}, config = {})
|
14
|
+
setup!(defaults,
|
15
|
+
:params_filename => ".vagrantuser",
|
16
|
+
:current_path => Helper.find_project_path(),
|
17
|
+
:key_error => Proc.new do |key|
|
18
|
+
raise Errors::ParameterNotFoundError, :key => key.to_s
|
19
|
+
end,
|
20
|
+
:parse_error => Proc.new do |filename, error|
|
21
|
+
raise Errors::VagrantUserParseError, :filename => filename.to_s, :error => error
|
22
|
+
end
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,96 +1,96 @@
|
|
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
|
-
vagrantfile_name = [vagrantfile_name] if vagrantfile_name && !vagrantfile_name.is_a?(Array)
|
24
|
-
|
25
|
-
root_finder = lambda do |path|
|
26
|
-
vagrantfile = find_vagrantfile(path, vagrantfile_name)
|
27
|
-
|
28
|
-
return path if vagrantfile
|
29
|
-
return nil if path.root? || !File.exist?(path)
|
30
|
-
|
31
|
-
root_finder.call(path.parent)
|
32
|
-
end
|
33
|
-
|
34
|
-
root_finder.call(get_vagrant_working_directory())
|
35
|
-
end
|
36
|
-
|
37
|
-
##
|
38
|
-
# Finds the Vagrantfile in the given directory.
|
39
|
-
#
|
40
|
-
# Copied from `lib\vagrant\environment.rb#732` (tag: v1.6.2)
|
41
|
-
#
|
42
|
-
# @param [Pathname] path Path to search in.
|
43
|
-
# @return [Pathname]
|
44
|
-
#
|
45
|
-
def self.find_vagrantfile(search_path, filenames = nil)
|
46
|
-
filenames ||= ["Vagrantfile", "vagrantfile"]
|
47
|
-
filenames.each do |vagrantfile|
|
48
|
-
current_path = search_path.join(vagrantfile)
|
49
|
-
return current_path if current_path.file?
|
50
|
-
end
|
51
|
-
|
52
|
-
nil
|
53
|
-
end
|
54
|
-
|
55
|
-
##
|
56
|
-
# Returns Vagrant working directory to use.
|
57
|
-
#
|
58
|
-
# Copied from `lib\vagrant\environment.rb#80` (tag: v1.6.2)
|
59
|
-
#
|
60
|
-
# @return [Pathname] The working directory to start search in.
|
61
|
-
#
|
62
|
-
def self.get_vagrant_working_directory()
|
63
|
-
cwd = nil
|
64
|
-
|
65
|
-
# Set the default working directory to look for the vagrantfile
|
66
|
-
cwd ||= ENV["VAGRANT_CWD"] if ENV.has_key?("VAGRANT_CWD")
|
67
|
-
cwd ||= Dir.pwd
|
68
|
-
cwd = Pathname.new(cwd)
|
69
|
-
|
70
|
-
if !cwd.directory?
|
71
|
-
raise Errors::EnvironmentNonExistentCWD, cwd: cwd.to_s
|
72
|
-
end
|
73
|
-
|
74
|
-
cwd = cwd.expand_path
|
75
|
-
end
|
76
|
-
|
77
|
-
def self.get_restricted_keys()
|
78
|
-
bag_methods = Nugrant::Bag.instance_methods
|
79
|
-
parameters_methods = V2::Config::User.instance_methods
|
80
|
-
|
81
|
-
(bag_methods | parameters_methods).map(&:to_s)
|
82
|
-
end
|
83
|
-
|
84
|
-
def self.get_used_restricted_keys(hash, restricted_keys)
|
85
|
-
keys = []
|
86
|
-
hash.each do |key, value|
|
87
|
-
keys << key if restricted_keys.include?(key)
|
88
|
-
keys += get_used_restricted_keys(value, restricted_keys) if value.kind_of?(Hash)
|
89
|
-
end
|
90
|
-
|
91
|
-
keys.uniq
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
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
|
+
vagrantfile_name = [vagrantfile_name] if vagrantfile_name && !vagrantfile_name.is_a?(Array)
|
24
|
+
|
25
|
+
root_finder = lambda do |path|
|
26
|
+
vagrantfile = find_vagrantfile(path, vagrantfile_name)
|
27
|
+
|
28
|
+
return path if vagrantfile
|
29
|
+
return nil if path.root? || !File.exist?(path)
|
30
|
+
|
31
|
+
root_finder.call(path.parent)
|
32
|
+
end
|
33
|
+
|
34
|
+
root_finder.call(get_vagrant_working_directory())
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# Finds the Vagrantfile in the given directory.
|
39
|
+
#
|
40
|
+
# Copied from `lib\vagrant\environment.rb#732` (tag: v1.6.2)
|
41
|
+
#
|
42
|
+
# @param [Pathname] path Path to search in.
|
43
|
+
# @return [Pathname]
|
44
|
+
#
|
45
|
+
def self.find_vagrantfile(search_path, filenames = nil)
|
46
|
+
filenames ||= ["Vagrantfile", "vagrantfile"]
|
47
|
+
filenames.each do |vagrantfile|
|
48
|
+
current_path = search_path.join(vagrantfile)
|
49
|
+
return current_path if current_path.file?
|
50
|
+
end
|
51
|
+
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# Returns Vagrant working directory to use.
|
57
|
+
#
|
58
|
+
# Copied from `lib\vagrant\environment.rb#80` (tag: v1.6.2)
|
59
|
+
#
|
60
|
+
# @return [Pathname] The working directory to start search in.
|
61
|
+
#
|
62
|
+
def self.get_vagrant_working_directory()
|
63
|
+
cwd = nil
|
64
|
+
|
65
|
+
# Set the default working directory to look for the vagrantfile
|
66
|
+
cwd ||= ENV["VAGRANT_CWD"] if ENV.has_key?("VAGRANT_CWD")
|
67
|
+
cwd ||= Dir.pwd
|
68
|
+
cwd = Pathname.new(cwd)
|
69
|
+
|
70
|
+
if !cwd.directory?
|
71
|
+
raise Errors::EnvironmentNonExistentCWD, cwd: cwd.to_s
|
72
|
+
end
|
73
|
+
|
74
|
+
cwd = cwd.expand_path
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.get_restricted_keys()
|
78
|
+
bag_methods = Nugrant::Bag.instance_methods
|
79
|
+
parameters_methods = V2::Config::User.instance_methods
|
80
|
+
|
81
|
+
(bag_methods | parameters_methods).map(&:to_s)
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.get_used_restricted_keys(hash, restricted_keys)
|
85
|
+
keys = []
|
86
|
+
hash.each do |key, value|
|
87
|
+
keys << key if restricted_keys.include?(key)
|
88
|
+
keys += get_used_restricted_keys(value, restricted_keys) if value.kind_of?(Hash)
|
89
|
+
end
|
90
|
+
|
91
|
+
keys.uniq
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -1,34 +1,34 @@
|
|
1
|
-
require 'nugrant/vagrant/v2/action'
|
2
|
-
|
3
|
-
module Nugrant
|
4
|
-
module Vagrant
|
5
|
-
module V2
|
6
|
-
class Plugin < ::Vagrant.plugin("2")
|
7
|
-
name "Nugrant"
|
8
|
-
description <<-DESC
|
9
|
-
Plugin to define and use user specific parameters from various location inside your Vagrantfile.
|
10
|
-
DESC
|
11
|
-
|
12
|
-
class << self
|
13
|
-
def provision(hook)
|
14
|
-
hook.before(::Vagrant::Action::Builtin::Provision, Nugrant::Vagrant::V2::Action.auto_export)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
action_hook(:nugrant_provision, :machine_action_up, &method(:provision))
|
19
|
-
action_hook(:nugrant_provision, :machine_action_reload, &method(:provision))
|
20
|
-
action_hook(:nugrant_provision, :machine_action_provision, &method(:provision))
|
21
|
-
|
22
|
-
command "user" do
|
23
|
-
require_relative "command/root"
|
24
|
-
Command::Root
|
25
|
-
end
|
26
|
-
|
27
|
-
config "user" do
|
28
|
-
require_relative "config/user"
|
29
|
-
Config::User
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
1
|
+
require 'nugrant/vagrant/v2/action'
|
2
|
+
|
3
|
+
module Nugrant
|
4
|
+
module Vagrant
|
5
|
+
module V2
|
6
|
+
class Plugin < ::Vagrant.plugin("2")
|
7
|
+
name "Nugrant"
|
8
|
+
description <<-DESC
|
9
|
+
Plugin to define and use user specific parameters from various location inside your Vagrantfile.
|
10
|
+
DESC
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def provision(hook)
|
14
|
+
hook.before(::Vagrant::Action::Builtin::Provision, Nugrant::Vagrant::V2::Action.auto_export)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
action_hook(:nugrant_provision, :machine_action_up, &method(:provision))
|
19
|
+
action_hook(:nugrant_provision, :machine_action_reload, &method(:provision))
|
20
|
+
action_hook(:nugrant_provision, :machine_action_provision, &method(:provision))
|
21
|
+
|
22
|
+
command "user" do
|
23
|
+
require_relative "command/root"
|
24
|
+
Command::Root
|
25
|
+
end
|
26
|
+
|
27
|
+
config "user" do
|
28
|
+
require_relative "config/user"
|
29
|
+
Config::User
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/nugrant/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Nugrant
|
2
|
-
VERSION = "2.1.
|
3
|
-
end
|
1
|
+
module Nugrant
|
2
|
+
VERSION = "2.1.4"
|
3
|
+
end
|