Class: ChefWebui::Knife

Inherits:
Chef::Knife show all
Defined in:
lib/chef_webui/knife.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.common_optionsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/chef_webui/knife.rb', line 7

def self.common_options
  option :username,
    :long => '--username USERNAME',
    :description => 'Hosted Chef Username'

  option :password,
    :long => '--password PASSWORD',
    :description => 'Hosted Chef Password'

  option :manage_url,
    :long => '--manage-url URL',
    :description => 'Hosted Chef Manage URL (default: https://manage.opscode.com)'

  option :account_url,
    :long => '--account-url URL',
    :description => 'Hosted Chef Account URL (default: https://www.opscode.com)'
end

Instance Method Details

#configure_chefObject



32
33
34
35
36
37
38
# File 'lib/chef_webui/knife.rb', line 32

def configure_chef
  super
  init_config_variable(:manage_url, 'https://manage.opscode.com')
  init_config_variable(:account_url, 'https://www.opscode.com')
  init_config_variable(:username)
  init_config_variable(:password)
end

#init_config_variable(variable_name, default = nil) ⇒ Object



25
26
27
28
29
30
# File 'lib/chef_webui/knife.rb', line 25

def init_config_variable(variable_name, default = nil)
  Chef::Config[variable_name] = config[variable_name] if config[variable_name]
  if default
    Chef::Config[variable_name] ||= default
  end
end

#webui_sessionObject



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/chef_webui/knife.rb', line 40

def webui_session
  @webui_session ||= begin
    if !Chef::Config[:username]
      Chef::Config[:username] = ask("Enter your username:")
    end
    if !Chef::Config[:password]
      Chef::Config[:password] = ask("Enter your password:") { |q| q.echo = '*' }
    end
    session = ChefWebui::Session.new(Chef::Config[:manage_url], Chef::Config[:account_url])
    session.(Chef::Config[:username], Chef::Config[:password])
    session
  end
end