Class: Proboscis

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

Class Method Summary collapse

Class Method Details

.client(environment, client_id) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/proboscis_cli.rb', line 36

def self.client(environment, client_id)
  response = HTTParty.get("#{self.host(environment)}/api/api/clients/#{client_id["id"]}/products", headers: {"X-Authorization" => @auth_code})
  if response.code != 200
    puts "Unable to fetch details of client with id #{client_id}"
    exit -1
  end
  infra_info = JSON::parse(response.body)
  if infra_info.empty?
    puts "No Products Mapped!"
    exit -1
  end
  @infra_info = JSON::parse(infra_info.first["infrastructureInfo"])
end

.client_list(environment) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/proboscis_cli.rb', line 50

def self.client_list(environment)
  response = HTTParty.get("#{self.host(environment)}/api/api/clients", headers: {"X-Authorization" => @auth_code})
  if response.code != 200
    puts "Unable to get the client list.."
    exit -1
  end
  @client_list = JSON::parse(response.body)["content"]
end

.connect(environment, subdomain, target) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/proboscis_cli.rb', line 16

def self.connect(environment, subdomain, target)
  self. environment
  self.client_list environment
  client_id = @client_list.select {|c| c["domain"] == subdomain}
  if client_id.empty?
    puts "Unable to find client with subdomain #{subdomain}"
    exit -1
  end
  self.client environment, client_id.first
  if(!@infra_info["#{target.upcase}_IP"])
    puts "Unable to find target #{target.upcase}_IP in #{@infra_info}. Is the machine up?"
    exit -1
  end
  ip = @infra_info["#{target.upcase}_IP"]
  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

.host(environment) ⇒ Object



8
9
10
# File 'lib/proboscis_cli.rb', line 8

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

.login(environment) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/proboscis_cli.rb', line 59

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



12
13
14
# File 'lib/proboscis_cli.rb', line 12

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