EndlessWaffleCLI 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: df630c1c06a03d41d2153b9b51eaa55dc2edd9cd
4
+ data.tar.gz: 95c6de991d5d603246078b76a179163812c65493
5
+ SHA512:
6
+ metadata.gz: 67d4bca71069d9f972592c3a60a6980a0d5934f2a38d6bf6d28e952fff258d7337e8eb4ff3dd29933dc69ec80424eccb01cc14d5a0255a50a64d603c35610d1d
7
+ data.tar.gz: 05ddb7e7a43eeba421f68d1014d5dddd6cfd86aee20ac9310c8e2dfa26144cadd717b8e3238f3356be1324b5c76dfb0f97bf6cb6f90fcf7ae083298accf9d48d
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,44 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'EndlessWaffleCLI/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "EndlessWaffleCLI"
8
+ spec.version = EndlessWaffleCLI::VERSION
9
+ spec.authors = ["Dr. Ogg"]
10
+ spec.email = ["ogg@sr375.com"]
11
+
12
+ spec.summary = %q{Command line tools for the Endless Waffle server}
13
+ spec.description = %q{Command line tools for the Endless Waffle server}
14
+ spec.homepage = ""
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ # spec.add_development_dependency "bundler", "~> 1.12"
30
+ # spec.add_development_dependency "rake", "~> 10.0"
31
+
32
+ spec.add_dependency "bundler", "~> 1.12"
33
+ spec.add_dependency "rake", "~> 10.0"
34
+ spec.add_dependency 'mime-types', '~> 3.1'
35
+ spec.add_dependency 'unf_ext', '~> 0.0.7.2'
36
+ spec.add_dependency 'unf', '~> 0.1.4'
37
+ spec.add_dependency 'rest-client', '~> 2.0'
38
+ spec.add_dependency 'console_table', '~> 0.2.4'
39
+ spec.add_dependency 'colorize', '~> 0.8.1'
40
+ spec.add_dependency 'net-ssh-multi', '~> 1.2', '>= 1.2.1'
41
+ spec.add_dependency 'net-ssh-gateway', '~> 1.2'
42
+ spec.add_dependency 'net-ssh', '~> 3.2'
43
+ spec.add_dependency 'highline', '~> 1.7', '>= 1.7.8'
44
+ end
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in EndlessWaffleCLI.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # EndlessWaffleCLI
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/EndlessWaffleCLI`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'EndlessWaffleCLI'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install EndlessWaffleCLI
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/EndlessWaffleCLI.
36
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "EndlessWaffleCLI"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/build/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/build/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in build.gemspec
4
+ gemspec
data/build/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Build
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/build`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'build'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install build
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/build.
36
+
data/build/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/build/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "build"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/build/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'EndlessWaffleCLI/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "EndlessWaffleCLI"
8
+ spec.version = EndlessWaffleCLI::VERSION
9
+ spec.authors = ["Dr. Ogg"]
10
+ spec.email = ["ogg@sr375.com"]
11
+
12
+ spec.summary = %q{Command line tools for the Endless Waffle server}
13
+ spec.description = %q{Command line tools for the Endless Waffle server}
14
+ spec.homepage = ""
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.12"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+
32
+ spec.add_dependency 'rest-client', '~> 2.0'
33
+ spec.add_dependency 'console_table', '~> 0.2.4'
34
+ spec.add_dependency 'colorize', '~> 0.8.1'
35
+
36
+ end
@@ -0,0 +1,5 @@
1
+ require "build/version"
2
+
3
+ module Build
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module Build
2
+ VERSION = "0.1.0"
3
+ end
data/exe/enum ADDED
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "EndlessWaffleCLI"
5
+ require 'json'
6
+ require 'getoptlong'
7
+ require 'console_table'
8
+ require 'colorize'
9
+
10
+ query = {}
11
+ updateCache = false
12
+ showList = false
13
+ showJSON = false
14
+
15
+ if ENV['EndlessWaffleURL'].nil?
16
+ puts "EndlessWaffleCLI requires the 'EndlessWaffleURL' environment variable to be set."
17
+ exit 1
18
+ else
19
+ EndlessWaffleCLI.setServer ENV['EndlessWaffleURL']
20
+ end
21
+
22
+ if ENV['EndlessWaffleToken'].nil?
23
+ puts "EndlessWaffleCLI requires the 'EndlessWaffleToken' environment variable to be set."
24
+ exit 1
25
+ else
26
+ EndlessWaffleCLI.setToken ENV['EndlessWaffleToken']
27
+ end
28
+
29
+ def colorizeState(state)
30
+ if state == "running"
31
+ state.colorize(:green)
32
+ else
33
+ state.colorize(:red)
34
+ end
35
+ end
36
+
37
+ def showHelp
38
+ puts
39
+ puts "Endless Waffle Enumerate"
40
+ puts "Usage example: #{$0} -e dev1 -r frontend"
41
+ puts
42
+ puts "Options:"
43
+ puts "-m or --monochrome".ljust(30) +"-> Show results in monochrome"
44
+ puts "-e or --environment".ljust(30) +"-> Specifiy environment"
45
+ puts "-r or --role".ljust(30) +"-> Specifiy role"
46
+ puts "-l or --list".ljust(30) +"-> List Public DNS names only, hint: for scripts"
47
+ puts "-j or --json".ljust(30) +"-> Raw JSON output"
48
+ puts "-i or --instanceId".ljust(30) +"-> Find by instanceId"
49
+ puts "-n or --name".ljust(30) +"-> Find by Instance Name"
50
+ puts "-c or --cache ".ljust(30) +"-> Update local Cache database with current AWS data"
51
+ puts "-h or --help".ljust(30) +"-> Show this help message."
52
+ puts
53
+ end
54
+
55
+ parser = GetoptLong.new
56
+ parser.set_options(["-m", "--monochrome", GetoptLong::NO_ARGUMENT],
57
+ ["-e", "--environment", GetoptLong::NO_ARGUMENT],
58
+ ["-r", "--role", GetoptLong::NO_ARGUMENT],
59
+ ["-l", "--list", GetoptLong::NO_ARGUMENT],
60
+ ["-j", "--json", GetoptLong::NO_ARGUMENT],
61
+ ["-i", "--instanceId", GetoptLong::NO_ARGUMENT],
62
+ ["-n", "--name", GetoptLong::NO_ARGUMENT],
63
+ ["-c", "--cache", GetoptLong::NO_ARGUMENT],
64
+ ["-h", "--help", GetoptLong::NO_ARGUMENT]
65
+ )
66
+
67
+ begin
68
+ begin
69
+ opt,arg = parser.get_option
70
+ break if not opt
71
+ case opt
72
+ when "-h" || "--help"
73
+ showHelp
74
+ exit
75
+ when "-m" || "--monochrome"
76
+ String.disable_colorization = true
77
+ when "-e" || "--environment"
78
+ query.store(:environment, ARGV[0])
79
+ when "-r" || "--role"
80
+ query.store(:role, ARGV[0])
81
+ when "-l" || "--list"
82
+ showList = true
83
+ when "-j" || "--json"
84
+ showJSON = true
85
+ when "-i" || "--instanceId"
86
+ query.store(:instanceId, ARGV[0])
87
+ when "-n" || "--name"
88
+ query.store(:name, ARGV[0])
89
+ when "-c" || "--cache"
90
+ updateCache = true
91
+ end
92
+ rescue => err
93
+ puts "#{err.class()}: #{err.message}"
94
+ exit 1
95
+ end
96
+ end while 1
97
+
98
+
99
+ def showTable(result)
100
+ table_config = [
101
+ {:key=>:instanceId, :size=>13, :title=>"Instance Id"},
102
+ {:key=>:name, :size=>9, :title=>"Name"},
103
+ {:key=>:role, :size=>8, :title=>"Role"},
104
+ {:key=>:environment, :size=>8, :title=>"Env"},
105
+ {:key=>:instanceType, :size=>10, :title=>"Type"},
106
+ {:key=>:availabilityZone, :size=>12, :title=>"Zone"},
107
+ {:key=>:instanceState, :size=>12, :title=>"State"},
108
+ {:key=>:dnsName, :size=>"*", :title=>"DNS Name"},
109
+ ]
110
+ ConsoleTable.define(table_config) do |table|
111
+ result.each do |r|
112
+ table << [
113
+ r["instanceId"].colorize(:yellow),
114
+ r["nodemap"]["name"],
115
+ r["nodemap"]["role"],
116
+ r["nodemap"]["environment"],
117
+ r["instanceType"],
118
+ r["placement"]["availabilityZone"],
119
+ colorizeState(r["instanceState"]["name"]),
120
+ r["dnsName"]]
121
+ end
122
+ end
123
+ end
124
+
125
+
126
+ def showJSON(result)
127
+ puts JSON.pretty_generate(result)
128
+ end
129
+
130
+ def showList(result)
131
+ output = []
132
+ result.each do |i|
133
+ output.push i["dnsName"]
134
+ end
135
+ puts output.join(' ')
136
+ end
137
+
138
+ if updateCache == true
139
+ puts "Running Cache Update:"
140
+ puts EndlessWaffleCLI.updateEc2Cache
141
+ end
142
+
143
+ result = EndlessWaffleCLI.queryEc2 query
144
+
145
+
146
+ if showList == false && showJSON == false
147
+ showTable result
148
+ elsif showJSON == true
149
+ showJSON result
150
+ elsif showList == true
151
+ showList result
152
+ end
data/exe/enum-ssh ADDED
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "EndlessWaffleCLI"
5
+ require 'getoptlong'
6
+ require 'net/ssh/multi'
7
+
8
+ query = {}
9
+ runCommand = nil
10
+ username = ENV['USER']
11
+ promptPassword=false
12
+
13
+ if ENV['EndlessWaffleURL'].nil?
14
+ puts "EndlessWaffleCLI requires the 'EndlessWaffleURL' environment variable to be set."
15
+ exit 1
16
+ else
17
+ EndlessWaffleCLI.setServer ENV['EndlessWaffleURL']
18
+ end
19
+
20
+ if ENV['EndlessWaffleToken'].nil?
21
+ puts "EndlessWaffleCLI requires the 'EndlessWaffleToken' environment variable to be set."
22
+ exit 1
23
+ else
24
+ EndlessWaffleCLI.setToken ENV['EndlessWaffleToken']
25
+ end
26
+
27
+ def colorizeState(state)
28
+ if state == "running"
29
+ state.colorize(:green)
30
+ else
31
+ state.colorize(:red)
32
+ end
33
+ end
34
+
35
+ def showHelp
36
+ puts
37
+ puts "Endless Waffle Enumerate SSH"
38
+ puts "Usage example: #{$0} -e dev1 -r frontend -c 'uptime' "
39
+ puts
40
+ puts "Options:"
41
+ puts "-e or --environment".ljust(30) +"-> Specifiy environment"
42
+ puts "-r or --role".ljust(30) +"-> Specifiy role"
43
+ puts "-c or --command".ljust(30) +"-> Specifiy command"
44
+ puts "-u or --username".ljust(30) +"-> Specifiy username"
45
+ puts "-p or --password".ljust(30) +"-> Prompt for password"
46
+ puts "-h or --help".ljust(30) +"-> Show this help message."
47
+ puts
48
+ end
49
+
50
+ parser = GetoptLong.new
51
+ parser.set_options(["-e", "--environment", GetoptLong::NO_ARGUMENT],
52
+ ["-r", "--role", GetoptLong::NO_ARGUMENT],
53
+ ["-c", "--command", GetoptLong::NO_ARGUMENT],
54
+ ["-h", "--help", GetoptLong::NO_ARGUMENT],
55
+ ["-p", "--password", GetoptLong::NO_ARGUMENT]
56
+ )
57
+
58
+ begin
59
+ begin
60
+ opt,arg = parser.get_option
61
+ break if not opt
62
+ case opt
63
+ when "-h" || "--help"
64
+ showHelp
65
+ exit
66
+ when "-e" || "--environment"
67
+ query.store(:environment, ARGV[0])
68
+ when "-r" || "--role"
69
+ query.store(:role, ARGV[0])
70
+ when "-c" || "--command"
71
+ runCommand = ARGV[0]
72
+ when "-u" || "--username"
73
+ username = ARGV[0]
74
+ when "-p" || "--password"
75
+ promptPassword = true
76
+ end
77
+ rescue => err
78
+ puts "#{err.class()}: #{err.message}"
79
+ exit 1
80
+ end
81
+ end while 1
82
+
83
+ def ssh_using_key(command,query,username)
84
+ Net::SSH::Multi.start(:on_error => :warn) do |session|
85
+ list = EndlessWaffleCLI.queryEc2 query
86
+ list.each do |machine|
87
+ session.use "#{username}@#{machine['dnsName']}"
88
+ end
89
+ session.exec command
90
+ end
91
+ end
92
+
93
+ def ssh_runthis(command,host,user,password)
94
+ Net::SSH.start(host, user, :password => password) do |ssh|
95
+ output = ssh.exec!(command)
96
+ puts "[#{host}] #{output}"
97
+ end
98
+ end
99
+
100
+ def ssh_using_password(command,query,username,password)
101
+ list = EndlessWaffleCLI.queryEc2 query
102
+ list.each do |machine|
103
+ ssh_runthis(command,machine['dnsName'],username,password)
104
+ end
105
+ end
106
+
107
+ if query[:environment].nil?
108
+ puts "You need to sepecify a environment"
109
+ exit 1
110
+ end
111
+
112
+ if runCommand.nil?
113
+ puts "You need to sepecify a command to run"
114
+ exit 1
115
+ end
116
+
117
+ if promptPassword
118
+ print "Password for #{username}: "
119
+ password=STDIN.noecho(&:gets).chomp
120
+ puts ""
121
+ ssh_using_password(runCommand,query,username,password)
122
+ else
123
+ ssh_using_key(runCommand,query,username)
124
+ end
data/exe/ewssh ADDED
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "EndlessWaffleCLI"
5
+
6
+ if ENV['EndlessWaffleURL'].nil?
7
+ puts "EndlessWaffleCLI requires the 'EndlessWaffleURL' environment variable to be set."
8
+ exit 1
9
+ else
10
+ EndlessWaffleCLI.setServer ENV['EndlessWaffleURL']
11
+ end
12
+
13
+ if ENV['EndlessWaffleToken'].nil?
14
+ puts "EndlessWaffleCLI requires the 'EndlessWaffleToken' environment variable to be set."
15
+ exit 1
16
+ else
17
+ EndlessWaffleCLI.setToken ENV['EndlessWaffleToken']
18
+ end
19
+
20
+ def showHelp
21
+ puts
22
+ puts "Endless Waffle SSH"
23
+ puts "Usage example: #{$0} name.enviroment"
24
+ puts "Usage example: #{$0} user@name.enviroment some_remote_command"
25
+ puts "Usage example: #{$0} api.prod1"
26
+ puts "Usage example: #{$0} ogg@api.prod1"
27
+ puts "Usage example: #{$0} ogg@api.prod1 uptime"
28
+ puts
29
+ end
30
+
31
+ if ARGV.length >= 1
32
+ a = ARGV[0].split('@')
33
+ if a.length > 1
34
+ username = a[0]
35
+ destention = a[1]
36
+ else
37
+ destention = a[0]
38
+ username = ENV['USER']
39
+ end
40
+ if ARGV.length > 1
41
+ remote_command = ARGV[1,ARGV.length].join(' ')
42
+ end
43
+
44
+ if !destention.include? '.'
45
+ showHelp
46
+ exit 1
47
+ end
48
+ destention_parts = destention.split('.')
49
+ if destention_parts.length > 2
50
+ showHelp
51
+ exit 1
52
+ end
53
+ node_name = destention_parts[0]
54
+ environment = destention_parts[1]
55
+ else
56
+ showHelp
57
+ exit 1
58
+ end
59
+
60
+
61
+ query = {
62
+ :environment => environment,
63
+ :name => node_name
64
+ }
65
+
66
+ result = EndlessWaffleCLI.queryEc2 query
67
+
68
+ if result.length < 1
69
+ puts "No resutls found...."
70
+ exit 1
71
+ end
72
+
73
+ if remote_command.nil?
74
+ exec "ssh #{username}@#{result.first["dnsName"]}"
75
+ else
76
+ exec "ssh #{username}@#{result.first["dnsName"]} #{remote_command}"
77
+ end
data/exe/ewssl ADDED
@@ -0,0 +1,210 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'getoptlong'
4
+ require 'pp'
5
+ require 'colorize'
6
+ require 'json'
7
+ require 'pty'
8
+ require 'fileutils'
9
+ require 'console_table'
10
+ require 'openssl'
11
+
12
+
13
+
14
+ @results_directory = "#{ENV["HOME"]}/.ewssl"
15
+ @config_file = "#{ENV["HOME"]}/.ewssl.json"
16
+
17
+ example_config = {
18
+ :snpp => {
19
+ :digest_algorithm => "sha256",
20
+ :key_size_bits => 4096,
21
+ :city => "Springfield",
22
+ :country => "US",
23
+ :organization => "Springfield Nuclear Power Plant",
24
+ :state => "Illinois"
25
+ }
26
+ }
27
+ def writeSampleConfig(path,data)
28
+ File.open(path,"w") do |f|
29
+ f.write(JSON.pretty_generate(data))
30
+ end
31
+ end
32
+
33
+ FileUtils.mkdir_p(@results_directory) if !File.directory? @results_directory
34
+ writeSampleConfig(@config_file,example_config) if !File.exists? @config_file
35
+
36
+ begin
37
+ @config = JSON.parse(File.read @config_file)
38
+ rescue
39
+ puts "I'm So Sorry, I can't open or read or find your config file".colorize(:red)
40
+ exit 1
41
+ end
42
+
43
+ def display_help
44
+ puts
45
+ puts "This is a tool to generate SSL CSR's and KEYs "
46
+ puts "Config File: #{@config_file.colorize(:blue)}"
47
+ puts
48
+ puts "Options:"
49
+ puts "-h or --help ".ljust(30) +"-> Display this help message"
50
+ puts "-c or --config".ljust(30) +"-> Specifiy Config to use"
51
+ puts "-f or --fqdn".ljust(30) +"-> Domain name you want a CRT for"
52
+ puts "-l or --list".ljust(30) + "-> List Valid Configs"
53
+ puts
54
+ exit 1
55
+ end
56
+
57
+ def parse_cli
58
+ if ARGV[0] == nil
59
+ display_help
60
+ end
61
+
62
+ parser = GetoptLong.new
63
+ parser.set_options(["-h", "--help", GetoptLong::NO_ARGUMENT],
64
+ ["-c", "--config", GetoptLong::NO_ARGUMENT],
65
+ ["-f", "--fqdn", GetoptLong::NO_ARGUMENT],
66
+ ["-l", "--list", GetoptLong::NO_ARGUMENT]
67
+ )
68
+
69
+ begin
70
+ begin
71
+ opt,arg = parser.get_option
72
+ break if not opt
73
+ case opt
74
+ when "-h" || "--help"
75
+ display_help
76
+ exit
77
+ when "-c" || "--config"
78
+ @active_config = ARGV[0].strip().downcase()
79
+ when "-f" || "--fqdn"
80
+ @fqdn = ARGV[0].strip().downcase()
81
+ when "-l" || "--list"
82
+ @list = true
83
+ end
84
+ rescue => err
85
+ puts "#{err.class()}: #{err.message}"
86
+ puts "this should never happen, Did'nt i warn you?".red.blink
87
+ display_help
88
+ exit
89
+ end
90
+ end while 1
91
+
92
+ end
93
+
94
+
95
+ def list
96
+ puts "\nHint: Use the #{"Blue".colorize(:blue)} items and your config name"
97
+ table_config = [
98
+ {:key=>:shortname, :size=>7, :title=>"Config"},
99
+ {:key=>:organization, :size=>50, :title=>"Organization"},
100
+ {:key=>:digest_algorithm, :size=>10, :title=>"Algorithm"},
101
+ {:key=>:key_size_bits, :size=>10, :title=>"Key Size"}
102
+ ]
103
+ ConsoleTable.define(table_config) do |table|
104
+ @config.each do |item|
105
+ table << [
106
+ item[0].dup.colorize(:blue),
107
+ item[1]["organization"],
108
+ item[1]["digest_algorithm"].colorize(:yellow),
109
+ item[1]["key_size_bits"].to_s.colorize(:purple)
110
+ ]
111
+ end
112
+ end
113
+ puts
114
+ exit 0
115
+ end
116
+
117
+
118
+ def makeDirs
119
+ # root/org/fqdn
120
+ @my_path = "#{@results_directory}/#{@active_config}/#{@fqdn.gsub('*','star')}"
121
+ FileUtils.mkdir_p(@my_path) if !File.directory? @my_path
122
+ puts "Storing results in #{@my_path}"
123
+ end
124
+
125
+ def generateKey
126
+ @key = OpenSSL::PKey::RSA.new @sel_config["key_size_bits"]
127
+ @my_key_path = "#{@my_path}/#{@fqdn.gsub('*','star')}-#{@timestamp}.key"
128
+ open @my_key_path, 'w' do |io| io.write @key.to_pem end
129
+ puts "New key generated (bits: #{@sel_config["key_size_bits"]}): #{@my_key_path}"
130
+ end
131
+
132
+ def generateCSR
133
+ request = OpenSSL::X509::Request.new
134
+ request.version = 0
135
+ request.subject = OpenSSL::X509::Name.new([
136
+ ['C', @sel_config["country"], OpenSSL::ASN1::PRINTABLESTRING],
137
+ ['ST', @sel_config["state"], OpenSSL::ASN1::PRINTABLESTRING],
138
+ ['L', @sel_config["city"], OpenSSL::ASN1::PRINTABLESTRING],
139
+ ['O', @sel_config["organization"], OpenSSL::ASN1::UTF8STRING],
140
+ ['CN', @fqdn, OpenSSL::ASN1::UTF8STRING]
141
+ ])
142
+ request.public_key = @key.public_key
143
+ request.sign(@key, Kernel.const_get("OpenSSL::Digest::#{@sel_config["digest_algorithm"].upcase}").new)
144
+ @my_csr_path = "#{@my_path}/#{@fqdn.gsub('*','star')}-#{@timestamp}.csr"
145
+ puts "Storing CSR at: #{@my_csr_path}".colorize(:green)
146
+ File.open(@my_csr_path,"w") do |f|
147
+ f.write(request)
148
+ end
149
+ puts request
150
+ end
151
+
152
+ def storeSignedCert
153
+ puts "Please Paste the CERT in here (End with ^D):".colorize(:green)
154
+ @my_cert_path = "#{@my_path}/#{@fqdn.gsub('*','star')}-#{@timestamp}.pem"
155
+ @signed_cert = $stdin.read
156
+ if @signed_cert.length > 0
157
+ puts "Writing Cert to: #{@my_cert_path}"
158
+ File.open(@my_cert_path, 'w') {|f| f.write( @signed_cert ) }
159
+ else
160
+ puts "no data found, skippking"
161
+ end
162
+ end
163
+
164
+ def storeCertificateChain
165
+ puts "Please Paste the Certificate Chain in here (End with ^D):".colorize(:green)
166
+ @my_chain_path = "#{@my_path}/#{@fqdn.gsub('*','star')}-chain-#{@timestamp}.pem"
167
+ @chain = $stdin.read
168
+ if @chain.length > 0
169
+ puts "Writing Cert to: #{@my_chain_path}"
170
+ File.open(@my_chain_path, 'w') {|f| f.write( @chain ) }
171
+ else
172
+ puts "no data found, skippking"
173
+ end
174
+ end
175
+
176
+ def genDataBag
177
+ @my_databag_path = "#{@my_path}/#{@fqdn.gsub('*','star')}-chain-#{@timestamp}.json"
178
+ databag = {}
179
+ databag.store(:id, "ssl")
180
+ databag.store(:key, @key.to_pem)
181
+ databag.store(:cert, @signed_cert)
182
+ databag.store(:chain, @chain)
183
+ puts "Writing databag to: #{@my_databag_path}"
184
+ File.open(@my_databag_path,"w") do |f|
185
+ f.write(JSON.pretty_generate(databag))
186
+ end
187
+ end
188
+
189
+
190
+ parse_cli
191
+ if @list == true
192
+ list
193
+ else
194
+ if @fqdn.nil?
195
+ puts "You must specify a FQDN!"
196
+ exit 1
197
+ end
198
+ @sel_config = @config[@active_config]
199
+ @timestamp = Time.now.strftime("%m-%d-%Y")
200
+ if @sel_config == nil
201
+ puts "Help, I can't seem to find the config your asking for in #{@config_file}".colorize(:red)
202
+ exit 1
203
+ end
204
+ makeDirs
205
+ generateKey
206
+ generateCSR
207
+ storeSignedCert
208
+ storeCertificateChain
209
+ genDataBag
210
+ end
data/exe/ewtoken ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ require "EndlessWaffleCLI"
4
+ require 'getoptlong'
5
+ username = ENV['USER']
6
+ resetToken = false
7
+
8
+ if ENV['EndlessWaffleURL'].nil?
9
+ puts "EndlessWaffleCLI requires the 'EndlessWaffleURL' environment variable to be set."
10
+ exit 1
11
+ else
12
+ EndlessWaffleCLI.setServer ENV['EndlessWaffleURL']
13
+ end
14
+
15
+ def showHelp
16
+ puts
17
+ puts "Endless Waffle Token Tool"
18
+ puts "Usage example: #{$0} -u bob"
19
+ puts
20
+ puts "Options:"
21
+ puts "-r or --reset".ljust(30) +"-> Reset your token"
22
+ puts "-u or --username".ljust(30) +"-> Specifiy username"
23
+ puts "-h or --help".ljust(30) +"-> Show this help message."
24
+ puts
25
+ end
26
+
27
+ parser = GetoptLong.new
28
+ parser.set_options( ["-u", "--username", GetoptLong::NO_ARGUMENT],
29
+ ["-r", "--reset", GetoptLong::NO_ARGUMENT])
30
+
31
+ begin
32
+ begin
33
+ opt,arg = parser.get_option
34
+ break if not opt
35
+ case opt
36
+ when "-h" || "--help"
37
+ showHelp
38
+ exit
39
+ when "-r" || "--reset"
40
+ resetToken = true
41
+ when "-u" || "--username"
42
+ username = ARGV[0]
43
+ end
44
+ rescue => err
45
+ puts "#{err.class()}: #{err.message}"
46
+ exit 1
47
+ end
48
+ end while 1
49
+
50
+
51
+
52
+ print "Password for #{username}: "
53
+ password=STDIN.noecho(&:gets).chomp
54
+ puts ""
55
+
56
+ if resetToken
57
+ result = EndlessWaffleCLI.resetToken(username,password)
58
+ else
59
+ result = EndlessWaffleCLI.getToken(username,password)
60
+ end
61
+ puts "You're new token: #{result["token"]}"
62
+ puts "Remember to set your environment EndlessWaffleToken with your new token"
63
+ puts "export EndlessWaffleToken=\"#{result["token"]}\""
@@ -0,0 +1,52 @@
1
+ require "EndlessWaffleCLI/version"
2
+
3
+ module EndlessWaffleCLI
4
+ require 'rest-client'
5
+ require 'json'
6
+ @@server=nil
7
+
8
+ def self.setServer(server)
9
+ @@server = server
10
+ end
11
+
12
+ def self.setToken(token)
13
+ @@token = token
14
+ end
15
+
16
+ def self.updateEc2Cache
17
+ begin
18
+ result = RestClient.get "#{@@server}/ec2/update", :accept => :json, :Authorization => "Token token=\"#{@@token}\""
19
+ JSON.parse(result.body)
20
+ rescue => e
21
+ raise e
22
+ end
23
+ end
24
+
25
+ def self.queryEc2(query={})
26
+ begin
27
+ result = RestClient.post "#{@@server}/ec2", { :query => query }.to_json, :content_type => :json, :accept => :json, :Authorization => "Token token=\"#{@@token}\""
28
+ JSON.parse(result.body)
29
+ rescue => e
30
+ raise e
31
+ end
32
+ end
33
+
34
+ def self.getToken(username,password)
35
+ begin
36
+ result = RestClient::Request.execute method: :get, url: "#{@@server}/token/get", user: username, password: password
37
+ JSON.parse(result.body)
38
+ rescue => e
39
+ raise e
40
+ end
41
+ end
42
+
43
+ def self.resetToken(username,password)
44
+ begin
45
+ result = RestClient::Request.execute method: :get, url: "#{@@server}/token/reset", user: username, password: password
46
+ JSON.parse(result.body)
47
+ rescue => e
48
+ raise e
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,3 @@
1
+ module EndlessWaffleCLI
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,252 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: EndlessWaffleCLI
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Dr. Ogg
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mime-types
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: unf_ext
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.7.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.0.7.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: unf
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.1.4
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.1.4
83
+ - !ruby/object:Gem::Dependency
84
+ name: rest-client
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: console_table
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.2.4
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.2.4
111
+ - !ruby/object:Gem::Dependency
112
+ name: colorize
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.8.1
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.8.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: net-ssh-multi
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.2'
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: 1.2.1
135
+ type: :runtime
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - "~>"
140
+ - !ruby/object:Gem::Version
141
+ version: '1.2'
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 1.2.1
145
+ - !ruby/object:Gem::Dependency
146
+ name: net-ssh-gateway
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '1.2'
152
+ type: :runtime
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '1.2'
159
+ - !ruby/object:Gem::Dependency
160
+ name: net-ssh
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - "~>"
164
+ - !ruby/object:Gem::Version
165
+ version: '3.2'
166
+ type: :runtime
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - "~>"
171
+ - !ruby/object:Gem::Version
172
+ version: '3.2'
173
+ - !ruby/object:Gem::Dependency
174
+ name: highline
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: '1.7'
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: 1.7.8
183
+ type: :runtime
184
+ prerelease: false
185
+ version_requirements: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - "~>"
188
+ - !ruby/object:Gem::Version
189
+ version: '1.7'
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: 1.7.8
193
+ description: Command line tools for the Endless Waffle server
194
+ email:
195
+ - ogg@sr375.com
196
+ executables:
197
+ - enum
198
+ - enum-ssh
199
+ - ewssh
200
+ - ewssl
201
+ - ewtoken
202
+ extensions: []
203
+ extra_rdoc_files: []
204
+ files:
205
+ - ".gitignore"
206
+ - EndlessWaffleCLI.gemspec
207
+ - Gemfile
208
+ - README.md
209
+ - Rakefile
210
+ - bin/console
211
+ - bin/setup
212
+ - build/.gitignore
213
+ - build/Gemfile
214
+ - build/README.md
215
+ - build/Rakefile
216
+ - build/bin/console
217
+ - build/bin/setup
218
+ - build/build.gemspec
219
+ - build/lib/build.rb
220
+ - build/lib/build/version.rb
221
+ - exe/enum
222
+ - exe/enum-ssh
223
+ - exe/ewssh
224
+ - exe/ewssl
225
+ - exe/ewtoken
226
+ - lib/EndlessWaffleCLI.rb
227
+ - lib/EndlessWaffleCLI/version.rb
228
+ homepage: ''
229
+ licenses: []
230
+ metadata:
231
+ allowed_push_host: https://rubygems.org
232
+ post_install_message:
233
+ rdoc_options: []
234
+ require_paths:
235
+ - lib
236
+ required_ruby_version: !ruby/object:Gem::Requirement
237
+ requirements:
238
+ - - ">="
239
+ - !ruby/object:Gem::Version
240
+ version: '0'
241
+ required_rubygems_version: !ruby/object:Gem::Requirement
242
+ requirements:
243
+ - - ">="
244
+ - !ruby/object:Gem::Version
245
+ version: '0'
246
+ requirements: []
247
+ rubyforge_project:
248
+ rubygems_version: 2.5.1
249
+ signing_key:
250
+ specification_version: 4
251
+ summary: Command line tools for the Endless Waffle server
252
+ test_files: []