Class: Aide::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/aide/service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/aide/service.rb', line 3

def name
  @name
end

Instance Method Details

#addressObject



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

Returns:

  • (Boolean)


105
106
107
# File 'lib/aide/service.rb', line 105

def empty?
  service.to_h.empty?
end

#passwordObject



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_keyObject



77
78
79
# File 'lib/aide/service.rb', line 77

def password_key
  config[:password_key]
end

#protocolObject



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_keyObject



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

#userObject



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_keyObject



63
64
65
# File 'lib/aide/service.rb', line 63

def user_key
  config[:user_key]
end