Class: Proboscis
- Inherits:
-
Object
- Object
- Proboscis
- Defined in:
- lib/proboscis_cli.rb
Class Method Summary collapse
- .connect(environment, subdomain, target, type, subpath = 'araneae') ⇒ Object
- .get_machine(target, type) ⇒ Object
- .host(environment) ⇒ Object
- .login(environment) ⇒ Object
- .param(environment, lookup) ⇒ Object
Class Method Details
.connect(environment, subdomain, target, type, subpath = 'araneae') ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/proboscis_cli.rb', line 113 def self.connect(environment, subdomain, target, type, subpath='araneae') type = type == 'b' ? 'BUSY_BEE' : (type == 'i' ? 'INSTANT_HONEY' : 'CASH_REPLENISHMENT') @host = self.host(environment) self.login environment machine = self.get_machine target, type ip = machine.ip @auth_code, @host, environment, subdomain, type, subpath if(!ip) puts "Unable to find target #{ip}. Is the machine up?" exit -1 end user = ENV["proboscis_#{environment}_target_user"] || "root" port = machine.port environment, type, subpath puts "Executing ssh #{user}@#{ip} -p #{port}" system "ssh #{user}@#{ip} -p #{port}" end |
.get_machine(target, type) ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/proboscis_cli.rb', line 129 def self.get_machine(target, type) if type == 'CASH_REPLENISHMENT' target == 'server' ? CashServer : CashWorker else target == 'server' ? Server : Worker end end |
.host(environment) ⇒ Object
105 106 107 |
# File 'lib/proboscis_cli.rb', line 105 def self.host(environment) ENV["proboscis_#{environment}"] end |
.login(environment) ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/proboscis_cli.rb', line 137 def self.login(environment) response = HTTParty.post("#{@host}/api/login", body: {phoneNumber: self.param(environment, 'user'), password: self.param(environment, 'pass')}.to_json, headers: { 'Content-Type' => 'application/json', 'X-Captcha-Cli-Secret': self.param(environment, 'cli_key')}) if response.code != 200 puts "Unable to login to proboscis.." exit -1 end @auth_code = Base64.strict_encode64(JSON::parse(response.body)["accessToken"]) end |
.param(environment, lookup) ⇒ Object
109 110 111 |
# File 'lib/proboscis_cli.rb', line 109 def self.param(environment, lookup) ENV["proboscis_#{environment}_#{lookup}"] end |