Commit 5a4ea5ee authored by Sean McGivern's avatar Sean McGivern

Merge branch 'grapify-ldap-api' into 'master'

Grapify the LDAP API

See merge request !1003
parents 09d78a38 78863f87
module API module API
# groups API
class Ldap < Grape::API class Ldap < Grape::API
before { authenticate! } before { authenticate! }
resource :ldap do resource :ldap do
helpers do helpers do
def get_group_list(provider, search) def get_group_list(provider, search)
search ||= ""
search = Net::LDAP::Filter.escape(search) search = Net::LDAP::Filter.escape(search)
Gitlab::LDAP::Adapter.new(provider).groups("#{search}*", 20) Gitlab::LDAP::Adapter.new(provider).groups("#{search}*", 20)
end end
params :search_params do
optional :search, type: String, default: '', desc: 'Search for a specific LDAP group'
end
end end
# Get a LDAP groups list. Limit size to 20 of them. desc 'Get a LDAP groups list. Limit size to 20 of them.' do
# Filter results by name using search param success Entities::LdapGroup
# end
# Example Request: params do
# GET /ldap/groups use :search_params
end
get 'groups' do get 'groups' do
provider = Gitlab::LDAP::Config.servers.first['provider_name'] provider = Gitlab::LDAP::Config.servers.first['provider_name']
@groups = get_group_list(provider, params[:search]) groups = get_group_list(provider, params[:search])
present @groups, with: Entities::LdapGroup present groups, with: Entities::LdapGroup
end end
# Get a LDAP groups list by the requested provider. Lited size to 20 of them. desc 'Get a LDAP groups list by the requested provider. Limit size to 20 of them.' do
# Filter results by name using search param success Entities::LdapGroup
# end
# Example Request: params do
# GET /ldap/ldapmain/groups use :search_params
end
get ':provider/groups' do get ':provider/groups' do
@groups = get_group_list(params[:provider], params[:search]) groups = get_group_list(params[:provider], params[:search])
present @groups, with: Entities::LdapGroup present groups, with: Entities::LdapGroup
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment