[PATCH conductor] Rake task to insert ldap users.

Scott Seago sseago at redhat.com
Mon Dec 5 06:43:55 UTC 2011


This is a barebones rake task to insert ldap users into the conductor user database. This is only needed if the admin wants to pre-configure non-default permissions for the user before the user logs in. If the user is being set up with the default permissions (on the default pool, etc) this isn't needed, as the user is automatically created upon initial login.

We're not doing any validation of the users other than the standard model validation on the login field. We don't have the user's password, so we can't test login here. I'm not sure what additional validation is required here, if any, but an invalid user is fairly safe - the user can't log in if it's not a valid ldap username, so the only harm is cluttering iup the database with extra users that aren't useful for anything.

At the moment, this script does not set default permissions for the users. I'm not sure whether we want that or not -- currently create_ldap_user! does not do this, even for ldap users created via user logins, so if we want this, we should probably modify create_ldap_user! to use RegistrationService.

Syntax to create ldap users is as follows:
  rake dc:create_ldap_users[username1:username2:username3:...]
---
 src/lib/tasks/dc_tasks.rake |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/src/lib/tasks/dc_tasks.rake b/src/lib/tasks/dc_tasks.rake
index 28653cd..84637bb 100644
--- a/src/lib/tasks/dc_tasks.rake
+++ b/src/lib/tasks/dc_tasks.rake
@@ -28,6 +28,30 @@ namespace :dc do
   end
 
 
+  desc 'Create and register a list of ldap users, separated by ":"'
+  task :create_ldap_users, [:logins] => :environment do |t, args|
+    unless args.logins
+      puts "Usage: rake 'dc:create_ldap_users[login1:login2:...]'"
+      exit(1)
+    end
+
+    args.logins.split(":").each do |login|
+      user = User.find_by_login(args.login)
+
+      if user
+        puts "User already exists: #{login}"
+      end
+
+      begin
+        user = User.create_ldap_user!(login)
+        puts "User #{login} registered"
+      rescue Exception => e
+        puts "User registration failed: #{e}"
+      end
+    end
+  end
+
+
   desc 'Grant administrator privileges to registred user'
   task :site_admin, [:login] => :environment do |t, args|
     unless args.login
-- 
1.7.6.4




More information about the aeolus-devel mailing list