Module: Chelsea

Defined in:
lib/chelsea/config.rb,
lib/chelsea/db.rb,
lib/chelsea/bom.rb,
lib/chelsea/cli.rb,
lib/chelsea/deps.rb,
lib/chelsea/gems.rb,
lib/chelsea/spinner.rb,
lib/chelsea/version.rb,
lib/chelsea/iq_client.rb,
lib/chelsea/oss_index.rb,
lib/chelsea/formatters/xml.rb,
lib/chelsea/formatters/json.rb,
lib/chelsea/formatters/text.rb,
lib/chelsea/dependency_exception.rb

Overview

Copyright 2019-Present Sonatype Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Defined Under Namespace

Classes: Bom, CLI, DB, DependencyException, Deps, Gems, IQClient, JsonFormatter, OSSIndex, Spinner, TextFormatter, XMLFormatter

Constant Summary collapse

VERSION =
'0.0.43'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

._write_oss_index_config_file(config) ⇒ Object



85
86
87
88
89
90
# File 'lib/chelsea/config.rb', line 85

def self._write_oss_index_config_file(config)
  Dir.mkdir(@oss_index_config_location) unless File.exist? @oss_index_config_location
  File.open(File.join(@oss_index_config_location, @oss_index_config_filename), 'w') do |file|
    file.write config.to_yaml
  end
end

.client(options = {}) ⇒ Object



44
45
46
47
# File 'lib/chelsea/config.rb', line 44

def self.client(options = {})
  @client ||= config(options)
  @client
end

.config(options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/chelsea/config.rb', line 31

def self.config(options = {})
  if !options[:user].nil? && !options[:token].nil?
    Chelsea::OSSIndex.new(
      options: {
        oss_index_user_name: options[:user],
        oss_index_user_token: options[:token]
      }
    )
  else
    Chelsea::OSSIndex.new(options: oss_index_config)
  end
end

.oss_index_configObject

rubocop:disable Metrics/MethodLength



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/chelsea/config.rb', line 49

def self.oss_index_config # rubocop:disable Metrics/MethodLength
  if File.exist? File.join(@oss_index_config_location, @oss_index_config_filename)
    conf_hash = YAML.safe_load(
      File.read(
        File.join(@oss_index_config_location, @oss_index_config_filename)
      )
    )
    {
      oss_index_user_name: conf_hash['Username'],
      oss_index_user_token: conf_hash['Token']
    }
  else
    { oss_index_user_name: '', oss_index_user_token: '' }
  end
end

.read_oss_index_config_from_command_lineObject



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/chelsea/config.rb', line 73

def self.read_oss_index_config_from_command_line
  config = {}

  puts 'What username do you want to authenticate as (ex: your email address)? '
  config['Username'] = $stdin.gets.chomp

  puts 'What token do you want to use? '
  config['Token'] = $stdin.gets.chomp

  _write_oss_index_config_file(config)
end

.to_purl(name, version) ⇒ Object



27
28
29
# File 'lib/chelsea/config.rb', line 27

def self.to_purl(name, version)
  "pkg:gem/#{name}@#{version}"
end

Instance Method Details

#get_white_list_vuln_config(white_list_config_path) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/chelsea/config.rb', line 65

def get_white_list_vuln_config(white_list_config_path)
  if white_list_config_path.nil?
    YAML.safe_load(File.read(File.join(Dir.pwd, 'chelsea-ignore.yaml')))
  else
    YAML.safe_load(File.read(white_list_config_path))
  end
end