Class: Chef::Knife::EcKeyExport
Instance Method Summary
collapse
Methods included from EcKeyBase
#db, included, #load_config_from_file!, #sql_password, #veil, #veil_config
Instance Method Details
#export(table, path) ⇒ Object
60
61
62
63
|
# File 'lib/chef/knife/ec_key_export.rb', line 60
def export(table, path)
data = db.select.from(table)
File.open(path, 'w') { |file| file.write(data.all.to_json) }
end
|
#export_keys(path) ⇒ Object
55
56
57
58
|
# File 'lib/chef/knife/ec_key_export.rb', line 55
def export_keys(path)
data = db.fetch('SELECT keys_by_name.*, orgs.name AS "org_name" FROM keys_by_name LEFT JOIN orgs ON keys_by_name.org_id=orgs.id')
File.open(path, 'w') { |file| file.write(data.all.to_json) }
end
|
#run ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/chef/knife/ec_key_export.rb', line 30
def run
if config[:sql_user].nil? || config[:sql_password].nil?
load_config_from_file!
end
user_data_path = @name_args[0] || "key_dump.json"
key_data_path = @name_args[1] || "key_table_dump.json"
export(:users, user_data_path) unless config[:skip_users_table]
begin
export_keys(key_data_path) unless config[:skip_keys_table]
rescue Sequel::DatabaseError => e
if e.message =~ /^PG::UndefinedTable/
ui.error "Keys table not found. The keys table only exists on Chef Server 12."
ui.error "Chef Server 11 users should use the --skip-keys-table option to avoid this error."
exit 1
else
raise
end
end
end
|