Class: ConsulDo::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/consul_do/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



8
9
10
11
12
13
14
# File 'lib/consul_do/config.rb', line 8

def initialize
  @host = 'localhost'
  @port = '8500'
  @key = 'consul_do'
  @http_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
  parse
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



6
7
8
# File 'lib/consul_do/config.rb', line 6

def host
  @host
end

#http_proxyObject

Returns the value of attribute http_proxy.



6
7
8
# File 'lib/consul_do/config.rb', line 6

def http_proxy
  @http_proxy
end

#keyObject

Returns the value of attribute key.



6
7
8
# File 'lib/consul_do/config.rb', line 6

def key
  @key
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/consul_do/config.rb', line 6

def port
  @port
end

#tokenObject

Returns the value of attribute token.



6
7
8
# File 'lib/consul_do/config.rb', line 6

def token
  @token
end

#verboseObject

Returns the value of attribute verbose.



6
7
8
# File 'lib/consul_do/config.rb', line 6

def verbose
  @verbose
end

Instance Method Details

#http_clientObject



44
45
46
47
48
49
50
# File 'lib/consul_do/config.rb', line 44

def http_client
  if proxy.host && proxy.port
    ConsulDo.log "http_client", net_http_proxy
  else
    ConsulDo.log "http_client", Net::HTTP
  end
end

#net_http_proxyObject



40
41
42
# File 'lib/consul_do/config.rb', line 40

def net_http_proxy
  Net::HTTP.Proxy(proxy.host, proxy.port, proxy.user, proxy.password)
end

#parseObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/consul_do/config.rb', line 16

def parse
  OptionParser.new do |opts|
    opts.banner = "Usage: consul-do OPTIONS"
    opts.on("-k", "--key KEY=consul_do", "Coordination key"){ |v| self.key = v }
    opts.on("-h", "--consul-host HOST=localhost", "Consul hostname"){ |v| self.host = v }
    opts.on("-p", "--consul-port PORT=8500", "Consul port"){ |v| self.port = v }
    opts.on("-t", "--token TOKEN", "ACL Token"){ |v| self.token = v }
    opts.on("--http_proxy http://HOST:PORT", "Use supplied proxy instead of ENV "){ |v| self.http_proxy = v }
    opts.on("-v", "--verbose", "Consul port"){ |v| self.verbose = v }
  end.parse!
end

#proxyObject



28
29
30
31
32
33
34
# File 'lib/consul_do/config.rb', line 28

def proxy
  begin
    URI.parse(http_proxy)
  rescue URI::InvalidURIError
    URI::Generic.new(nil,nil,nil,nil,nil,nil,nil,nil,nil)
  end
end

#session_nameObject



36
37
38
# File 'lib/consul_do/config.rb', line 36

def session_name
  "consul-do_#{key}_session"
end