Class: Goz::Group::EtcGroup

Inherits:
Base
  • Object
show all
Defined in:
lib/goz/group/etc_group.rb

Overview

Goz::Group::EtcGroup - /etc/group derived users (mostly for testing)

Usage

TODO

Author

blair christensen. <[email protected]>

Homepage

github.com/blairc/goz/

Constant Summary collapse

TAG =
self.name

Instance Attribute Summary

Attributes inherited from Base

#display_name, #identifier, #klass, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#[], configuration, #to_hash, #to_s

Constructor Details

#initialize(g) ⇒ EtcGroup

Returns a new instance of EtcGroup.



30
31
32
33
34
35
# File 'lib/goz/group/etc_group.rb', line 30

def initialize(g)
  @display_name = g[:name]
  @identifier   = g[:gid]
  @klass        = self.class.name
  @name         = g[:name]
end

Class Method Details

.find_by_name(name) ⇒ Object

Find Goz::Group by name or return nil



41
42
43
44
45
46
47
48
49
# File 'lib/goz/group/etc_group.rb', line 41

def self.find_by_name(name)
  Goz::Logger.debug TAG, "find_by_name( name=#{name} )"
  begin
    return self.new( Etc.getgrnam(name) )
  rescue ArgumentError => e
    Goz::Logger.warn TAG, "find_by_name( name=#{name} ) - not found"
  end
  nil
end

.groups(user) ⇒ Object

Return groups where user is an admin.



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/goz/group/etc_group.rb', line 79

def self.groups(user)
  Goz::Logger.debug TAG, "groups( user.login=#{user.} )"
  groups = []
  return groups if user.nil? || user.identifier.nil? || user.name.nil?
  loop do
    g = Etc.getgrent
    break if g.nil?
    groups << self.new(g) if ( '0' === user.identifier || ( g[:gid].to_s === user.identifier && g[:name] == user. ) )
  end
  Etc.endgrent
  return groups
end

.memberships(user) ⇒ Object

Return groups where user is a member.



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/goz/group/etc_group.rb', line 95

def self.memberships(user)
  Goz::Logger.debug TAG, "groups( user.login=#{user.} )"
  groups = []
  return groups if user.nil? || user..nil? || user.identifier.nil?
  loop do
    g = Etc.getgrent
    break if g.nil?
    groups << self.new(g) if ( g[:mem].include?(user.) || ( g[:gid].to_s == user.identifier && g[:name] == user. ) )
  end
  Etc.endgrent
  return groups
end

Instance Method Details

#adminsObject

TODO



54
55
56
57
58
59
60
61
# File 'lib/goz/group/etc_group.rb', line 54

def admins()
  Goz::Logger.debug TAG, "name=#{self.name} - #admins()"
  users = []
  g = Etc.getgrnam self.name
  return users if g.nil?
  # XXX ???
  users
end

#membersObject

TODO



66
67
68
69
70
71
72
73
74
# File 'lib/goz/group/etc_group.rb', line 66

def members()
  Goz::Logger.debug TAG, "#{self.name} - #members()"
  users = []
  g = Etc.getgrnam self.name
  return users if g.nil?
  users = g[:mem].collect { |m| Goz::User. m }
  users.delete_if { |_| _.nil? }
  users
end