module QC

Constants

AccessKeyId
CERT_FILE
Key
VERSION
Zone

Public Class Methods

hmac(key, data) click to toggle source
# File lib/qc.rb, line 53
def QC.hmac key, data
  hmac = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), key, data)
  b64_hmac = Base64.encode64(hmac).strip
  url_b64_hmac = CGI.escape(b64_hmac)
end
load_config(key) click to toggle source
# File lib/qc.rb, line 12
def QC.load_config key
  f = File.expand_path('~/.qingcloud/config.yaml')
  if File.exists? f
    config = YAML.load(File.open(f))
    if config.has_key? key
      config[key]
    else
      raise "'#{key}' is missing in configuration file"
    end
  else
    puts "'#{f}' doesn't exist!"
    print "Do you want to create it? (Y/n)"
    a = $stdin.gets.strip
    if a == 'n'
      puts "No configuration file!"
      exit
    elsif a.downcase == 'y' or a == ''
      h = {}
      print 'Secret Key:'
      h['qy_secret_access_key'] = $stdin.gets.strip
      print 'Access Key ID:'
      h['qy_access_key_id'] = $stdin.gets.strip
      print 'Zone:'
      h['zone'] = $stdin.gets.strip
      begin
        FileUtils.mkdir_p(File.dirname(f))
        File.new(f, 'w+').puts YAML.dump(h)
        puts "Configuration file was created!"
      rescue Exception => e
        raise "Configuration file couldn't be created! (#{e.class}: #{e.message})"
      end
      exit
    end
  end
end