diff options
| author | mo khan <mo.khan@gmail.com> | 2020-05-22 15:48:21 +0000 |
|---|---|---|
| committer | Can Eldem <celdem@gitlab.com> | 2020-05-22 15:48:21 +0000 |
| commit | ef80bee8d1f97830449132afd1a4514c1d9d145b (patch) | |
| tree | 93a45ec7990788dcff4c1c18a29920698889e593 /lib/license/management/shell.rb | |
| parent | 7e044195b5148b1b9ecbb92d88eb2e4c57a3d81b (diff) | |
Add functional tests to the pipeline
* Move jobs to gitlab-ci.yml files that match the stage they belong to.
* Move linter job to build stage
* Add functional test jobs
* Reduce max size to 2 GB
* Pass the current pipeline image to the downstream jobs
* Replace `edge` tag with `latest`
* Use $CI_DEFAULT_BRANCH instead of master
* Move `.env*` files to config dir and update RELEASE instructions
* Combine `tag` and `release` stages into `deploy` stage as recommended in GitLab docs
* Make the `build-docker-image` job interruptible
* Fix issues found in code quality report
Diffstat (limited to 'lib/license/management/shell.rb')
| -rw-r--r-- | lib/license/management/shell.rb | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/lib/license/management/shell.rb b/lib/license/management/shell.rb index 9053a3f..9ea66ca 100644 --- a/lib/license/management/shell.rb +++ b/lib/license/management/shell.rb @@ -9,7 +9,7 @@ module License 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) + trust!(certificate) if present?(certificate) end def execute(command, env: {}) @@ -18,8 +18,7 @@ module License stdout, stderr, status = Open3.capture3(env, expanded_command) - logger.debug(stdout) unless stdout.nil? || stdout.empty? - logger.error(stderr) unless stderr.nil? || stderr.empty? + record(stdout, stderr) [stdout, stderr, status] end @@ -38,8 +37,6 @@ module License end def trust!(certificate) - return unless present?(certificate) - custom_certificate_path.write(certificate) Dir.chdir custom_certificate_path.dirname do execute([:awk, SPLIT_SCRIPT, '<', custom_certificate_path]) @@ -48,29 +45,41 @@ module License Dir.glob('custom.*.crt').each do |path| full_path = File.expand_path(path) execute([:openssl, :x509, '-in', full_path, '-text', '-noout']) - keystore_path = "#{ENV['JAVA_HOME']}/jre/lib/security/cacerts" - execute([ - :keytool, - '-importcert', - '-alias', Time.now.to_i, - '-file', full_path, - '-trustcacerts', - '-noprompt', - '-storepass', 'changeit', - '-keystore', keystore_path - ]) - execute([ - :keytool, '-list', '-v', - '-storepass changeit', - '-keystore', keystore_path - ]) + execute(keytool_import_command(full_path)) + execute(keytool_list_command) end end 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 + + def record(stdout, stderr) + logger.debug(stdout) if present?(stdout) + logger.error(stderr) if present?(stderr) + end end end end |
