summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-05-22 15:48:21 +0000
committerCan Eldem <celdem@gitlab.com>2020-05-22 15:48:21 +0000
commitef80bee8d1f97830449132afd1a4514c1d9d145b (patch)
tree93a45ec7990788dcff4c1c18a29920698889e593 /lib
parent7e044195b5148b1b9ecbb92d88eb2e4c57a3d81b (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')
-rw-r--r--lib/license/finder/ext/go_modules.rb24
-rw-r--r--lib/license/management/shell.rb51
2 files changed, 44 insertions, 31 deletions
diff --git a/lib/license/finder/ext/go_modules.rb b/lib/license/finder/ext/go_modules.rb
index 9fdd263..3b9042e 100644
--- a/lib/license/finder/ext/go_modules.rb
+++ b/lib/license/finder/ext/go_modules.rb
@@ -12,24 +12,28 @@ module LicenseFinder
end
def current_packages
- stdout, _stderr, status = shell.execute([
- :go, :list, '-m', '-f', "'{{.Path}},{{.Version}},{{.Dir}}'", :all
- ])
+ stdout, _stderr, status = shell.execute(go_list_command)
return [] unless status.success?
- stdout.each_line.map do |line|
- name, version, dir = line.chomp.split(',')
- next if dir.nil?
- next if Pathname(dir).cleanpath == absolute_project_path
-
- Package.new(name, version, install_path: dir)
- end.compact
+ stdout.each_line.map { |line| map_from(line) }.compact
end
private
+ def go_list_command
+ [:go, :list, '-m', '-f', "'{{.Path}},{{.Version}},{{.Dir}}'", :all]
+ end
+
def absolute_project_path
@absolute_project_path ||= Pathname(project_path).cleanpath
end
+
+ def map_from(line)
+ name, version, dir = line.chomp.split(',')
+ return if dir.nil?
+ return if Pathname(dir).cleanpath == absolute_project_path
+
+ Package.new(name, version, install_path: dir)
+ end
end
end
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