Class: Chef::ChefFS::FileSystem::AclEntry

Inherits:
RestListEntry show all
Defined in:
lib/chef/chef_fs/file_system/acl_entry.rb

Constant Summary collapse

PERMISSIONS =
%w(create read update delete grant)

Instance Attribute Summary

Attributes inherited from BaseFSObject

#name, #parent, #path

Instance Method Summary collapse

Methods inherited from RestListEntry

#_read_json, #api_child_name, #api_error_text, #chef_object, #compare_to, #data_handler, #environment, #exists?, #initialize, #minimize_value, #org, #read, #rest

Methods inherited from BaseFSObject

#can_have_child?, #chef_object, #child, #children, #compare_to, #create_child, #dir?, #exists?, #initialize, #path_for_printing, #read, #root

Constructor Details

This class inherits a constructor from Chef::ChefFS::FileSystem::RestListEntry

Instance Method Details

#api_pathObject



30
31
32
# File 'lib/chef/chef_fs/file_system/acl_entry.rb', line 30

def api_path
  "#{super}/_acl"
end

#delete(recurse) ⇒ Object



34
35
36
# File 'lib/chef/chef_fs/file_system/acl_entry.rb', line 34

def delete(recurse)
  raise Chef::ChefFS::FileSystem::OperationNotAllowedError.new(:delete, self), "ACLs cannot be deleted."
end

#write(file_contents) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/chef/chef_fs/file_system/acl_entry.rb', line 38

def write(file_contents)
  # ACL writes are fun.
  acls = data_handler.normalize(Chef::JSONCompat.parse(file_contents), self)
  PERMISSIONS.each do |permission|
    begin
      rest.put("#{api_path}/#{permission}", { permission => acls[permission] })
    rescue Timeout::Error => e
      raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, e), "Timeout writing: #{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(:write, self, e), "HTTP error writing: #{e}"
      end
    end
  end
end