Class: Aide::Service
- Inherits:
-
Object
- Object
- Aide::Service
- Defined in:
- lib/aide/service.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #address ⇒ Object
- #auth(filtered: false) ⇒ Object
- #database ⇒ Object
- #database_key ⇒ Object
- #display_url(filtered: false) ⇒ Object
- #empty? ⇒ Boolean
- #host ⇒ Object
-
#initialize(name:) ⇒ Service
constructor
A new instance of Service.
- #multi_url(filtered: false) ⇒ Object
- #multi_url! ⇒ Object
- #node(node_service = service) ⇒ Object
- #node! ⇒ Object
- #nodes ⇒ Object
- #password ⇒ Object
- #password_key ⇒ Object
- #protocol ⇒ Object
- #protocol_key ⇒ Object
- #url(filtered: false) ⇒ Object
- #url! ⇒ Object
- #user ⇒ Object
- #user_key ⇒ Object
Constructor Details
#initialize(name:) ⇒ Service
Returns a new instance of Service.
7 8 9 |
# File 'lib/aide/service.rb', line 7 def initialize(name:) @name = name end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/aide/service.rb', line 5 def name @name end |
Instance Method Details
#address ⇒ Object
13 14 15 |
# File 'lib/aide/service.rb', line 13 def address send(Aide.config.service_address_method) end |
#auth(filtered: false) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/aide/service.rb', line 85 def auth(filtered: false) template = config[:auth] if template.nil? || self.user.nil? || self.password.nil? return end template = template.dup template.gsub!(/{{\.user}}/, self.user.to_s) password = nil if filtered password = 'PASSWORD' else password = self.password.to_s end template.gsub!(/{{\.password}}/, password) template end |
#database ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/aide/service.rb', line 187 def database return if database_key.nil? return @database if defined?(@database) @database = begin database = Diplomat::Kv.get(database_key, {}, :return) database = nil if database == "" database end end |
#database_key ⇒ Object
183 184 185 |
# File 'lib/aide/service.rb', line 183 def database_key config[:database_key] end |
#display_url(filtered: false) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/aide/service.rb', line 71 def display_url(filtered: false) if !config[:multi_url].nil? multi_url(filtered: filtered) else url(filtered: filtered) end end |
#empty? ⇒ Boolean
199 200 201 |
# File 'lib/aide/service.rb', line 199 def empty? service.to_h.empty? end |
#host ⇒ Object
79 80 81 82 83 |
# File 'lib/aide/service.rb', line 79 def host return address if url.nil? URI.parse(url).host end |
#multi_url(filtered: false) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/aide/service.rb', line 50 def multi_url(filtered: false) template = config[:multi_url] return if template.nil? return if empty? && !config[:allow_missing] template = template.dup template.gsub!(/{{\.protocol}}/, self.protocol.to_s) template.gsub!(/{{\.auth}}/, self.auth(filtered: filtered).to_s) template.gsub!(/{{\.database}}/, self.database.to_s) template.gsub!(/{{\.nodes}}/, self.nodes.to_s) template end |
#multi_url! ⇒ Object
65 66 67 68 69 |
# File 'lib/aide/service.rb', line 65 def multi_url! multi_url.tap do |orig_url| raise MissingService.new(name) if orig_url.nil? end end |
#node(node_service = service) ⇒ Object
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/aide/service.rb', line 118 def node(node_service=service) template = config[:node] return if template.nil? template = template.dup template.gsub!(/{{.address}}/, node_service.send(Aide.config.service_address_method).to_s) template.gsub!(/{{.port}}/, node_service.ServicePort.to_s) template end |
#node! ⇒ Object
129 130 131 132 133 |
# File 'lib/aide/service.rb', line 129 def node! node.tap do |orig_node| raise MissingService.new(name) if orig_node.nil? end end |
#nodes ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/aide/service.rb', line 107 def nodes template = config[:node] return if template.nil? return if empty? && !config[:allow_missing] services.map do |service| self.node(service) end.join(',') end |
#password ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/aide/service.rb', line 155 def password return if password_key.nil? return @password if defined?(@password) @password = begin password = Diplomat::Kv.get(password_key, {}, :return) password = nil if password == "" password end end |
#password_key ⇒ Object
151 152 153 |
# File 'lib/aide/service.rb', line 151 def password_key config[:password_key] end |
#protocol ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/aide/service.rb', line 171 def protocol return if protocol_key.nil? return @protocol if defined?(@protocol) @protocol = begin protocol = Diplomat::Kv.get(protocol_key, {}, :return) protocol = nil if protocol == "" protocol end end |
#protocol_key ⇒ Object
167 168 169 |
# File 'lib/aide/service.rb', line 167 def protocol_key config[:protocol_key] end |
#url(filtered: false) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/aide/service.rb', line 19 def url(filtered: false) template = if !config[:url_env_key].nil? ENV[config[:url_env_key]] else config[:url] end return if template.nil? return if empty? && !config[:allow_missing] template = template.dup template.gsub!(/{{\.protocol}}/, self.protocol.to_s) template.gsub!(/{{\.address}}/, self.address.to_s) template.gsub!(/{{\.Address}}/, self.Address.to_s) template.gsub!(/{{\.ServiceAddress}}/, self.ServiceAddress.to_s) template.gsub!(/{{\.ServicePort}}/, self.ServicePort.to_s) template.gsub!(/{{\.port}}/, self.port.to_s) template.gsub!(/{{\.auth}}/, self.auth(filtered: filtered).to_s) template.gsub!(/{{\.database}}/, self.database.to_s) template end |
#url! ⇒ Object
44 45 46 47 48 |
# File 'lib/aide/service.rb', line 44 def url! self.url.tap do |orig_url| raise MissingService.new(name) if orig_url.nil? end end |
#user ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/aide/service.rb', line 139 def user return if user_key.nil? return @user if defined?(@user) @user = begin user = Diplomat::Kv.get(user_key, {}, :return) user = nil if user == "" user end end |
#user_key ⇒ Object
135 136 137 |
# File 'lib/aide/service.rb', line 135 def user_key config[:user_key] end |