diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-02-09 18:06:55 +0100 |
---|---|---|
committer | James Edwards-Jones <jedwardsjones@gitlab.com> | 2017-01-31 22:53:57 +0000 |
commit | 5f7257c27dace1dcb9d3eb4732caf68f061a8d68 (patch) | |
tree | a00cfa51f1aa44ae3592d49c3232795d21d3fae4 /app/services/projects/update_pages_configuration_service.rb | |
parent | c4c8ca04052aaf7d37c2335066381b536df68427 (diff) | |
download | gitlab-ce-5f7257c27dace1dcb9d3eb4732caf68f061a8d68.tar.gz |
Initial work on GitLab Pages update
Diffstat (limited to 'app/services/projects/update_pages_configuration_service.rb')
-rw-r--r-- | app/services/projects/update_pages_configuration_service.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/app/services/projects/update_pages_configuration_service.rb b/app/services/projects/update_pages_configuration_service.rb new file mode 100644 index 00000000000..be4c2fbef8c --- /dev/null +++ b/app/services/projects/update_pages_configuration_service.rb @@ -0,0 +1,53 @@ +module Projects + class UpdatePagesConfigurationService < BaseService + attr_reader :project + + def initialize(project) + @project = project + end + + def execute + update_file(pages_cname_file, project.pages_custom_domain) + update_file(pages_certificate_file, project.pages_custom_certificate) + update_file(pages_certificate_file_key, project.pages_custom_certificate_key) + reload_daemon + success + rescue => e + error(e.message) + end + + private + + def reload_daemon + # GitLab Pages daemon constantly watches for modification time of `pages.path` + # It reloads configuration when `pages.path` is modified + File.touch(Settings.pages.path) + end + + def pages_path + @pages_path ||= project.pages_path + end + + def pages_cname_file + File.join(pages_path, 'CNAME') + end + + def pages_certificate_file + File.join(pages_path, 'domain.crt') + end + + def pages_certificate_key_file + File.join(pages_path, 'domain.key') + end + + def update_file(file, data) + if data + File.open(file, 'w') do |file| + file.write(data) + end + else + File.rm_r(file) + end + end + end +end |