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

44 lines
1.1 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2015-09-25 12:07:36 +05:30
module API
# Keys API
class Keys < Grape::API
before { authenticate! }
resource :keys do
2016-11-03 12:29:30 +05:30
desc 'Get single ssh key by id. Only available to admin users' do
success Entities::SSHKeyWithUser
end
2015-09-25 12:07:36 +05:30
get ":id" do
authenticated_as_admin!
key = Key.find(params[:id])
2018-11-18 11:00:15 +05:30
present key, with: Entities::SSHKeyWithUser, current_user: current_user
2015-09-25 12:07:36 +05:30
end
2020-01-01 13:55:28 +05:30
desc 'Get SSH Key information' do
success Entities::UserWithAdmin
end
params do
requires :fingerprint, type: String, desc: 'Search for a SSH fingerprint'
end
get do
authenticated_with_can_read_all_resources!
2020-03-13 15:44:24 +05:30
key = KeysFinder.new(params).execute
2020-01-01 13:55:28 +05:30
not_found!('Key') unless key
2020-03-13 15:44:24 +05:30
if key.type == "DeployKey"
present key, with: Entities::DeployKeyWithUser, current_user: current_user
else
present key, with: Entities::SSHKeyWithUser, current_user: current_user
end
2020-01-01 13:55:28 +05:30
rescue KeysFinder::InvalidFingerprint
render_api_error!('Failed to return the key', 400)
end
2015-09-25 12:07:36 +05:30
end
end
end