[PATCH conductor] Rake task to insert ldap users.

Jan Provazník jprovazn at redhat.com
Tue Dec 20 19:31:32 UTC 2011


On 12/20/2011 07:33 PM, Scott Seago wrote:
> On 12/05/2011 01:43 AM, Scott Seago wrote:
>> 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
> Has anyone with a working ldap setup had a chance to test this? The task
> seems to do what it ought to, but before I push I'd rather someone who
> is actually using conductor w/ ldap confirm that users imported in this
> way can actually log in.
>
> Scott
>

ACK



More information about the aeolus-devel mailing list