Class: Chef::Provider::ChefOrganization

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

Defined Under Namespace

Classes: OrganizationDataHandler

Instance Method Summary collapse

Instance Method Details

#data_handlerObject



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

def data_handler
  OrganizationDataHandler.new
end

#existing_membersObject



61
62
63
# File 'lib/chef/provider/chef_organization.rb', line 61

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

#invites_to_removeObject



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/chef/provider/chef_organization.rb', line 75

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



131
132
133
134
135
136
# File 'lib/chef/provider/chef_organization.rb', line 131

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

#load_current_resourceObject



107
108
109
110
111
112
113
114
115
116
117
# File 'lib/chef/provider/chef_organization.rb', line 107

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



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/chef/provider/chef_organization.rb', line 87

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



65
66
67
68
69
70
71
72
73
# File 'lib/chef/provider/chef_organization.rb', line 65

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



123
124
125
# File 'lib/chef/provider/chef_organization.rb', line 123

def resource_class
  Chef::Resource::ChefOrganization
end

#whyrun_supported?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/chef/provider/chef_organization.rb', line 7

def whyrun_supported?
  true
end