Commit 5ab12ad0 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Gitlab Geo initial node discovery

parent bd064da6
# == Schema Information
#
# Table name: geo_nodes
#
# id :integer not null, primary key
# host :string
# relative_url_root :string
# primary :boolean
#
class GeoNode < ActiveRecord::Base
default_value_for :primary, false
default_value_for :relative_url_root, ''
validates :host, hostname: true, presence: true, uniqueness: { case_sensitive: false }
validates :primary, uniqueness: { message: 'primary node already exists' }, if: :primary
end
# HostnameValidator
#
# Custom validator for Hostnames.
#
# This is similar to an URI validator, but will make sure no schema or
# path is present, only the domain part.
#
class HostnameValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless valid_hostname?(value)
record.errors.add(attribute, 'must be a valid host')
end
end
private
def valid_hostname?(value)
URI.parse("fake://#{value}").hostname == value
end
end
class CreateGeoNodes < ActiveRecord::Migration
def change
create_table :geo_nodes do |t|
t.string :host
t.string :relative_url_root
t.boolean :primary
end
end
end
......@@ -400,6 +400,12 @@ ActiveRecord::Schema.define(version: 20160119170055) do
add_index "forked_project_links", ["forked_to_project_id"], name: "index_forked_project_links_on_forked_to_project_id", unique: true, using: :btree
create_table "geo_nodes", force: :cascade do |t|
t.string "host"
t.string "relative_url_root"
t.boolean "primary"
end
create_table "git_hooks", force: :cascade do |t|
t.string "force_push_regex"
t.string "delete_branch_regex"
......
module Gitlab
module Geo
def self.enabled?
GeoNode.exists?
end
def self.current_node
GeoNode.find_by(host: Gitlab.config.gitlab.host, relative_url_root: Gitlab.config.gitlab.relative_url_root)
end
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