debian-mirror-gitlab/lib/tasks/gitlab/ldap.rake

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
2.1 KiB
Ruby
Raw Normal View History

2021-03-11 19:13:27 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
namespace :gitlab do
namespace :ldap do
desc 'GitLab | LDAP | Rename provider'
2018-12-13 13:39:08 +05:30
task :rename_provider, [:old_provider, :new_provider] => :gitlab_environment do |_, args|
2017-08-17 22:00:37 +05:30
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
2021-02-22 17:27:13 +05:30
namespace :secret do
desc 'GitLab | LDAP | Secret | Write LDAP secrets'
task write: [:environment] do
2021-09-04 01:27:46 +05:30
content = $stdin.tty? ? $stdin.gets : $stdin.read
2021-02-22 17:27:13 +05:30
Gitlab::EncryptedLdapCommand.write(content)
end
desc 'GitLab | LDAP | Secret | Edit LDAP secrets'
task edit: [:environment] do
Gitlab::EncryptedLdapCommand.edit
end
desc 'GitLab | LDAP | Secret | Show LDAP secrets'
task show: [:environment] do
Gitlab::EncryptedLdapCommand.show
end
end
2017-08-17 22:00:37 +05:30
end
end