proboscis_cli 0.0.3 → 0.0.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.
- checksums.yaml +5 -5
- data/README.md +2 -0
- data/bin/proboscis +9 -5
- data/lib/proboscis_cli.rb +114 -16
- data/lib/proboscis_cli/version.rb +1 -1
- data/proboscis_cli.gemspec +4 -4
- metadata +7 -8
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 9b08e20f2e8f4a6771b7a8192a86a2083c169546137f1a0b069bdb4fb9bf6648
         | 
| 4 | 
            +
              data.tar.gz: f63e3d0c12e1563317e2d4034172bc239b51d3f5690e6c72a9bacd45b4897b73
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9be97117c7a5d2d6efa5b6f00ab6dd2f9cc29c13e0e19e49fb5b8983a52bfa8ab49c5ae631cb5b2f72d8d77fa1b87575d417b58c4a71fe6a24eec0ff745d5265
         | 
| 7 | 
            +
              data.tar.gz: 85ec027dbac647f5479cfc6b573d43b0a8fc1a0678fba499e9d32e52a175c6abe90cc7ce213883a76376a877a237da72dc464fe6317d95667bab1f02b1798114
         | 
    
        data/README.md
    CHANGED
    
    | @@ -30,6 +30,8 @@ Or install it yourself as: | |
| 30 30 | 
             
              $ export proboscis_qa_target_user=<target_ssh_user>
         | 
| 31 31 | 
             
              $ export proboscis_prod_target_port=<target_ssh_port>
         | 
| 32 32 | 
             
              $ export proboscis_prod_target_user=<target_ssh_user>
         | 
| 33 | 
            +
              $ export araneae_qa_token=<araneae_token>
         | 
| 34 | 
            +
              $ export araneae_prod_token=<araneae_token>
         | 
| 33 35 | 
             
            ```
         | 
| 34 36 |  | 
| 35 37 | 
             
            ```bash
         | 
    
        data/bin/proboscis
    CHANGED
    
    | @@ -1,8 +1,8 @@ | |
| 1 1 | 
             
            #!/usr/bin/env ruby
         | 
| 2 2 | 
             
            require 'proboscis_cli'
         | 
| 3 3 |  | 
| 4 | 
            -
            if(ARGV.empty? || ARGV.size  | 
| 5 | 
            -
              puts "Usage proboscis <qa|prod> <subdomain> <server|worker> <b|i>"
         | 
| 4 | 
            +
            if(ARGV.empty? || ARGV.size > 5)
         | 
| 5 | 
            +
              puts "Usage proboscis <qa|prod> <subdomain> <server|worker> <b|i|c>"
         | 
| 6 6 | 
             
              exit
         | 
| 7 7 | 
             
            end
         | 
| 8 8 |  | 
| @@ -10,12 +10,16 @@ environment = ARGV[0].downcase | |
| 10 10 | 
             
            subdomain = ARGV[1].downcase
         | 
| 11 11 | 
             
            target = ARGV[2].downcase
         | 
| 12 12 | 
             
            type = ARGV[3].downcase
         | 
| 13 | 
            +
            subpath = 'araneae'
         | 
| 14 | 
            +
            if not ARGV[4].nil?
         | 
| 15 | 
            +
              subpath = ARGV[4].downcase
         | 
| 16 | 
            +
            end
         | 
| 13 17 |  | 
| 14 18 | 
             
            if((%w(qa prod).select {|e| e == environment}).empty? ||
         | 
| 15 19 | 
             
              (%w(server worker).select {|e| e == target}).empty? ||
         | 
| 16 | 
            -
              (%w(b i).select {|e| e == type}).empty?)
         | 
| 17 | 
            -
              puts "Usage proboscis <qa|prod> <subdomain> <server|worker> <b|i>"
         | 
| 20 | 
            +
              (%w(b i c).select {|e| e == type}).empty?)
         | 
| 21 | 
            +
              puts "Usage proboscis <qa|prod> <subdomain> <server|worker> <b|i|c>"
         | 
| 18 22 | 
             
              exit
         | 
| 19 23 | 
             
            end
         | 
| 20 24 |  | 
| 21 | 
            -
            Proboscis.connect(environment, subdomain, target, type)
         | 
| 25 | 
            +
            Proboscis.connect(environment, subdomain, target, type, subpath=subpath)
         | 
    
        data/lib/proboscis_cli.rb
    CHANGED
    
    | @@ -3,6 +3,104 @@ require 'httparty' | |
| 3 3 | 
             
            require 'json'
         | 
| 4 4 | 
             
            require "base64"
         | 
| 5 5 |  | 
| 6 | 
            +
            class Machine
         | 
| 7 | 
            +
              def self.port(environment, type, subpath)
         | 
| 8 | 
            +
                ENV["proboscis_#{environment}_target_port"] || "22"
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
            end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            class Server < Machine
         | 
| 13 | 
            +
              def self.ip(auth_code, host, environment, subdomain, type, subpath)
         | 
| 14 | 
            +
                response = HTTParty.get("#{host}/api/api/hives/#{subdomain}/#{type}", headers: {"X-Authorization" => auth_code})
         | 
| 15 | 
            +
                if response.code != 200
         | 
| 16 | 
            +
                  puts "Unable to fetch details for domain #{subdomain}"
         | 
| 17 | 
            +
                  exit -1
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
                hive = JSON::parse(response.body)
         | 
| 20 | 
            +
                @ipAddress = hive["ip_address"]
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
            end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            class CashServer < Server
         | 
| 25 | 
            +
              def self.port(environment, type, subpath)
         | 
| 26 | 
            +
                subpath == 'araneae' ? "1729" : "22"
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              def self.param(environment, lookup)
         | 
| 30 | 
            +
                ENV["araneae_#{environment}_#{lookup}"]
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              def self.ip(auth_code, host, environment, subdomain, type, subpath)
         | 
| 34 | 
            +
                super
         | 
| 35 | 
            +
                if subpath == 'araneae'
         | 
| 36 | 
            +
                  return @ipAddress
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
                res = HTTParty.get("http://#{@ipAddress}/admin/hosts", headers: {'X-Auth-Key': self.param(environment, 'token')})
         | 
| 39 | 
            +
                if res.code != 200
         | 
| 40 | 
            +
                  puts "Failed to get subpath details. #{res.code}"
         | 
| 41 | 
            +
                  exit -1
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
                subservers = JSON::parse(res.body)
         | 
| 44 | 
            +
                @ipAddress = subservers.select {|s| s['name'] == subpath}[0]['host']
         | 
| 45 | 
            +
                @ipAddress
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
            end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            class Worker < Machine
         | 
| 50 | 
            +
              def self.ip(auth_code, host, environment, subdomain, type, subpath)
         | 
| 51 | 
            +
                @auth_code = auth_code
         | 
| 52 | 
            +
                @host = host
         | 
| 53 | 
            +
                self.client_list environment
         | 
| 54 | 
            +
                client_id = @client_list.select {|c| c["domain"] == subdomain}
         | 
| 55 | 
            +
                if client_id.empty?
         | 
| 56 | 
            +
                  puts "Unable to find client with subdomain #{subdomain}"
         | 
| 57 | 
            +
                  exit -1
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
                self.client environment, client_id.first
         | 
| 60 | 
            +
                self.worker_ip subpath
         | 
| 61 | 
            +
              end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
              def self.worker_ip(subpath)
         | 
| 64 | 
            +
                if(!@infra_info["WORKER_IP"])
         | 
| 65 | 
            +
                  puts "Unable to find target WORKER_IP in #{@infra_info}. Is the machine up?"
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
                @infra_info["WORKER_IP"]
         | 
| 68 | 
            +
              end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
              def self.client_list(environment)
         | 
| 71 | 
            +
                response = HTTParty.get("#{@host}/api/api/clients", headers: {"X-Authorization" => @auth_code})
         | 
| 72 | 
            +
                if response.code != 200
         | 
| 73 | 
            +
                  puts "Unable to get the client list.."
         | 
| 74 | 
            +
                  exit -1
         | 
| 75 | 
            +
                end
         | 
| 76 | 
            +
                @client_list = JSON::parse(response.body)
         | 
| 77 | 
            +
              end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
              def self.client(environment, client_id)
         | 
| 80 | 
            +
                response = HTTParty.get("#{@host}/api/api/clients/#{client_id["id"]}/products", headers: {"X-Authorization" => @auth_code})
         | 
| 81 | 
            +
                if response.code != 200
         | 
| 82 | 
            +
                  puts "Unable to fetch details of client with id #{client_id}"
         | 
| 83 | 
            +
                  exit -1
         | 
| 84 | 
            +
                end
         | 
| 85 | 
            +
                infra_info = JSON::parse(response.body)
         | 
| 86 | 
            +
                if infra_info.empty?
         | 
| 87 | 
            +
                  puts "No Products Mapped!"
         | 
| 88 | 
            +
                  exit -1
         | 
| 89 | 
            +
                end
         | 
| 90 | 
            +
                @infra_info = JSON::parse(infra_info["infrastructureInfo"])
         | 
| 91 | 
            +
               end
         | 
| 92 | 
            +
            end
         | 
| 93 | 
            +
             | 
| 94 | 
            +
            class CashWorker < Worker
         | 
| 95 | 
            +
              def self.worker_ip(subpath)
         | 
| 96 | 
            +
                key = "#{subpath.gsub('_', '-')}_WORKER_IP"
         | 
| 97 | 
            +
                if(!@infra_info[key])
         | 
| 98 | 
            +
                  puts "Unable to find target WORKER_IP in #{@infra_info}. Is the machine up?"
         | 
| 99 | 
            +
                end
         | 
| 100 | 
            +
                @infra_info[key]
         | 
| 101 | 
            +
              end
         | 
| 102 | 
            +
            end
         | 
| 103 | 
            +
             | 
| 6 104 | 
             
            class Proboscis
         | 
| 7 105 | 
             
              def self.host(environment)
         | 
| 8 106 | 
             
                ENV["proboscis_#{environment}"]
         | 
| @@ -12,32 +110,32 @@ class Proboscis | |
| 12 110 | 
             
                ENV["proboscis_#{environment}_#{lookup}"]
         | 
| 13 111 | 
             
              end
         | 
| 14 112 |  | 
| 15 | 
            -
              def self.connect(environment, subdomain, target, type)
         | 
| 16 | 
            -
                type = type == 'b' ? 'BUSY_BEE' : 'INSTANT_HONEY'
         | 
| 113 | 
            +
              def self.connect(environment, subdomain, target, type, subpath='araneae')
         | 
| 114 | 
            +
                type = type == 'b' ? 'BUSY_BEE' : (type == 'i' ? 'INSTANT_HONEY' : 'CASH_REPLENISHMENT')
         | 
| 115 | 
            +
                @host = self.host(environment)
         | 
| 17 116 | 
             
                self.login environment
         | 
| 18 | 
            -
                self. | 
| 19 | 
            -
                 | 
| 20 | 
            -
             | 
| 117 | 
            +
                machine = self.get_machine target, type
         | 
| 118 | 
            +
                ip = machine.ip @auth_code, @host, environment, subdomain, type, subpath
         | 
| 119 | 
            +
                if(!ip)
         | 
| 120 | 
            +
                  puts "Unable to find target #{ip}. Is the machine up?"
         | 
| 21 121 | 
             
                  exit -1
         | 
| 22 122 | 
             
                end
         | 
| 23 123 | 
             
                user = ENV["proboscis_#{environment}_target_user"] || "root"
         | 
| 24 | 
            -
                port =  | 
| 25 | 
            -
                puts "Executing ssh #{user}@#{ | 
| 26 | 
            -
                system "ssh #{user}@#{ | 
| 124 | 
            +
                port = machine.port environment, type, subpath
         | 
| 125 | 
            +
                puts "Executing ssh #{user}@#{ip} -p #{port}"
         | 
| 126 | 
            +
                system "ssh #{user}@#{ip} -p #{port}"
         | 
| 27 127 | 
             
              end
         | 
| 28 128 |  | 
| 29 | 
            -
              def self. | 
| 30 | 
            -
                 | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
                   | 
| 129 | 
            +
              def self.get_machine(target, type)
         | 
| 130 | 
            +
                if type == 'c'
         | 
| 131 | 
            +
                  target == 'server' ? Server : Worker
         | 
| 132 | 
            +
                else
         | 
| 133 | 
            +
                  target == 'server' ? CashServer : CashWorker
         | 
| 34 134 | 
             
                end
         | 
| 35 | 
            -
                hive = JSON::parse(response.body)
         | 
| 36 | 
            -
                @ipAddress = hive["ip_address"]
         | 
| 37 135 | 
             
              end
         | 
| 38 136 |  | 
| 39 137 | 
             
              def self.login(environment)
         | 
| 40 | 
            -
                response = HTTParty.post("#{ | 
| 138 | 
            +
                response = HTTParty.post("#{@host}/api/login", body: {phoneNumber: self.param(environment, 'user'), password: self.param(environment, 'pass')}.to_json, headers: { 'Content-Type' => 'application/json' })
         | 
| 41 139 | 
             
                if response.code != 200
         | 
| 42 140 | 
             
                  puts "Unable to login to proboscis.."
         | 
| 43 141 | 
             
                  exit -1
         | 
    
        data/proboscis_cli.gemspec
    CHANGED
    
    | @@ -1,11 +1,11 @@ | |
| 1 1 | 
             
            Gem::Specification.new do |s|
         | 
| 2 2 | 
             
              s.name        = 'proboscis_cli'
         | 
| 3 | 
            -
              s.version     = '0.0. | 
| 4 | 
            -
              s.date        = ' | 
| 3 | 
            +
              s.version     = '0.0.8'
         | 
| 4 | 
            +
              s.date        = '2018-04-10'
         | 
| 5 5 | 
             
              s.summary     = "A cli client for proboscis"
         | 
| 6 6 | 
             
              s.description = "A cli client for proboscis"
         | 
| 7 7 | 
             
              s.authors     = ["Simon Roy", "Arvind"]
         | 
| 8 | 
            -
              s.email       = ' | 
| 8 | 
            +
              s.email       = 'info@delium.co'
         | 
| 9 9 | 
             
              s.homepage    =
         | 
| 10 10 | 
             
                'http://rubygems.org/gems/proboscis_cli'
         | 
| 11 11 | 
             
              s.license       = 'MIT'
         | 
| @@ -18,4 +18,4 @@ Gem::Specification.new do |s| | |
| 18 18 | 
             
              s.add_development_dependency 'bundler', '~> 1.3'
         | 
| 19 19 | 
             
              s.add_development_dependency 'rake', '~> 0'
         | 
| 20 20 | 
             
              s.add_runtime_dependency 'httparty', "~> 0.15.6"
         | 
| 21 | 
            -
            end
         | 
| 21 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,15 +1,15 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: proboscis_cli
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.8
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Simon Roy
         | 
| 8 8 | 
             
            - Arvind
         | 
| 9 | 
            -
            autorequire: | 
| 9 | 
            +
            autorequire:
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date:  | 
| 12 | 
            +
            date: 2018-04-10 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: bundler
         | 
| @@ -54,7 +54,7 @@ dependencies: | |
| 54 54 | 
             
                  - !ruby/object:Gem::Version
         | 
| 55 55 | 
             
                    version: 0.15.6
         | 
| 56 56 | 
             
            description: A cli client for proboscis
         | 
| 57 | 
            -
            email:  | 
| 57 | 
            +
            email: info@delium.co
         | 
| 58 58 | 
             
            executables:
         | 
| 59 59 | 
             
            - proboscis
         | 
| 60 60 | 
             
            extensions: []
         | 
| @@ -73,7 +73,7 @@ homepage: http://rubygems.org/gems/proboscis_cli | |
| 73 73 | 
             
            licenses:
         | 
| 74 74 | 
             
            - MIT
         | 
| 75 75 | 
             
            metadata: {}
         | 
| 76 | 
            -
            post_install_message: | 
| 76 | 
            +
            post_install_message:
         | 
| 77 77 | 
             
            rdoc_options: []
         | 
| 78 78 | 
             
            require_paths:
         | 
| 79 79 | 
             
            - lib
         | 
| @@ -88,9 +88,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 88 88 | 
             
                - !ruby/object:Gem::Version
         | 
| 89 89 | 
             
                  version: '0'
         | 
| 90 90 | 
             
            requirements: []
         | 
| 91 | 
            -
             | 
| 92 | 
            -
             | 
| 93 | 
            -
            signing_key: 
         | 
| 91 | 
            +
            rubygems_version: 3.0.4
         | 
| 92 | 
            +
            signing_key:
         | 
| 94 93 | 
             
            specification_version: 4
         | 
| 95 94 | 
             
            summary: A cli client for proboscis
         | 
| 96 95 | 
             
            test_files: []
         |