Class: Briefbag::Diplomat

Inherits:
Object
  • Object
show all
Defined in:
lib/briefbag/diplomat.rb

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Diplomat

Returns a new instance of Diplomat.



11
12
13
14
15
16
# File 'lib/briefbag/diplomat.rb', line 11

def initialize(config)
  @config = config
  @host = config[:consul_host]
  @port = config[:consul_port].nil? ? 443 : config[:consul_port]
  @consul_folder = "#{config[:environment]}/#{config[:consul_folder]}"
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/briefbag/diplomat.rb', line 9

def config
  @config
end

#consul_folderObject (readonly)

Returns the value of attribute consul_folder.



9
10
11
# File 'lib/briefbag/diplomat.rb', line 9

def consul_folder
  @consul_folder
end

#hostObject (readonly)

Returns the value of attribute host.



9
10
11
# File 'lib/briefbag/diplomat.rb', line 9

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



9
10
11
# File 'lib/briefbag/diplomat.rb', line 9

def port
  @port
end

Instance Method Details

#callObject



18
19
20
21
# File 'lib/briefbag/diplomat.rb', line 18

def call
  configuration
  data_from_consul
end

#configurationObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/briefbag/diplomat.rb', line 23

def configuration
  ::Diplomat.configure do |conf|
    # Set up a custom Consul URL
    conf.url = url_build
    break if config[:consul_token].nil?

    conf.options = {
      ssl: { version: :TLSv1_2 }, # rubocop:disable Naming/VariableNumber
      headers: { 'X-Consul-Token' => config[:consul_token] }
    }
  end
end