class Chef::ChefFS::FileSystem::ChefServer::OrganizationInvitesEntry

/organizations/NAME/invitations.json read data from:

write data to:

Public Class Methods

new(name, parent, exists = nil) click to toggle source
Calls superclass method
# File lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb, line 16
def initialize(name, parent, exists = nil)
  super(name, parent)
  @exists = exists
end

Public Instance Methods

api_path() click to toggle source

/organizations/foo/invites.json -> /organizations/foo/association_requests

# File lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb, line 26
def api_path
  File.join(parent.api_path, "association_requests")
end
data_handler() click to toggle source
# File lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb, line 21
def data_handler
  Chef::ChefFS::DataHandler::OrganizationInvitesDataHandler.new
end
delete(recurse) click to toggle source
# File lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb, line 38
def delete(recurse)
  raise Chef::ChefFS::FileSystem::OperationNotAllowedError.new(:delete, self)
end
display_path() click to toggle source
# File lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb, line 30
def display_path
  "/invitations.json"
end
exists?() click to toggle source
# File lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb, line 34
def exists?
  parent.exists?
end
write(contents) click to toggle source
# File lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb, line 42
def write(contents)
  desired_invites = minimize_value(Chef::JSONCompat.parse(contents, :create_additions => false))
  actual_invites = _read_json.inject({}) { |h, val| h[val["username"]] = val["id"]; h }
  invites = actual_invites.keys
  (desired_invites - invites).each do |invite|
    begin
      rest.post(api_path, { "user" => invite })
    rescue Net::HTTPServerException => e
      if e.response.code == "409"
        Chef::Log.warn("Could not invite #{invite} to organization #{org}: #{api_error_text(e.response)}")
      else
        raise
      end
    end
  end
  (invites - desired_invites).each do |invite|
    rest.delete(File.join(api_path, actual_invites[invite]))
  end
end