2016-02-09 12:06:55 -05:00
|
|
|
module Projects
|
|
|
|
class UpdatePagesConfigurationService < BaseService
|
|
|
|
attr_reader :project
|
|
|
|
|
|
|
|
def initialize(project)
|
|
|
|
@project = project
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2016-02-10 09:06:31 -05:00
|
|
|
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
|
|
|
|
|
2016-02-10 09:06:31 -05:00
|
|
|
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
|
|
|
|
|
2016-02-10 09:06:31 -05:00
|
|
|
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
|