fissher 1.0.2 → 1.0.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.
data/README.rdoc CHANGED
@@ -5,16 +5,18 @@ Fissher is a simple utility to run commands on multiple servers, powered by Net:
5
5
 
6
6
  === Usage
7
7
 
8
- fissher [flags] [command]
9
- -G Hostgroup Execute command on all hosts listed in the JSON config for the
10
- specified group.
11
- -H Host1,Host2 Execute command on hosts listed on the command line
12
- -g jumpbox Manually specify/override a jump server, if necessary.
13
- -s Execute the provided commands with sudo.
14
- -u username Manually specify/override username to connect with.
15
- -p Use password based authentication, specified via STDIN
16
- -c config.json Manually specify the path to your fissher config file
17
- -n num Number of concurrent connections. Enter 0 for unlimited.
8
+ fissher [flags] [command]:
9
+ -G Hostgroup Execute command on all hosts listed in the JSON config for
10
+ the specified group.
11
+ -H Host1,Host2 Execute command on hosts listed on the command line
12
+ -g jumpbox Manually specify/override a jump server, if necessary.
13
+ -s Execute the provided commands with sudo.
14
+ -u username Manually specify/override username to connect with.
15
+ -p Use password based authentication, specified via STDIN
16
+ -c config.json Manually specify the path to your fissher config file
17
+ -n num Number of concurrent connections. Enter 0 for unlimited.
18
+ -U username Specify an alternate user in conjunction with -s
19
+ (E.G. -U webmaster)
18
20
 
19
21
  === Installation
20
22
 
@@ -2,6 +2,7 @@
2
2
  "user": "user", // Default user name
3
3
  "concurrency": "10", // Set to 0 to disable max concurrency
4
4
  "default_gateway": "jumpbox1.sampledomain.com", // Default jump box, if needed.
5
+ "enable_password": "false", // Set this to true to enable -p by default.
5
6
  "hostgroups": {
6
7
  "app": {
7
8
  "gateway": "jumpbox2.sampledomain.com", // Override the default
data/lib/fissher_base.rb CHANGED
@@ -6,7 +6,9 @@ require 'net/ssh/multi'
6
6
  require 'fissher_conf'
7
7
  include FissherConf
8
8
 
9
+ # Main class. This one does all the dirty work.
9
10
  class FissherBase
11
+ # The guts of the app. This handles putting everything together and running the commands via Net::SSH::Multi.
10
12
  def go_time
11
13
  opts = FissherConf.handle_opts unless !opts.nil?
12
14
  abort "No hosts specified! Please use -H or -G!\n" unless !opts[:hostlist].nil?
data/lib/fissher_conf.rb CHANGED
@@ -7,13 +7,26 @@ require 'json'
7
7
  require 'highline/import'
8
8
  require 'getopt/std'
9
9
 
10
+ # Module for all aspects of configuration within fissher.
10
11
  module FissherConf
12
+
13
+ # Misc methods for doing dirty work within the app.
11
14
  class Misc
15
+
16
+ # A wrapper function used to request the password from stdin.
17
+ #
18
+ # @param prompt [String] The banner displayed to the user.
19
+ # @return [String] The password, as entered by the user.
12
20
  def getpass(prompt="Enter remote password: ")
13
21
  ask(prompt) {|q| q.echo = false}
14
22
  end
15
23
 
16
24
  # Method for returning hosts from hostgroup.
25
+ #
26
+ # @param grp [String] The hostgroup, contained within the config.
27
+ # @param conf [Hash] The parsed configuration file
28
+ # @param conf_file [String] The configuration file, with path.
29
+ # @return [Array] An array of the hosts contained in the hostgroup within the config file.
17
30
  def group_hosts( grp,conf,conf_file )
18
31
  if conf[:hostgroups][:"#{grp}"]
19
32
  conf[:hostgroups][:"#{grp}"][:hosts]
@@ -23,26 +36,33 @@ module FissherConf
23
36
  end
24
37
  end
25
38
 
39
+ # Print usage message
26
40
  def usage
27
- puts "#{$0} [flags] [command]:\n"
28
- puts "-G Hostgroup Execute command on all hosts listed in the JSON config for the\n"
29
- puts " specified group.\n"
41
+ app = File.basename($0)
42
+ puts "#{app} [flags] [command]:\n"
43
+ puts "-G Hostgroup Execute command on all hosts listed in the JSON config for \n"
44
+ puts " the specified group.\n"
30
45
  puts "-H Host1,Host2 Execute command on hosts listed on the command line\n"
31
46
  puts "-g jumpbox Manually specify/override a jump server, if necessary.\n"
32
- puts "-s Execute the provided commands with sudo."
47
+ puts "-s Execute the provided commands with sudo."
33
48
  puts "-u username Manually specify/override username to connect with.\n"
34
49
  puts "-p Use password based authentication, specified via STDIN\n"
35
50
  puts "-c config.json Manually specify the path to your fissher config file\n"
36
51
  puts "-n num Number of concurrent connections. Enter 0 for unlimited.\n"
37
- puts "-U username Specify an alternate user in conjunction with -s (E.G. -U webmaster)\n"
52
+ puts "-U username Specify an alternate user in conjunction with -s\n"
53
+ puts " (E.G. -U webmaster)\n"
38
54
  end
39
55
 
56
+ # A shortcut method to make errors a little more graceful.
57
+ #
58
+ # @param msg [String] the message to be displayed before the usage message.
40
59
  def die( msg )
41
60
  puts "#{msg}\n"
42
61
  usage
43
62
  exit 1
44
63
  end
45
64
 
65
+ # Parse command line options using getopt and options within the json config file.
46
66
  def handle_opts
47
67
  opt = Getopt::Std.getopts("pc:g:G:u:n:sH:hU:")
48
68
  ret = Hash.new
@@ -141,14 +161,6 @@ EOB
141
161
  end
142
162
  end
143
163
 
144
- # Get our account password
145
- if opt["p"]
146
- p = Misc.new
147
- ret[:password] = p.getpass()
148
- else
149
- ret[:password] = nil
150
- end
151
-
152
164
  # Our command
153
165
  if ARGV.count >= 1
154
166
  if sudo_cmd
@@ -159,6 +171,15 @@ EOB
159
171
  else
160
172
  die "No command specified!\n" unless !ret[:command].nil?
161
173
  end
174
+
175
+ # Get our account password
176
+ if (opt["p"] || config[:enable_password] == 'true')
177
+ p = Misc.new
178
+ ret[:password] = p.getpass()
179
+ else
180
+ ret[:password] = nil
181
+ end
182
+
162
183
  ret
163
184
  end
164
185
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fissher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -113,3 +113,4 @@ signing_key:
113
113
  specification_version: 3
114
114
  summary: Fissher
115
115
  test_files: []
116
+ has_rdoc: