2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
module API
|
|
|
|
# Keys API
|
2021-01-03 14:25:43 +05:30
|
|
|
class Keys < ::API::Base
|
2015-09-25 12:07:36 +05:30
|
|
|
before { authenticate! }
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
feature_category :system_access
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
resource :keys do
|
2016-11-03 12:29:30 +05:30
|
|
|
desc 'Get single ssh key by id. Only available to admin users' do
|
2023-01-13 00:05:48 +05:30
|
|
|
detail 'Get SSH key with user by ID of an SSH key. Note only administrators can lookup SSH key with user by ID\
|
|
|
|
of an SSH key'
|
2016-11-03 12:29:30 +05:30
|
|
|
success Entities::SSHKeyWithUser
|
|
|
|
end
|
2023-01-13 00:05:48 +05:30
|
|
|
params do
|
|
|
|
requires :id, types: [String, Integer], desc: 'The ID of an SSH key', documentation: { example: '2' }
|
|
|
|
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
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
desc 'Get user by fingerprint of SSH key' do
|
2020-01-01 13:55:28 +05:30
|
|
|
success Entities::UserWithAdmin
|
2023-01-13 00:05:48 +05:30
|
|
|
detail 'You can search for a user that owns a specific SSH key. Note only administrators can lookup SSH key\
|
|
|
|
with the fingerprint of an SSH key'
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|
|
|
|
params do
|
2023-01-13 00:05:48 +05:30
|
|
|
requires :fingerprint, type: String, desc: 'The fingerprint of an SSH key',
|
|
|
|
documentation: { example: 'ba:81:59:68:d7:6c:cd:02:02:bf:6a:9b:55:4e:af:d1' }
|
2020-01-01 13:55:28 +05:30
|
|
|
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
|