proboscis_cli 0.0.6 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4578f24a079b4789659c3a0446a4ac1f20b40fae53512f977f0628c184e8f044
4
- data.tar.gz: 7b6a3aef023c40eaf5b1d27061189eac4ffbc54ee62baf957d37adcaad87523a
3
+ metadata.gz: 5840c0c18402852bb98c40cf7f197421efde9782d16086145597d5bf4f95888e
4
+ data.tar.gz: 8d79311402a8cfaccc6e386789c0ad9df0b932aee2dbb94741aa18ee39a12c93
5
5
  SHA512:
6
- metadata.gz: 6f9edf6526cfbb3f1dd817032494f3f301f5d0d727740f967086c4524f46f90a115c607febb60fd0e3f5609313a6a9decc574755de5eaab756eece3164d69260
7
- data.tar.gz: e3d92f0981d2c9023f44791ae91600ff7d6944c569355d81aec35a4bc6aecf819d674697465de13e6e771748420b0209034b93ac0149edc2165c38d9d24345ad
6
+ metadata.gz: 03cf8eb0a43d393cfe82e8eaed6aa5bf9466193b3ebeb45d4a197f42d87dcd277a0f36b9bc6f1f14dfbc1582b627a3b5acdb3cc4d2cb11a9ed72a72237ba1236
7
+ data.tar.gz: 9272ef301098306bb369cc95c1b2a2774182ac154ca1ff4249116b517075a3b3e0603095fa4256055567e822c8aeb684bc24762b205366c0afbef83c06fd367c
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,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'proboscis_cli'
3
3
 
4
- if(ARGV.empty? || ARGV.size != 4)
4
+ if(ARGV.empty? || ARGV.size > 5)
5
5
  puts "Usage proboscis <qa|prod> <subdomain> <server|worker> <b|i|c>"
6
6
  exit
7
7
  end
@@ -10,6 +10,10 @@ 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? ||
@@ -18,4 +22,4 @@ if((%w(qa prod).select {|e| e == environment}).empty? ||
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,8 +3,14 @@ require 'httparty'
3
3
  require 'json'
4
4
  require "base64"
5
5
 
6
- class Server
7
- def self.ip(auth_code, host, environment, subdomain, type)
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)
8
14
  response = HTTParty.get("#{host}/api/api/hives/#{subdomain}/#{type}", headers: {"X-Authorization" => auth_code})
9
15
  if response.code != 200
10
16
  puts "Unable to fetch details for domain #{subdomain}"
@@ -15,8 +21,33 @@ class Server
15
21
  end
16
22
  end
17
23
 
18
- class Worker
19
- def self.ip(auth_code, host, environment, subdomain, type)
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("https://#{subdomain}.delium.io/api/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)
20
51
  @auth_code = auth_code
21
52
  @host = host
22
53
  self.client_list environment
@@ -26,6 +57,10 @@ class Worker
26
57
  exit -1
27
58
  end
28
59
  self.client environment, client_id.first
60
+ self.worker_ip subpath
61
+ end
62
+
63
+ def self.worker_ip(subpath)
29
64
  if(!@infra_info["WORKER_IP"])
30
65
  puts "Unable to find target WORKER_IP in #{@infra_info}. Is the machine up?"
31
66
  end
@@ -34,11 +69,11 @@ class Worker
34
69
 
35
70
  def self.client_list(environment)
36
71
  response = HTTParty.get("#{@host}/api/api/clients", headers: {"X-Authorization" => @auth_code})
37
- if response.code != 200
72
+ if response.code != 200
38
73
  puts "Unable to get the client list.."
39
74
  exit -1
40
- end
41
- @client_list = JSON::parse(response.body)["content"]
75
+ end
76
+ @client_list = JSON::parse(response.body)
42
77
  end
43
78
 
44
79
  def self.client(environment, client_id)
@@ -56,6 +91,17 @@ class Worker
56
91
  end
57
92
  end
58
93
 
94
+ class CashWorker < Worker
95
+ def self.worker_ip(subpath)
96
+ key = "#{subpath.gsub('_', '-')}_WORKER_IP"
97
+ puts @infra_info
98
+ if(!@infra_info[key])
99
+ puts "Unable to find target WORKER_IP in #{@infra_info}. Is the machine up?"
100
+ end
101
+ @infra_info[key]
102
+ end
103
+ end
104
+
59
105
  class Proboscis
60
106
  def self.host(environment)
61
107
  ENV["proboscis_#{environment}"]
@@ -65,21 +111,31 @@ class Proboscis
65
111
  ENV["proboscis_#{environment}_#{lookup}"]
66
112
  end
67
113
 
68
- def self.connect(environment, subdomain, target, type)
114
+ def self.connect(environment, subdomain, target, type, subpath='araneae')
69
115
  type = type == 'b' ? 'BUSY_BEE' : (type == 'i' ? 'INSTANT_HONEY' : 'CASH_REPLENISHMENT')
70
116
  @host = self.host(environment)
71
117
  self.login environment
72
- ip = self.get_ip environment, subdomain, type, target
118
+ machine = self.get_machine target, type
119
+ ip = machine.ip @auth_code, @host, environment, subdomain, type, subpath
73
120
  if(!ip)
74
121
  puts "Unable to find target #{ip}. Is the machine up?"
75
122
  exit -1
76
123
  end
77
124
  user = ENV["proboscis_#{environment}_target_user"] || "root"
78
- port = ENV["proboscis_#{environment}_target_port"] || "22"
125
+ port = machine.port environment, type, subpath
79
126
  puts "Executing ssh #{user}@#{ip} -p #{port}"
80
127
  system "ssh #{user}@#{ip} -p #{port}"
81
128
  end
82
129
 
130
+ def self.get_machine(target, type)
131
+ puts type
132
+ if type == 'CASH_REPLENISHMENT'
133
+ target == 'server' ? CashServer : CashWorker
134
+ else
135
+ target == 'server' ? Server : Worker
136
+ end
137
+ end
138
+
83
139
  def self.login(environment)
84
140
  response = HTTParty.post("#{@host}/api/login", body: {phoneNumber: self.param(environment, 'user'), password: self.param(environment, 'pass')}.to_json, headers: { 'Content-Type' => 'application/json' })
85
141
  if response.code != 200
@@ -88,9 +144,4 @@ class Proboscis
88
144
  end
89
145
  @auth_code = Base64.strict_encode64(JSON::parse(response.body)["accessToken"])
90
146
  end
91
-
92
- def self.get_ip(environment, subdomain, type, target)
93
- machine = target.downcase == 'server' ? Server : Worker
94
- machine.ip @auth_code, @host, environment, subdomain, type
95
- end
96
147
  end
@@ -1,3 +1,3 @@
1
1
  module ProboscisCli
2
- VERSION = '0.0.6'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'proboscis_cli'
3
- s.version = '0.0.6'
3
+ s.version = '0.1.0'
4
4
  s.date = '2018-04-10'
5
5
  s.summary = "A cli client for proboscis"
6
6
  s.description = "A cli client for proboscis"
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proboscis_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
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
12
  date: 2018-04-10 00:00:00.000000000 Z
@@ -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
- rubyforge_project:
92
- rubygems_version: 2.7.3
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: []