summaryrefslogtreecommitdiff
path: root/lib/license/management/shell.rb
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-03-23 15:36:17 -0600
committermo khan <mo.khan@gmail.com>2020-04-03 16:28:53 -0600
commit93f7c568e1104936de011626d3bd7f56ebe66355 (patch)
treead7b589d18aec83d4f09d0e64b75e1581c85589b /lib/license/management/shell.rb
parent93a00df11d79c9f59141ff42ce05ab3b3d329375 (diff)
Install root certificate
* Install certificate in root ca trust store * Use PIP_CERT environment variable to specify path to the certificate bundle * Do not override user provided PIP_CERT * Perform shallow clone when possible * Update CHANGELOG and bump version
Diffstat (limited to 'lib/license/management/shell.rb')
-rw-r--r--lib/license/management/shell.rb21
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