Class: Chef::ChefFS::FileSystem::ChefServer::VersionedCookbooksDir

Inherits:
CookbooksDir show all
Defined in:
lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb

Overview

/cookbooks or /cookbook_artifacts

Example children of /cookbooks:

  • apache2-1.0.0

  • apache2-1.0.1

  • mysql-2.0.5

Example children of /cookbook_artifacts:

  • apache2-ab234098245908ddf324a

  • apache2-295387a9823745feff239

  • mysql-1a2b9e1298734dfe90444

Instance Attribute Summary

Attributes inherited from RestListDir

#api_path, #data_handler

Attributes inherited from BaseFSObject

#name, #parent, #path

Instance Method Summary collapse

Methods inherited from CookbooksDir

#create_child_from, #upload_cookbook_from, #with_actual_cookbooks_dir

Methods included from Mixin::FileClass

#file_class

Methods inherited from RestListDir

#create_child, #environment, #initialize, #org, #rest

Methods inherited from BaseFSDir

#dir?, #empty?, #initialize

Methods inherited from BaseFSObject

#chef_object, #child, #compare_to, #create_child, #delete, #dir?, #exists?, #initialize, #path_for_printing, #read, #root, #write

Constructor Details

This class inherits a constructor from Chef::ChefFS::FileSystem::ChefServer::RestListDir

Instance Method Details

#can_have_child?(name, is_dir) ⇒ Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb', line 104

def can_have_child?(name, is_dir)
  is_dir && name =~ Chef::ChefFS::FileSystem::ChefServer::VersionedCookbookDir::VALID_VERSIONED_COOKBOOK_NAME
end

#chef_restObject



100
101
102
# File 'lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb', line 100

def chef_rest
  Chef::ServerAPI.new(root.chef_rest.url, root.chef_rest.options.merge(version_class: Chef::CookbookManifestVersions))
end

#childrenObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb', line 48

def children
  @children ||= begin
    result = []
    root.get_json("#{api_path}/?num_versions=all").each_pair do |cookbook_name, cookbooks|
      cookbooks["versions"].each do |cookbook_version|
        result << VersionedCookbookDir.new("#{cookbook_name}-#{cookbook_version["version"]}", self)
      end
    end
    result.sort_by(&:name)
  end
end

#make_child_entry(name) ⇒ Object



43
44
45
46
# File 'lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb', line 43

def make_child_entry(name)
  result = @children.find { |child| child.name == name } if @children
  result || VersionedCookbookDir.new(name, self)
end

#upload_cookbook(other, options) ⇒ Object

Knife currently does not understand versioned cookbooks Cookbook Version uploader also requires a lot of refactoring to make this work. So instead, we make a temporary cookbook symlinking back to real cookbook, and upload the proxy.



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
94
95
96
97
98
# File 'lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb', line 64

def upload_cookbook(other, options)
  cookbook_name = Chef::ChefFS::FileSystem::Repository::ChefRepositoryFileSystemCookbookDir.canonical_cookbook_name(other.name)

  Dir.mktmpdir do |temp_cookbooks_path|
    proxy_cookbook_path = "#{temp_cookbooks_path}/#{cookbook_name}"

    # Make a symlink
    file_class.symlink other.file_path, proxy_cookbook_path

    # Instantiate a proxy loader using the temporary symlink
    proxy_loader = Chef::Cookbook::CookbookVersionLoader.new(proxy_cookbook_path, other.chefignore)
    proxy_loader.load!

    cookbook_to_upload = proxy_loader.cookbook_version
    cookbook_to_upload.freeze_version if options[:freeze]

    # Instantiate a new uploader based on the proxy loader
    uploader = Chef::CookbookUploader.new(cookbook_to_upload, force: options[:force], rest: chef_rest)

    with_actual_cookbooks_dir(temp_cookbooks_path) do
      uploader.upload_cookbooks
    end

    #
    # When the temporary directory is being deleted on
    # windows, the contents of the symlink under that
    # directory is also deleted. So explicitly remove
    # the symlink without removing the original contents if we
    # are running on windows
    #
    if ChefUtils.windows?
      Dir.rmdir proxy_cookbook_path
    end
  end
end