Class: Cyclid::Client::Config

Inherits:
Object
  • Object
show all
Includes:
AuthMethods
Defined in:
lib/cyclid/config.rb

Overview

Cyclid client per-organization configuration

Constant Summary

Constants included from AuthMethods

AuthMethods::AUTH_NONE

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.

Parameters:

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

Options Hash (options):

  • :path (String)

    Fully qualified path to the configuration file

  • :auth (FixNum)

    Authentication method

  • :username (String)

    Users username.

  • :secret (String)

    Users secret for use with HMAC authentication.

  • :password (String)

    Users password for use with HTTP Basic authentication.

  • :token (String)

    Users API token for use with Token authentication.

  • :server (String)

    API server address.

  • :port (Integer)

    API server port.

  • :organization (String)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/cyclid/config.rb', line 54

def initialize(options = {})
  # Load the config if a path was provided
  @path = options[:path] || nil
  @config = @path.nil? ? nil : YAML.load_file(@path)

  # Select the authentication type & associated authentication data.
  @auth = options[:auth] || AUTH_HMAC
  case @auth
  when AUTH_NONE
    # Nothing
  when AUTH_HMAC
    @secret = options[:secret] || @config['secret']
  when AUTH_BASIC
    @password = options[:password] || @config['password']
  when AUTH_TOKEN
    @token = options[:token] || @config['token']
  end

  # Set defaults from the options
  @server = options[:server] || nil
  @port = options[:port] || nil
  @organization = options[:organization] || nil
  @username = options[:username] || nil

  # Get anything provided in the config file
  if @config
    @server ||= @config['server']
    @port ||= @config['port'] || 8361
    @organization ||= @config['organization']
    @username ||= @config['username']
  end

  # Server & Username *must* be set
  raise 'server address must be provided' if @server.nil?
  raise 'username must be provided' if @username.nil? and @auth != AUTH_NONE
end

Instance Attribute Details

#authObject (readonly)

Returns the value of attribute auth.



22
23
24
# File 'lib/cyclid/config.rb', line 22

def auth
  @auth
end

#organizationObject (readonly)

Returns the value of attribute organization.



22
23
24
# File 'lib/cyclid/config.rb', line 22

def organization
  @organization
end

#passwordObject (readonly)

Returns the value of attribute password.



22
23
24
# File 'lib/cyclid/config.rb', line 22

def password
  @password
end

#pathObject (readonly)

Returns the value of attribute path.



22
23
24
# File 'lib/cyclid/config.rb', line 22

def path
  @path
end

#portObject (readonly)

Returns the value of attribute port.



22
23
24
# File 'lib/cyclid/config.rb', line 22

def port
  @port
end

#secretObject (readonly)

Returns the value of attribute secret.



22
23
24
# File 'lib/cyclid/config.rb', line 22

def secret
  @secret
end

#serverObject (readonly)

Returns the value of attribute server.



22
23
24
# File 'lib/cyclid/config.rb', line 22

def server
  @server
end

#tokenObject (readonly)

Returns the value of attribute token.



22
23
24
# File 'lib/cyclid/config.rb', line 22

def token
  @token
end

#usernameObject (readonly)

Returns the value of attribute username.



22
23
24
# File 'lib/cyclid/config.rb', line 22

def username
  @username
end