summaryrefslogtreecommitdiff
path: root/app/controllers/projects/pages_controller.rb
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-02-10 15:06:31 +0100
committerJames Edwards-Jones <jedwardsjones@gitlab.com>2017-01-31 22:53:57 +0000
commit13b6bad17ec46eb78878f6972da1e7e34be86bb5 (patch)
tree745e04a26813be3e65200bc4ab6ece3fe73e6069 /app/controllers/projects/pages_controller.rb
parent6e99226cca41f36d92c4ccb2cd398d2256091adc (diff)
downloadgitlab-ce-13b6bad17ec46eb78878f6972da1e7e34be86bb5.tar.gz
Implement extra domains and save pages configuration
Diffstat (limited to 'app/controllers/projects/pages_controller.rb')
-rw-r--r--app/controllers/projects/pages_controller.rb94
1 files changed, 33 insertions, 61 deletions
diff --git a/app/controllers/projects/pages_controller.rb b/app/controllers/projects/pages_controller.rb
index 055f182ae00..82814afe196 100644
--- a/app/controllers/projects/pages_controller.rb
+++ b/app/controllers/projects/pages_controller.rb
@@ -2,25 +2,45 @@ class Projects::PagesController < Projects::ApplicationController
layout 'project_settings'
before_action :authorize_update_pages!, except: [:show]
- before_action :authorize_remove_pages!, only: :destroy
+ before_action :authorize_remove_pages!, only: [:remove_pages]
+ before_action :label, only: [:destroy]
+ before_action :domain, only: [:show]
helper_method :valid_certificate?, :valid_certificate_key?
helper_method :valid_key_for_certificiate?, :valid_certificate_intermediates?
helper_method :certificate, :certificate_key
+ def index
+ @domains = @project.pages_domains.order(:domain)
+ end
+
def show
end
- def update
- if @project.update_attributes(pages_params)
+ def new
+ @domain = @project.pages_domains.new
+ end
+
+ def create
+ @domain = @project.pages_domains.create(pages_domain_params)
+
+ if @domain.valid?
redirect_to namespace_project_pages_path(@project.namespace, @project)
else
- render 'show'
+ render 'new'
end
end
- def certificate
- @project.remove_pages_certificate
+ def destroy
+ @domain.destroy
+
+ respond_to do |format|
+ format.html do
+ redirect_to(namespace_project_pages_path(@project.namespace, @project),
+ notice: 'Domain was removed')
+ end
+ format.js
+ end
end
def destroy
@@ -33,63 +53,15 @@ class Projects::PagesController < Projects::ApplicationController
private
- def pages_params
- params.require(:project).permit(
- :pages_custom_certificate,
- :pages_custom_certificate_key,
- :pages_custom_domain,
- :pages_redirect_http,
+ def pages_domain_params
+ params.require(:pages_domain).permit(
+ :certificate,
+ :key,
+ :domain
)
end
- def valid_certificate?
- certificate.present?
- end
-
- def valid_certificate_key?
- certificate_key.present?
- end
-
- def valid_key_for_certificiate?
- return false unless certificate
- return false unless certificate_key
-
- # We compare the public key stored in certificate with public key from certificate key
- certificate.public_key.to_pem == certificate_key.public_key.to_pem
- rescue OpenSSL::X509::CertificateError, OpenSSL::PKey::PKeyError
- false
- end
-
- def valid_certificate_intermediates?
- return false unless certificate
-
- store = OpenSSL::X509::Store.new
- store.set_default_paths
-
- # This forces to load all intermediate certificates stored in `pages_custom_certificate`
- Tempfile.open('project_certificate') do |f|
- f.write(@project.pages_custom_certificate)
- f.flush
- store.add_file(f.path)
- end
-
- store.verify(certificate)
- rescue OpenSSL::X509::StoreError
- false
- end
-
- def certificate
- return unless @project.pages_custom_certificate
-
- @certificate ||= OpenSSL::X509::Certificate.new(@project.pages_custom_certificate)
- rescue OpenSSL::X509::CertificateError
- nil
- end
-
- def certificate_key
- return unless @project.pages_custom_certificate_key
- @certificate_key ||= OpenSSL::PKey::RSA.new(@project.pages_custom_certificate_key)
- rescue OpenSSL::PKey::PKeyError, OpenSSL::Cipher::CipherError
- nil
+ def domain
+ @domain ||= @project.pages_domains.find_by(domain: params[:id].to_s)
end
end