Class: Cyclid::Client::Config
- Inherits:
-
Object
- Object
- Cyclid::Client::Config
- Includes:
- AuthMethods
- Defined in:
- lib/cyclid/config.rb
Overview
Cyclid client per-organization configuration
Constant Summary
Constants included from AuthMethods
Instance Attribute Summary collapse
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#organization ⇒ Object
readonly
Returns the value of attribute organization.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#ssl_verify_none ⇒ Object
readonly
Returns the value of attribute ssl_verify_none.
-
#tls ⇒ Object
readonly
Returns the value of attribute tls.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/cyclid/config.rb', line 67 def initialize( = {}) # Load the config if a path was provided @path = [:path] || nil unless File.file?(@path) raise "no config found at #{@path} - Have you selected an organisation with " \ '`cyclid organization use <name>`?' end @config = @path.nil? ? nil : YAML.load_file(@path) # Select the authentication type & associated authentication data. @auth = [:auth] || AUTH_HMAC case @auth when AUTH_NONE # Nothing nil when AUTH_HMAC @secret = [:secret] || @config['secret'] when AUTH_BASIC @password = [:password] || @config['password'] when AUTH_TOKEN @token = [:token] || @config['token'] end # Set defaults from the options @url = [:url] || nil @server = [:server] || nil @port = [:port] || nil @tls = [:tls] || nil @ssl_verify_none = [:ssl_verify_none] || nil @organization = [:organization] || nil @username = [:username] || nil # Get anything provided in the config file if @config @url ||= @config['url'] @server ||= @config['server'] @port ||= @config['port'] || 8361 @tls ||= @config['tls'] || false @ssl_verify_none ||= @config['ssl_verify_none'] || false @organization ||= @config['organization'] @username ||= @config['username'] end # Parse the URL if one was given if @url uri = URI.parse(@url) # Items parsed from the uri always over-write any individual # configuration settings @server = uri.host @port = uri.port @tls = uri.scheme == 'https' ? true : false 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
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
25 26 27 |
# File 'lib/cyclid/config.rb', line 25 def auth @auth end |
#organization ⇒ Object (readonly)
Returns the value of attribute organization.
25 26 27 |
# File 'lib/cyclid/config.rb', line 25 def organization @organization end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
25 26 27 |
# File 'lib/cyclid/config.rb', line 25 def password @password end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
25 26 27 |
# File 'lib/cyclid/config.rb', line 25 def path @path end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
25 26 27 |
# File 'lib/cyclid/config.rb', line 25 def port @port end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
25 26 27 |
# File 'lib/cyclid/config.rb', line 25 def secret @secret end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
25 26 27 |
# File 'lib/cyclid/config.rb', line 25 def server @server end |
#ssl_verify_none ⇒ Object (readonly)
Returns the value of attribute ssl_verify_none.
25 26 27 |
# File 'lib/cyclid/config.rb', line 25 def ssl_verify_none @ssl_verify_none end |
#tls ⇒ Object (readonly)
Returns the value of attribute tls.
25 26 27 |
# File 'lib/cyclid/config.rb', line 25 def tls @tls end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
25 26 27 |
# File 'lib/cyclid/config.rb', line 25 def token @token end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
25 26 27 |
# File 'lib/cyclid/config.rb', line 25 def username @username end |