Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
299ee71a
Commit
299ee71a
authored
Jan 20, 2020
by
Rajendra Kadam
Committed by
James Lopez
Jan 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add changelog
add support for username to get user ssh keys
parent
fd74d775
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
9 deletions
+33
-9
changelogs/unreleased/unauthaccess-to-public-keys.yml
changelogs/unreleased/unauthaccess-to-public-keys.yml
+5
-0
doc/api/users.md
doc/api/users.md
+4
-4
lib/api/users.rb
lib/api/users.rb
+3
-5
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+21
-0
No files found.
changelogs/unreleased/unauthaccess-to-public-keys.yml
0 → 100644
View file @
299ee71a
---
title
:
Allow SSH keys API endpoint to be requested for a given username
merge_request
:
22899
author
:
Rajendra Kadam
type
:
changed
doc/api/users.md
View file @
299ee71a
...
...
@@ -677,12 +677,12 @@ Parameters:
Get a list of a specified user's SSH keys.
```
GET /users/:id/keys
GET /users/:id
_or_username
/keys
```
Parameters:
-
`id`
(required) - id of specified user
| Attribute | Type | Required | Description |
| ---------------- | ------ | -------- | ----------- |
|
`id_or_username`
| string | yes | The id or username of the user to get the SSH keys for. |
## Single SSH key
...
...
lib/api/users.rb
View file @
299ee71a
...
...
@@ -252,17 +252,15 @@ module API
success
Entities
::
SSHKey
end
params
do
requires
:
id
,
type:
Integer
,
desc:
'The ID
of the user'
requires
:
user_id
,
type:
String
,
desc:
'The ID or username
of the user'
use
:pagination
end
# rubocop: disable CodeReuse/ActiveRecord
get
':id/keys'
do
user
=
User
.
find_by
(
id:
params
[
:id
])
get
':user_id/keys'
,
requirements:
API
::
USER_REQUIREMENTS
do
user
=
find_user
(
params
[
:user_id
])
not_found!
(
'User'
)
unless
user
&&
can?
(
current_user
,
:read_user
,
user
)
present
paginate
(
user
.
keys
),
with:
Entities
::
SSHKey
end
# rubocop: enable CodeReuse/ActiveRecord
desc
'Delete an existing SSH key from a specified user. Available only for admins.'
do
success
Entities
::
SSHKey
...
...
spec/requests/api/users_spec.rb
View file @
299ee71a
...
...
@@ -913,6 +913,27 @@ describe API::Users do
end
end
describe
'GET /user/:user_id/keys'
do
it
'returns 404 for non-existing user'
do
get
api
(
"/users/
#{
not_existing_user_id
}
/keys"
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 User Not Found'
)
end
it
'returns array of ssh keys'
do
user
.
keys
<<
key
user
.
save
get
api
(
"/users/
#{
user
.
username
}
/keys"
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
key
.
title
)
end
end
describe
'DELETE /user/:id/keys/:key_id'
do
before
do
admin
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment