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
# 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'
  end
end

Instance Method Details

#dbObject



53
54
55
56
57
58
# File 'lib/chef/knife/ec_key_base.rb', line 53

def db
  @db ||= begin
            server_string = "#{config[:sql_user]}:#{config[:sql_password]}@#{config[:sql_host]}:#{config[:sql_port]}/opscode_chef"
            Sequel.connect("postgres://#{server_string}")
          end
end

#load_config_from_file!Object

Loads SQL user and password from running config if not passed as a command line option



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

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