Commit ab60acb8 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Added PagesDomain

parent 6b69bf76
class PagesDomain < ActiveRecord::Base
belongs_to :project
validates :domain, hostname: true
validates_uniqueness_of :domain, allow_nil: true, allow_blank: true
validates :certificate, certificate: true, allow_nil: true, allow_blank: true
validates :key, certificate_key: true, allow_nil: true, allow_blank: true
attr_encrypted :pages_custom_certificate_key, mode: :per_attribute_iv_and_salt, key: Gitlab::Application.secrets.db_key_base
after_create :update
after_save :update
after_destroy :update
def url
return unless domain
return unless Dir.exist?(project.public_pages_path)
if certificate
return "https://#{domain}"
else
return "http://#{domain}"
end
end
def update
UpdatePagesConfigurationService.new(project).execute
end
end
...@@ -162,6 +162,7 @@ class Project < ActiveRecord::Base ...@@ -162,6 +162,7 @@ class Project < ActiveRecord::Base
has_many :lfs_objects, through: :lfs_objects_projects has_many :lfs_objects, through: :lfs_objects_projects
has_many :project_group_links, dependent: :destroy has_many :project_group_links, dependent: :destroy
has_many :invited_groups, through: :project_group_links, source: :group has_many :invited_groups, through: :project_group_links, source: :group
has_many :pages_domains, dependent: :destroy
has_one :import_data, dependent: :destroy, class_name: "ProjectImportData" has_one :import_data, dependent: :destroy, class_name: "ProjectImportData"
...@@ -209,18 +210,11 @@ class Project < ActiveRecord::Base ...@@ -209,18 +210,11 @@ class Project < ActiveRecord::Base
validates :avatar, file_size: { maximum: 200.kilobytes.to_i } validates :avatar, file_size: { maximum: 200.kilobytes.to_i }
validates :approvals_before_merge, numericality: true, allow_blank: true validates :approvals_before_merge, numericality: true, allow_blank: true
validates :pages_custom_domain, hostname: true, allow_blank: true, allow_nil: true
validates_uniqueness_of :pages_custom_domain, allow_nil: true, allow_blank: true
validates :pages_custom_certificate, certificate: true, allow_nil: true, allow_blank: true
validates :pages_custom_certificate_key, certificate_key: true, allow_nil: true, allow_blank: true
add_authentication_token_field :runners_token add_authentication_token_field :runners_token
before_save :ensure_runners_token before_save :ensure_runners_token
mount_uploader :avatar, AvatarUploader mount_uploader :avatar, AvatarUploader
attr_encrypted :pages_custom_certificate_key, mode: :per_attribute_iv_and_salt, key: Gitlab::Application.secrets.db_key_base
# Scopes # Scopes
scope :sorted_by_activity, -> { reorder(last_activity_at: :desc) } scope :sorted_by_activity, -> { reorder(last_activity_at: :desc) }
scope :sorted_by_stars, -> { reorder('projects.star_count DESC') } scope :sorted_by_stars, -> { reorder('projects.star_count DESC') }
...@@ -1066,17 +1060,6 @@ class Project < ActiveRecord::Base ...@@ -1066,17 +1060,6 @@ class Project < ActiveRecord::Base
"#{url}/#{path}" "#{url}/#{path}"
end end
def pages_custom_url
return unless pages_custom_domain
return unless Dir.exist?(public_pages_path)
if Gitlab.config.pages.https
return "https://#{pages_custom_domain}"
else
return "http://#{pages_custom_domain}"
end
end
def pages_path def pages_path
File.join(Settings.pages.path, path_with_namespace) File.join(Settings.pages.path, path_with_namespace)
end end
...@@ -1085,32 +1068,15 @@ class Project < ActiveRecord::Base ...@@ -1085,32 +1068,15 @@ class Project < ActiveRecord::Base
File.join(pages_path, 'public') File.join(pages_path, 'public')
end end
def remove_pages_certificate
update(
pages_custom_certificate: nil,
pages_custom_certificate_key: nil
)
UpdatePagesConfigurationService.new(self).execute
end
def remove_pages def remove_pages
# 1. We rename pages to temporary directory # 1. We rename pages to temporary directory
# 2. We wait 5 minutes, due to NFS caching # 2. We wait 5 minutes, due to NFS caching
# 3. We asynchronously remove pages with force # 3. We asynchronously remove pages with force
temp_path = "#{path}.#{SecureRandom.hex}" temp_path = "#{path}.#{SecureRandom.hex}.deleted"
if Gitlab::PagesTransfer.new.rename_project(path, temp_path, namespace.path) if Gitlab::PagesTransfer.new.rename_project(path, temp_path, namespace.path)
PagesWorker.perform_in(5.minutes, :remove, namespace.path, temp_path) PagesWorker.perform_in(5.minutes, :remove, namespace.path, temp_path)
end end
update(
pages_custom_certificate: nil,
pages_custom_certificate_key: nil,
pages_custom_domain: nil
)
UpdatePagesConfigurationService.new(self).execute
end end
def merge_method def merge_method
......
class AddPagesCustomDomainToProjects < ActiveRecord::Migration
def change
add_column :projects, :pages_custom_certificate, :text
add_column :projects, :encrypted_pages_custom_certificate_key, :text
add_column :projects, :encrypted_pages_custom_certificate_key_iv, :string
add_column :projects, :encrypted_pages_custom_certificate_key_salt, :string
add_column :projects, :pages_custom_domain, :string, unique: true
add_column :projects, :pages_redirect_http, :boolean, default: false, null: false
end
end
class CreatePagesDomain < ActiveRecord::Migration
def change
create_table :pages_domains do |t|
t.integer :project_id
t.text :certificate
t.text :encrypted_key
t.string :encrypted_key_iv
t.string :encrypted_key_salt
t.string :domain
end
add_index :pages_domains, :domain, unique: true
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