Class: Chef::ChefFS::FileSystem::ChefServer::DataBagsDir

Inherits:
RestListDir show all
Defined in:
lib/chef/chef_fs/file_system/chef_server/data_bags_dir.rb

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 RestListDir

#environment, #initialize, #org, #rest

Methods inherited from BaseFSDir

#dir?, #empty?, #initialize

Methods inherited from BaseFSObject

#chef_object, #child, #compare_to, #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)


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

def can_have_child?(name, is_dir)
  is_dir
end

#childrenObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/chef/chef_fs/file_system/chef_server/data_bags_dir.rb', line 32

def children
  @children ||= root.get_json(api_path).keys.sort.map { |entry| make_child_entry(entry, true) }
rescue Timeout::Error => e
  raise Chef::ChefFS::FileSystem::OperationFailedError.new(:children, self, e, "Timeout getting children: #{e}")
rescue Net::HTTPClientException => e
  if e.response.code == "404"
    raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e)
  else
    raise Chef::ChefFS::FileSystem::OperationFailedError.new(:children, self, e, "HTTP error getting children: #{e}")
  end
end

#create_child(name, file_contents) ⇒ Object



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

def create_child(name, file_contents)
  begin
    rest.post(api_path, { "name" => name })
  rescue Timeout::Error => e
    raise Chef::ChefFS::FileSystem::OperationFailedError.new(:create_child, self, e, "Timeout creating child '#{name}': #{e}")
  rescue Net::HTTPClientException => e
    if e.response.code == "409"
      raise Chef::ChefFS::FileSystem::AlreadyExistsError.new(:create_child, self, e, "Cannot create #{name} under #{path}: already exists")
    else
      raise Chef::ChefFS::FileSystem::OperationFailedError.new(:create_child, self, e, "HTTP error creating child '#{name}': #{e}")
    end
  end
  @children = nil
  DataBagDir.new(name, self, true)
end

#make_child_entry(name, exists = false) ⇒ Object



27
28
29
30
# File 'lib/chef/chef_fs/file_system/chef_server/data_bags_dir.rb', line 27

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