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

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
# 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_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 :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

#dbObject



63
64
65
66
67
68
69
# File 'lib/chef/knife/ec_key_base.rb', line 63

def db
  @db ||= begin
            require 'sequel'
            server_string = "#{config[:sql_user]}:#{config[:sql_password]}@#{config[:sql_host]}:#{config[:sql_port]}/opscode_chef"
            ::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



73
74
75
76
77
78
79
80
81
82
# File 'lib/chef/knife/ec_key_base.rb', line 73

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"))
    config[:sql_user] ||= running_config['private_chef']['postgresql']['sql_user']
    config[:sql_password] ||= running_config['private_chef']['postgresql']['sql_password']
  end
end