diff --git a/app/config/storage.yml b/app/config/storage.yml index 6deadad..966af18 100644 --- a/app/config/storage.yml +++ b/app/config/storage.yml @@ -58,7 +58,7 @@ - 'organizationalRole' - 'MailAlias' - :dnPat: "cn=#{:user},o=#{:mail|sub(/.*@/, '')}" + :dnPat: "cn=#{:user},o=#{:mail|:sub, /.*@/, ''}" :map: :cn: :user @@ -72,7 +72,7 @@ - 'person' - 'MailAlias' - :dnPat: "mail=#{:mail},o=#{:mail|sub(/.*@/, '')}" + :dnPat: "mail=#{:mail},o=#{:mail|:sub, /.*@/, ''}" :map: :sn: :surname @@ -87,7 +87,7 @@ - 'person' - 'MailAccount' - :dnPat: "mail=#{:mail},o=#{:mail|sub(/.*@/, '')}" + :dnPat: "mail=#{:mail},o=#{:mail|:sub, /.*@/, ''}" :map: :homedirectory: :home diff --git a/app/storage/config.rb b/app/storage/config.rb index a7782b8..00abc7e 100644 --- a/app/storage/config.rb +++ b/app/storage/config.rb @@ -20,16 +20,29 @@ class DsAdmin::Storage::Config ## # replace special patterns within config strings with data # given by the data hash param. These patterns also allow to send - # a message to the replaces data e.g. for some kind of subtitution. + # a message to the actual substituted data to do any kind of + # conversion to it. + # + # actually this is used within the handling of the ldap specific + # :dnPat config parameter to generate the dn entry for a given model + # Data (create or replace) + # + # TODO: I would like to get rid of the eval statements but i don't know + # a better way to build the correct objects from the config strings # def eval_pattern(pattern, data = {}) scan_exp = /([^#]*)(#\{(:[^}|]+)(\|([^}]*))?\})?/ result = String.new pattern.scan(scan_exp) do |m| - key = m[2][1..m[2].length].to_sym if m[2] + key = (eval m[2]) if m[2] val = data[key] if data[key] - val = eval('"' + val + '".send ' + m[4]) if val && m[4] + + args = m[4].split(',').map do |arg| + eval arg.strip + end if m[4] + + val = val.send *args if args result += m[0] + (val || "") end diff --git a/app/tester.rb b/app/tester.rb index 6f7f304..0b5e161 100644 --- a/app/tester.rb +++ b/app/tester.rb @@ -148,5 +148,10 @@ user.name = 'brad' puts 'returns: ' + user.save puts 'base: ' + user.inspect +puts +alias_person.mail = 'noop@steffers.org' +puts 'returns: ' + alias_person.save +puts 'base: ' + alias_person.inspect + puts puts 'Memory useage: ' + `ps -o rss= -p #{Process.pid}`