Module: Bundler::Security::Voting::Versions::Remote

Defined in:
lib/bundler/security/voting/versions/remote.rb

Overview

Module responsible for fetching safe/malicious votes for current or current/new versions of gems

Class Method Summary collapse

Class Method Details

.call(command, definition) ⇒ Object

Parameters:

  • command (String)

    either install or update

  • definition (Bundler::Definition)

    definition for your source



21
22
23
24
25
26
27
# File 'lib/bundler/security/voting/versions/remote.rb', line 21

def call(command, definition)
  config = fetch_config

  Request
    .call(config, payload(command, config&.repository_id, definition))
    .then { |response| JSON.parse(response.body) }
end

.fetch_configOpenStruct?

Fetch coditsu config file

Returns:

  • (OpenStruct, nil)

    configuration object

Raises:



48
49
50
51
52
53
54
# File 'lib/bundler/security/voting/versions/remote.rb', line 48

def fetch_config
  Config::Fetcher.call(
    File.expand_path('..', Bundler.bin_path)
  )
rescue Errors::MissingConfigurationFile
  nil
end

.payload(command, repository_id, definition) ⇒ Hash

Returns payload for differ bundler endpoint.

Parameters:

  • command (String)

    either install or update

  • repository_id (String)

    coditsu repository_id

  • definition (Bundler::Definition)

    definition for your source

Returns:

  • (Hash)

    payload for differ bundler endpoint



34
35
36
37
38
39
40
41
# File 'lib/bundler/security/voting/versions/remote.rb', line 34

def payload(command, repository_id, definition)
  Local.call(command, definition).each_with_object({}) do |(name, versions), hash|
    hash[:data] ||= {}
    hash[:data][:repository_id] = repository_id if repository_id
    hash[:data][:gems] ||= {}
    hash[:data][:gems][name] = versions
  end
end