summaryrefslogtreecommitdiff
path: root/lib/license/management/repository.rb
diff options
context:
space:
mode:
authorTetiana Chupryna <tchupryna@gitlab.com>2019-10-24 13:38:32 +0000
committerTetiana Chupryna <tchupryna@gitlab.com>2019-10-24 13:38:32 +0000
commited6d15ee8d8167f94b7ca03f26526c7ab29aab02 (patch)
tree04fe5855bbd079a399f8fc2ccdf148c54bf1b024 /lib/license/management/repository.rb
parent1fd208bf51631029e89daf88600fdd62224c7207 (diff)
parentcdfa8116a4c7d0c7659ed98aee289b489646c658 (diff)
Merge branch '12651-dotnet-2.2+3.0' into 'master'v1.7.4
Install .NET Core 2.2 and .NET Core 3.0 See merge request gitlab-org/security-products/license-management!70
Diffstat (limited to 'lib/license/management/repository.rb')
-rw-r--r--lib/license/management/repository.rb34
1 files changed, 27 insertions, 7 deletions
diff --git a/lib/license/management/repository.rb b/lib/license/management/repository.rb
index 0c428dd..ed2519f 100644
--- a/lib/license/management/repository.rb
+++ b/lib/license/management/repository.rb
@@ -5,6 +5,11 @@ module License
class Repository
include Loggable
include Verifiable
+ KNOWN_SOURCES = [
+ 'licenses.nuget.org',
+ 'opensource.org',
+ 'www.opensource.org',
+ ].freeze
def initialize(
compatibility_path: License::Management.root.join('normalized-licenses.yml'),
@@ -25,6 +30,8 @@ module License
attr_reader :spdx_data, :compatibility_data
def spdx_data_for(id)
+ return if blank?(id)
+
data = spdx_data[id]
if data
{
@@ -32,15 +39,15 @@ module License
'name' => data['name'],
'url' => data['seeAlso'][-1]
}
- else
- log_info("Could not find license `#{id}` in SPDX")
- nil
end
end
def id_for(license)
ids = compatibility_data['ids']
- ids[license.send(:short_name)] || ids[license.url]
+ ids[license.send(:short_name)] ||
+ ids[license.url] ||
+ known_sources(license.send(:short_name)) ||
+ known_sources(license.url)
end
# When `license_finder` is unable to determine the license it will use the full
@@ -53,10 +60,11 @@ module License
end
def generate_item_for(license)
- log_info("detected unknown license named `#{license.send(:short_name)}`")
+ log_info("detected unknown license named `#{license.send(:short_name)}`:`#{license.url}`")
+ name = take_first_line_from(license.name)
{
- 'id' => 'unknown',
- 'name' => take_first_line_from(license.name),
+ 'id' => name.downcase,
+ 'name' => name,
'url' => present?(license.url) ? license.url : ''
}
end
@@ -71,6 +79,18 @@ module License
memo
end
end
+
+ def known_sources(url)
+ return if blank?(url)
+ return unless url =~ /\A#{::URI::DEFAULT_PARSER.make_regexp(['http', 'https'])}\z/
+
+ uri = URI.parse(url)
+ return unless KNOWN_SOURCES.include?(uri.host.downcase)
+ uri.path.split('/')[-1]
+ rescue => error
+ log_info(error)
+ nil
+ end
end
end
end