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
-
#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.
5 6 7 |
# File 'lib/aide/service.rb', line 5 def initialize(name:) @name = name end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/aide/service.rb', line 3 def name @name end |
Instance Method Details
#address ⇒ Object
11 12 13 |
# File 'lib/aide/service.rb', line 11 def address send(Aide.config.service_address_method) end |
#auth(filtered: false) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/aide/service.rb', line 71 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
167 168 169 170 171 172 173 174 175 |
# File 'lib/aide/service.rb', line 167 def database return if database_key.nil? @database ||= begin database = Diplomat::Kv.get(database_key, {}, :return) database = nil if database == "" database end end |
#database_key ⇒ Object
163 164 165 |
# File 'lib/aide/service.rb', line 163 def database_key config[:database_key] end |
#display_url(filtered: false) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/aide/service.rb', line 63 def display_url(filtered: false) if !config[:multi_url].nil? multi_url(filtered: filtered) else url(filtered: filtered) end end |
#empty? ⇒ Boolean
177 178 179 |
# File 'lib/aide/service.rb', line 177 def empty? service.to_h.empty? end |
#multi_url(filtered: false) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/aide/service.rb', line 42 def multi_url(filtered: false) return if empty? template = config[:multi_url] return if template.nil? 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
57 58 59 60 61 |
# File 'lib/aide/service.rb', line 57 def multi_url! self.multi_url.tap do |orig_url| raise MissingService.new(name) if orig_url.nil? end end |
#node(node_service = service) ⇒ Object
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/aide/service.rb', line 104 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
115 116 117 118 119 |
# File 'lib/aide/service.rb', line 115 def node! self.node.tap do |orig_node| raise MissingService.new(name) if orig_node.nil? end end |
#nodes ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/aide/service.rb', line 93 def nodes return if empty? template = config[:node] return if template.nil? services.map do |service| self.node(service) end.join(',') end |
#password ⇒ Object
139 140 141 142 143 144 145 146 147 |
# File 'lib/aide/service.rb', line 139 def password return if password_key.nil? @password ||= begin password = Diplomat::Kv.get(password_key, {}, :return) password = nil if password == "" password end end |
#password_key ⇒ Object
135 136 137 |
# File 'lib/aide/service.rb', line 135 def password_key config[:password_key] end |
#protocol ⇒ Object
153 154 155 156 157 158 159 160 161 |
# File 'lib/aide/service.rb', line 153 def protocol return if protocol_key.nil? @protocol ||= begin protocol = Diplomat::Kv.get(protocol_key, {}, :return) protocol = nil if protocol == "" protocol end end |
#protocol_key ⇒ Object
149 150 151 |
# File 'lib/aide/service.rb', line 149 def protocol_key config[:protocol_key] end |
#url(filtered: false) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/aide/service.rb', line 17 def url(filtered: false) return if empty? template = config[:url] return if template.nil? 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
36 37 38 39 40 |
# File 'lib/aide/service.rb', line 36 def url! self.url.tap do |orig_url| raise MissingService.new(name) if orig_url.nil? end end |
#user ⇒ Object
125 126 127 128 129 130 131 132 133 |
# File 'lib/aide/service.rb', line 125 def user return if user_key.nil? @user ||= begin user = Diplomat::Kv.get(user_key, {}, :return) user = nil if user == "" user end end |
#user_key ⇒ Object
121 122 123 |
# File 'lib/aide/service.rb', line 121 def user_key config[:user_key] end |