Class: GitHub::Ldap::Group
- Inherits:
-
Object
- Object
- GitHub::Ldap::Group
- Defined in:
- lib/github/ldap/group.rb
Overview
This class represents an LDAP group. It encapsulates operations that you can perform against a group, like retrieving its members.
To get a group, you’ll need to create a ‘Ldap` object and then call the method `group` with the name of its base.
For example:
domain = GitHub::Ldap.new(options).group(“cn=enterprise,dc=github,dc=com”)
Constant Summary collapse
- GROUP_CLASS_NAMES =
%w(groupOfNames groupOfUniqueNames)
Instance Method Summary collapse
-
#group?(object_class) ⇒ Boolean
Check if an object class includes the member names Use ‘&` rathen than `include?` because both are arrays.
-
#initialize(ldap, entry) ⇒ Group
constructor
A new instance of Group.
-
#member_entries ⇒ Object
Get all the member entries for a group.
-
#member_names ⇒ Object
Get all the names under ‘member` and `uniqueMember`.
-
#members ⇒ Object
Get all members that belong to a group.
-
#subgroups ⇒ Object
Get all the subgroups from a group recursively.
Constructor Details
#initialize(ldap, entry) ⇒ Group
Returns a new instance of Group.
15 16 17 |
# File 'lib/github/ldap/group.rb', line 15 def initialize(ldap, entry) @ldap, @entry = ldap, entry end |
Instance Method Details
#group?(object_class) ⇒ Boolean
Check if an object class includes the member names Use ‘&` rathen than `include?` because both are arrays.
Returns true if the object class includes one of the group class names.
68 69 70 |
# File 'lib/github/ldap/group.rb', line 68 def group?(object_class) !(GROUP_CLASS_NAMES & object_class).empty? end |
#member_entries ⇒ Object
Get all the member entries for a group.
Returns an array of Net::LDAP::Entry.
51 52 53 54 55 |
# File 'lib/github/ldap/group.rb', line 51 def member_entries @member_entries ||= member_names.map do |m| @ldap.domain(m).bind end end |
#member_names ⇒ Object
Get all the names under ‘member` and `uniqueMember`.
Returns an array with all the DN members.
60 61 62 |
# File 'lib/github/ldap/group.rb', line 60 def member_names @entry[:member] + @entry[:uniqueMember] end |
#members ⇒ Object
Get all members that belong to a group. This list also includes the members of subgroups.
Returns an array with all the member entries.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/github/ldap/group.rb', line 23 def members groups, members = member_entries.partition {|e| group?(e[:objectclass])} results = members groups.each do |result| results.concat @ldap.group(result.dn).members end results.uniq {|m| m.dn } end |
#subgroups ⇒ Object
Get all the subgroups from a group recursively.
Returns an array with all the subgroup entries.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/github/ldap/group.rb', line 37 def subgroups groups, _ = member_entries.partition {|e| group?(e[:objectclass])} results = groups groups.each do |result| results.concat @ldap.group(result.dn).subgroups end results end |