octosh 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gem 'net-ssh', '2.6.1'
4
+ gem 'highline', '1.6.15'
4
5
 
5
6
  group :test do
6
7
  gem 'rake', '0.9.2.2'
data/Gemfile.lock CHANGED
@@ -2,6 +2,7 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  diff-lcs (1.1.3)
5
+ highline (1.6.15)
5
6
  net-ssh (2.6.1)
6
7
  rake (0.9.2.2)
7
8
  rspec (2.12.0)
@@ -17,6 +18,7 @@ PLATFORMS
17
18
  ruby
18
19
 
19
20
  DEPENDENCIES
21
+ highline (= 1.6.15)
20
22
  net-ssh (= 2.6.1)
21
23
  rake (= 0.9.2.2)
22
24
  rspec (= 2.12.0)
data/lib/octosh/cli.rb CHANGED
@@ -38,14 +38,22 @@ module Octosh
38
38
  options.default_user = user
39
39
  end
40
40
 
41
+ options.password_prompt = false
42
+ opts.on('-p', '--password', 'Prompt for password') do
43
+ options.password_prompt = true
44
+ end
45
+
46
+ options.uniform_password = false
47
+ opts.on('-a', '--uniform-password', 'Use the same password for all hosts') do
48
+ options.uniform_password = true
49
+ end
50
+
41
51
  opts.on_tail('-h', '--help', 'Display this screen' ) do
42
52
  puts opts
43
53
  exit
44
54
  end
45
55
  end.parse!
46
56
 
47
- puts options.config
48
-
49
57
  if not ARGV.empty? and not options.config
50
58
  options.config = ARGV[0]
51
59
  options.mode = Octosh::CLI::MODE::CONFIG
@@ -57,12 +65,48 @@ module Octosh
57
65
  elsif (options.bash or options.script) and options.hosts
58
66
  puts "Using inline execution"
59
67
  options.mode = Octosh::CLI::MODE::INLINE
68
+
69
+ if options.bash and options.script
70
+ "Error -- Cannot specify both an inline command to run (-b) and a script file (-s)"
71
+ exit
72
+ elsif options.bash
73
+ self.inline_bash(options.hosts, options.bash, options.password_prompt, options.uniform_password)
74
+ elsif options.script
75
+ pass
76
+ else
77
+ "Error -- Something broke"
78
+ exit
79
+ end
80
+
60
81
  else
61
82
  puts "Error -- Must either provide an Octo config file or arguments for inline execution (--hosts along with -b or -s)"
62
83
  exit
63
84
  end
85
+
86
+ end
87
+
88
+ def self.inline_bash(hosts, bash, password_prompt=true, uniform_password=false)
64
89
 
65
- puts options.inspect
90
+ password = nil
91
+
92
+ hosts.each do |host|
93
+ if password_prompt
94
+ # Password authentication
95
+ if uniform_password and password.nil?
96
+ # One password for all hosts
97
+ password = Octosh::Helper.password_prompt("Password: ")
98
+ elsif not uniform_password
99
+ # One password for each host
100
+ password = Octosh::Helper.password_prompt("Password for #{host}: ")
101
+ end
102
+ user,hostname = host.split("@")
103
+ worker = Octosh::Worker.new(hostname, user, password)
104
+ puts worker.exec(bash)
105
+ else
106
+ # Identify file authentication
107
+ end
108
+ end
66
109
  end
110
+
67
111
  end
68
112
  end
@@ -0,0 +1,12 @@
1
+ module Octosh
2
+ class Helper
3
+
4
+ def self.password_prompt(prompt="Password: ")
5
+ require 'highline/import'
6
+ ask(prompt) do |p|
7
+ p.echo = false
8
+ end
9
+ end
10
+
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Octosh
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,3 +1,5 @@
1
+ require 'net/ssh'
2
+
1
3
  module Octosh
2
4
  class Worker
3
5
 
data/lib/octosh.rb CHANGED
@@ -1 +1,3 @@
1
+ require 'octosh/helper'
2
+
1
3
  require 'octosh/worker'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octosh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -28,6 +28,7 @@ files:
28
28
  - bin/octoch
29
29
  - lib/octosh.rb
30
30
  - lib/octosh/cli.rb
31
+ - lib/octosh/helper.rb
31
32
  - lib/octosh/version.rb
32
33
  - lib/octosh/worker.rb
33
34
  - lib/octosh/worker/worker.rb