Class: Chef::Knife::EcKeyImport
Instance Method Summary
collapse
Methods included from EcKeyBase
#db, included, #load_config_from_file!
Instance Method Details
#import(path) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/chef/knife/ec_key_import.rb', line 46
def import(path)
key_data = JSON.parse(File.read(path))
key_data.each do |d|
username = d['username']
key = d['public_key']
version = d['pubkey_version']
hashed_password = d['hashed_password']
hash_type = d['hash_type']
salt = d['salt']
if username == 'pivotal' && config[:skip_pivotal]
ui.warn "Skipping pivotal user."
next
end
ui.msg "Updating key for #{username}"
users_to_update = db[:users].where(:username => username)
if users_to_update.count != 1
ui.warn "Wrong number of users to update for #{username}. Skipping"
else
users_to_update.update(:public_key => key,
:pubkey_version => version,
:salt => salt,
:hashed_password => hashed_password,
:hash_type => hash_type)
end
end
end
|
#run ⇒ Object
36
37
38
39
40
41
42
43
|
# File 'lib/chef/knife/ec_key_import.rb', line 36
def run
if config[:sql_user].nil? || config[:sql_password].nil?
load_config_from_file!
end
path = @name_args[0] || "key_dump.json"
import(path)
end
|