Commit 7c7ef7ce authored by Sean McGivern's avatar Sean McGivern

Merge branch 'tc-geo-open-edit-primary-api' into 'master'

Make it possible to edit Geo primary through API

Closes #9454

See merge request gitlab-org/gitlab-ee!9328
parents c95a3cfb 7241d4c8
...@@ -70,7 +70,7 @@ Example response: ...@@ -70,7 +70,7 @@ Example response:
## Edit a Geo node ## Edit a Geo node
Updates an existing Geo secondary node. The primary node cannot be edited. Updates settings of an existing Geo node.
_This can only be run against a primary Geo node._ _This can only be run against a primary Geo node._
...@@ -92,8 +92,8 @@ Example response: ...@@ -92,8 +92,8 @@ Example response:
```json ```json
{ {
"id": 1, "id": 1,
"url": "https://primary.example.com/", "url": "https://secondary.example.com/",
"primary": true, "primary": false,
"enabled": true, "enabled": true,
"current": true, "current": true,
"files_max_capacity": 10, "files_max_capacity": 10,
...@@ -107,6 +107,9 @@ Example response: ...@@ -107,6 +107,9 @@ Example response:
Removes the Geo node. Removes the Geo node.
NOTE: **Note:**
Only a Geo primary node will accept this request.
``` ```
DELETE /geo_nodes/:id DELETE /geo_nodes/:id
``` ```
......
...@@ -21,6 +21,7 @@ class GeoNode < ActiveRecord::Base ...@@ -21,6 +21,7 @@ class GeoNode < ActiveRecord::Base
validate :check_url_is_valid validate :check_url_is_valid
validates :primary, uniqueness: { message: 'node already exists' }, if: :primary validates :primary, uniqueness: { message: 'node already exists' }, if: :primary
validates :enabled, if: :primary, acceptance: { message: 'Geo primary node cannot be disabled' }
validates :access_key, presence: true validates :access_key, presence: true
validates :encrypted_secret_access_key, presence: true validates :encrypted_secret_access_key, presence: true
......
---
title: Make it possible to edit Geo primary through API
merge_request: 9328
author:
type: changed
...@@ -138,7 +138,7 @@ module API ...@@ -138,7 +138,7 @@ module API
# #
# Example request: # Example request:
# PUT /geo_nodes/:id # PUT /geo_nodes/:id
desc 'Edit an existing Geo secondary node' do desc 'Update an existing Geo node' do
success EE::API::Entities::GeoNode success EE::API::Entities::GeoNode
end end
params do params do
...@@ -153,9 +153,7 @@ module API ...@@ -153,9 +153,7 @@ module API
update_params = declared_params(include_missing: false) update_params = declared_params(include_missing: false)
if geo_node.primary? if geo_node.update(update_params)
forbidden!('Primary node cannot be edited')
elsif geo_node.update(update_params)
present geo_node, with: EE::API::Entities::GeoNode present geo_node, with: EE::API::Entities::GeoNode
else else
render_validation_error!(geo_node) render_validation_error!(geo_node)
......
...@@ -13,8 +13,7 @@ describe Gitlab::Geo::JwtRequestDecoder do ...@@ -13,8 +13,7 @@ describe Gitlab::Geo::JwtRequestDecoder do
end end
it 'fails to decode when node is disabled' do it 'fails to decode when node is disabled' do
primary_node.enabled = false primary_node.update_attribute(:enabled, false)
primary_node.save
expect(subject.decode).to be_nil expect(subject.decode).to be_nil
end end
......
...@@ -27,6 +27,15 @@ describe GeoNode, type: :model do ...@@ -27,6 +27,15 @@ describe GeoNode, type: :model do
it { is_expected.to validate_numericality_of(:files_max_capacity).is_greater_than_or_equal_to(0) } it { is_expected.to validate_numericality_of(:files_max_capacity).is_greater_than_or_equal_to(0) }
it { is_expected.to validate_numericality_of(:verification_max_capacity).is_greater_than_or_equal_to(0) } it { is_expected.to validate_numericality_of(:verification_max_capacity).is_greater_than_or_equal_to(0) }
it { is_expected.to validate_numericality_of(:minimum_reverification_interval).is_greater_than_or_equal_to(1) } it { is_expected.to validate_numericality_of(:minimum_reverification_interval).is_greater_than_or_equal_to(1) }
context 'primary node' do
it 'cannot be disabled' do
primary_node.enabled = false
expect(primary_node).not_to be_valid
expect(primary_node.errors).to include(:enabled)
end
end
end end
context 'default values' do context 'default values' do
......
...@@ -223,6 +223,28 @@ describe API::GeoNodes, :geo, :prometheus, api: true do ...@@ -223,6 +223,28 @@ describe API::GeoNodes, :geo, :prometheus, api: true do
expect(response).to match_response_schema('public_api/v4/geo_node', dir: 'ee') expect(response).to match_response_schema('public_api/v4/geo_node', dir: 'ee')
expect(json_response).to include(params) expect(json_response).to include(params)
end end
it 'can update primary' do
params = {
url: 'https://updated.example.com/'
}.stringify_keys
put api("/geo_nodes/#{primary.id}", admin), params: params
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('public_api/v4/geo_node', dir: 'ee')
expect(json_response).to include(params)
end
it 'cannot disable a primary' do
params = {
enabled: false
}.stringify_keys
put api("/geo_nodes/#{primary.id}", admin), params: params
expect(response).to have_gitlab_http_status(400)
end
end end
describe 'DELETE /geo_nodes/:id' do describe 'DELETE /geo_nodes/:id' do
......
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