Class: Chef::ChefFS::FileSystem::ChefServer::OrganizationMembersEntry
- Inherits:
-
RestListEntry
- Object
- BaseFSObject
- RestListEntry
- Chef::ChefFS::FileSystem::ChefServer::OrganizationMembersEntry
- Defined in:
- lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb
Overview
/organizations/NAME/members.json reads data from:
-
GET /organizations/NAME/users
writes data to:
-
remove from list: DELETE /organizations/NAME/users/name
-
add to list: POST /organizations/NAME/users/name
Instance Attribute Summary
Attributes inherited from BaseFSObject
Instance Method Summary collapse
-
#api_path ⇒ Object
/organizations/foo/members.json -> /organizations/foo/users.
- #data_handler ⇒ Object
- #delete(recurse) ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(name, parent, exists = nil) ⇒ OrganizationMembersEntry
constructor
A new instance of OrganizationMembersEntry.
- #write(contents) ⇒ Object
Methods inherited from RestListEntry
#_read_json, #api_child_name, #api_error_text, #chef_object, #compare_to, #environment, #minimize_value, #org, #read, #rest
Methods inherited from BaseFSObject
#can_have_child?, #chef_object, #child, #children, #compare_to, #create_child, #dir?, #path_for_printing, #read, #root
Constructor Details
#initialize(name, parent, exists = nil) ⇒ OrganizationMembersEntry
Returns a new instance of OrganizationMembersEntry.
16 17 18 19 |
# File 'lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb', line 16 def initialize(name, parent, exists = nil) super(name, parent) @exists = exists end |
Instance Method Details
#api_path ⇒ Object
/organizations/foo/members.json -> /organizations/foo/users
26 27 28 |
# File 'lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb', line 26 def api_path File.join(parent.api_path, "users") end |
#data_handler ⇒ Object
21 22 23 |
# File 'lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb', line 21 def data_handler Chef::ChefFS::DataHandler::OrganizationMembersDataHandler.new end |
#delete(recurse) ⇒ Object
34 35 36 |
# File 'lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb', line 34 def delete(recurse) raise Chef::ChefFS::FileSystem::OperationNotAllowedError.new(:delete, self) end |
#exists? ⇒ Boolean
30 31 32 |
# File 'lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb', line 30 def exists? parent.exists? end |
#write(contents) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb', line 38 def write(contents) desired_members = minimize_value(Chef::JSONCompat.parse(contents, :create_additions => false)) members = minimize_value(_read_json) (desired_members - members).each do |member| begin rest.post(api_path, "username" => member) rescue Net::HTTPServerException => e if %w{404 405}.include?(e.response.code) raise "Chef server at #{api_path} does not allow you to directly add members. Please either upgrade your Chef server or move the users you want into invitations.json instead of members.json." else raise end end end (members - desired_members).each do |member| rest.delete(File.join(api_path, member)) end end |