gitlab-org--gitlab-foss/app/services/projects/update_pages_configuration_service.rb

60 lines
1.1 KiB
Ruby
Raw Normal View History

2016-02-09 12:06:55 -05:00
module Projects
class UpdatePagesConfigurationService < BaseService
attr_reader :project
def initialize(project)
@project = project
end
def execute
update_file(pages_config_file, pages_config)
2016-02-09 12:06:55 -05:00
reload_daemon
success
rescue => e
error(e.message)
end
private
def pages_config
{
domains: pages_domains_config
}
end
def pages_domains_config
project.pages_domains.map do |domain|
{
domain: domain.domain,
certificate: domain.certificate,
key: domain.key,
}
end
end
2016-02-09 12:06:55 -05:00
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_config_file
File.join(pages_path, 'config.jso')
2016-02-09 12:06:55 -05:00
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