Commit 931099d6 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Generalize some operations and check jh/ directory

parent 7c79dba3
...@@ -56,38 +56,29 @@ module Gitlab ...@@ -56,38 +56,29 @@ module Gitlab
config.generators.templates.push("#{config.root}/generator_templates") config.generators.templates.push("#{config.root}/generator_templates")
if Gitlab.ee? load_paths = lambda do |dir:|
ee_paths = config.eager_load_paths.each_with_object([]) do |path, memo| ext_paths = config.eager_load_paths.each_with_object([]) do |path, memo|
ee_path = config.root.join('ee', Pathname.new(path).relative_path_from(config.root)) ext_path = config.root.join(dir, Pathname.new(path).relative_path_from(config.root))
memo << ee_path.to_s memo << ext_path.to_s
end end
ee_paths << "#{config.root}/ee/app/replicators" ext_paths << "#{config.root}/#{dir}/app/replicators"
# Eager load should load CE first # Eager load should load CE first
config.eager_load_paths.push(*ee_paths) config.eager_load_paths.push(*ext_paths)
config.helpers_paths.push "#{config.root}/ee/app/helpers" config.helpers_paths.push "#{config.root}/#{dir}/app/helpers"
# Other than Ruby modules we load EE first # Other than Ruby modules we load extensions first
config.paths['lib/tasks'].unshift "#{config.root}/ee/lib/tasks" config.paths['lib/tasks'].unshift "#{config.root}/#{dir}/lib/tasks"
config.paths['app/views'].unshift "#{config.root}/ee/app/views" config.paths['app/views'].unshift "#{config.root}/#{dir}/app/views"
end end
if Gitlab.jh? Gitlab.ee do
jh_paths = config.eager_load_paths.each_with_object([]) do |path, memo| load_paths.call(dir: 'ee')
jh_path = config.root.join('jh', Pathname.new(path).relative_path_from(config.root)) end
memo << jh_path.to_s
end
jh_paths << "#{config.root}/jh/app/replicators"
# Eager load should load CE/EE first
config.eager_load_paths.push(*jh_paths)
config.helpers_paths.push "#{config.root}/jh/app/helpers"
# Other than Ruby modules we load JH first Gitlab.jh do
config.paths['lib/tasks'].unshift "#{config.root}/jh/lib/tasks" load_paths.call(dir: 'jh')
config.paths['app/views'].unshift "#{config.root}/jh/app/views"
end end
# Rake tasks ignore the eager loading settings, so we need to set the # Rake tasks ignore the eager loading settings, so we need to set the
......
# frozen_string_literal: true # frozen_string_literal: true
Gitlab.ee do load_license = lambda do |dir:, license_name:|
prefix = ENV['GITLAB_LICENSE_MODE'] == 'test' ? 'test_' : '' prefix = ENV['GITLAB_LICENSE_MODE'] == 'test' ? 'test_' : ''
public_key_file = File.read(Rails.root.join(".#{prefix}license_encryption_key.pub")) public_key_file = File.read(Rails.root.join(dir, ".#{prefix}license_encryption_key.pub"))
public_key = OpenSSL::PKey::RSA.new(public_key_file) public_key = OpenSSL::PKey::RSA.new(public_key_file)
Gitlab::License.encryption_key = public_key Gitlab::License.encryption_key = public_key
rescue rescue
warn "WARNING: No valid license encryption key provided." warn "WARNING: No valid #{license_name} encryption key provided."
end
Gitlab.ee do
load_license.call(dir: '.', license_name: 'license')
end end
Gitlab.jh do Gitlab.jh do
prefix = ENV['GITLAB_LICENSE_MODE'] == 'test' ? 'test_' : '' load_license.call(dir: 'jh', license_name: 'JH license')
public_key_file = File.read(Rails.root.join("jh", ".#{prefix}license_encryption_key.pub"))
public_key = OpenSSL::PKey::RSA.new(public_key_file)
Gitlab::License.encryption_key = public_key
rescue
warn "WARNING: No valid JH license encryption key provided."
end end
...@@ -111,7 +111,7 @@ module Gitlab ...@@ -111,7 +111,7 @@ module Gitlab
def self.jh? def self.jh?
@is_jh ||= @is_jh ||=
ee? && ee? &&
root.join('jh/app/helpers/jh/appearances_helper.rb').exist? && root.join('jh').exist? &&
!%w[true 1].include?(ENV['EE_ONLY'].to_s) !%w[true 1].include?(ENV['EE_ONLY'].to_s)
end end
......
...@@ -329,7 +329,7 @@ RSpec.describe Gitlab do ...@@ -329,7 +329,7 @@ RSpec.describe Gitlab do
before do before do
stub_path( stub_path(
'ee/app/models/license.rb', 'ee/app/models/license.rb',
'jh/app/helpers/jh/appearances_helper.rb', 'jh',
exist?: true) exist?: 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