Class: ChefAPI::Resource::User

Inherits:
Base
  • Object
show all
Defined in:
lib/chef-api/resources/user.rb

Instance Attribute Summary

Attributes inherited from Base

#associations

Class Method Summary collapse

Methods inherited from Base

#_attributes, #_prefix, all, #attribute?, build, classname, collection, collection_path, connection, count, create, delete, #destroy, destroy, destroy_all, #diff, #dirty?, #errors, exists?, expanded_collection_path, fetch, from_file, from_json, from_url, has_many, #id, #ignore_attribute?, #initialize, inspect, #inspect, list, #new_resource?, post, #primary_key, protect, #protected?, protected_resources, put, #reload!, resource_path, #resource_path, #save, #save!, schema, #to_hash, #to_json, to_s, #to_s, type, update, #update, #update_attribute, #valid?, #validate!, #validators

Constructor Details

This class inherits a constructor from ChefAPI::Resource::Base

Class Method Details

.authenticate(options = {}) ⇒ Hash

Note:

Requires Enterprise Chef

Authenticate a user with the given username and password.

Examples:

Authenticate a user

User.authenticate(username: 'user', password: 'pass')
  #=> { "status" => "linked", "user" => { ... } }

Parameters:

  • options (Hash) (defaults to: {})

    the list of options to authenticate with

Options Hash (options):

  • username (String)

    the username to authenticate with

  • password (String)

    the plain-text password to authenticate with

Returns:

  • (Hash)

    the parsed JSON response from the server



77
78
79
# File 'lib/chef-api/resources/user.rb', line 77

def authenticate(options = {})
  connection.post('/authenticate_user', options.to_json)
end

.each(prefix = {}, &block) ⇒ Object

See Also:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/chef-api/resources/user.rb', line 35

def each(prefix = {}, &block)
  users = collection(prefix)

  # HEC/EC returns a slightly different response than OSC/CZ
  if users.is_a?(Array)
    users.each do |info|
      name = URI.escape(info['user']['username'])
      response = connection.get("/users/#{name}")
      result = from_json(response, prefix)

      block.call(result) if block
    end
  else
    users.each do |_, path|
      response = connection.get(path)
      result = from_json(response, prefix)

      block.call(result) if block
    end
  end
end