Class: Inspec::Resources::UserInfo

Inherits:
Object
  • Object
show all
Includes:
Converter
Defined in:
lib/inspec/resources/users.rb

Overview

This is an abstract class that every user provoider has to implement. A user provider implements a system abstracts and helps the InSpec resource hand-over system specific behavior to those providers

Direct Known Subclasses

UnixUser, WindowsUser

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Converter

#convert_to_i, to_boolean

Constructor Details

#initialize(inspec) ⇒ UserInfo

Returns a new instance of UserInfo.



407
408
409
# File 'lib/inspec/resources/users.rb', line 407

def initialize(inspec)
  @inspec = inspec
end

Instance Attribute Details

#inspecObject (readonly)

Returns the value of attribute inspec.



406
407
408
# File 'lib/inspec/resources/users.rb', line 406

def inspec
  @inspec
end

Instance Method Details

#collect_user_detailsObject

returns the full information list for a user



457
458
459
460
461
# File 'lib/inspec/resources/users.rb', line 457

def collect_user_details
  list_users.map do |username|
    user_details(username.chomp)
  end
end

#credentials(_username) ⇒ Object

returns a hash with meta-data about user credentials

mindays: 1,
maxdays: 1,
warndays: 1,

this method is optional and may not be implemented by each provider



435
436
437
# File 'lib/inspec/resources/users.rb', line 435

def credentials(_username)
  nil
end

#identity(_username) ⇒ Object

returns a hash with user-specific values:

uid: '',
user: '',
gid: '',
group: '',
groups: '',



419
420
421
# File 'lib/inspec/resources/users.rb', line 419

def identity(_username)
  raise "user provider must implement the `identity` method"
end

#list_usersObject

returns an array with users



440
441
442
# File 'lib/inspec/resources/users.rb', line 440

def list_users
  raise "user provider must implement the `list_users` method"
end

#meta_info(_username) ⇒ Object

returns optional information about a user, eg shell



424
425
426
# File 'lib/inspec/resources/users.rb', line 424

def meta_info(_username)
  nil
end

#user_details(username) ⇒ Object

retuns all aspects of the user as one hash



445
446
447
448
449
450
451
452
453
454
# File 'lib/inspec/resources/users.rb', line 445

def user_details(username)
  item = {}
  id = identity(username)
  item.merge!(id) unless id.nil?
  meta = meta_info(username)
  item.merge!(meta) unless meta.nil?
  cred = credentials(username)
  item.merge!(cred) unless cred.nil?
  item
end