Commit 1d18d63e authored by James Lopez's avatar James Lopez

change endpoint to avoid passing an ID

parent a23fa7c8
...@@ -140,11 +140,11 @@ Example response: ...@@ -140,11 +140,11 @@ Example response:
} }
``` ```
## Retrieve project sync failures ocurred on a specific node (only available for the current node) ## Retrieve project sync failures ocurred on the current node
``` ```
GET /geo_nodes/:id/failures GET /geo_nodes/failures
``` ```
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
...@@ -154,7 +154,7 @@ GET /geo_nodes/:id/failures ...@@ -154,7 +154,7 @@ GET /geo_nodes/:id/failures
This endpoint uses [Pagination](README.md#pagination). This endpoint uses [Pagination](README.md#pagination).
```bash ```bash
curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/geo_nodes/2/failures curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/geo_nodes/failures
``` ```
Example response: Example response:
......
...@@ -33,6 +33,27 @@ module API ...@@ -33,6 +33,27 @@ module API
present paginate(status), with: GeoNodeStatusEntity present paginate(status), with: GeoNodeStatusEntity
end end
# Get project registry failures for the current Geo node
#
# Example request:
# GET /geo_nodes/failures
desc 'Get project registry failures for the current Geo node' do
success ::GeoProjectRegistryEntity
end
params do
optional :type, type: String, values: %w[wiki repository], desc: 'Type of failure (repository/wiki)'
use :pagination
end
get '/failures' do
geo_node = Gitlab::Geo.current_node
not_found('Geo node not found') unless geo_node
project_registries = paginate(geo_node.filtered_project_registries(params[:type]))
present project_registries, with: ::GeoProjectRegistryEntity
end
# Get all Geo node information # Get all Geo node information
# #
# Example request: # Example request:
...@@ -77,32 +98,6 @@ module API ...@@ -77,32 +98,6 @@ module API
present status, with: ::GeoNodeStatusEntity present status, with: ::GeoNodeStatusEntity
end end
# Get project registry failures for the current Geo node
#
# Example request:
# GET /geo_nodes/:id/failures
desc 'Get project registry failures for the current Geo node' do
success Entities::GeoNode
end
params do
requires :id, type: Integer, desc: 'The ID of the node'
optional :type, type: String, values: %w[wiki repository], desc: 'Type of failure (repository/wiki)'
use :pagination
end
get ':id/failures' do
unless Gitlab::Geo.current_node.id == params[:id]
forbidden!('Geo node is not the current node.')
end
geo_node = Gitlab::Geo.current_node
not_found('Geo node not found') unless geo_node
project_registries = paginate(geo_node.filtered_project_registries(params[:type]))
present project_registries, with: ::GeoProjectRegistryEntity
end
end end
end end
end end
...@@ -87,7 +87,7 @@ describe API::GeoNodes, :geo, api: true do ...@@ -87,7 +87,7 @@ describe API::GeoNodes, :geo, api: true do
end end
end end
describe 'GET /geo_nodes/:id/failures/:type' do describe 'GET /geo_nodes/failures/:type' do
it 'fetches the current node failures' do it 'fetches the current node failures' do
create(:geo_project_registry, :sync_failed) create(:geo_project_registry, :sync_failed)
create(:geo_project_registry, :sync_failed) create(:geo_project_registry, :sync_failed)
...@@ -95,7 +95,7 @@ describe API::GeoNodes, :geo, api: true do ...@@ -95,7 +95,7 @@ describe API::GeoNodes, :geo, api: true do
stub_current_geo_node(secondary) stub_current_geo_node(secondary)
expect(Gitlab::Geo).to receive(:current_node).and_return(secondary) expect(Gitlab::Geo).to receive(:current_node).and_return(secondary)
get api("/geo_nodes/#{secondary.id}/failures", admin) get api("/geo_nodes/failures", admin)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('geo_project_registry') expect(response).to match_response_schema('geo_project_registry')
...@@ -107,7 +107,7 @@ describe API::GeoNodes, :geo, api: true do ...@@ -107,7 +107,7 @@ describe API::GeoNodes, :geo, api: true do
stub_current_geo_node(secondary) stub_current_geo_node(secondary)
expect(Gitlab::Geo).to receive(:current_node).and_return(secondary) expect(Gitlab::Geo).to receive(:current_node).and_return(secondary)
get api("/geo_nodes/#{secondary.id}/failures", admin) get api("/geo_nodes/failures", admin)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response.count).to be_zero expect(json_response.count).to be_zero
...@@ -121,7 +121,7 @@ describe API::GeoNodes, :geo, api: true do ...@@ -121,7 +121,7 @@ describe API::GeoNodes, :geo, api: true do
stub_current_geo_node(secondary) stub_current_geo_node(secondary)
expect(Gitlab::Geo).to receive(:current_node).and_return(secondary) expect(Gitlab::Geo).to receive(:current_node).and_return(secondary)
get api("/geo_nodes/#{secondary.id}/failures?type=wiki", admin) get api("/geo_nodes/failures?type=wiki", admin)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response.count).to eq(1) expect(json_response.count).to eq(1)
...@@ -137,7 +137,7 @@ describe API::GeoNodes, :geo, api: true do ...@@ -137,7 +137,7 @@ describe API::GeoNodes, :geo, api: true do
stub_current_geo_node(secondary) stub_current_geo_node(secondary)
expect(Gitlab::Geo).to receive(:current_node).and_return(secondary) expect(Gitlab::Geo).to receive(:current_node).and_return(secondary)
get api("/geo_nodes/#{secondary.id}/failures?type=repository", admin) get api("/geo_nodes/failures?type=repository", admin)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response.count).to eq(1) expect(json_response.count).to eq(1)
...@@ -149,14 +149,14 @@ describe API::GeoNodes, :geo, api: true do ...@@ -149,14 +149,14 @@ describe API::GeoNodes, :geo, api: true do
it 'returns a bad request' do it 'returns a bad request' do
create(:geo_project_registry, :repository_sync_failed) create(:geo_project_registry, :repository_sync_failed)
get api("/geo_nodes/#{secondary.id}/failures?type=nonexistent", admin) get api("/geo_nodes/failures?type=nonexistent", admin)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(400)
end end
end end
it 'denies access if not admin' do it 'denies access if not admin' do
get api("/geo_nodes/#{secondary.id}/failures", user) get api("/geo_nodes/failures", user)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(403)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment