Class: Chelsea::OSSIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/chelsea/oss_index.rb

Overview

OSS Index audit operations

Constant Summary collapse

DEFAULT_OPTIONS =
{
  oss_index_username: '',
  oss_index_user_token: ''
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(options: DEFAULT_OPTIONS) ⇒ OSSIndex

Returns a new instance of OSSIndex.



30
31
32
33
34
# 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

Instance Method Details

#call_oss_index(coords) ⇒ Object



52
53
54
55
# 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) ⇒ Object

Makes REST calls to OSS for vulnerabilities 128 coordinates at a time Checks cache and stores results in cache



39
40
41
42
43
44
45
46
47
48
49
50
# 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