Class: Chef::ChefFS::FileSystem::DataBagsDir
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
#_make_child_entry, #environment, #org, #rest
Methods inherited from BaseFSDir
#dir?
#chef_object, #compare_to, #delete, #dir?, #exists?, #path_for_printing, #read, #root, #write
Constructor Details
Returns a new instance of DataBagsDir.
26
27
28
|
# File 'lib/chef/chef_fs/file_system/data_bags_dir.rb', line 26
def initialize(parent)
super("data_bags", parent, "data")
end
|
Instance Method Details
#can_have_child?(name, is_dir) ⇒ Boolean
51
52
53
|
# File 'lib/chef/chef_fs/file_system/data_bags_dir.rb', line 51
def can_have_child?(name, is_dir)
is_dir
end
|
#child(name) ⇒ Object
30
31
32
33
|
# File 'lib/chef/chef_fs/file_system/data_bags_dir.rb', line 30
def child(name)
result = @children.select { |child| child.name == name }.first if @children
result || DataBagDir.new(name, self)
end
|
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/chef/chef_fs/file_system/data_bags_dir.rb', line 35
def children
begin
@children ||= root.get_json(api_path).keys.sort.map do |entry|
DataBagDir.new(entry, self, true)
end
rescue Timeout::Error => e
raise Chef::ChefFS::FileSystem::OperationFailedError.new(:children, self, e), "Timeout getting children: #{e}"
rescue Net::HTTPServerException => 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
end
|
#create_child(name, file_contents) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/chef/chef_fs/file_system/data_bags_dir.rb', line 55
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::HTTPServerException => 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
|