Skip to content

Commit

Permalink
Search for all organizations.
Browse files Browse the repository at this point in the history
I feel silly that I forgot that you can't fetch a specific DN with LDAP.
  • Loading branch information
cdchapman committed Nov 7, 2019
1 parent c98f0ea commit f5f3c9d
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions commands/update-company-data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
option :u, :user,
'the user RDN (appended to the active users and base subsequences) to bind to the LDAP server',
default: 'uid=admin', argument: :required
option :c, :company, 'the RDN subsequence (appended to the base) of the company entry',
default: 'o=pentandra,cn=organizations', argument: :required
option :os, :organizations,
'the RDN subsequence (appended to the base) at which to locate organizations',
default: 'cn=organizations', argument: :required
option :au, :active_users,
'the RDN subsequence (appended to base) at which to locate active users',
default: 'cn=users,cn=accounts', argument: :required
Expand All @@ -33,21 +34,24 @@
option :o, :output, 'output LDIF into this file', argument: :required
no_params

require 'net/ldap'

class UpdateCompanyData < ::Nanoc::CLI::CommandRunner

COMPANY_ATTRS = %w[
c cn description displayName l mail memberOf o ou postalAddress
personalTitle postalCode st street telephoneNumber
ORGANIZATION_FILTER = Net::LDAP::Filter.eq('objectClass', 'organization')
ORGANIZATION_ATTRS = %w[
c cn description displayName l labeledURI mail o ou postalCode st street
telephoneNumber
]

EMPLOYEE_ATTRS ||= %w[
cn description displayName eduPersonOrcid employeeNumber employeeType
generationQualifier givenName initials jpegPhoto mail manager mobile o ou
personalTitle preferredLanguage sn telephoneNumber title userCertificate
generationQualifier givenName initials jpegPhoto labeledURI mail manager
mobile o ou personalTitle preferredLanguage sn telephoneNumber title
userCertificate
]

def run
require 'net/ldap'

ldif_out = String.new(<<~LDIF_PREAMBLE)
Expand Down Expand Up @@ -79,9 +83,11 @@ def run

ldap.open do |ldap|
ldap.search(
#base: options.fetch_values(:organizations, :base).join(','),
base: [options[:organizations], options[:base]].join(','),
scope: Net::LDAP::SearchScope_SingleLevel,
filter: Net::LDAP::Filter.eq('dn', options[:company]),
attributes: COMPANY_ATTRS) do |entry|
filter: ORGANIZATION_FILTER,
attributes: ORGANIZATION_ATTRS) do |entry|
ldif_out << entry.to_ldif
ldif_out << "\n"
end
Expand Down

0 comments on commit f5f3c9d

Please sign in to comment.