class Chelsea::OSSIndex
OSS Index audit operations
Constants
- DEFAULT_OPTIONS
Public Class Methods
new(options: DEFAULT_OPTIONS)
click to toggle source
# File lib/chelsea/oss_index.rb, line 30 def initialize(options: DEFAULT_OPTIONS) @oss_index_user_name = options[:oss_index_user_name] @oss_index_user_token = options[:oss_index_user_token] @db = DB.new end
Public Instance Methods
call_oss_index(coords)
click to toggle source
# File lib/chelsea/oss_index.rb, line 52 def call_oss_index(coords) r = _resource.post coords.to_json, _headers r.code == 200 ? r.body : {} end
get_vulns(coordinates)
click to toggle source
Makes REST calls to OSS for vulnerabilities 128 coordinates at a time Checks cache and stores results in cache
# File lib/chelsea/oss_index.rb, line 39 def get_vulns(coordinates) remaining_coordinates, cached_server_response = _cache(coordinates) return cached_server_response unless remaining_coordinates['coordinates'].count.positive? remaining_coordinates['coordinates'].each_slice(128).to_a.each do |coords| res_json = JSON.parse(call_oss_index({ 'coordinates' => coords })) cached_server_response.concat(res_json) @db.save_values_to_db(res_json) end cached_server_response end
Private Instance Methods
_api_url()
click to toggle source
# File lib/chelsea/oss_index.rb, line 89 def _api_url 'https://ossindex.sonatype.org/api/v3/component-report' end
_cache(coordinates)
click to toggle source
# File lib/chelsea/oss_index.rb, line 59 def _cache(coordinates) # rubocop:disable Metrics/MethodLength new_coords = { 'coordinates' => [] } cached_server_response = [] coordinates['coordinates'].each do |coord| record = @db.get_cached_value_from_db(coord) if record.nil? new_coords['coordinates'].push(coord) else cached_server_response << record end end [new_coords, cached_server_response] end
_headers()
click to toggle source
# File lib/chelsea/oss_index.rb, line 73 def _headers { :content_type => :json, :accept => :json, 'User-Agent' => _user_agent } end
_resource()
click to toggle source
# File lib/chelsea/oss_index.rb, line 77 def _resource if !@oss_index_user_name.empty? && !@oss_index_user_token.empty? RestClient::Resource.new( _api_url, user: @oss_index_user_name, password: @oss_index_user_token ) else RestClient::Resource.new(_api_url) end end
_user_agent()
click to toggle source
# File lib/chelsea/oss_index.rb, line 93 def _user_agent "chelsea/#{Chelsea::VERSION}" end