debian-mirror-gitlab/lib/api/applications.rb

65 lines
1.9 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module API
# External applications API
2020-07-28 23:09:34 +05:30
class Applications < Grape::API::Instance
2018-03-17 18:26:18 +05:30
before { authenticated_as_admin! }
resource :applications do
2020-11-24 15:15:51 +05:30
helpers do
def validate_redirect_uri(value)
uri = ::URI.parse(value)
!uri.is_a?(URI::HTTP) || uri.host
rescue URI::InvalidURIError
false
end
end
2018-03-17 18:26:18 +05:30
desc 'Create a new application' do
detail 'This feature was introduced in GitLab 10.5'
success Entities::ApplicationWithSecret
end
params do
requires :name, type: String, desc: 'Application name'
requires :redirect_uri, type: String, desc: 'Application redirect URI'
requires :scopes, type: String, desc: 'Application scopes'
2020-03-13 15:44:24 +05:30
optional :confidential, type: Boolean, default: true,
desc: 'Application will be used where the client secret is confidential'
2018-03-17 18:26:18 +05:30
end
post do
2020-11-24 15:15:51 +05:30
# Validate that host in uri is specified
# Please remove it when https://github.com/doorkeeper-gem/doorkeeper/pull/1440 is merged
# and the doorkeeper gem version is bumped
unless validate_redirect_uri(declared_params[:redirect_uri])
render_api_error!({ redirect_uri: ["must be an absolute URI."] }, :bad_request)
end
2018-03-17 18:26:18 +05:30
application = Doorkeeper::Application.new(declared_params)
if application.save
present application, with: Entities::ApplicationWithSecret
else
render_validation_error! application
end
end
2018-12-13 13:39:08 +05:30
desc 'Get applications' do
success Entities::Application
end
get do
applications = ApplicationsFinder.new.execute
present applications, with: Entities::Application
end
desc 'Delete an application'
delete ':id' do
application = ApplicationsFinder.new(params).execute
application.destroy
2020-03-13 15:44:24 +05:30
no_content!
2018-12-13 13:39:08 +05:30
end
2018-03-17 18:26:18 +05:30
end
end
end