Class: AutomateIt::AccountManager::Portable

Inherits:
BaseDriver show all
Defined in:
lib/automateit/account_manager/portable.rb

Overview

AccountManager::Portable

A pure-Ruby, portable driver for the AccountManager. It is only suitable for doing queries and lacks methods such as add_user. Platform-specific drivers inherit from this class and provide these methods.

Direct Known Subclasses

Linux

Defined Under Namespace

Classes: GroupQuery, UserQuery

Constant Summary

Constants inherited from Plugin::Driver

Plugin::Driver::BASE_DRIVER_NAME

Constants included from Constants

Constants::PERROR, Constants::PEXEC, Constants::PNOTE, Constants::WARNING_BOILERPLATE

Instance Attribute Summary

Attributes inherited from Plugin::Driver

#manager

Attributes inherited from Common

#interpreter

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Plugin::Driver

abstract_driver, #available?, base_driver, base_driver?, depends_on, inherited, manager_token, #setup

Methods inherited from Plugin::Base

#setup, #token, token

Methods inherited from Common

#initialize, #log, #nitpick, #noop, #noop=, #noop?, #preview, #preview=, #preview?, #preview_for, #setup, #superuser?, #writing, #writing=, #writing?

Constructor Details

This class inherits a constructor from AutomateIt::Common

Class Method Details

.has_etc?Boolean

Does this platform provide a way of querying users and groups through the ‘etc’ module?

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
# File 'lib/automateit/account_manager/portable.rb', line 15

def self.has_etc?
  begin
    require 'etc'
    return defined?(Etc)
  rescue LoadError
    return false
  end
end

Instance Method Details

#groupsObject

See AccountManager#groups



88
89
90
# File 'lib/automateit/account_manager/portable.rb', line 88

def groups
  return GroupQuery.new
end

#groups_for_user(query) ⇒ Object

See AccountManager#groups_for_user



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/automateit/account_manager/portable.rb', line 98

def groups_for_user(query)
  pwent = users[query]
  return [] if preview? and not pwent
  username = pwent.name
  result = Set.new
  result << groups[pwent.gid].name if groups[pwent.gid]
  Etc.group do |grent|
    result << grent.name if grent.mem.include?(username)
  end
  return result.to_a
end

#has_etc?Boolean

Alias for AccountManager::Portable.has_etc?

Returns:

  • (Boolean)


25
26
27
# File 'lib/automateit/account_manager/portable.rb', line 25

def has_etc?
  self.has_etc?
end

#has_group?(query) ⇒ Boolean

See AccountManager#has_group?

Returns:

  • (Boolean)


93
94
95
# File 'lib/automateit/account_manager/portable.rb', line 93

def has_group?(query)
  return ! groups[query].nil?
end

#has_user?(query) ⇒ Boolean

See AccountManager#has_user?

Returns:

  • (Boolean)


59
60
61
# File 'lib/automateit/account_manager/portable.rb', line 59

def has_user?(query)
  return ! users[query].nil?
end

#suitability(method, *args) ⇒ Object

:nodoc:



9
10
11
# File 'lib/automateit/account_manager/portable.rb', line 9

def suitability(method, *args) # :nodoc:
  return 1
end

#usersObject

See AccountManager#users



54
55
56
# File 'lib/automateit/account_manager/portable.rb', line 54

def users
  return UserQuery.new
end

#users_for_group(query) ⇒ Object

See AccountManager#users_for_group



111
112
113
114
# File 'lib/automateit/account_manager/portable.rb', line 111

def users_for_group(query)
  grent = groups[query]
  return (preview? || ! grent) ? [] : grent.mem
end

#users_to_groupsObject

See AccountManager#users_to_groups



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/automateit/account_manager/portable.rb', line 117

def users_to_groups
  result = {}
  Etc.group do |grent|
    grent.mem.each do |username|
      result[username] ||= Set.new
      result[username] << grent.name
    end
  end
  Etc.passwd do |pwent|
    grent = groups[pwent.gid]
    unless grent
      log.fatal(PNOTE+"WARNING: User's default group doesn't exist: user %s, gid %s" % [pwent.name, pwent.gid])
      next
    end
    result[pwent.name] ||= Set.new
    result[pwent.name] << grent.name
  end
  return result
end