Module: Chef::Knife::EcKeyBase
- Included in:
- EcKeyExport, EcKeyImport
- Defined in:
- lib/chef/knife/ec_key_base.rb
Class Method Summary collapse
Instance Method Summary collapse
- #db ⇒ Object
-
#load_config_from_file! ⇒ Object
Loads SQL user and password from running config if not passed as a command line option.
- #sql_password ⇒ Object
- #veil ⇒ Object
- #veil_config ⇒ Object
Class Method Details
.included(includer) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 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 |
# File 'lib/chef/knife/ec_key_base.rb', line 25 def self.included(includer) includer.class_eval do deps do require 'sequel' require 'json' end option :sql_host, :long => '--sql-host HOSTNAME', :description => 'Postgresql database hostname (default: localhost)', :default => "localhost" option :sql_port, :long => '--sql-port PORT', :description => 'Postgresql database port (default: 5432)', :default => 5432 option :sql_db, :long => '--sql-db DBNAME', :description => 'Postgresql Chef Server database name (default: opscode_chef)', :default => "opscode_chef" option :sql_user, :long => "--sql-user USERNAME", :description => 'User used to connect to the postgresql database.' option :sql_password, :long => "--sql-password PASSWORD", :description => 'Password used to connect to the postgresql database' option :secrets_file_path, :long => '--secrets-file PATH', :description => 'Path to a valid private-chef-secrets.json file (default: /etc/opscode/private-chef-secrets.json)', :default => '/etc/opscode/private-chef-secrets.json' option :skip_keys_table, :long => "--skip-keys-table", :description => "Skip Chef 12-only keys table", :default => false option :skip_users_table, :long => "--skip-users-table", :description => "Skip users table", :default => false end end |
Instance Method Details
#db ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/chef/knife/ec_key_base.rb', line 73 def db @db ||= begin require 'sequel' server_string = "#{config[:sql_user]}:#{config[:sql_password]}@#{config[:sql_host]}:#{config[:sql_port]}/#{config[:sql_db]}" ::Sequel.connect("postgres://#{server_string}", :convert_infinite_timestamps => :string) end end |
#load_config_from_file! ⇒ Object
Loads SQL user and password from running config if not passed as a command line option
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/chef/knife/ec_key_base.rb', line 83 def load_config_from_file! if ! File.exists?("/etc/opscode/chef-server-running.json") ui.fatal "SQL User or Password not provided as option and running config cannot be found!" exit 1 else running_config ||= JSON.parse(File.read("/etc/opscode/chef-server-running.json")) # Latest versions of chef server put the database info under opscode-erchef.sql_user hash_key = if running_config['private_chef']['opscode-erchef'].has_key? 'sql_user' 'opscode-erchef' else 'postgresql' end config[:sql_user] ||= running_config['private_chef'][hash_key]['sql_user'] config[:sql_password] ||= sql_password end end |
#sql_password ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/chef/knife/ec_key_base.rb', line 109 def sql_password if config[:sql_password] config[:sql_password] elsif veil.exist?("opscode_erchef", "sql_password") veil.get("opscode_erchef", "sql_password") else veil.exist?("postgresql", "sql_password") veil.get("postgresql", "sql_password") end end |
#veil ⇒ Object
105 106 107 |
# File 'lib/chef/knife/ec_key_base.rb', line 105 def veil Veil::CredentialCollection.from_config(veil_config) end |
#veil_config ⇒ Object
100 101 102 103 |
# File 'lib/chef/knife/ec_key_base.rb', line 100 def veil_config { provider: 'chef-secrets-file', path: config[:secrets_file_path] } end |