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
1c46199b
Commit
1c46199b
authored
Sep 29, 2020
by
Michelle Gill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get a specific GPG key for a given user
Ability to access the public key for a user without authentication
parent
82f7405e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
1 deletion
+51
-1
changelogs/unreleased/mgill-user-gpg.yml
changelogs/unreleased/mgill-user-gpg.yml
+5
-0
doc/api/users.md
doc/api/users.md
+1
-1
lib/api/users.rb
lib/api/users.rb
+20
-0
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+25
-0
No files found.
changelogs/unreleased/mgill-user-gpg.yml
0 → 100644
View file @
1c46199b
---
title
:
API support for a specific GPG Key for given user
merge_request
:
43693
author
:
type
:
added
doc/api/users.md
View file @
1c46199b
...
...
@@ -980,7 +980,7 @@ Example response:
## Get a specific GPG key for a given user
Get a specific GPG key for a given user.
Available only for admins
.
Get a specific GPG key for a given user.
This endpoint can be accessed without authentication
.
```
plaintext
GET /users/:id/gpg_keys/:key_id
...
...
lib/api/users.rb
View file @
1c46199b
...
...
@@ -367,6 +367,26 @@ module API
end
# rubocop: enable CodeReuse/ActiveRecord
desc
'Get a specific GPG key for a given user.'
do
detail
'This feature was added in GitLab 13.5'
success
Entities
::
GpgKey
end
params
do
requires
:id
,
type:
Integer
,
desc:
'The ID of the user'
requires
:key_id
,
type:
Integer
,
desc:
'The ID of the GPG key'
end
# rubocop: disable CodeReuse/ActiveRecord
get
':id/gpg_keys/:key_id'
do
user
=
User
.
find_by
(
id:
params
[
:id
])
not_found!
(
'User'
)
unless
user
key
=
user
.
gpg_keys
.
find_by
(
id:
params
[
:key_id
])
not_found!
(
'GPG Key'
)
unless
key
present
key
,
with:
Entities
::
GpgKey
end
# rubocop: enable CodeReuse/ActiveRecord
desc
'Delete an existing GPG key from a specified user. Available only for admins.'
do
detail
'This feature was added in GitLab 10.0'
end
...
...
spec/requests/api/users_spec.rb
View file @
1c46199b
...
...
@@ -1496,6 +1496,31 @@ RSpec.describe API::Users, :do_not_mock_admin_mode do
end
end
describe
'GET /user/:id/gpg_keys/:key_id'
do
it
'returns 404 for non-existing user'
do
get
api
(
'/users/0/gpg_keys/1'
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 User Not Found'
)
end
it
'returns 404 for non-existing key'
do
get
api
(
"/users/
#{
user
.
id
}
/gpg_keys/0"
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 GPG Key Not Found'
)
end
it
'returns a single GPG key'
do
user
.
gpg_keys
<<
gpg_key
get
api
(
"/users/
#{
user
.
id
}
/gpg_keys/
#{
gpg_key
.
id
}
"
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'key'
]).
to
eq
(
gpg_key
.
key
)
end
end
describe
'DELETE /user/:id/gpg_keys/:key_id'
do
context
'when unauthenticated'
do
it
'returns authentication error'
do
...
...
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