diff options
author | Drew Blessing <drew@gitlab.com> | 2015-12-22 15:09:35 -0600 |
---|---|---|
committer | Drew Blessing <drew@gitlab.com> | 2016-12-16 09:57:05 -0600 |
commit | e0eb86ee809aaad86be4ca1d985a5e67c0657a6f (patch) | |
tree | e24cc5d86b0fcfc591bff3cdb764b2eaf49aa0ae /lib/tasks | |
parent | bdb5e6771856c280fa1cf92b19a47fb83a4988ec (diff) | |
download | gitlab-ce-e0eb86ee809aaad86be4ca1d985a5e67c0657a6f.tar.gz |
Add LDAP task to rename a provider
Sometimes admins will change the LDAP configuration, not realizing
that problems will occur if the user's LDAP identities are not
also updated to use the new provider name. This task will give
admins a single command to run to update identities and will
prevent having to run multiple Rails console queries.
Diffstat (limited to 'lib/tasks')
-rw-r--r-- | lib/tasks/gitlab/ldap.rake | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/tasks/gitlab/ldap.rake b/lib/tasks/gitlab/ldap.rake new file mode 100644 index 00000000000..c66a2a263dc --- /dev/null +++ b/lib/tasks/gitlab/ldap.rake @@ -0,0 +1,40 @@ +namespace :gitlab do + namespace :ldap do + desc 'GitLab | LDAP | Rename provider' + task :rename_provider, [:old_provider, :new_provider] => :environment do |_, args| + old_provider = args[:old_provider] || + prompt('What is the old provider? Ex. \'ldapmain\': '.color(:blue)) + new_provider = args[:new_provider] || + prompt('What is the new provider ID? Ex. \'ldapcustom\': '.color(:blue)) + puts '' # Add some separation in the output + + identities = Identity.where(provider: old_provider) + identity_count = identities.count + + if identities.empty? + puts "Found no user identities with '#{old_provider}' provider." + puts 'Please check the provider name and try again.' + exit 1 + end + + plural_id_count = ActionController::Base.helpers.pluralize(identity_count, 'user') + + unless ENV['force'] == 'yes' + puts "#{plural_id_count} with provider '#{old_provider}' will be updated to '#{new_provider}'" + puts 'If the new provider is incorrect, users will be unable to sign in' + ask_to_continue + puts '' + end + + updated_count = identities.update_all(provider: new_provider) + + if updated_count == identity_count + puts 'User identities were successfully updated'.color(:green) + else + plural_updated_count = ActionController::Base.helpers.pluralize(updated_count, 'user') + puts 'Some user identities could not be updated'.color(:red) + puts "Successfully updated #{plural_updated_count} out of #{plural_id_count} total" + end + end + end +end |