summaryrefslogtreecommitdiff
path: root/lib/license/management/shell.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/license/management/shell.rb')
-rw-r--r--lib/license/management/shell.rb52
1 files changed, 24 insertions, 28 deletions
diff --git a/lib/license/management/shell.rb b/lib/license/management/shell.rb
index 1a99895..b066bc1 100644
--- a/lib/license/management/shell.rb
+++ b/lib/license/management/shell.rb
@@ -4,12 +4,29 @@ module License
module Management
class Shell
SPLIT_SCRIPT = "'BEGIN {x=0;} /BEGIN CERT/{x++} { print > \"custom.\" x \".crt\" }'"
- attr_reader :default_certificate_path, :custom_certificate_path, :logger
+ COMMAND_MAP = {
+ asdf: '/opt/asdf/bin/asdf',
+ bundle: '/opt/asdf/bin/asdf exec bundle',
+ cargo: '/opt/asdf/bin/asdf exec cargo',
+ cert_sync: '/opt/asdf/installs/mono/6.8.0.123/bin/cert-sync',
+ embedded_bundle: '/opt/gitlab/embedded/bin/bundle',
+ gem: '/opt/asdf/bin/asdf exec gem',
+ go: '/opt/asdf/bin/asdf exec go',
+ keytool: '/opt/asdf/bin/asdf exec keytool',
+ mono: '/opt/asdf/installs/mono/6.8.0.123/bin/mono',
+ mvn: '/opt/asdf/bin/asdf exec mvn',
+ nuget: '/opt/asdf/installs/mono/6.8.0.123/bin/nuget.exe',
+ ruby: '/opt/asdf/bin/asdf exec ruby',
+ yarn: '/opt/asdf/bin/asdf exec yarn'
+ }.freeze
+
+ attr_reader :default_env, :default_certificate_path, :custom_certificate_path, :logger
def initialize(logger: License::Management.logger, certificate: ENV['ADDITIONAL_CA_CERT_BUNDLE'])
@logger = logger
@custom_certificate_path = Pathname.new('/usr/local/share/ca-certificates/custom.crt')
@default_certificate_path = Pathname.new('/etc/ssl/certs/ca-certificates.crt')
+ @default_env = { 'SSL_CERT_FILE' => @default_certificate_path.to_s }
trust!(certificate) if present?(certificate)
end
@@ -17,7 +34,7 @@ module License
expanded_command = expand(command)
collapsible_section(expanded_command) do
logger.debug(expanded_command)
- stdout, stderr, status = Open3.capture3(env, expanded_command)
+ stdout, stderr, status = Open3.capture3(default_env.merge(env), expanded_command)
record(stdout, stderr, status)
[stdout, stderr, status]
end
@@ -34,7 +51,10 @@ module License
private
def expand(command)
- Array(command).flatten.map(&:to_s).join(' ')
+ Array(command)
+ .flatten
+ .map { |x| COMMAND_MAP.fetch(x, x).to_s }
+ .join(' ')
end
def trust!(certificate)
@@ -44,37 +64,13 @@ module License
execute('update-ca-certificates -v')
Dir.glob('custom.*.crt').each do |path|
- full_path = File.expand_path(path)
- execute([:openssl, :x509, '-in', full_path, '-text', '-noout'])
- execute(keytool_import_command(full_path))
- execute(keytool_list_command)
+ execute([:openssl, :x509, '-in', File.expand_path(path), '-text', '-noout'])
end
end
execute([:cp, custom_certificate_path.to_s, "/usr/lib/ssl/certs/"])
execute([:c_rehash, '-v'])
end
- def keytool_import_command(file_path)
- [
- :keytool,
- '-importcert',
- '-alias', Time.now.to_i,
- '-file', file_path,
- '-trustcacerts',
- '-noprompt',
- '-storepass', 'changeit',
- '-keystore', keystore_path
- ]
- end
-
- def keytool_list_command
- [:keytool, '-list', '-v', '-storepass changeit', '-keystore', keystore_path]
- end
-
- def keystore_path
- "#{ENV['JAVA_HOME']}/jre/lib/security/cacerts"
- end
-
def present?(item)
!item.nil? && !item.empty?
end