Class: Proboscis

Inherits:
Object
  • Object
show all
Defined in:
lib/proboscis_cli.rb

Class Method Summary collapse

Class Method Details

.connect(environment, subdomain, target, type) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/proboscis_cli.rb', line 68

def self.connect(environment, subdomain, target, type)
  type = type == 'b' ? 'BUSY_BEE' : 'INSTANT_HONEY'
  @host = self.host(environment)
  self. environment
  ip = self.get_ip environment, subdomain, type, target
  if(!ip)
    puts "Unable to find target #{ip}. Is the machine up?"
    exit -1
  end
  user = ENV["proboscis_#{environment}_target_user"] || "root"
  port = ENV["proboscis_#{environment}_target_port"] || "22"
  puts "Executing ssh #{user}@#{ip} -p #{port}"
  system "ssh #{user}@#{ip} -p #{port}"
end

.get_ip(environment, subdomain, type, target) ⇒ Object



92
93
94
95
# File 'lib/proboscis_cli.rb', line 92

def self.get_ip(environment, subdomain, type, target)
  machine = target.downcase == 'server' ? Server : Worker
  machine.ip @auth_code, @host, environment, subdomain, type
end

.host(environment) ⇒ Object



60
61
62
# File 'lib/proboscis_cli.rb', line 60

def self.host(environment)
  ENV["proboscis_#{environment}"]
end

.login(environment) ⇒ Object



83
84
85
86
87
88
89
90
# File 'lib/proboscis_cli.rb', line 83

def self.(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' })
  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



64
65
66
# File 'lib/proboscis_cli.rb', line 64

def self.param(environment, lookup)
  ENV["proboscis_#{environment}_#{lookup}"]
end