Class: Chef::Knife::UserTarDownload

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.download_users(tar_file) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/chef/knife/user_tar_download.rb', line 27

def self.download_users(tar_file)
  dir = tar_file.web_users_path
  Chef::WebUIUser.list.each do |component_name, url|
    Chef::Log.info("Backing up user #{component_name}")
    component_obj = Chef::WebUIUser.load(component_name)
    File.open(File.join(dir, "#{component_name}.json"), "w") do |component_file|
      component_file.print(component_obj.to_json)
    end
  end
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/chef/knife/user_tar_download.rb', line 13

def run
  #Get Arguments
  if @name_args.size != 1
    ui.info("Please specify a tar path")
    show_usage
    exit 1
  end
  
  tar_file = Chef::TarFile.new(@name_args.first, true)
  UserTarDownload.download_users tar_file
  tar_file.save
  
end