leap_cli 1.7.4 → 1.8

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/bin/leap +6 -13
  3. data/lib/leap/platform.rb +2 -0
  4. data/lib/leap_cli.rb +2 -1
  5. data/lib/leap_cli/bootstrap.rb +197 -0
  6. data/lib/leap_cli/commands/common.rb +61 -0
  7. data/lib/leap_cli/commands/new.rb +5 -1
  8. data/lib/leap_cli/commands/pre.rb +1 -66
  9. data/lib/leap_cli/config/environment.rb +180 -0
  10. data/lib/leap_cli/config/manager.rb +100 -197
  11. data/lib/leap_cli/config/node.rb +2 -2
  12. data/lib/leap_cli/config/object.rb +56 -43
  13. data/lib/leap_cli/config/object_list.rb +6 -3
  14. data/lib/leap_cli/config/provider.rb +11 -0
  15. data/lib/leap_cli/config/secrets.rb +14 -1
  16. data/lib/leap_cli/config/tag.rb +2 -2
  17. data/lib/leap_cli/leapfile.rb +1 -0
  18. data/lib/leap_cli/log.rb +1 -0
  19. data/lib/leap_cli/logger.rb +16 -12
  20. data/lib/leap_cli/markdown_document_listener.rb +3 -1
  21. data/lib/leap_cli/path.rb +12 -0
  22. data/lib/leap_cli/remote/leap_plugin.rb +9 -34
  23. data/lib/leap_cli/remote/puppet_plugin.rb +0 -40
  24. data/lib/leap_cli/remote/tasks.rb +9 -34
  25. data/lib/leap_cli/ssh_key.rb +5 -2
  26. data/lib/leap_cli/version.rb +2 -2
  27. metadata +5 -18
  28. data/lib/leap_cli/commands/ca.rb +0 -518
  29. data/lib/leap_cli/commands/clean.rb +0 -16
  30. data/lib/leap_cli/commands/compile.rb +0 -340
  31. data/lib/leap_cli/commands/db.rb +0 -65
  32. data/lib/leap_cli/commands/deploy.rb +0 -368
  33. data/lib/leap_cli/commands/env.rb +0 -76
  34. data/lib/leap_cli/commands/facts.rb +0 -100
  35. data/lib/leap_cli/commands/inspect.rb +0 -144
  36. data/lib/leap_cli/commands/list.rb +0 -132
  37. data/lib/leap_cli/commands/node.rb +0 -165
  38. data/lib/leap_cli/commands/node_init.rb +0 -169
  39. data/lib/leap_cli/commands/ssh.rb +0 -220
  40. data/lib/leap_cli/commands/test.rb +0 -74
  41. data/lib/leap_cli/commands/user.rb +0 -136
  42. data/lib/leap_cli/commands/util.rb +0 -50
  43. data/lib/leap_cli/commands/vagrant.rb +0 -197
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fde4e852d415bcc30ed9d48a65e5b264ac999d4f
4
- data.tar.gz: a3658cdc96431cf991509bbd48e0d3aa4afdadc3
3
+ metadata.gz: a1517e12ad3324944287a8639f98cc6783c1945c
4
+ data.tar.gz: d7357d37b347982b7ea5b08f0e26fd9b30c8bc80
5
5
  SHA512:
6
- metadata.gz: 5ab70f0f7a3a39e09ccac39dd3fb69d7dd6a5b47366f1251b24dbfc283ada437ceed72ce1a9e5a27b96d620e7206da597e1c482c0722aca3d2116db115b5f9e5
7
- data.tar.gz: 9838e7df5040c85caae31cb394edad4da7f4f809c15c3e5046707e8d4ea97195c75f49d0947df289c91bfaad3fe1549249bf1409b2bce07d49ecae0bfdb9ddd7
6
+ metadata.gz: c650e4c2ce659cebd34582d7873d4d553ba948ca021751642082d65e22b2367c863f5fb2e2cc95314e3e2f5f11aece4d01e325655218fbb09734f0b69a463a8b
7
+ data.tar.gz: 2db42b92689dea62189b5a4b801f68e3d93205bb41e5a7a333d659d117a96d4a7ec0d23400a0558b5f997769c748a140e971cf15f2e204812527712d1d61cc11
data/bin/leap CHANGED
@@ -11,11 +11,11 @@ if ARGV.include?('--debug') || ARGV.include?('-d')
11
11
  rescue LoadError
12
12
  end
13
13
  else
14
+ $VERBOSE=nil
14
15
  DEBUG=false
15
16
  end
16
17
 
17
18
  LEAP_CLI_BASE_DIR = File.expand_path('..', File.dirname(File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__))
18
- ORIGINAL_ARGV = ARGV.dup
19
19
 
20
20
  begin
21
21
  # First, try to load the leap_cli code that is local to this `leap` command.
@@ -74,17 +74,13 @@ module LeapCli::Commands
74
74
  program_desc LeapCli::SUMMARY
75
75
  program_long_desc LeapCli::DESCRIPTION
76
76
 
77
+ LeapCli::Bootstrap::setup(ARGV)
78
+
77
79
  # handle --version ourselves (and not GLI)
78
80
  if ARGV.grep(/--version/).any?
79
- puts "leap #{LeapCli::VERSION}, ruby #{RUBY_VERSION}"
80
- begin
81
- commands_from('leap_cli/commands')
82
- initialize_leap_cli(false, {:verbose => 2})
83
- rescue StandardError => exc
84
- puts exc.to_s
85
- raise exc if DEBUG
86
- end
87
- exit(0)
81
+ LeapCli::Bootstrap::handle_version(self)
82
+ else
83
+ LeapCli::Bootstrap::load_libraries(self)
88
84
  end
89
85
 
90
86
  # disable GLI error catching
@@ -92,9 +88,6 @@ module LeapCli::Commands
92
88
  def error_message(msg)
93
89
  end
94
90
 
95
- # load commands
96
- commands_from('leap_cli/commands')
97
-
98
91
  # run command
99
92
  begin
100
93
  exit_status = run(ARGV)
data/lib/leap/platform.rb CHANGED
@@ -14,6 +14,7 @@ module Leap
14
14
  attr_accessor :monitor_username
15
15
  attr_accessor :reserved_usernames
16
16
 
17
+ attr_accessor :hiera_dir
17
18
  attr_accessor :hiera_path
18
19
  attr_accessor :files_dir
19
20
  attr_accessor :leap_dir
@@ -24,6 +25,7 @@ module Leap
24
25
  def define(&block)
25
26
  # some defaults:
26
27
  @reserved_usernames = []
28
+ @hiera_dir = '/etc/leap'
27
29
  @hiera_path = '/etc/leap/hiera.yaml'
28
30
  @leap_dir = '/srv/leap'
29
31
  @files_dir = '/srv/leap/files'
data/lib/leap_cli.rb CHANGED
@@ -36,6 +36,7 @@ require 'leap_cli/util/secret'
36
36
  require 'leap_cli/util/remote_command'
37
37
  require 'leap_cli/util/x509'
38
38
  require 'leap_cli/logger'
39
+ require 'leap_cli/bootstrap'
39
40
 
40
41
  require 'leap_cli/ssh_key'
41
42
  require 'leap_cli/config/object'
@@ -45,6 +46,7 @@ require 'leap_cli/config/provider'
45
46
  require 'leap_cli/config/secrets'
46
47
  require 'leap_cli/config/object_list'
47
48
  require 'leap_cli/config/filter'
49
+ require 'leap_cli/config/environment'
48
50
  require 'leap_cli/config/manager'
49
51
 
50
52
  require 'leap_cli/markdown_document_listener'
@@ -54,7 +56,6 @@ require 'leap_cli/markdown_document_listener'
54
56
  #
55
57
  module LeapCli
56
58
  Util.send(:extend, LeapCli::Log)
57
- Commands.send(:extend, LeapCli::Log)
58
59
  Config::Manager.send(:include, LeapCli::Log)
59
60
  extend LeapCli::Log
60
61
  end
@@ -0,0 +1,197 @@
1
+ #
2
+ # Initial bootstrap loading of all the necessary things that needed
3
+ # for the `leap` command.
4
+ #
5
+
6
+ module LeapCli
7
+ module Bootstrap
8
+ extend LeapCli::Log
9
+ extend self
10
+
11
+ #
12
+ # the argument leapfile_path is only used for tests
13
+ #
14
+ def setup(argv, leapfile_path=nil)
15
+ setup_logging(argv)
16
+ setup_leapfile(argv, leapfile_path)
17
+ end
18
+
19
+ #
20
+ # print out the version string and exit.
21
+ # called from leap executable.
22
+ #
23
+ def handle_version(app)
24
+ puts "leap #{LeapCli::VERSION}, ruby #{RUBY_VERSION}"
25
+ begin
26
+ log_version
27
+ rescue StandardError => exc
28
+ puts exc.to_s
29
+ raise exc if DEBUG
30
+ end
31
+ exit(0)
32
+ end
33
+
34
+ #
35
+ # load the commands.
36
+ # called from leap executable.
37
+ #
38
+ def load_libraries(app)
39
+ if LeapCli.log_level >= 2
40
+ log_version
41
+ end
42
+ load_commands(app)
43
+ load_macros
44
+ end
45
+
46
+ #
47
+ # initialize the global options.
48
+ # called from pre.rb
49
+ #
50
+ def setup_global_options(app, global)
51
+ if global[:force]
52
+ global[:yes] = true
53
+ end
54
+ if Process::Sys.getuid == 0
55
+ Util.bail! "`leap` should not be run as root."
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ #
62
+ # Initial logging
63
+ #
64
+ # This is called very early by leap executable, because
65
+ # everything depends on the log file and log options
66
+ # being set correctly before any work is done.
67
+ #
68
+ # The Leapfile might later load additional logging
69
+ # options.
70
+ #
71
+ def setup_logging(argv)
72
+ options = parse_logging_options(argv)
73
+ verbose = (options[:verbose] || 1).to_i
74
+ if verbose
75
+ LeapCli.set_log_level(verbose)
76
+ end
77
+ if options[:log]
78
+ LeapCli.log_file = options[:log]
79
+ LeapCli::Util.log_raw(:log) { $0 + ' ' + argv.join(' ')}
80
+ end
81
+ unless options[:color].nil?
82
+ LeapCli.log_in_color = options[:color]
83
+ end
84
+ end
85
+
86
+ #
87
+ # load the leapfile and set the Path variables.
88
+ #
89
+ def setup_leapfile(argv, leapfile_path)
90
+ LeapCli.leapfile.load(leapfile_path)
91
+ if LeapCli.leapfile.valid?
92
+ Path.set_platform_path(LeapCli.leapfile.platform_directory_path)
93
+ Path.set_provider_path(LeapCli.leapfile.provider_directory_path)
94
+ if !Path.provider || !File.directory?(Path.provider)
95
+ bail! { log :missing, "provider directory '#{Path.provider}'" }
96
+ end
97
+ if !Path.platform || !File.directory?(Path.platform)
98
+ bail! { log :missing, "platform directory '#{Path.platform}'" }
99
+ end
100
+ if LeapCli.log_file.nil? && LeapCli.leapfile.log
101
+ LeapCli.log_file = LeapCli.leapfile.log
102
+ end
103
+ elsif !leapfile_optional?(argv)
104
+ puts
105
+ puts " ="
106
+ log :note, "There is no `Leapfile` in this directory, or any parent directory.\n"+
107
+ " = "+
108
+ "Without this file, most commands will not be available."
109
+ puts " ="
110
+ puts
111
+ end
112
+ end
113
+
114
+ #
115
+ # Add a log entry for the leap command and leap platform versions.
116
+ #
117
+ def log_version(force=false)
118
+ str = "leap command v#{LeapCli::VERSION}"
119
+ if Util.is_git_directory?(LEAP_CLI_BASE_DIR)
120
+ str << " (%s %s)" % [Util.current_git_branch(LEAP_CLI_BASE_DIR),
121
+ Util.current_git_commit(LEAP_CLI_BASE_DIR)]
122
+ else
123
+ str << " (%s)" % LEAP_CLI_BASE_DIR
124
+ end
125
+ log str
126
+ if LeapCli.leapfile.valid?
127
+ str = "leap platform v#{Leap::Platform.version}"
128
+ if Util.is_git_directory?(Path.platform)
129
+ str << " (%s %s)" % [Util.current_git_branch(Path.platform), Util.current_git_commit(Path.platform)]
130
+ end
131
+ log str
132
+ end
133
+ end
134
+
135
+ def parse_logging_options(argv)
136
+ argv = argv.dup
137
+ options = {:color => true, :verbose => 1}
138
+ loop do
139
+ current = argv.shift
140
+ case current
141
+ when '--verbose' then options[:verbose] = argv.shift;
142
+ when /-v[0-9]/ then options[:verbose] = current[-1];
143
+ when '--log' then options[:log] = argv.shift;
144
+ when '--no-color' then options[:color] = false;
145
+ when nil then break;
146
+ end
147
+ end
148
+ options
149
+ end
150
+
151
+ #
152
+ # Returns true if loading the Leapfile is optional.
153
+ #
154
+ # We could make the 'new' command skip the 'pre' command, and then load Leapfile
155
+ # from 'pre', but for various reasons we want the Leapfile loaded even earlier
156
+ # than that. So, we need a way to test to see if loading the leapfile is optional
157
+ # before any of the commands are loaded and the argument list is parsed by GLI.
158
+ # Yes, hacky.
159
+ #
160
+ def leapfile_optional?(argv)
161
+ if argv.include?('--version')
162
+ return true
163
+ else
164
+ without_flags = argv.select {|i| i !~ /^-/}
165
+ if without_flags.first == 'new'
166
+ return true
167
+ end
168
+ end
169
+ return false
170
+ end
171
+
172
+ #
173
+ # loads the GLI command definition files
174
+ #
175
+ def load_commands(app)
176
+ app.commands_from('leap_cli/commands')
177
+ if Path.platform
178
+ app.commands_from(Path.platform + '/lib/leap_cli/commands')
179
+ end
180
+ end
181
+
182
+ #
183
+ # loads the platform's macro definition files
184
+ #
185
+ def load_macros
186
+ if Path.platform
187
+ platform_macro_files = Dir[Path.platform + '/lib/leap_cli/macros/*.rb']
188
+ if platform_macro_files.any?
189
+ platform_macro_files.each do |macro_file|
190
+ require macro_file
191
+ end
192
+ end
193
+ end
194
+ end
195
+
196
+ end
197
+ end
@@ -0,0 +1,61 @@
1
+ #
2
+ # Some common helpers available to all LeapCli::Commands
3
+ #
4
+ # This also includes utility methods, and makes all instance
5
+ # methods available as class methods.
6
+ #
7
+
8
+ module LeapCli
9
+ module Commands
10
+
11
+ extend self
12
+ extend LeapCli::Log
13
+ extend LeapCli::Util
14
+ extend LeapCli::Util::RemoteCommand
15
+
16
+ protected
17
+
18
+ def path(name)
19
+ Path.named_path(name)
20
+ end
21
+
22
+ #
23
+ # keeps prompting the user for a numbered choice, until they pick a good one or bail out.
24
+ #
25
+ # block is yielded and is responsible for rendering the choices.
26
+ #
27
+ def numbered_choice_menu(msg, items, &block)
28
+ while true
29
+ say("\n" + msg + ':')
30
+ items.each_with_index &block
31
+ say("q. quit")
32
+ index = ask("number 1-#{items.length}> ")
33
+ if index.empty?
34
+ next
35
+ elsif index =~ /q/
36
+ bail!
37
+ else
38
+ i = index.to_i - 1
39
+ if i < 0 || i >= items.length
40
+ bail!
41
+ else
42
+ return i
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ def parse_node_list(nodes)
49
+ if nodes.is_a? Config::Object
50
+ Config::ObjectList.new(nodes)
51
+ elsif nodes.is_a? Config::ObjectList
52
+ nodes
53
+ elsif nodes.is_a? String
54
+ manager.filter!(nodes)
55
+ else
56
+ bail! "argument error"
57
+ end
58
+ end
59
+
60
+ end
61
+ end
@@ -4,7 +4,7 @@ module LeapCli; module Commands
4
4
 
5
5
  desc 'Creates a new provider instance in the specified directory, creating it if necessary.'
6
6
  arg_name 'DIRECTORY'
7
- skips_pre
7
+ #skips_pre
8
8
  command :new do |c|
9
9
  c.flag 'name', :desc => "The name of the provider." #, :default_value => 'Example'
10
10
  c.flag 'domain', :desc => "The primary domain of the provider." #, :default_value => 'example.org'
@@ -12,6 +12,10 @@ module LeapCli; module Commands
12
12
  c.flag 'contacts', :desc => "Default email address contacts." #, :default_value => 'root'
13
13
 
14
14
  c.action do |global, options, args|
15
+ unless args.first
16
+ # this should not be needed, but GLI is not making it required.
17
+ bail! "Argument DIRECTORY is required."
18
+ end
15
19
  directory = File.expand_path(args.first)
16
20
  create_provider_directory(global, directory)
17
21
  options[:domain] ||= ask_string("The primary domain of the provider: ") {|q| q.default = 'example.org'}
@@ -31,73 +31,8 @@ module LeapCli; module Commands
31
31
  switch 'color', :negatable => true
32
32
 
33
33
  pre do |global,command,options,args|
34
- if global[:force]
35
- global[:yes] = true
36
- end
37
- initialize_leap_cli(true, global)
34
+ Bootstrap.setup_global_options(self, global)
38
35
  true
39
36
  end
40
37
 
41
- protected
42
-
43
- #
44
- # available options:
45
- # :verbose -- integer log verbosity level
46
- # :log -- log file path
47
- # :color -- true or false, to log in color or not.
48
- #
49
- def initialize_leap_cli(require_provider, options={})
50
- if Process::Sys.getuid == 0
51
- bail! "`leap` should not be run as root."
52
- end
53
-
54
- # set verbosity
55
- options[:verbose] ||= 1
56
- LeapCli.set_log_level(options[:verbose].to_i)
57
-
58
- # load Leapfile
59
- LeapCli.leapfile.load
60
- if LeapCli.leapfile.valid?
61
- Path.set_platform_path(LeapCli.leapfile.platform_directory_path)
62
- Path.set_provider_path(LeapCli.leapfile.provider_directory_path)
63
- if !Path.provider || !File.directory?(Path.provider)
64
- bail! { log :missing, "provider directory '#{Path.provider}'" }
65
- end
66
- if !Path.platform || !File.directory?(Path.platform)
67
- bail! { log :missing, "platform directory '#{Path.platform}'" }
68
- end
69
- elsif require_provider
70
- bail! { log :missing, 'Leapfile in directory tree' }
71
- end
72
-
73
- # set log file
74
- LeapCli.log_file = options[:log] || LeapCli.leapfile.log
75
- LeapCli::Util.log_raw(:log) { $0 + ' ' + ORIGINAL_ARGV.join(' ')}
76
- log_version
77
- LeapCli.log_in_color = options[:color]
78
- end
79
-
80
- #
81
- # add a log entry for the leap command and leap platform versions
82
- #
83
- def log_version
84
- if LeapCli.log_level >= 2
85
- str = "leap command v#{LeapCli::VERSION}"
86
- if Util.is_git_directory?(LEAP_CLI_BASE_DIR)
87
- str << " (%s %s)" % [Util.current_git_branch(LEAP_CLI_BASE_DIR),
88
- Util.current_git_commit(LEAP_CLI_BASE_DIR)]
89
- else
90
- str << " (%s)" % LEAP_CLI_BASE_DIR
91
- end
92
- log 2, str
93
- if LeapCli.leapfile.valid?
94
- str = "leap platform v#{Leap::Platform.version}"
95
- if Util.is_git_directory?(Path.platform)
96
- str << " (%s %s)" % [Util.current_git_branch(Path.platform), Util.current_git_commit(Path.platform)]
97
- end
98
- log 2, str
99
- end
100
- end
101
- end
102
-
103
38
  end; end