Class: Diplomat::Configuration

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

Overview

Methods for configuring Diplomat

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url = Configuration.parse_consul_addr, acl_token = ENV['CONSUL_HTTP_TOKEN'], options = {}) ⇒ Configuration

Override defaults for configuration

Parameters:

  • url (String) (defaults to: Configuration.parse_consul_addr)

    consul’s connection URL

  • acl_token (String) (defaults to: ENV['CONSUL_HTTP_TOKEN'])

    a connection token used when making requests to consul

  • options (Hash) (defaults to: {})

    extra options to configure Faraday::Connection



22
23
24
25
26
27
# File 'lib/diplomat/configuration.rb', line 22

def initialize(url = Configuration.parse_consul_addr, acl_token = ENV['CONSUL_HTTP_TOKEN'], options = {})
  @middleware = []
  @url = url
  @acl_token = acl_token
  @options = options
end

Instance Attribute Details

#acl_tokenObject

Returns the value of attribute acl_token.



7
8
9
# File 'lib/diplomat/configuration.rb', line 7

def acl_token
  @acl_token
end

#middlewareObject

Returns the value of attribute middleware.



6
7
8
# File 'lib/diplomat/configuration.rb', line 6

def middleware
  @middleware
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/diplomat/configuration.rb', line 7

def options
  @options
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/diplomat/configuration.rb', line 7

def url
  @url
end

Class Method Details

.parse_consul_addrObject

Get the most appropriate consul agent value from env Parse the environment variable ‘CONSUL_HTTP_ADDR` and prefixes it with http:// if needed Return default localhost:8500 if not found



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

def self.parse_consul_addr
  ret = ENV['CONSUL_HTTP_ADDR'] || 'http://localhost:8500'
  ret = "http://#{ret}" unless ret.start_with?('http://', 'https://')
  ret
end