Commit 160a6f81 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Remove token from geo_node and some 💄

parent a9095fcc
...@@ -19,8 +19,7 @@ class GeoNode < ActiveRecord::Base ...@@ -19,8 +19,7 @@ class GeoNode < ActiveRecord::Base
host: lambda { Gitlab.config.gitlab.host }, host: lambda { Gitlab.config.gitlab.host },
port: 80, port: 80,
relative_url_root: '', relative_url_root: '',
primary: false, primary: false
token: lambda { SecureRandom.hex(20) }
accepts_nested_attributes_for :geo_node_key, :system_hook accepts_nested_attributes_for :geo_node_key, :system_hook
...@@ -86,23 +85,17 @@ class GeoNode < ActiveRecord::Base ...@@ -86,23 +85,17 @@ class GeoNode < ActiveRecord::Base
def build_dependents def build_dependents
self.build_geo_node_key if geo_node_key.nil? self.build_geo_node_key if geo_node_key.nil?
update_system_hook!
end end
def update_dependents_attributes def update_dependents_attributes
self.geo_node_key.title = "Geo node: #{self.url}" if self.geo_node_key self.geo_node_key.title = "Geo node: #{self.url}" if self.geo_node_key
self.token = SecureRandom.hex(20) if !self.token.present?
if self.primary? if self.primary?
self.oauth_application = nil self.oauth_application = nil
else else
# OAuth Application update_oauth_application!
self.build_oauth_application if oauth_application.nil? update_system_hook!
self.oauth_application.name = "Geo node: #{self.url}"
self.oauth_application.redirect_uri = oauth_callback_url
# SystemHook
self.build_system_hook if system_hook.nil?
self.system_hook.url = geo_events_url
self.system_hook.token = token
end end
end end
...@@ -114,4 +107,16 @@ class GeoNode < ActiveRecord::Base ...@@ -114,4 +107,16 @@ class GeoNode < ActiveRecord::Base
record.errors[:base] << 'Current node must be the primary node or you will be locking yourself out' record.errors[:base] << 'Current node must be the primary node or you will be locking yourself out'
end end
end end
def update_oauth_application!
self.build_oauth_application if oauth_application.nil?
self.oauth_application.name = "Geo node: #{self.url}"
self.oauth_application.redirect_uri = oauth_callback_url
end
def update_system_hook!
self.build_system_hook if system_hook.nil?
self.system_hook.token = SecureRandom.hex(20) unless self.system_hook.token.present?
self.system_hook.url = geo_events_url if uri.present?
end
end end
class AddTokenToGeoNode < ActiveRecord::Migration
def change
add_column :geo_nodes, :token, :string
end
end
...@@ -420,7 +420,6 @@ ActiveRecord::Schema.define(version: 20160414064845) do ...@@ -420,7 +420,6 @@ ActiveRecord::Schema.define(version: 20160414064845) do
t.boolean "primary" t.boolean "primary"
t.integer "geo_node_key_id" t.integer "geo_node_key_id"
t.integer "oauth_application_id" t.integer "oauth_application_id"
t.string "token"
t.integer "system_hook_id" t.integer "system_hook_id"
end end
......
...@@ -382,7 +382,7 @@ module API ...@@ -382,7 +382,7 @@ module API
end end
def geo_token def geo_token
Gitlab::Geo.current_node.token Gitlab::Geo.current_node.system_hook.token
end end
def handle_member_errors(errors) def handle_member_errors(errors)
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe GeoNode, type: :model do describe GeoNode, type: :model do
subject(:new_node) { described_class.new(schema: 'https', host: 'localhost', port: 3000, relative_url_root: 'gitlab') } subject(:new_node) { described_class.new(schema: 'https', host: 'localhost', port: 3000, relative_url_root: 'gitlab') }
subject(:new_primary_node) { described_class.new(schema: 'https', host: 'localhost', port: 3000, relative_url_root: 'gitlab', primary: true) } subject(:new_primary_node) { described_class.new(schema: 'https', host: 'localhost', port: 3000, relative_url_root: 'gitlab', primary: true) }
subject(:empty_node) { described_class.new(schema: nil, host: nil, port: nil, relative_url_root: nil) } subject(:empty_node) { described_class.new }
subject(:primary_node) { FactoryGirl.create(:geo_node, :primary) } subject(:primary_node) { FactoryGirl.create(:geo_node, :primary) }
subject(:node) { FactoryGirl.create(:geo_node) } subject(:node) { FactoryGirl.create(:geo_node) }
...@@ -87,7 +87,6 @@ describe GeoNode, type: :model do ...@@ -87,7 +87,6 @@ describe GeoNode, type: :model do
expect(node.system_hook.url).to be_present expect(node.system_hook.url).to be_present
expect(node.system_hook.url).to eq(node.geo_events_url) expect(node.system_hook.url).to eq(node.geo_events_url)
expect(node.system_hook.token).to be_present expect(node.system_hook.token).to be_present
expect(node.system_hook.token).to eq(node.token)
end end
end end
end end
......
...@@ -27,7 +27,7 @@ describe API::API, api: true do ...@@ -27,7 +27,7 @@ describe API::API, api: true do
end end
let(:geo_token_header) do let(:geo_token_header) do
{ 'X-Gitlab-Token' => geo_node.token } { 'X-Gitlab-Token' => geo_node.system_hook.token }
end end
let(:key_create_payload) do let(:key_create_payload) 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