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
- #empty? ⇒ Boolean
-
#initialize(name:) ⇒ Service
constructor
A new instance of Service.
- #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
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/aide/service.rb', line 41 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 |
#empty? ⇒ Boolean
105 106 107 |
# File 'lib/aide/service.rb', line 105 def empty? service.to_h.empty? end |
#password ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/aide/service.rb', line 81 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
77 78 79 |
# File 'lib/aide/service.rb', line 77 def password_key config[:password_key] end |
#protocol ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/aide/service.rb', line 95 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
91 92 93 |
# File 'lib/aide/service.rb', line 91 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 |
# 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 end |
#url! ⇒ Object
35 36 37 38 39 |
# File 'lib/aide/service.rb', line 35 def url! self.url.tap do |orig_url| raise MissingService.new(name) if orig_url.nil? end end |
#user ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/aide/service.rb', line 67 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
63 64 65 |
# File 'lib/aide/service.rb', line 63 def user_key config[:user_key] end |