Class: VcoWorkflows::Config
- Inherits:
-
Object
- Object
- VcoWorkflows::Config
- Defined in:
- lib/vcoworkflows/config.rb,
lib/vcoworkflows/constants.rb
Overview
Class Config
Constant Summary collapse
- DEFAULT_CONFIG_DIR =
Where we nominally expect configuration files to be
File.join((ENV['HOME'] || ENV['HOMEDRIVE']), '.vcoworkflows')
- DEFAULT_CONFIG_FILE =
Default configuration file
File.join(DEFAULT_CONFIG_DIR, 'config.json')
Instance Attribute Summary collapse
-
#password ⇒ Object
Password to authenticate to vCenter Orchestrator.
-
#url ⇒ Object
URL for the vCenter Orchestrator REST API.
-
#username ⇒ Object
User name to authenticate to vCenter Orchestrator.
-
#verify_ssl ⇒ Object
Whether or not to do SSL/TLS Certificate verification.
Instance Method Summary collapse
-
#initialize(config_file: nil, url: nil, username: nil, password: nil, verify_ssl: true) ⇒ VcoWorkflows::Config
constructor
Constructor.
-
#load_config(config_file) ⇒ Object
load config file.
-
#to_json ⇒ Object
Return a JSON document for this object.
-
#to_s ⇒ String
Return a String representation of this object.
Constructor Details
#initialize(config_file: nil, url: nil, username: nil, password: nil, verify_ssl: true) ⇒ VcoWorkflows::Config
Constructor
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/vcoworkflows/config.rb', line 29 def initialize(config_file: nil, url: nil, username: nil, password: nil, verify_ssl: true) # If we're given a URL and no config_file, then build the configuration # from the values we're given (or can scrape from the environment). # Otherwise, load the given config file or the default config file if no # config file was given. if url && config_file.nil? self.url = url @username = username.nil? ? ENV['VCO_USER'] : username @password = password.nil? ? ENV['VCO_PASSWD'] : password @verify_ssl = verify_ssl else # First, check if an explicit config file was given config_file = DEFAULT_CONFIG_FILE if config_file.nil? load_config(config_file) end # Fail if we don't have both a username and a password. raise(IOError, ERR[:url_unset]) if @url.nil? raise(IOError, ERR[:username_unset]) if @username.nil? raise(IOError, ERR[:password_unset]) if @password.nil? end |
Instance Attribute Details
#password ⇒ Object
Password to authenticate to vCenter Orchestrator
15 16 17 |
# File 'lib/vcoworkflows/config.rb', line 15 def password @password end |
#url ⇒ Object
URL for the vCenter Orchestrator REST API
9 10 11 |
# File 'lib/vcoworkflows/config.rb', line 9 def url @url end |
#username ⇒ Object
User name to authenticate to vCenter Orchestrator
12 13 14 |
# File 'lib/vcoworkflows/config.rb', line 12 def username @username end |
#verify_ssl ⇒ Object
Whether or not to do SSL/TLS Certificate verification
18 19 20 |
# File 'lib/vcoworkflows/config.rb', line 18 def verify_ssl @verify_ssl end |
Instance Method Details
#load_config(config_file) ⇒ Object
load config file
63 64 65 66 67 68 69 70 |
# File 'lib/vcoworkflows/config.rb', line 63 def load_config(config_file) config_data = JSON.parse(File.read(config_file)) return if config_data.nil? self.url = config_data['url'] @username = config_data['username'] @password = config_data['password'] @verify_ssl = config_data['verify_ssl'] end |
#to_json ⇒ Object
Return a JSON document for this object
82 83 84 85 86 87 88 89 |
# File 'lib/vcoworkflows/config.rb', line 82 def to_json config = {} config['url'] = @url config['username'] = @username config['password'] = @password config['verify_ssl'] = @verify_ssl puts JSON.pretty_generate(config) end |
#to_s ⇒ String
Return a String representation of this object
74 75 76 77 78 79 |
# File 'lib/vcoworkflows/config.rb', line 74 def to_s puts "url: #{@url}" puts "username: #{@username}" puts "password: #{@password}" puts "verify_ssl: #{@verify_ssl}" end |