Class: SoftLayer::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/softlayer/Config.rb

Constant Summary collapse

FILE_LOCATIONS =
['/etc/softlayer.conf', '~/.softlayer']

Class Method Summary collapse

Class Method Details

.client_settings(provided_settings = {}) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/softlayer/Config.rb', line 68

def Config.client_settings(provided_settings = {})
  settings = file_settings
  settings.merge! environment_settings
  settings.merge! globals_settings
  settings.merge! provided_settings

  settings
end

.environment_settingsObject



35
36
37
38
39
40
# File 'lib/softlayer/Config.rb', line 35

def Config.environment_settings
  result = {}
  result[:username] =  ENV["SL_USERNAME"] if ENV["SL_USERNAME"]
  result[:api_key] = ENV["SL_API_KEY"] if ENV["SL_API_KEY"]
  result
end

.file_settings(*additional_files) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/softlayer/Config.rb', line 44

def Config.file_settings(*additional_files)
  result = {}

  search_path = FILE_LOCATIONS
  search_path = search_path + additional_files if additional_files
  search_path = search_path.map { |file_path| File.expand_path(file_path) }

  search_path.each do |file_path|

    if File.readable? file_path
      config = ConfigParser.new file_path
      softlayer_section = config["softlayer"]

      if softlayer_section
        result[:username] = softlayer_section['username'] if softlayer_section['username']
        result[:endpoint_url] = softlayer_section['endpoint_url'] if softlayer_section['endpoint_url']
        result[:api_key] = softlayer_section['api_key'] if softlayer_section['api_key']
      end
    end
  end

  result
end

.globals_settingsObject



27
28
29
30
31
32
33
# File 'lib/softlayer/Config.rb', line 27

def Config.globals_settings
  result = {}
  result[:username] =  $SL_API_USERNAME if $SL_API_USERNAME
  result[:api_key] = $SL_API_KEY if $SL_API_KEY
  result[:endpoint_url] = $SL_API_BASE_URL ? $SL_API_BASE_URL : API_PUBLIC_ENDPOINT
  result
end