Revision c5dc6a3c
src/cli/one_helper.rb | ||
---|---|---|
37 | 37 |
|
38 | 38 |
if ONE_LOCATION |
39 | 39 |
TABLE_CONF_PATH=ONE_LOCATION+"/etc/cli" |
40 |
VAR_LOCATION=ONE_LOCATION+"/var" if !defined?(VAR_LOCATION) |
|
40 | 41 |
else |
41 | 42 |
TABLE_CONF_PATH="/etc/one/cli" |
43 |
VAR_LOCATION="/var/lib/one" if !defined?(VAR_LOCATION) |
|
42 | 44 |
end |
43 | 45 |
|
44 | 46 |
EDITOR_PATH='/usr/bin/vi' |
... | ... | |
489 | 491 |
end |
490 | 492 |
end |
491 | 493 |
|
494 |
|
|
495 |
# receive a object key => value format |
|
496 |
# returns hashed values |
|
497 |
def encrypt(opts) |
|
498 |
|
|
499 |
res = {} |
|
500 |
key_one= File.read(VAR_LOCATION+'/.one/one_key') |
|
501 |
|
|
502 |
opts.each do |key, value| |
|
503 |
cipher = OpenSSL::Cipher::AES.new(256,:CBC) |
|
504 |
cipher.encrypt.key = key_one |
|
505 |
puts "cifrando #{key}" |
|
506 |
encrypted = cipher.update(value) + cipher.final |
|
507 |
#res.merge!({key => value}) |
|
508 |
res[key] = Base64::encode64(encrypted) |
|
509 |
puts "encriptado es: "+encrypted |
|
510 |
end |
|
511 |
|
|
512 |
return res |
|
513 |
end |
|
514 |
|
|
515 |
def decrypt(res) |
|
516 |
opts = {} |
|
517 |
key_one= File.read(VAR_LOCATION+'/.one/one_key') |
|
518 |
|
|
519 |
res.each do |key, encrypted_value| |
|
520 |
decipher = OpenSSL::Cipher::AES.new(256,:CBC) |
|
521 |
decipher.decrypt |
|
522 |
decipher.key = key_one |
|
523 |
puts "desencriptando #{key}" |
|
524 |
plain = decipher.update(Base64::decode64(encrypted_value)) + decipher.final |
|
525 |
puts "una vez desencriptado es "+plain |
|
526 |
opts[key] = plain |
|
527 |
end |
|
528 |
|
|
529 |
return opts |
|
530 |
|
|
531 |
end |
|
532 |
|
|
533 |
|
|
534 |
|
|
492 | 535 |
def list_pool(options, top=false, filter_flag=nil) |
493 | 536 |
if options[:describe] |
494 | 537 |
table = format_pool(options) |
src/cli/onehost | ||
---|---|---|
32 | 32 |
require 'command_parser' |
33 | 33 |
require 'one_helper/onehost_helper' |
34 | 34 |
require 'one_helper/onecluster_helper' |
35 |
require 'ec2_driver' |
|
36 | 35 |
|
37 | 36 |
cmd=CommandParser::CmdParser.new(ARGV) do |
38 | 37 |
usage "`onehost` <command> [<args>] [<options>]" |
... | ... | |
124 | 123 |
STDERR.puts "\t -v hypervisor driver" |
125 | 124 |
exit -1 |
126 | 125 |
end |
126 |
|
|
127 |
ec2_host = !options[:ec2access].nil? && !options[:ec2secret].nil? |
|
127 | 128 |
|
128 |
encrypt(options) |
|
129 |
if ec2_host |
|
130 |
ec2_opts = { |
|
131 |
:access => options[:ec2access], |
|
132 |
:secret => options[:ec2secret] |
|
133 |
} |
|
129 | 134 |
|
130 |
cid = options[:cluster] || ClusterPool::NONE_CLUSTER_ID |
|
135 |
encrypt_opts = helper.encrypt(ec2_opts) |
|
136 |
helper.decrypt(encrypt_opts) |
|
137 |
|
|
138 |
end |
|
131 | 139 |
|
140 |
cid = options[:cluster] || ClusterPool::NONE_CLUSTER_ID |
|
132 | 141 |
helper.create_resource(options) do |host| |
133 | 142 |
host.allocate(args[0], |
134 | 143 |
options[:im], |
135 | 144 |
options[:vm], |
136 | 145 |
cid) |
146 |
#template="" |
|
147 |
#encrypt_opts.each do |key, value| |
|
148 |
# template << "#{key}=\"+value\"\n"\ |
|
149 |
#end |
|
150 |
|
|
151 |
template = "EC2_ACCESS=\"#{encrypt_opts[:access]}\"\n"\ |
|
152 |
"EC2_SECRET=\"#{encrypt_opts[:secret]}\"\n"\ |
|
153 |
|
|
154 |
host.update(template, true) |
|
155 |
|
|
156 |
|
|
137 | 157 |
end |
138 | 158 |
end |
139 | 159 |
|
Also available in: Unified diff