Class: ScalrApiV2::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/scalr_api_v2/config.rb

Overview

config class

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



4
# File 'lib/scalr_api_v2/config.rb', line 4

def initialize; end

Instance Method Details

#configObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/scalr_api_v2/config.rb', line 15

def config
  config = {}

  if ENV['SCALR_URL'].nil? || ENV['SCALR_KEY_ID'].nil? || ENV['SCALR_KEY_SECRET'].nil?
    config['error'] = 'Missing Environment variables, please configure SCALR_URL, SCALR_KEY_ID, SCALR_KEY_SECRET'
    raise 'Missing Environment variables, please configure SCALR_URL, SCALR_KEY_ID, SCALR_KEY_SECRET'
  else
    config['url'] = ENV['SCALR_URL']
    config['key_id'] = ENV['SCALR_KEY_ID']
    config['key_secret'] = ENV['SCALR_KEY_SECRET']
    config['env_id'] = ENV['SCALR_ENV_ID'].nil? ? nil : ENV['SCALR_ENV_ID']
    config['mode_path'] = mode_path(config['env_id'])
  end
  return config
end

#mode_path(env_id) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/scalr_api_v2/config.rb', line 6

def mode_path(env_id)
  mode = if env_id.nil?
           'account'
         else
           Integer(env_id) >= 0 ? 'user' : 'account'
         end
  return mode == 'account' ? 'account' : "user/#{env_id}"
end