# class Chef::ChefFS::FileSystem::ChefServerRootDir

### Attributes

chef_private_key[R]
chef_server_url[R]
chef_username[R]
cookbook_version[R]
environment[R]
repo_mode[R]

### Public Class Methods

new(root_name, chef_config, options = {}) click to toggle source
Calls superclass method Chef::ChefFS::FileSystem::BaseFSDir.new

    # File lib/chef/chef_fs/file_system/chef_server_root_dir.rb, line 37
    def initialize(root_name, chef_config, options = {})
      super("", nil)
      @chef_server_url = chef_config[:chef_server_url]
      @chef_username = chef_config[:node_name]
      @chef_private_key = chef_config[:client_key]
      @environment = chef_config[:environment]
      @repo_mode = chef_config[:repo_mode]
      @root_name = root_name
      @cookbook_version = options[:cookbook_version] # Used in knife diff and download for server cookbook version
    end

### Public Instance Methods

api_path() click to toggle source

    # File lib/chef/chef_fs/file_system/chef_server_root_dir.rb, line 71
    def api_path
      ""
    end

can_have_child?(name, is_dir) click to toggle source

    # File lib/chef/chef_fs/file_system/chef_server_root_dir.rb, line 79
    def can_have_child?(name, is_dir)
      is_dir && children.any? { |child| child.name == name }
    end

chef_rest() click to toggle source

    # File lib/chef/chef_fs/file_system/chef_server_root_dir.rb, line 67
    def chef_rest
      Chef::REST.new(chef_server_url, chef_username, chef_private_key)
    end

children() click to toggle source

    # File lib/chef/chef_fs/file_system/chef_server_root_dir.rb, line 91
    def children
      @children ||= begin
        result = [
          CookbooksDir.new(self),
          DataBagsDir.new(self),
          EnvironmentsDir.new(self),
          RestListDir.new("roles", self, nil, Chef::ChefFS::DataHandler::RoleDataHandler.new)
        ]
        if repo_mode == 'hosted_everything'
          result += [
            AclsDir.new(self),
            RestListDir.new("clients", self, nil, Chef::ChefFS::DataHandler::ClientDataHandler.new),
            RestListDir.new("containers", self, nil, Chef::ChefFS::DataHandler::ContainerDataHandler.new),
            RestListDir.new("groups", self, nil, Chef::ChefFS::DataHandler::GroupDataHandler.new),
            NodesDir.new(self)
          ]
        elsif repo_mode != 'static'
          result += [
            RestListDir.new("clients", self, nil, Chef::ChefFS::DataHandler::ClientDataHandler.new),
            NodesDir.new(self),
            RestListDir.new("users", self, nil, Chef::ChefFS::DataHandler::UserDataHandler.new)
          ]
        end
        result.sort_by { |child| child.name }
      end
    end

fs_description() click to toggle source

    # File lib/chef/chef_fs/file_system/chef_server_root_dir.rb, line 55
    def fs_description
      "Chef server at #{chef_server_url} (user #{chef_username}), repo_mode = #{repo_mode}"
    end

get_json(path) click to toggle source

    # File lib/chef/chef_fs/file_system/chef_server_root_dir.rb, line 63
    def get_json(path)
      Chef::ServerAPI.new(chef_server_url, :client_name => chef_username, :signing_key_filename => chef_private_key).get(path)
    end

org() click to toggle source

    # File lib/chef/chef_fs/file_system/chef_server_root_dir.rb, line 83
    def org
      @org ||= if URI.parse(chef_server_url).path =~ /^\/+organizations\/+([^\/]+)$/
        $1
      else
        nil
      end
    end

path_for_printing() click to toggle source

    # File lib/chef/chef_fs/file_system/chef_server_root_dir.rb, line 75
    def path_for_printing
      "#{@root_name}/"
    end

rest() click to toggle source

    # File lib/chef/chef_fs/file_system/chef_server_root_dir.rb, line 59
    def rest
      Chef::ServerAPI.new(chef_server_url, :client_name => chef_username, :signing_key_filename => chef_private_key, :raw_output => true)
    end