Class: Chef::Knife::ConfigList

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

Direct Known Subclasses

ConfigListProfiles

Constant Summary

Constants inherited from Chef::Knife

CHEF_ORGANIZATION_MANAGEMENT, KNIFE_ROOT, OFFICIAL_PLUGINS, OPSCODE_HOSTED_CHEF_ACCESS_CONTROL, VERSION

Instance Attribute Summary

Attributes inherited from Chef::Knife

#name_args, #ui

Instance Method Summary collapse

Methods inherited from Chef::Knife

#api_key, #apply_computed_config, category, chef_config_dir, common_name, #config_file_defaults, #config_file_settings, config_loader, #config_source, #create_object, #delete_object, dependency_loaders, deps, #format_rest_error, guess_category, #humanize_exception, #humanize_http_exception, inherited, #initialize, list_commands, load_commands, load_config, load_deps, #maybe_setup_fips, #merge_configs, msg, #noauth_rest, #parse_options, reset_config_loader!, reset_subcommands!, #rest, #root_rest, run, #run_with_pretty_exceptions, #server_url, #show_usage, snake_case_name, subcommand_category, subcommand_class_from, subcommand_files, subcommand_loader, subcommands, subcommands_by_category, #test_mandatory_field, ui, unnamed?, use_separate_defaults?, #username

Constructor Details

This class inherits a constructor from Chef::Knife

Instance Method Details

#configure_chefObject



39
40
41
# File 'lib/chef/knife/config_list.rb', line 39

def configure_chef
  apply_computed_config
end

#runObject



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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/chef/knife/config_list.rb', line 43

def run
  credentials_data = self.class.config_loader.parse_credentials_file
  if credentials_data.nil? || credentials_data.empty?
    # Should this just show the ambient knife.rb config as "default" instead?
    ui.fatal("No profiles found, #{self.class.config_loader.credentials_file_path} does not exist or is empty")
    exit 1
  end

  current_profile = self.class.config_loader.credentials_profile(config[:profile])
  profiles = credentials_data.keys.map do |profile|
    if config[:ignore_knife_rb]
      # Don't do any fancy loading nonsense, just the raw data.
      profile_data = credentials_data[profile]
      {
        profile: profile,
        active: profile == current_profile,
        client_name: profile_data["client_name"] || profile_data["node_name"],
        client_key: profile_data["client_key"],
        server_url: profile_data["chef_server_url"],
      }
    else
      # Fancy loading nonsense so we get what the actual config would be.
      # Note that this modifies the global config, after this, all bets are
      # off as to whats in the config.
      Chef::Config.reset
      wcl = Chef::WorkstationConfigLoader.new(nil, Chef::Log, profile: profile)
      wcl.load
      {
        profile: profile,
        active: profile == current_profile,
        client_name: Chef::Config[:node_name],
        client_key: Chef::Config[:client_key],
        server_url: Chef::Config[:chef_server_url],
      }
    end
  end

  # Try to reset the config.
  unless config[:ignore_knife_rb]
    Chef::Config.reset
    apply_computed_config
  end

  if ui.interchange?
    # Machine-readable output.
    ui.output(profiles)
  else
    # Table output.
    ui.output(render_table(profiles))
  end
end