Class: Promote::Uploader

Inherits:
Object
  • Object
show all
Defined in:
lib/promote/uploader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Uploader

Returns a new instance of Uploader.



6
7
8
9
# File 'lib/promote/uploader.rb', line 6

def initialize(config)
  @config = config
  validate_config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



31
32
33
# File 'lib/promote/uploader.rb', line 31

def config
  @config
end

Instance Method Details

#upload_cookbook(cookbook_name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/promote/uploader.rb', line 11

def upload_cookbook(cookbook_name)
  berks_name = File.join(config.cookbook_directory, cookbook_name, "Berksfile")
  upload_dir = config.cookbook_directory
  if File.exist?(berks_name)
    FileUtils.rm_rf(config.temp_directory) if Dir.exist?(config.temp_directory)
    berksfile = Berkshelf::Berksfile.from_file(berks_name)
    berksfile.vendor(config.temp_directory)
    upload_dir = config.temp_directory
  end

  knife = Chef::Knife::CookbookUpload.new()
  Chef::Config.reset
  Chef::Config[:client_key] = config.client_key
  Chef::Config[:chef_server_url] = config.chef_server_url
  Chef::Config[:node_name] = config.node_name
  knife.config[:all] = true
  knife.config[:cookbook_path] = upload_dir
  knife.run
end