#4759 rake to create LDAP configurations

pull/4777/head
Kartones 9 years ago
parent 9d045f804c
commit 2ee08219f4

@ -24,13 +24,13 @@ class Carto::Ldap::Configuration < ActiveRecord::Base
# @param String host LDAP host or ip address
# @param Int port LDAP port e.g. 389, 636 (LDAPS)
# @param String encryption (Optional) Encryption type to use. Empty means standard/simple Auth
# @param String ca_file Certificate file path for start_tls encryption. Example: "/etc/cafile.pem"
# @param String ca_file UNUSED FOR NOW - Certificate file path for start_tls encryption. Example: "/etc/cafile.pem"
# @param String ssl_version For start_tls_encryption. Example: "TLSv1_1"
# @param String connection_user Full CN for "search connections" to LDAP: `CN=admin, DC=cartodb, DC=COM`
# @param String connection_password Password for "search connections" to LDAP
# @param String user_id_field Which LDAP entry field represents the user id. e.g. `sAMAccountName`, `uid`
# @param String username_field Which LDAP entry field represents the username (Optional)
# @param String username_field Which LDAP entry field represents the email
# @param String email_field Which LDAP entry field represents the email
# @param String domain_bases List of DCs conforming the path (serialized)
# @param String user_object_class Name of the attribute where the sers are maped in LDAP
# @param String group_object_class Name of the attribute where the groups are maped in LDAP

@ -0,0 +1,65 @@
namespace :cartodb do
namespace :ldap do
# INFO: Separate multiple domain names by commas
desc "Creates an LDAP Configuration entry"
task :create_ldap_configuration, [] => :environment do |t, args|
raise "Missing ORGANIZATION_ID" if ENV['ORGANIZATION_ID'].blank?
organization_id = ENV['ORGANIZATION_ID']
raise "Missing HOST" if ENV['HOST'].blank?
host = ENV['HOST']
raise "Missing PORT" if ENV['PORT'].blank?
port = ENV['PORT']
encryption = ENV['ENCRYPTION'].blank? ? nil : ENV['ENCRYPTION']
ssl_version = ENV['SSL_VERSION'].blank? ? nil : ENV['SSL_VERSION']
raise "Missing CONNECTION_USER" if ENV['CONNECTION_USER'].blank?
connection_user = ENV['CONNECTION_USER']
raise "Missing CONNECTION_PASSWORD" if ENV['CONNECTION_PASSWORD'].blank?
connection_password = ENV['CONNECTION_PASSWORD']
raise "Missing USER_ID_FIELD" if ENV['USER_ID_FIELD'].blank?
user_id_field = ENV['USER_ID_FIELD']
raise "Missing USERNAME_FIELD" if ENV['USERNAME_FIELD'].blank?
username_field = ENV['USERNAME_FIELD']
raise "Missing EMAIL_FIELD" if ENV['EMAIL_FIELD'].blank?
email_field = ENV['EMAIL_FIELD']
raise "Missing DOMAIN_BASES" if ENV['DOMAIN_BASES'].blank?
domain_bases = ENV['DOMAIN_BASES'].split(',')
raise "Missing USER_OBJECT_CLASS" if ENV['USER_OBJECT_CLASS'].blank?
user_object_class = ENV['USER_OBJECT_CLASS']
raise "Missing GROUP_OBJECT_CLASS" if ENV['GROUP_OBJECT_CLASS'].blank?
group_object_class = ENV['GROUP_OBJECT_CLASS']
ldap = Carto::Ldap::Configuration.create({
organization_id: organization_id,
host: host,
port: port,
encryption: encryption,
ssl_version: ssl_version,
connection_user: connection_user,
connection_password: connection_password,
user_id_field: user_id_field,
username_field: username_field,
email_field: email_field,
domain_bases_list: domain_bases,
user_object_class: user_object_class,
group_object_class: group_object_class
})
puts "LDAP configuration created with id: #{ldap.id}"
end
end
end
Loading…
Cancel
Save