lib/cratus/group.rb in cratus-0.2.1 vs lib/cratus/group.rb in cratus-0.2.2

- old
+ new

@@ -1,6 +1,7 @@ module Cratus + # An LDAP Group representation class Group include Comparable attr_reader :name, :search_base def initialize(name) @@ -23,26 +24,26 @@ end def member_of memrof_attr = Cratus.config.group_memberof_attribute - # TODO make this work with more things... + # TODO: make this work with more things... unless @raw_ldap_data STDERR.puts "WARNING: Group '#{@name}' appears to be invalid or beyond the search scope!" return [] end # TODO: move the search filter to a configurable param - raw_groups = @raw_ldap_data[memrof_attr].reject {|g| g.match /OU=Distribution Groups/ } + raw_groups = @raw_ldap_data[memrof_attr].reject { |g| g.match(/OU=Distribution Groups/) } initial_groups = raw_groups.map do |raw_group| Group.new(raw_group.match(/^#{Group.ldap_dn_attribute.to_s.upcase}=([^,]+),/)[1]) end all_the_groups = initial_groups initial_groups.each do |group| all_the_groups.concat(group.member_of) # recursion! end - all_the_groups.uniq { |g| g.name } + all_the_groups.uniq(&:name) end # LDAP description attribute def description @raw_ldap_data[Cratus.config.group_description_attribute].last @@ -50,11 +51,11 @@ # All the LDAP Groups def self.all filter = "(#{ldap_dn_attribute}=*)" Cratus::LDAP.search(filter, basedn: ldap_search_base, attrs: ldap_dn_attribute).map do |entry| - self.new(entry[ldap_dn_attribute].last) + new(entry[ldap_dn_attribute].last) end end def self.ldap_dn_attribute Cratus.config.group_dn_attribute.to_s @@ -82,14 +83,15 @@ end private # provides a Hash of member users and groups + # rubocop:disable Metrics/AbcSize, Metrics/MethodLength def all_members # filters used to determine if each group member is a User or Group - group_filter = "(objectClass=#{Cratus.config.group_objectclass.to_s})" - user_filter = "(objectClass=#{Cratus.config.user_objectclass.to_s})" + group_filter = "(objectClass=#{Cratus.config.group_objectclass})" + user_filter = "(objectClass=#{Cratus.config.user_objectclass})" # The raw LDAP data (a list of DNs) raw_members = @raw_ldap_data[Cratus.config.group_member_attribute] # Somewhere to store users and groups as we gather them @@ -121,11 +123,11 @@ end end end # deliver the results - results[:groups].uniq! { |g| g.name } - results[:users].uniq! { |u| u.username } - return results + results[:groups].uniq!(&:name) + results[:users].uniq!(&:username) + results end end end