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

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

Constant Summary collapse

PERMISSIONS =
%w{create read update delete grant}.freeze

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, #display_name, #environment, #exists?, #initialize, #minimize_value, #normalize_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::ChefServer::RestListEntry

Instance Method Details

#api_pathObject



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

def api_path
  "#{super}/_acl"
end

#delete(recurse) ⇒ Object



42
43
44
# File 'lib/chef/chef_fs/file_system/chef_server/acl_entry.rb', line 42

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

#display_pathObject



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

def display_path
  pth = if parent.name == "acls"
          "/acls/#{name}"
        else
          "/acls/#{parent.name}/#{name}"
        end
  File.extname(pth).empty? ? pth + ".json" : pth
end

#write(file_contents) ⇒ Object



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

def write(file_contents)
  # ACL writes are fun.
  acls = data_handler.normalize(Chef::JSONCompat.parse(file_contents), self)
  PERMISSIONS.each do |permission|

    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::HTTPClientException => 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