Class: AutomateIt::AccountManager::Etc
- Inherits:
-
BaseDriver
- Object
- Common
- Plugin::Base
- Plugin::Driver
- BaseDriver
- AutomateIt::AccountManager::Etc
- Defined in:
- lib/automateit/account_manager/etc.rb
Overview
AccountManager::Etc
An AccountManager driver for Unix-like OSes that have the Ruby Etc module. It is only suitable for doing queries and lacks methods that perform modifications, such as add_user
. Platform-specific drivers inherit from this class and provide methods that perform modifications.
Defined Under Namespace
Classes: GroupQuery, UserQuery
Constant Summary
Constants inherited from Plugin::Driver
Plugin::Driver::BASE_DRIVER_NAME
Constants included from Constants
Constants::HELPERS_DIR, Constants::INSTALL_DIR, Constants::PERROR, Constants::PEXEC, Constants::PNOTE, Constants::WARNING_BOILERPLATE
Instance Attribute Summary
Attributes inherited from Plugin::Driver
Attributes inherited from Common
Instance Method Summary collapse
-
#groups ⇒ Object
See AccountManager#groups.
-
#groups_for_user(query) ⇒ Object
See AccountManager#groups_for_user.
-
#has_group?(query) ⇒ Boolean
See AccountManager#has_group?.
-
#has_user?(query) ⇒ Boolean
See AccountManager#has_user?.
-
#suitability(method, *args) ⇒ Object
:nodoc:.
-
#users ⇒ Object
See AccountManager#users.
-
#users_for_group(query) ⇒ Object
See AccountManager#users_for_group.
-
#users_to_groups ⇒ Object
See AccountManager#users_to_groups.
Methods inherited from Plugin::Driver
abstract_driver, #available?, base_driver, base_driver?, depends_on, inherited, manager_token, #setup
Methods inherited from Plugin::Base
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
Instance Method Details
#groups ⇒ Object
See AccountManager#groups
80 81 82 |
# File 'lib/automateit/account_manager/etc.rb', line 80 def groups return GroupQuery.new end |
#groups_for_user(query) ⇒ Object
See AccountManager#groups_for_user
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/automateit/account_manager/etc.rb', line 90 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_group?(query) ⇒ Boolean
See AccountManager#has_group?
85 86 87 |
# File 'lib/automateit/account_manager/etc.rb', line 85 def has_group?(query) return ! groups[query].nil? end |
#has_user?(query) ⇒ Boolean
See AccountManager#has_user?
51 52 53 |
# File 'lib/automateit/account_manager/etc.rb', line 51 def has_user?(query) return ! users[query].nil? end |
#suitability(method, *args) ⇒ Object
:nodoc:
17 18 19 |
# File 'lib/automateit/account_manager/etc.rb', line 17 def suitability(method, *args) # :nodoc: return available? ? 1 : 0 end |
#users ⇒ Object
See AccountManager#users
46 47 48 |
# File 'lib/automateit/account_manager/etc.rb', line 46 def users return UserQuery.new end |
#users_for_group(query) ⇒ Object
See AccountManager#users_for_group
103 104 105 106 |
# File 'lib/automateit/account_manager/etc.rb', line 103 def users_for_group(query) grent = groups[query] return (preview? || ! grent) ? [] : grent.mem end |
#users_to_groups ⇒ Object
See AccountManager#users_to_groups
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/automateit/account_manager/etc.rb', line 109 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 |