Class: Chef::Provider::ChefOrganization

Inherits:
Cheffish::ChefProviderBase show all
Defined in:
lib/chef/provider/chef_organization.rb

Defined Under Namespace

Classes: OrganizationDataHandler

Instance Method Summary collapse

Methods inherited from Cheffish::ChefProviderBase

#apply_modifiers, #apply_run_list_modifiers, #augment_current_json, #augment_new_json, #current_json, #current_resource_exists?, #json_differences, #json_differences_internal, #json_to_resource, #new_json, #normalize, #normalize_for_post, #normalize_for_put, #not_found_resource, #resource_to_json, #rest, #same_run_list_item

Instance Method Details

#data_handlerObject



130
131
132
# File 'lib/chef/provider/chef_organization.rb', line 130

def data_handler
  OrganizationDataHandler.new
end

#existing_membersObject



64
65
66
# File 'lib/chef/provider/chef_organization.rb', line 64

def existing_members
  @existing_members ||= rest.get("#{rest.root_url}/organizations/#{new_resource.name}/users").map { |u| u['user']['username'] }
end

#invites_to_removeObject



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/chef/provider/chef_organization.rb', line 78

def invites_to_remove
  if new_resource.complete
    if new_resource.invites_specified? || new_resource.members_specified?
      outstanding_invites.keys - (new_resource.invites | new_resource.members)
    else
      []
    end
  else
    new_resource.remove_members
  end
end

#keysObject



134
135
136
137
138
139
# File 'lib/chef/provider/chef_organization.rb', line 134

def keys
  {
    'name' => :name,
    'full_name' => :full_name
  }
end

#load_current_resourceObject



110
111
112
113
114
115
116
117
118
119
120
# File 'lib/chef/provider/chef_organization.rb', line 110

def load_current_resource
  begin
    @current_resource = json_to_resource(rest.get("#{rest.root_url}/organizations/#{new_resource.name}"))
  rescue Net::HTTPServerException => e
    if e.response.code == "404"
      @current_resource = not_found_resource
    else
      raise
    end
  end
end

#members_to_removeObject



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/chef/provider/chef_organization.rb', line 90

def members_to_remove
  if new_resource.complete
    if new_resource.members_specified?
      existing_members - (new_resource.invites | new_resource.members)
    else
      []
    end
  else
    new_resource.remove_members
  end
end

#outstanding_invitesObject



68
69
70
71
72
73
74
75
76
# File 'lib/chef/provider/chef_organization.rb', line 68

def outstanding_invites
  @outstanding_invites ||= begin
    invites = {}
    rest.get("#{rest.root_url}/organizations/#{new_resource.name}/association_requests").each do |r|
      invites[r['username']] = r['id']
    end
    invites
  end
end

#resource_classObject

Helpers



126
127
128
# File 'lib/chef/provider/chef_organization.rb', line 126

def resource_class
  Chef::Resource::ChefOrganization
end

#whyrun_supported?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/chef/provider/chef_organization.rb', line 10

def whyrun_supported?
  true
end