proboscis_cli 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5e3b6f2f18f6f9665c39527fcf3506b71313fe57
4
+ data.tar.gz: c2247b2671caac429aed7efb01bcffc0b063b7d6
5
+ SHA512:
6
+ metadata.gz: 04dd7bd6846b352f7c889315ae8e7f6c3788b00268a680d2a402aefeb71294cb8806a2627fbf3f5273c3941cc7031b67e59bcc1f2f97d4a49577d59fdf9f1390
7
+ data.tar.gz: 764138989c723e0fec2aa2c48c11a1f2e6a89654171c1ca231ad4c5703e344e1e364b819563ccace874f0294e8f8effbe32bb3b2aebed42425b06e8c6648f27e
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ .idea/
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rmake.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2017 Simon
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # Proboscis CLI
2
+
3
+ A cli interface to connect to proboscis for quick ssh to clients
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'proboscis_cli'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install proboscis_cli
18
+
19
+ ## Usage
20
+ ### Configuring environmental variables
21
+
22
+ ```bash
23
+ $ export proboscis_qa=<base_path>
24
+ $ export proboscis_prod=<base_path>
25
+ $ export proboscis_qa_user=<username>
26
+ $ export proboscis_qa_pass=<password>
27
+ $ export proboscis_prod_user=<username>
28
+ $ export proboscis_prod_pass=<password>
29
+ $ export proboscis_qa_target_port=<target_ssh_port>
30
+ $ export proboscis_qa_target_user=<target_ssh_user>
31
+ $ export proboscis_prod_target_port=<target_ssh_port>
32
+ $ export proboscis_prod_target_user=<target_ssh_user>
33
+ ```
34
+
35
+ ```bash
36
+ $ ssh-add <path to qa private key>
37
+ $ ssh-add <path to prod private key>
38
+ ```
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/proboscis ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ require 'proboscis_cli'
3
+
4
+ if(ARGV.empty? || ARGV.size != 3)
5
+ puts "Usage proboscis <qa|prod> <subdomain> <server|worker>"
6
+ exit
7
+ end
8
+
9
+ environment = ARGV[0].downcase
10
+ subdomain = ARGV[1].downcase
11
+ target = ARGV[2].downcase
12
+
13
+ if((%w(qa prod).select {|e| e == environment}).empty? || (%w(server worker).select {|e| e == target}).empty?)
14
+ puts "Usage proboscis <qa|prod> <subdomain> <server|worker>"
15
+ exit
16
+ end
17
+
18
+ Proboscis.connect(environment, subdomain, target)
@@ -0,0 +1,67 @@
1
+ require "proboscis_cli/version"
2
+ require 'httparty'
3
+ require 'json'
4
+ require "base64"
5
+
6
+ class Proboscis
7
+
8
+ def self.host(environment)
9
+ ENV["proboscis_#{environment}"]
10
+ end
11
+
12
+ def self.param(environment, lookup)
13
+ ENV["proboscis_#{environment}_#{lookup}"]
14
+ end
15
+
16
+ def self.connect(environment, subdomain, target)
17
+ self.login environment
18
+ self.client_list environment
19
+ client_id = @client_list.select {|c| c["domain"] == subdomain}
20
+ if client_id.empty?
21
+ puts "Unable to find client with subdomain #{subdomain}"
22
+ exit -1
23
+ end
24
+ self.client environment, client_id.first
25
+ if(!@infra_info["#{target.upcase}_IP"])
26
+ puts "Unable to find target #{target.upcase}_IP in #{@infra_info}. Is the machine up?"
27
+ exit -1
28
+ end
29
+ ip = @infra_info["#{target.upcase}_IP"]
30
+ user = ENV["proboscis_#{environment}_target_user"] || "root"
31
+ port = ENV["proboscis_#{environment}_target_port"] || "22"
32
+ puts "Executing ssh #{user}@#{ip} -p #{port}"
33
+ system "ssh #{user}@#{ip} -p #{port}"
34
+ end
35
+
36
+ def self.client(environment, client_id)
37
+ response = HTTParty.get("#{self.host(environment)}/api/api/clients/#{client_id["id"]}/products", headers: {"X-Authorization" => @auth_code})
38
+ if response.code != 200
39
+ puts "Unable to fetch details of client with id #{client_id}"
40
+ exit -1
41
+ end
42
+ infra_info = JSON::parse(response.body)
43
+ if infra_info.empty?
44
+ puts "No Products Mapped!"
45
+ exit -1
46
+ end
47
+ @infra_info = JSON::parse(infra_info.first["infrastructureInfo"])
48
+ end
49
+
50
+ def self.client_list(environment)
51
+ response = HTTParty.get("#{self.host(environment)}/api/api/clients", headers: {"X-Authorization" => @auth_code})
52
+ if response.code != 200
53
+ puts "Unable to get the client list.."
54
+ exit -1
55
+ end
56
+ @client_list = JSON::parse(response.body)["content"]
57
+ end
58
+
59
+ def self.login(environment)
60
+ response = HTTParty.post("#{self.host(environment)}/api/login", body: {phoneNumber: self.param(environment, 'user'), password: self.param(environment, 'pass')}.to_json, headers: { 'Content-Type' => 'application/json' })
61
+ if response.code != 200
62
+ puts "Unable to login to proboscis.."
63
+ exit -1
64
+ end
65
+ @auth_code = Base64.strict_encode64(JSON::parse(response.body)["accessToken"])
66
+ end
67
+ end
@@ -0,0 +1,3 @@
1
+ module ProboscisCli
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,21 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'proboscis_cli'
3
+ s.version = '0.0.1'
4
+ s.date = '2017-11-13'
5
+ s.summary = "A cli client for proboscis"
6
+ s.description = "A cli client for proboscis"
7
+ s.authors = ["Simon Roy"]
8
+ s.email = 'simon@delium.co'
9
+ s.homepage =
10
+ 'http://rubygems.org/gems/proboscis_cli'
11
+ s.license = 'MIT'
12
+
13
+ s.files = `git ls-files`.split($/)
14
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
+ s.require_paths = ["lib"]
17
+
18
+ s.add_development_dependency 'bundler', '~> 1.3'
19
+ s.add_development_dependency 'rake', '~> 0'
20
+ s.add_runtime_dependency 'httparty', "~> 0.15.6"
21
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: proboscis_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Simon Roy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-13 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.15.6
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.15.6
55
+ description: A cli client for proboscis
56
+ email: simon@delium.co
57
+ executables:
58
+ - proboscis
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - bin/proboscis
68
+ - lib/proboscis_cli.rb
69
+ - lib/proboscis_cli/version.rb
70
+ - proboscis_cli.gemspec
71
+ homepage: http://rubygems.org/gems/proboscis_cli
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.6.13
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: A cli client for proboscis
95
+ test_files: []