Class: Chef::ChefFS::FileSystem::OrganizationInvitesEntry

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

Overview

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

  • GET /organizations/NAME/association_requests

write data to:

  • remove from list: DELETE /organizations/NAME/association_requests/id

  • add to list: POST /organizations/NAME/association_requests

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, #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) ⇒ OrganizationInvitesEntry

Returns a new instance of OrganizationInvitesEntry.



15
16
17
18
# File 'lib/chef/chef_fs/file_system/organization_invites_entry.rb', line 15

def initialize(name, parent, exists = nil)
  super(name, parent)
  @exists = exists
end

Instance Method Details

#api_pathObject

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



25
26
27
# File 'lib/chef/chef_fs/file_system/organization_invites_entry.rb', line 25

def api_path
  File.join(parent.api_path, 'association_requests')
end

#data_handlerObject



20
21
22
# File 'lib/chef/chef_fs/file_system/organization_invites_entry.rb', line 20

def data_handler
  Chef::ChefFS::DataHandler::OrganizationInvitesDataHandler.new
end

#delete(recurse) ⇒ Object



33
34
35
# File 'lib/chef/chef_fs/file_system/organization_invites_entry.rb', line 33

def delete(recurse)
  raise Chef::ChefFS::FileSystem::OperationNotAllowedError.new(:delete, self)
end

#exists?Boolean

Returns:

  • (Boolean)


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

def exists?
  parent.exists?
end

#write(contents) ⇒ Object



37
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/organization_invites_entry.rb', line 37

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