diff options
Diffstat (limited to 'lib/license/management/shell.rb')
| -rw-r--r-- | lib/license/management/shell.rb | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/license/management/shell.rb b/lib/license/management/shell.rb index a1a1412..691a8ea 100644 --- a/lib/license/management/shell.rb +++ b/lib/license/management/shell.rb @@ -3,10 +3,12 @@ module License module Management class Shell - attr_reader :logger + attr_reader :custom_certificate_path, :logger - def initialize(logger: License::Management.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') + trust!(certificate) end def execute(command, env: {}) @@ -24,11 +26,26 @@ module License execute("sh -c '#{expand(command)}'", env: env) end + def custom_certificate_installed? + present?(ENV['ADDITIONAL_CA_CERT_BUNDLE']) && custom_certificate_path.exist? + end + private def expand(command) Array(command).map(&:to_s).join(' ') end + + def trust!(certificate) + return unless present?(certificate) + + custom_certificate_path.write(certificate) + execute('update-ca-certificates -v') + end + + def present?(item) + !item.nil? && !item.empty? + end end end end |
