aide 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c01f8d45784fd63a3cdc2b22cf2a8994951e968
4
- data.tar.gz: 74089e428c739b10404e253119b7a694d6d9d1aa
3
+ metadata.gz: 594b97487398ab5462e49e81809708ff410c9483
4
+ data.tar.gz: 56d6e52bea45352b5729bcbe7a4c8d67c8e8a968
5
5
  SHA512:
6
- metadata.gz: 5f93664c613e9d839ec7766bdb164d6f483b737fb38210a867c615c036332df6af635003607fa271013df16939379ecf03e0174a21d570fae75c36c8b086cd6e
7
- data.tar.gz: dccf0c39e44413b0048532de41fa53f72f906e56e49529b1a29509386470f4cff47eeebb31db08c6fb70777dc1aa4cc9aad2bbac879638069334728c7b631831
6
+ metadata.gz: 14a0faf679c5c972812149364215336f385a713d8ef37005c4428d6f5e5aa251a5997e332effdd951918c0c9bb8aee7d008ac9a708138e9f625ca13d11a65dc5
7
+ data.tar.gz: d77fc8fcc7c7e69e994072c1af3871494ccd3b85638c0e0be95829ec8d1cb326c8b5deb5146b1543896c03049e2549f49c6edd030bed7509fe230a456af8bb4d
data/lib/aide.rb CHANGED
@@ -27,7 +27,7 @@ module Aide
27
27
 
28
28
  puts "Aide Services (Using #{config.service_address_key}):"
29
29
  self.services.each do |name, service|
30
- puts "==> #{name}: #{service.address}#{service.port.nil? ? '' : ":#{service.port}"} #{service.url(filtered: true)}".strip
30
+ puts "==> #{name}: #{service.address}#{service.port.nil? ? '' : ":#{service.port}"} #{service.display_url(filtered: true)}".strip
31
31
  end
32
32
  end
33
33
 
data/lib/aide/config.rb CHANGED
@@ -25,14 +25,17 @@ module Aide
25
25
  self.service_address_method = SERVICE_ADDRESS_METHOD
26
26
  end
27
27
 
28
- def add_service(name:, url:nil, auth:nil, user_key:nil, password_key:nil, protocol_key:nil)
28
+ def add_service(name:, url:nil, auth:nil, user_key:nil, password_key:nil, protocol_key:nil, multi_url:nil, node:nil, database_key:nil)
29
29
  services[name] = {
30
30
  name: name,
31
31
  url: url,
32
+ multi_url: multi_url,
32
33
  auth: auth,
33
34
  user_key: user_key,
34
35
  password_key: password_key,
35
- protocol_key: protocol_key
36
+ protocol_key: protocol_key,
37
+ node: node,
38
+ database_key: database_key
36
39
  }
37
40
  end
38
41
 
data/lib/aide/service.rb CHANGED
@@ -28,6 +28,7 @@ module Aide
28
28
  template.gsub!(/{{\.ServicePort}}/, self.ServicePort.to_s)
29
29
  template.gsub!(/{{\.port}}/, self.port.to_s)
30
30
  template.gsub!(/{{\.auth}}/, self.auth(filtered: filtered).to_s)
31
+ template.gsub!(/{{\.database}}/, self.database.to_s)
31
32
 
32
33
  template
33
34
  end
@@ -38,6 +39,35 @@ module Aide
38
39
  end
39
40
  end
40
41
 
42
+ def multi_url(filtered: false)
43
+ return if empty?
44
+
45
+ template = config[:multi_url]
46
+ return if template.nil?
47
+
48
+ template = template.dup
49
+ template.gsub!(/{{\.protocol}}/, self.protocol.to_s)
50
+ template.gsub!(/{{\.auth}}/, self.auth(filtered: filtered).to_s)
51
+ template.gsub!(/{{\.database}}/, self.database.to_s)
52
+ template.gsub!(/{{\.nodes}}/, self.nodes.to_s)
53
+
54
+ template
55
+ end
56
+
57
+ def multi_url!
58
+ self.multi_url.tap do |orig_url|
59
+ raise MissingService.new(name) if orig_url.nil?
60
+ end
61
+ end
62
+
63
+ def display_url(filtered: false)
64
+ if !config[:multi_url].nil?
65
+ multi_url(filtered: filtered)
66
+ else
67
+ url(filtered: filtered)
68
+ end
69
+ end
70
+
41
71
  def auth(filtered: false)
42
72
  template = config[:auth]
43
73
 
@@ -60,6 +90,34 @@ module Aide
60
90
  template
61
91
  end
62
92
 
93
+ def nodes
94
+ return if empty?
95
+
96
+ template = config[:node]
97
+ return if template.nil?
98
+
99
+ services.map do |service|
100
+ self.node(service)
101
+ end.join(',')
102
+ end
103
+
104
+ def node(node_service=service)
105
+ template = config[:node]
106
+ return if template.nil?
107
+
108
+ template = template.dup
109
+ template.gsub!(/{{.address}}/, node_service.send(Aide.config.service_address_method).to_s)
110
+ template.gsub!(/{{.port}}/, node_service.ServicePort.to_s)
111
+
112
+ template
113
+ end
114
+
115
+ def node!
116
+ self.node.tap do |orig_node|
117
+ raise MissingService.new(name) if orig_node.nil?
118
+ end
119
+ end
120
+
63
121
  def user_key
64
122
  config[:user_key]
65
123
  end
@@ -102,6 +160,20 @@ module Aide
102
160
  end
103
161
  end
104
162
 
163
+ def database_key
164
+ config[:database_key]
165
+ end
166
+
167
+ def database
168
+ return if database_key.nil?
169
+
170
+ @database ||= begin
171
+ database = Diplomat::Kv.get(database_key, {}, :return)
172
+ database = nil if database == ""
173
+ database
174
+ end
175
+ end
176
+
105
177
  def empty?
106
178
  service.to_h.empty?
107
179
  end
@@ -111,6 +183,10 @@ module Aide
111
183
  @service ||= Diplomat::Service.get(name)
112
184
  end
113
185
 
186
+ def services
187
+ @services || Diplomat::Service.get(name, :all)
188
+ end
189
+
114
190
  def config
115
191
  @config ||= Aide.config.get_service(name: name)
116
192
  end
data/lib/aide/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Aide
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aide
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Schlesinger
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-02 00:00:00.000000000 Z
11
+ date: 2016-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler