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
8dd127e1
Commit
8dd127e1
authored
Jun 01, 2021
by
Valery Sizov
Committed by
charlie ablett
Jun 01, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add repository storage data to REST API
parent
4e3b102b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
95 additions
and
0 deletions
+95
-0
doc/api/projects.md
doc/api/projects.md
+25
-0
lib/api/entities/project_repository_storage.rb
lib/api/entities/project_repository_storage.rb
+16
-0
lib/api/projects.rb
lib/api/projects.rb
+12
-0
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+42
-0
No files found.
doc/api/projects.md
View file @
8dd127e1
...
@@ -2597,3 +2597,28 @@ GET /projects/:id/snapshot
...
@@ -2597,3 +2597,28 @@ GET /projects/:id/snapshot
|-----------|----------------|------------------------|-------------|
|-----------|----------------|------------------------|-------------|
|
`id`
| integer/string |
**{check-circle}**
Yes | The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
. |
|
`id`
| integer/string |
**{check-circle}**
Yes | The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
. |
|
`wiki`
| boolean |
**{dotted-circle}**
No | Whether to download the wiki, rather than project, repository. |
|
`wiki`
| boolean |
**{dotted-circle}**
No | Whether to download the wiki, rather than project, repository. |
## Get the path to repository storage
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/29861) in GitLab 14.0.
Get the path to repository storage for specified project. Available for administrators only.
```
plaintext
GET /projects/:id/storage
```
| Attribute | Type | Required | Description |
|--------------|----------------|------------------------|-------------|
|
`id`
| integer/string |
**{check-circle}**
Yes | ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
. |
```
json
[
{
"project_id"
:
1
,
"disk_path"
:
"@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b"
,
"created_at"
:
"2012-10-12T17:04:47Z"
,
"repository_storage"
:
"default"
}
]
```
lib/api/entities/project_repository_storage.rb
0 → 100644
View file @
8dd127e1
# frozen_string_literal: true
module
API
module
Entities
class
ProjectRepositoryStorage
<
Grape
::
Entity
include
Gitlab
::
Routing
expose
:disk_path
do
|
project
|
project
.
repository
.
disk_path
end
expose
:id
,
as: :project_id
expose
:repository_storage
,
:created_at
end
end
end
lib/api/projects.rb
View file @
8dd127e1
...
@@ -660,6 +660,18 @@ module API
...
@@ -660,6 +660,18 @@ module API
render_api_error!
(
"Failed to transfer project
#{
user_project
.
errors
.
messages
}
"
,
400
)
render_api_error!
(
"Failed to transfer project
#{
user_project
.
errors
.
messages
}
"
,
400
)
end
end
end
end
desc
'Show the storage information'
do
success
Entities
::
ProjectRepositoryStorage
end
params
do
requires
:id
,
type:
String
,
desc:
'ID of a project'
end
get
':id/storage'
,
feature_category: :projects
do
authenticated_as_admin!
present
user_project
,
with:
Entities
::
ProjectRepositoryStorage
,
current_user:
current_user
end
end
end
end
end
end
end
...
...
spec/requests/api/projects_spec.rb
View file @
8dd127e1
...
@@ -3864,6 +3864,48 @@ RSpec.describe API::Projects do
...
@@ -3864,6 +3864,48 @@ RSpec.describe API::Projects do
end
end
end
end
describe
'GET /projects/:id/storage'
do
context
'when unauthenticated'
do
it
'does not return project storage data'
do
get
api
(
"/projects/
#{
project
.
id
}
/storage"
)
expect
(
response
).
to
have_gitlab_http_status
(
:unauthorized
)
end
end
it
'returns project storage data when user is admin'
do
get
api
(
"/projects/
#{
project
.
id
}
/storage"
,
create
(
:admin
))
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'project_id'
]).
to
eq
(
project
.
id
)
expect
(
json_response
[
'disk_path'
]).
to
eq
(
project
.
repository
.
disk_path
)
expect
(
json_response
[
'created_at'
]).
to
be_present
expect
(
json_response
[
'repository_storage'
]).
to
eq
(
project
.
repository_storage
)
end
it
'does not return project storage data when user is not admin'
do
get
api
(
"/projects/
#{
project
.
id
}
/storage"
,
user3
)
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
end
it
'responds with a 401 for unauthenticated users trying to access a non-existent project id'
do
expect
(
Project
.
find_by
(
id:
non_existing_record_id
)).
to
be_nil
get
api
(
"/projects/
#{
non_existing_record_id
}
/storage"
)
expect
(
response
).
to
have_gitlab_http_status
(
:unauthorized
)
end
it
'responds with a 403 for non-admin users trying to access a non-existent project id'
do
expect
(
Project
.
find_by
(
id:
non_existing_record_id
)).
to
be_nil
get
api
(
"/projects/
#{
non_existing_record_id
}
/storage"
,
user3
)
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
end
end
it_behaves_like
'custom attributes endpoints'
,
'projects'
do
it_behaves_like
'custom attributes endpoints'
,
'projects'
do
let
(
:attributable
)
{
project
}
let
(
:attributable
)
{
project
}
let
(
:other_attributable
)
{
project2
}
let
(
:other_attributable
)
{
project2
}
...
...
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