Class: Imperium::Configuration

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/imperium/configuration.rb

Overview

The Configuration class represents the values necessary for making contact with a Consul agent.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url: 'http://localhost:8500', token: nil) ⇒ Configuration

Returns a new instance of Configuration.



30
31
32
33
34
35
36
# File 'lib/imperium/configuration.rb', line 30

def initialize(url: 'http://localhost:8500', token: nil)
  @url = Addressable::URI.parse(url)
  @connect_timeout = 5
  @send_timeout = 15
  @receive_timeout = 60
  @token = token
end

Instance Attribute Details

#connect_timeoutInteger

to open before failing, default: 5

Returns:

  • (Integer)

    The number of seconds to wait for a connection to Consul



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/imperium/configuration.rb', line 24

class Configuration
  extend Forwardable

  attr_reader :url
  attr_accessor :connect_timeout, :receive_timeout, :send_timeout, :token

  def initialize(url: 'http://localhost:8500', token: nil)
    @url = Addressable::URI.parse(url)
    @connect_timeout = 5
    @send_timeout = 15
    @receive_timeout = 60
    @token = token
  end

  def_delegators :@url, :host, :host=, :port, :port=

  # Check if the specified URL is using SSL/TLS
  # @return [Boolean]
  def ssl?
    @url.scheme == 'https'
  end

  # Configure the clients to use SSL/TLS (or not).
  #
  # @param value [Boolean]
  # @raise [NoMethodError] When the URL has previously been set to nil.
  def ssl=(value)
    @url.scheme = (!!value ? 'https' : 'http')
  end

  # Check for the presence of a token
  # @return [Boolean]
  def token?
    @token && !@token.empty?
  end

  # Set the URL
  #
  # This method will append a trailing slash to the supplied URL if not
  # included. We're doing this because merging a path onto a URL missing the
  # trailing slash will remove any extant path components.
  #
  # @param value [String, Addressable::URI, URI::GenericURI] The new value to use.
  def url=(value)
    if value.nil?
      @url = nil
    else
      @url = Addressable::URI.parse(value)
      @url.path << '/' unless @url.path.end_with?('/')
    end
  end
end

#receive_timeoutInteger

to open before failing, default: 60. This default is quite high in order to support long polling.

Returns:

  • (Integer)

    The number of seconds to wait for a response from Consul



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/imperium/configuration.rb', line 24

class Configuration
  extend Forwardable

  attr_reader :url
  attr_accessor :connect_timeout, :receive_timeout, :send_timeout, :token

  def initialize(url: 'http://localhost:8500', token: nil)
    @url = Addressable::URI.parse(url)
    @connect_timeout = 5
    @send_timeout = 15
    @receive_timeout = 60
    @token = token
  end

  def_delegators :@url, :host, :host=, :port, :port=

  # Check if the specified URL is using SSL/TLS
  # @return [Boolean]
  def ssl?
    @url.scheme == 'https'
  end

  # Configure the clients to use SSL/TLS (or not).
  #
  # @param value [Boolean]
  # @raise [NoMethodError] When the URL has previously been set to nil.
  def ssl=(value)
    @url.scheme = (!!value ? 'https' : 'http')
  end

  # Check for the presence of a token
  # @return [Boolean]
  def token?
    @token && !@token.empty?
  end

  # Set the URL
  #
  # This method will append a trailing slash to the supplied URL if not
  # included. We're doing this because merging a path onto a URL missing the
  # trailing slash will remove any extant path components.
  #
  # @param value [String, Addressable::URI, URI::GenericURI] The new value to use.
  def url=(value)
    if value.nil?
      @url = nil
    else
      @url = Addressable::URI.parse(value)
      @url.path << '/' unless @url.path.end_with?('/')
    end
  end
end

#send_timeoutInteger

finish uploading to Consul to open before failing, default: 15.

Returns:

  • (Integer)

    The number of seconds to wait for the request body to



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/imperium/configuration.rb', line 24

class Configuration
  extend Forwardable

  attr_reader :url
  attr_accessor :connect_timeout, :receive_timeout, :send_timeout, :token

  def initialize(url: 'http://localhost:8500', token: nil)
    @url = Addressable::URI.parse(url)
    @connect_timeout = 5
    @send_timeout = 15
    @receive_timeout = 60
    @token = token
  end

  def_delegators :@url, :host, :host=, :port, :port=

  # Check if the specified URL is using SSL/TLS
  # @return [Boolean]
  def ssl?
    @url.scheme == 'https'
  end

  # Configure the clients to use SSL/TLS (or not).
  #
  # @param value [Boolean]
  # @raise [NoMethodError] When the URL has previously been set to nil.
  def ssl=(value)
    @url.scheme = (!!value ? 'https' : 'http')
  end

  # Check for the presence of a token
  # @return [Boolean]
  def token?
    @token && !@token.empty?
  end

  # Set the URL
  #
  # This method will append a trailing slash to the supplied URL if not
  # included. We're doing this because merging a path onto a URL missing the
  # trailing slash will remove any extant path components.
  #
  # @param value [String, Addressable::URI, URI::GenericURI] The new value to use.
  def url=(value)
    if value.nil?
      @url = nil
    else
      @url = Addressable::URI.parse(value)
      @url.path << '/' unless @url.path.end_with?('/')
    end
  end
end

#tokenString

APIs. Defaults to ‘nil`

Returns:

  • (String)

    The token to be used when making requests to the Consul



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/imperium/configuration.rb', line 24

class Configuration
  extend Forwardable

  attr_reader :url
  attr_accessor :connect_timeout, :receive_timeout, :send_timeout, :token

  def initialize(url: 'http://localhost:8500', token: nil)
    @url = Addressable::URI.parse(url)
    @connect_timeout = 5
    @send_timeout = 15
    @receive_timeout = 60
    @token = token
  end

  def_delegators :@url, :host, :host=, :port, :port=

  # Check if the specified URL is using SSL/TLS
  # @return [Boolean]
  def ssl?
    @url.scheme == 'https'
  end

  # Configure the clients to use SSL/TLS (or not).
  #
  # @param value [Boolean]
  # @raise [NoMethodError] When the URL has previously been set to nil.
  def ssl=(value)
    @url.scheme = (!!value ? 'https' : 'http')
  end

  # Check for the presence of a token
  # @return [Boolean]
  def token?
    @token && !@token.empty?
  end

  # Set the URL
  #
  # This method will append a trailing slash to the supplied URL if not
  # included. We're doing this because merging a path onto a URL missing the
  # trailing slash will remove any extant path components.
  #
  # @param value [String, Addressable::URI, URI::GenericURI] The new value to use.
  def url=(value)
    if value.nil?
      @url = nil
    else
      @url = Addressable::URI.parse(value)
      @url.path << '/' unless @url.path.end_with?('/')
    end
  end
end

#urlAddressable::URI

the Consul agent. Defaults to ‘localhost:8500`

Returns:

  • (Addressable::URI)

    The base URL, including port, for contacting



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/imperium/configuration.rb', line 24

class Configuration
  extend Forwardable

  attr_reader :url
  attr_accessor :connect_timeout, :receive_timeout, :send_timeout, :token

  def initialize(url: 'http://localhost:8500', token: nil)
    @url = Addressable::URI.parse(url)
    @connect_timeout = 5
    @send_timeout = 15
    @receive_timeout = 60
    @token = token
  end

  def_delegators :@url, :host, :host=, :port, :port=

  # Check if the specified URL is using SSL/TLS
  # @return [Boolean]
  def ssl?
    @url.scheme == 'https'
  end

  # Configure the clients to use SSL/TLS (or not).
  #
  # @param value [Boolean]
  # @raise [NoMethodError] When the URL has previously been set to nil.
  def ssl=(value)
    @url.scheme = (!!value ? 'https' : 'http')
  end

  # Check for the presence of a token
  # @return [Boolean]
  def token?
    @token && !@token.empty?
  end

  # Set the URL
  #
  # This method will append a trailing slash to the supplied URL if not
  # included. We're doing this because merging a path onto a URL missing the
  # trailing slash will remove any extant path components.
  #
  # @param value [String, Addressable::URI, URI::GenericURI] The new value to use.
  def url=(value)
    if value.nil?
      @url = nil
    else
      @url = Addressable::URI.parse(value)
      @url.path << '/' unless @url.path.end_with?('/')
    end
  end
end

Instance Method Details

#ssl=(value) ⇒ Object

Configure the clients to use SSL/TLS (or not).

Parameters:

  • value (Boolean)

Raises:

  • (NoMethodError)

    When the URL has previously been set to nil.



50
51
52
# File 'lib/imperium/configuration.rb', line 50

def ssl=(value)
  @url.scheme = (!!value ? 'https' : 'http')
end

#ssl?Boolean

Check if the specified URL is using SSL/TLS

Returns:

  • (Boolean)


42
43
44
# File 'lib/imperium/configuration.rb', line 42

def ssl?
  @url.scheme == 'https'
end

#token?Boolean

Check for the presence of a token

Returns:

  • (Boolean)


56
57
58
# File 'lib/imperium/configuration.rb', line 56

def token?
  @token && !@token.empty?
end