Module: QC
Defined Under Namespace
Modules: API
Classes: DataType, Eip, Image, Instance, KeyPair, Volume
Constant Summary
collapse
- VERSION =
'0.0.10'
- CERT_FILE =
File.open(File.join(File.dirname(__FILE__), "qingcloud.com.cert.pem")).readlines.join
- Key =
QC.load_config('qy_secret_access_key')
- AccessKeyId =
QC.load_config('qy_access_key_id')
- Zone =
QC.load_config('zone')
Class Method Summary
collapse
Class Method Details
.hmac(key, data) ⇒ Object
53
54
55
56
57
|
# 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) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# 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
|