class ChefAPI::Resource::User

Public Class Methods

authenticate(options = {}) click to toggle source

Authenticate a user with the given username and password.

@note Requires Enterprise Chef

@example Authenticate a user

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

@param [Hash] options

the list of options to authenticate with

@option options [String] username

the username to authenticate with

@option options [String] password

the plain-text password to authenticate with

@return [Hash]

the parsed JSON response from the server
# File lib/chef-api/resources/user.rb, line 79
def authenticate(options = {})
  connection.post("/authenticate_user", options.to_json)
end
each(prefix = {}, &block) click to toggle source

@see Base.each

# File lib/chef-api/resources/user.rb, line 37
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 = CGI.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