diffend 0.2.29 → 0.2.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - checksums.yaml.gz.sig +0 -0
 - data.tar.gz.sig +0 -0
 - data/.ruby-version +1 -1
 - data/CHANGELOG.md +33 -1
 - data/Gemfile +0 -2
 - data/Gemfile.lock +4 -16
 - data/config/diffend.yml +6 -0
 - data/diffend.gemspec +2 -3
 - data/lib/diffend.rb +0 -138
 - data/lib/diffend/build_bundler_definition.rb +1 -1
 - data/lib/diffend/config.rb +80 -0
 - data/lib/diffend/configs/fetcher.rb +64 -0
 - data/lib/diffend/configs/validator.rb +85 -0
 - data/lib/diffend/errors.rb +2 -4
 - data/lib/diffend/{voting.rb → execute.rb} +37 -28
 - data/lib/diffend/handle_errors/report.rb +9 -17
 - data/lib/diffend/latest_version.rb +50 -0
 - data/lib/diffend/local_context.rb +23 -0
 - data/lib/diffend/local_context/diffend.rb +33 -0
 - data/lib/diffend/local_context/host.rb +88 -0
 - data/lib/diffend/local_context/packages.rb +302 -0
 - data/lib/diffend/local_context/platform.rb +58 -0
 - data/lib/diffend/logger.rb +66 -0
 - data/lib/diffend/monitor.rb +27 -14
 - data/lib/diffend/plugin.rb +86 -0
 - data/lib/diffend/request.rb +12 -11
 - data/lib/diffend/request_verdict.rb +52 -0
 - data/lib/diffend/track.rb +7 -39
 - data/lib/diffend/version.rb +6 -0
 - data/plugins.rb +2 -2
 - data/scripts/generate_payload_for_file.rb +1 -2
 - metadata +19 -10
 - metadata.gz.sig +0 -0
 - data/lib/diffend/config/fetcher.rb +0 -117
 - data/lib/diffend/config/file_finder.rb +0 -38
 - data/lib/diffend/config/validator.rb +0 -25
 - data/lib/diffend/voting/versions/local.rb +0 -304
 - data/lib/diffend/voting/versions/remote.rb +0 -227
 
| 
         @@ -0,0 +1,86 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            %w[
         
     | 
| 
      
 4 
     | 
    
         
            +
              bundler
         
     | 
| 
      
 5 
     | 
    
         
            +
            ].each(&method(:require))
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            %w[
         
     | 
| 
      
 8 
     | 
    
         
            +
              version
         
     | 
| 
      
 9 
     | 
    
         
            +
              logger
         
     | 
| 
      
 10 
     | 
    
         
            +
              latest_version
         
     | 
| 
      
 11 
     | 
    
         
            +
              errors
         
     | 
| 
      
 12 
     | 
    
         
            +
              build_bundler_definition
         
     | 
| 
      
 13 
     | 
    
         
            +
              commands
         
     | 
| 
      
 14 
     | 
    
         
            +
              config
         
     | 
| 
      
 15 
     | 
    
         
            +
              configs/fetcher
         
     | 
| 
      
 16 
     | 
    
         
            +
              configs/validator
         
     | 
| 
      
 17 
     | 
    
         
            +
              handle_errors/messages
         
     | 
| 
      
 18 
     | 
    
         
            +
              handle_errors/build_exception_payload
         
     | 
| 
      
 19 
     | 
    
         
            +
              handle_errors/display_to_stdout
         
     | 
| 
      
 20 
     | 
    
         
            +
              handle_errors/report
         
     | 
| 
      
 21 
     | 
    
         
            +
              request_object
         
     | 
| 
      
 22 
     | 
    
         
            +
              request
         
     | 
| 
      
 23 
     | 
    
         
            +
              local_context/diffend
         
     | 
| 
      
 24 
     | 
    
         
            +
              local_context/host
         
     | 
| 
      
 25 
     | 
    
         
            +
              local_context/packages
         
     | 
| 
      
 26 
     | 
    
         
            +
              local_context/platform
         
     | 
| 
      
 27 
     | 
    
         
            +
              local_context
         
     | 
| 
      
 28 
     | 
    
         
            +
              request_verdict
         
     | 
| 
      
 29 
     | 
    
         
            +
              execute
         
     | 
| 
      
 30 
     | 
    
         
            +
              track
         
     | 
| 
      
 31 
     | 
    
         
            +
            ].each { |file| require "diffend/#{file}" }
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            module Diffend
         
     | 
| 
      
 34 
     | 
    
         
            +
              module Plugin
         
     | 
| 
      
 35 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 36 
     | 
    
         
            +
                  # Registers the plugin and add before install all hook
         
     | 
| 
      
 37 
     | 
    
         
            +
                  def register
         
     | 
| 
      
 38 
     | 
    
         
            +
                    ::Bundler::Plugin.add_hook('before-install-all') do |_|
         
     | 
| 
      
 39 
     | 
    
         
            +
                      execute
         
     | 
| 
      
 40 
     | 
    
         
            +
                    end
         
     | 
| 
      
 41 
     | 
    
         
            +
                  end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                  # Execute diffend plugin
         
     | 
| 
      
 44 
     | 
    
         
            +
                  def execute
         
     | 
| 
      
 45 
     | 
    
         
            +
                    return unless enabled?
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                    config = Diffend::Config.new(severity: Diffend::Logger::INFO)
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                    Diffend::LatestVersion.call(config)
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                    Diffend::Execute.call(config)
         
     | 
| 
      
 52 
     | 
    
         
            +
                  rescue Diffend::Errors::HandledException
         
     | 
| 
      
 53 
     | 
    
         
            +
                    # config will not be initialized when configuration file is missing
         
     | 
| 
      
 54 
     | 
    
         
            +
                    return if config&.ignore_errors?
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                    exit 255
         
     | 
| 
      
 57 
     | 
    
         
            +
                  rescue StandardError => e
         
     | 
| 
      
 58 
     | 
    
         
            +
                    Diffend::HandleErrors::Report.call(
         
     | 
| 
      
 59 
     | 
    
         
            +
                      exception: e,
         
     | 
| 
      
 60 
     | 
    
         
            +
                      config: config,
         
     | 
| 
      
 61 
     | 
    
         
            +
                      message: :unhandled_exception,
         
     | 
| 
      
 62 
     | 
    
         
            +
                      report: true,
         
     | 
| 
      
 63 
     | 
    
         
            +
                      raise_exception: false
         
     | 
| 
      
 64 
     | 
    
         
            +
                    )
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                    return if config.ignore_errors?
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                    exit 255
         
     | 
| 
      
 69 
     | 
    
         
            +
                  end
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                  # Checks if plugin is enabled
         
     | 
| 
      
 72 
     | 
    
         
            +
                  #
         
     | 
| 
      
 73 
     | 
    
         
            +
                  # @return [Boolean] true if enabled, false otherwise
         
     | 
| 
      
 74 
     | 
    
         
            +
                  def enabled?
         
     | 
| 
      
 75 
     | 
    
         
            +
                    ::Bundler
         
     | 
| 
      
 76 
     | 
    
         
            +
                      .default_gemfile
         
     | 
| 
      
 77 
     | 
    
         
            +
                      .read
         
     | 
| 
      
 78 
     | 
    
         
            +
                      .split("\n")
         
     | 
| 
      
 79 
     | 
    
         
            +
                      .reject(&:empty?)
         
     | 
| 
      
 80 
     | 
    
         
            +
                      .map(&:strip)
         
     | 
| 
      
 81 
     | 
    
         
            +
                      .select { |line| line.start_with?('plugin') }
         
     | 
| 
      
 82 
     | 
    
         
            +
                      .any? { |line| line.include?('diffend') }
         
     | 
| 
      
 83 
     | 
    
         
            +
                  end
         
     | 
| 
      
 84 
     | 
    
         
            +
                end
         
     | 
| 
      
 85 
     | 
    
         
            +
              end
         
     | 
| 
      
 86 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/diffend/request.rb
    CHANGED
    
    | 
         @@ -14,7 +14,8 @@ module Diffend 
     | 
|
| 
       14 
14 
     | 
    
         
             
                  Errno::ECONNRESET,
         
     | 
| 
       15 
15 
     | 
    
         
             
                  Errno::ENETUNREACH,
         
     | 
| 
       16 
16 
     | 
    
         
             
                  Errno::EHOSTUNREACH,
         
     | 
| 
       17 
     | 
    
         
            -
                  Errno::ECONNREFUSED
         
     | 
| 
      
 17 
     | 
    
         
            +
                  Errno::ECONNREFUSED,
         
     | 
| 
      
 18 
     | 
    
         
            +
                  SocketError
         
     | 
| 
       18 
19 
     | 
    
         
             
                ].freeze
         
     | 
| 
       19 
20 
     | 
    
         
             
                # Message displayed when timeout occured and we will retry
         
     | 
| 
       20 
21 
     | 
    
         
             
                TIMEOUT_MESSAGE = 'We experienced a connection issue, retrying...'
         
     | 
| 
         @@ -67,7 +68,7 @@ module Diffend 
     | 
|
| 
       67 
68 
     | 
    
         
             
                  rescue Diffend::Errors::RequestServerError => e
         
     | 
| 
       68 
69 
     | 
    
         
             
                    retry_count += 1
         
     | 
| 
       69 
70 
     | 
    
         | 
| 
       70 
     | 
    
         
            -
                    retry if handle_retry(SERVER_ERROR_MESSAGE, retry_count)
         
     | 
| 
      
 71 
     | 
    
         
            +
                    retry if handle_retry(request_object.config, SERVER_ERROR_MESSAGE, retry_count)
         
     | 
| 
       71 
72 
     | 
    
         | 
| 
       72 
73 
     | 
    
         
             
                    Diffend::HandleErrors::Report.call(
         
     | 
| 
       73 
74 
     | 
    
         
             
                      exception: e,
         
     | 
| 
         @@ -78,7 +79,7 @@ module Diffend 
     | 
|
| 
       78 
79 
     | 
    
         
             
                  rescue *CONNECTION_EXCEPTIONS => e
         
     | 
| 
       79 
80 
     | 
    
         
             
                    retry_count += 1
         
     | 
| 
       80 
81 
     | 
    
         | 
| 
       81 
     | 
    
         
            -
                    retry if handle_retry(CONNECTION_MESSAGE, retry_count)
         
     | 
| 
      
 82 
     | 
    
         
            +
                    retry if handle_retry(request_object.config, CONNECTION_MESSAGE, retry_count)
         
     | 
| 
       82 
83 
     | 
    
         | 
| 
       83 
84 
     | 
    
         
             
                    Diffend::HandleErrors::Report.call(
         
     | 
| 
       84 
85 
     | 
    
         
             
                      exception: e,
         
     | 
| 
         @@ -89,7 +90,7 @@ module Diffend 
     | 
|
| 
       89 
90 
     | 
    
         
             
                  rescue *TIMEOUT_EXCEPTIONS => e
         
     | 
| 
       90 
91 
     | 
    
         
             
                    retry_count += 1
         
     | 
| 
       91 
92 
     | 
    
         | 
| 
       92 
     | 
    
         
            -
                    retry if handle_retry(TIMEOUT_MESSAGE, retry_count)
         
     | 
| 
      
 93 
     | 
    
         
            +
                    retry if handle_retry(request_object.config, TIMEOUT_MESSAGE, retry_count)
         
     | 
| 
       93 
94 
     | 
    
         | 
| 
       94 
95 
     | 
    
         
             
                    Diffend::HandleErrors::Report.call(
         
     | 
| 
       95 
96 
     | 
    
         
             
                      exception: e,
         
     | 
| 
         @@ -101,12 +102,13 @@ module Diffend 
     | 
|
| 
       101 
102 
     | 
    
         | 
| 
       102 
103 
     | 
    
         
             
                  # Handle retry
         
     | 
| 
       103 
104 
     | 
    
         
             
                  #
         
     | 
| 
      
 105 
     | 
    
         
            +
                  # @param config [Diffend::Config]
         
     | 
| 
       104 
106 
     | 
    
         
             
                  # @param message [String] message we want to display
         
     | 
| 
       105 
107 
     | 
    
         
             
                  # @param retry_count [Integer]
         
     | 
| 
       106 
     | 
    
         
            -
                  def handle_retry(message, retry_count)
         
     | 
| 
      
 108 
     | 
    
         
            +
                  def handle_retry(config, message, retry_count)
         
     | 
| 
       107 
109 
     | 
    
         
             
                    return false if retry_count == RETRIES
         
     | 
| 
       108 
110 
     | 
    
         | 
| 
       109 
     | 
    
         
            -
                     
     | 
| 
      
 111 
     | 
    
         
            +
                    config.logger.warn(message)
         
     | 
| 
       110 
112 
     | 
    
         
             
                    sleep(exponential_backoff(retry_count))
         
     | 
| 
       111 
113 
     | 
    
         | 
| 
       112 
114 
     | 
    
         
             
                    retry_count < RETRIES
         
     | 
| 
         @@ -123,8 +125,8 @@ module Diffend 
     | 
|
| 
       123 
125 
     | 
    
         
             
                      uri.port,
         
     | 
| 
       124 
126 
     | 
    
         
             
                      use_ssl: uri.scheme == 'https',
         
     | 
| 
       125 
127 
     | 
    
         
             
                      verify_mode: OpenSSL::SSL::VERIFY_NONE,
         
     | 
| 
       126 
     | 
    
         
            -
                      open_timeout:  
     | 
| 
       127 
     | 
    
         
            -
                      read_timeout:  
     | 
| 
      
 128 
     | 
    
         
            +
                      open_timeout: 15,
         
     | 
| 
      
 129 
     | 
    
         
            +
                      read_timeout: 15
         
     | 
| 
       128 
130 
     | 
    
         
             
                    ) { |http| yield(http, uri) }
         
     | 
| 
       129 
131 
     | 
    
         
             
                  end
         
     | 
| 
       130 
132 
     | 
    
         | 
| 
         @@ -132,7 +134,7 @@ module Diffend 
     | 
|
| 
       132 
134 
     | 
    
         
             
                  #
         
     | 
| 
       133 
135 
     | 
    
         
             
                  # @param uri [URI::HTTPS]
         
     | 
| 
       134 
136 
     | 
    
         
             
                  # @param request_method [Symbol]
         
     | 
| 
       135 
     | 
    
         
            -
                  # @param config [ 
     | 
| 
      
 137 
     | 
    
         
            +
                  # @param config [Diffend::Config]
         
     | 
| 
       136 
138 
     | 
    
         
             
                  # @param payload [Hash] with versions to check
         
     | 
| 
       137 
139 
     | 
    
         
             
                  #
         
     | 
| 
       138 
140 
     | 
    
         
             
                  # @return [Net::HTTP::Post, Net::HTTP::Put]
         
     | 
| 
         @@ -160,9 +162,8 @@ module Diffend 
     | 
|
| 
       160 
162 
     | 
    
         
             
                  # Assigns basic authorization if provided in the config
         
     | 
| 
       161 
163 
     | 
    
         
             
                  #
         
     | 
| 
       162 
164 
     | 
    
         
             
                  # @param request [Net::HTTP::Post] prepared http post
         
     | 
| 
       163 
     | 
    
         
            -
                  # @param config [ 
     | 
| 
      
 165 
     | 
    
         
            +
                  # @param config [Diffend::Config]
         
     | 
| 
       164 
166 
     | 
    
         
             
                  def assign_auth(request, config)
         
     | 
| 
       165 
     | 
    
         
            -
                    return unless config
         
     | 
| 
       166 
167 
     | 
    
         
             
                    return unless config.shareable_id
         
     | 
| 
       167 
168 
     | 
    
         
             
                    return unless config.shareable_key
         
     | 
| 
       168 
169 
     | 
    
         | 
| 
         @@ -0,0 +1,52 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'json'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            module Diffend
         
     | 
| 
      
 6 
     | 
    
         
            +
              # Module responsible for fetching diffend verdict on local context
         
     | 
| 
      
 7 
     | 
    
         
            +
              module RequestVerdict
         
     | 
| 
      
 8 
     | 
    
         
            +
                # Exceptions that we handle when there is a resolve issue
         
     | 
| 
      
 9 
     | 
    
         
            +
                RESOLVE_EXCEPTIONS = [
         
     | 
| 
      
 10 
     | 
    
         
            +
                  Bundler::GemNotFound,
         
     | 
| 
      
 11 
     | 
    
         
            +
                  Bundler::VersionConflict,
         
     | 
| 
      
 12 
     | 
    
         
            +
                  Bundler::GitError
         
     | 
| 
      
 13 
     | 
    
         
            +
                ].freeze
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 16 
     | 
    
         
            +
                  # @param config [Diffend::Config]
         
     | 
| 
      
 17 
     | 
    
         
            +
                  # @param definition [Bundler::Definition] definition for your source
         
     | 
| 
      
 18 
     | 
    
         
            +
                  def call(config, definition)
         
     | 
| 
      
 19 
     | 
    
         
            +
                    payload = Diffend::LocalContext.call(config, definition)
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                    response = Diffend::Request.call(
         
     | 
| 
      
 22 
     | 
    
         
            +
                      build_request_object(config, payload)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    )
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                    JSON.parse(response.body)
         
     | 
| 
      
 26 
     | 
    
         
            +
                  rescue *RESOLVE_EXCEPTIONS
         
     | 
| 
      
 27 
     | 
    
         
            +
                    raise ::Diffend::Errors::DependenciesResolveException
         
     | 
| 
      
 28 
     | 
    
         
            +
                  rescue StandardError => e
         
     | 
| 
      
 29 
     | 
    
         
            +
                    Diffend::HandleErrors::Report.call(
         
     | 
| 
      
 30 
     | 
    
         
            +
                      exception: e,
         
     | 
| 
      
 31 
     | 
    
         
            +
                      payload: payload || {},
         
     | 
| 
      
 32 
     | 
    
         
            +
                      config: config,
         
     | 
| 
      
 33 
     | 
    
         
            +
                      message: :unhandled_exception,
         
     | 
| 
      
 34 
     | 
    
         
            +
                      report: true
         
     | 
| 
      
 35 
     | 
    
         
            +
                    )
         
     | 
| 
      
 36 
     | 
    
         
            +
                  end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                  # @param config [Diffend::Config]
         
     | 
| 
      
 39 
     | 
    
         
            +
                  # @param payload [Hash]
         
     | 
| 
      
 40 
     | 
    
         
            +
                  #
         
     | 
| 
      
 41 
     | 
    
         
            +
                  # @return [Diffend::RequestObject]
         
     | 
| 
      
 42 
     | 
    
         
            +
                  def build_request_object(config, payload)
         
     | 
| 
      
 43 
     | 
    
         
            +
                    Diffend::RequestObject.new(
         
     | 
| 
      
 44 
     | 
    
         
            +
                      config: config,
         
     | 
| 
      
 45 
     | 
    
         
            +
                      url: config.commands_url,
         
     | 
| 
      
 46 
     | 
    
         
            +
                      payload: payload,
         
     | 
| 
      
 47 
     | 
    
         
            +
                      request_method: :post
         
     | 
| 
      
 48 
     | 
    
         
            +
                    )
         
     | 
| 
      
 49 
     | 
    
         
            +
                  end
         
     | 
| 
      
 50 
     | 
    
         
            +
                end
         
     | 
| 
      
 51 
     | 
    
         
            +
              end
         
     | 
| 
      
 52 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/diffend/track.rb
    CHANGED
    
    | 
         @@ -9,14 +9,16 @@ module Diffend 
     | 
|
| 
       9 
9 
     | 
    
         
             
                RETRY_SLEEP = 15
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
                # Initialize tracking
         
     | 
| 
       12 
     | 
    
         
            -
                 
     | 
| 
      
 12 
     | 
    
         
            +
                #
         
     | 
| 
      
 13 
     | 
    
         
            +
                # @param config [Diffend::Config]
         
     | 
| 
      
 14 
     | 
    
         
            +
                def initialize(config)
         
     | 
| 
       13 
15 
     | 
    
         
             
                  @mutex = Mutex.new
         
     | 
| 
       14 
     | 
    
         
            -
                  @config =  
     | 
| 
      
 16 
     | 
    
         
            +
                  @config = config
         
     | 
| 
       15 
17 
     | 
    
         
             
                end
         
     | 
| 
       16 
18 
     | 
    
         | 
| 
       17 
19 
     | 
    
         
             
                # Start tracking
         
     | 
| 
       18 
20 
     | 
    
         
             
                def start
         
     | 
| 
       19 
     | 
    
         
            -
                  response =  
     | 
| 
      
 21 
     | 
    
         
            +
                  response = Diffend::Execute.call(@config)
         
     | 
| 
       20 
22 
     | 
    
         | 
| 
       21 
23 
     | 
    
         
             
                  perform(response['id'])
         
     | 
| 
       22 
24 
     | 
    
         
             
                rescue Diffend::Errors::HandledException
         
     | 
| 
         @@ -40,27 +42,12 @@ module Diffend 
     | 
|
| 
       40 
42 
     | 
    
         
             
                # @param request_id [String]
         
     | 
| 
       41 
43 
     | 
    
         
             
                def perform(request_id)
         
     | 
| 
       42 
44 
     | 
    
         
             
                  loop do
         
     | 
| 
       43 
     | 
    
         
            -
                    @mutex.synchronize  
     | 
| 
       44 
     | 
    
         
            -
                      track_request(request_id)
         
     | 
| 
       45 
     | 
    
         
            -
                    end
         
     | 
| 
      
 45 
     | 
    
         
            +
                    @mutex.synchronize { track_request(request_id) }
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
       47 
47 
     | 
    
         
             
                    sleep(TRACK_SLEEP)
         
     | 
| 
       48 
48 
     | 
    
         
             
                  end
         
     | 
| 
       49 
49 
     | 
    
         
             
                end
         
     | 
| 
       50 
50 
     | 
    
         | 
| 
       51 
     | 
    
         
            -
                # Perform an exec request
         
     | 
| 
       52 
     | 
    
         
            -
                def exec_request
         
     | 
| 
       53 
     | 
    
         
            -
                  Diffend::Voting.call(
         
     | 
| 
       54 
     | 
    
         
            -
                    Diffend::Commands::EXEC,
         
     | 
| 
       55 
     | 
    
         
            -
                    @config,
         
     | 
| 
       56 
     | 
    
         
            -
                    Diffend::BuildBundlerDefinition.call(
         
     | 
| 
       57 
     | 
    
         
            -
                      Diffend::Commands::EXEC,
         
     | 
| 
       58 
     | 
    
         
            -
                      Bundler.default_gemfile,
         
     | 
| 
       59 
     | 
    
         
            -
                      Bundler.default_lockfile
         
     | 
| 
       60 
     | 
    
         
            -
                    )
         
     | 
| 
       61 
     | 
    
         
            -
                  )
         
     | 
| 
       62 
     | 
    
         
            -
                end
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
51 
     | 
    
         
             
                # Perform a track request
         
     | 
| 
       65 
52 
     | 
    
         
             
                #
         
     | 
| 
       66 
53 
     | 
    
         
             
                # @param request_id [String]
         
     | 
| 
         @@ -76,29 +63,10 @@ module Diffend 
     | 
|
| 
       76 
63 
     | 
    
         
             
                def build_request_object(request_id)
         
     | 
| 
       77 
64 
     | 
    
         
             
                  Diffend::RequestObject.new(
         
     | 
| 
       78 
65 
     | 
    
         
             
                    config: @config,
         
     | 
| 
       79 
     | 
    
         
            -
                    url:  
     | 
| 
      
 66 
     | 
    
         
            +
                    url: @config.track_url(request_id),
         
     | 
| 
       80 
67 
     | 
    
         
             
                    payload: { id: request_id }.freeze,
         
     | 
| 
       81 
68 
     | 
    
         
             
                    request_method: :put
         
     | 
| 
       82 
69 
     | 
    
         
             
                  ).freeze
         
     | 
| 
       83 
70 
     | 
    
         
             
                end
         
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
                # Fetch diffend config file
         
     | 
| 
       86 
     | 
    
         
            -
                #
         
     | 
| 
       87 
     | 
    
         
            -
                # @return [OpenStruct, nil] configuration object
         
     | 
| 
       88 
     | 
    
         
            -
                #
         
     | 
| 
       89 
     | 
    
         
            -
                # @raise [Errors::MissingConfigurationFile] when no config file
         
     | 
| 
       90 
     | 
    
         
            -
                def fetch_config
         
     | 
| 
       91 
     | 
    
         
            -
                  Config::Fetcher.call(
         
     | 
| 
       92 
     | 
    
         
            -
                    File.expand_path('..', Bundler.bin_path)
         
     | 
| 
       93 
     | 
    
         
            -
                  )
         
     | 
| 
       94 
     | 
    
         
            -
                end
         
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
                # @param project_id [String] diffend project_id
         
     | 
| 
       97 
     | 
    
         
            -
                # @param request_id [String]
         
     | 
| 
       98 
     | 
    
         
            -
                #
         
     | 
| 
       99 
     | 
    
         
            -
                # @return [String]
         
     | 
| 
       100 
     | 
    
         
            -
                def track_url(project_id, request_id)
         
     | 
| 
       101 
     | 
    
         
            -
                  "https://my.diffend.io/api/projects/#{project_id}/bundle/#{request_id}/track"
         
     | 
| 
       102 
     | 
    
         
            -
                end
         
     | 
| 
       103 
71 
     | 
    
         
             
              end
         
     | 
| 
       104 
72 
     | 
    
         
             
            end
         
     | 
    
        data/plugins.rb
    CHANGED
    
    
| 
         @@ -3,7 +3,6 @@ 
     | 
|
| 
       3 
3 
     | 
    
         
             
            require 'byebug'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'diffend'
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
6 
     | 
    
         
             
            command = 'install'
         
     | 
| 
       8 
7 
     | 
    
         
             
            project_id = nil
         
     | 
| 
       9 
8 
     | 
    
         | 
| 
         @@ -12,4 +11,4 @@ lockfile = ARGV[1] 
     | 
|
| 
       12 
11 
     | 
    
         | 
| 
       13 
12 
     | 
    
         
             
            definition = Diffend::BuildBundlerDefinition.call(command, gemfile lockfile)
         
     | 
| 
       14 
13 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
            pp Diffend:: 
     | 
| 
      
 14 
     | 
    
         
            +
            pp Diffend::LocalContext.call(command, project_id, definition)
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: diffend
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.34
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Tomasz Pajor
         
     | 
| 
         @@ -34,7 +34,7 @@ cert_chain: 
     | 
|
| 
       34 
34 
     | 
    
         
             
              9MmF6uCQa1EjK2p8tYT0MnbHrFkoehxdX4VO9y99GAkhZyJNKPYPtyAUFV27sT2V
         
     | 
| 
       35 
35 
     | 
    
         
             
              LfCJRk4ifKIN/FUCwDSn8Cz0m6oH265q0p6wdzI6qrWOjP8tGOMBTA==
         
     | 
| 
       36 
36 
     | 
    
         
             
              -----END CERTIFICATE-----
         
     | 
| 
       37 
     | 
    
         
            -
            date: 2020- 
     | 
| 
      
 37 
     | 
    
         
            +
            date: 2020-10-30 00:00:00.000000000 Z
         
     | 
| 
       38 
38 
     | 
    
         
             
            dependencies:
         
     | 
| 
       39 
39 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       40 
40 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -90,25 +90,34 @@ files: 
     | 
|
| 
       90 
90 
     | 
    
         
             
            - bin/rspec
         
     | 
| 
       91 
91 
     | 
    
         
             
            - certs/mensfeld.pem
         
     | 
| 
       92 
92 
     | 
    
         
             
            - certs/tomaszpajor.pem
         
     | 
| 
      
 93 
     | 
    
         
            +
            - config/diffend.yml
         
     | 
| 
       93 
94 
     | 
    
         
             
            - diffend.gemspec
         
     | 
| 
       94 
95 
     | 
    
         
             
            - lib/diffend.rb
         
     | 
| 
       95 
96 
     | 
    
         
             
            - lib/diffend/build_bundler_definition.rb
         
     | 
| 
       96 
97 
     | 
    
         
             
            - lib/diffend/commands.rb
         
     | 
| 
       97 
     | 
    
         
            -
            - lib/diffend/config 
     | 
| 
       98 
     | 
    
         
            -
            - lib/diffend/ 
     | 
| 
       99 
     | 
    
         
            -
            - lib/diffend/ 
     | 
| 
      
 98 
     | 
    
         
            +
            - lib/diffend/config.rb
         
     | 
| 
      
 99 
     | 
    
         
            +
            - lib/diffend/configs/fetcher.rb
         
     | 
| 
      
 100 
     | 
    
         
            +
            - lib/diffend/configs/validator.rb
         
     | 
| 
       100 
101 
     | 
    
         
             
            - lib/diffend/errors.rb
         
     | 
| 
      
 102 
     | 
    
         
            +
            - lib/diffend/execute.rb
         
     | 
| 
       101 
103 
     | 
    
         
             
            - lib/diffend/handle_errors/build_exception_payload.rb
         
     | 
| 
       102 
104 
     | 
    
         
             
            - lib/diffend/handle_errors/display_to_stdout.rb
         
     | 
| 
       103 
105 
     | 
    
         
             
            - lib/diffend/handle_errors/messages.rb
         
     | 
| 
       104 
106 
     | 
    
         
             
            - lib/diffend/handle_errors/report.rb
         
     | 
| 
      
 107 
     | 
    
         
            +
            - lib/diffend/latest_version.rb
         
     | 
| 
      
 108 
     | 
    
         
            +
            - lib/diffend/local_context.rb
         
     | 
| 
      
 109 
     | 
    
         
            +
            - lib/diffend/local_context/diffend.rb
         
     | 
| 
      
 110 
     | 
    
         
            +
            - lib/diffend/local_context/host.rb
         
     | 
| 
      
 111 
     | 
    
         
            +
            - lib/diffend/local_context/packages.rb
         
     | 
| 
      
 112 
     | 
    
         
            +
            - lib/diffend/local_context/platform.rb
         
     | 
| 
      
 113 
     | 
    
         
            +
            - lib/diffend/logger.rb
         
     | 
| 
       105 
114 
     | 
    
         
             
            - lib/diffend/monitor.rb
         
     | 
| 
      
 115 
     | 
    
         
            +
            - lib/diffend/plugin.rb
         
     | 
| 
       106 
116 
     | 
    
         
             
            - lib/diffend/request.rb
         
     | 
| 
       107 
117 
     | 
    
         
             
            - lib/diffend/request_object.rb
         
     | 
| 
      
 118 
     | 
    
         
            +
            - lib/diffend/request_verdict.rb
         
     | 
| 
       108 
119 
     | 
    
         
             
            - lib/diffend/track.rb
         
     | 
| 
       109 
     | 
    
         
            -
            - lib/diffend/ 
     | 
| 
       110 
     | 
    
         
            -
            - lib/diffend/voting/versions/local.rb
         
     | 
| 
       111 
     | 
    
         
            -
            - lib/diffend/voting/versions/remote.rb
         
     | 
| 
      
 120 
     | 
    
         
            +
            - lib/diffend/version.rb
         
     | 
| 
       112 
121 
     | 
    
         
             
            - plugins.rb
         
     | 
| 
       113 
122 
     | 
    
         
             
            - scripts/generate_payload_for_file.rb
         
     | 
| 
       114 
123 
     | 
    
         
             
            homepage: https://diffend.io
         
     | 
| 
         @@ -130,8 +139,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       130 
139 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       131 
140 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       132 
141 
     | 
    
         
             
            requirements: []
         
     | 
| 
       133 
     | 
    
         
            -
            rubygems_version: 3.1. 
     | 
| 
      
 142 
     | 
    
         
            +
            rubygems_version: 3.1.4
         
     | 
| 
       134 
143 
     | 
    
         
             
            signing_key:
         
     | 
| 
       135 
144 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       136 
     | 
    
         
            -
            summary: OSS supply chain security and management platform 
     | 
| 
      
 145 
     | 
    
         
            +
            summary: OSS supply chain security and management platform
         
     | 
| 
       137 
146 
     | 
    
         
             
            test_files: []
         
     | 
    
        metadata.gz.sig
    CHANGED
    
    | 
         Binary file 
     | 
| 
         @@ -1,117 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # frozen_string_literal: true
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            require 'yaml'
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            module Diffend
         
     | 
| 
       6 
     | 
    
         
            -
              # Module for all the components related to setting up the config
         
     | 
| 
       7 
     | 
    
         
            -
              module Config
         
     | 
| 
       8 
     | 
    
         
            -
                # Class responsible for fetching the config from .diffend.yml
         
     | 
| 
       9 
     | 
    
         
            -
                module Fetcher
         
     | 
| 
       10 
     | 
    
         
            -
                  # All the errors for missing keys in the configuration file
         
     | 
| 
       11 
     | 
    
         
            -
                  MISSING_KEY_ERRORS = [
         
     | 
| 
       12 
     | 
    
         
            -
                    Errors::ProjectIdMissingInConfigurationFile,
         
     | 
| 
       13 
     | 
    
         
            -
                    Errors::ShareableIdMissingInConfigurationFile,
         
     | 
| 
       14 
     | 
    
         
            -
                    Errors::ShareableKeyMissingInConfigurationFile,
         
     | 
| 
       15 
     | 
    
         
            -
                    Errors::BuildPathMissingInConfigurationFile
         
     | 
| 
       16 
     | 
    
         
            -
                  ].freeze
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                  class << self
         
     | 
| 
       19 
     | 
    
         
            -
                    # @param build_path [String] path of the current build
         
     | 
| 
       20 
     | 
    
         
            -
                    #
         
     | 
| 
       21 
     | 
    
         
            -
                    # @return [OpenStruct] open struct with config details
         
     | 
| 
       22 
     | 
    
         
            -
                    #
         
     | 
| 
       23 
     | 
    
         
            -
                    # @example
         
     | 
| 
       24 
     | 
    
         
            -
                    #   details = Fetcher.new.call('./')
         
     | 
| 
       25 
     | 
    
         
            -
                    #   details.build_path #=> './'
         
     | 
| 
       26 
     | 
    
         
            -
                    def call(build_path)
         
     | 
| 
       27 
     | 
    
         
            -
                      build(build_path)
         
     | 
| 
       28 
     | 
    
         
            -
                    rescue Errors::MissingConfigurationFile
         
     | 
| 
       29 
     | 
    
         
            -
                      Bundler.ui.error(build_missing_error_message(build_path))
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                      raise Diffend::Errors::HandledException
         
     | 
| 
       32 
     | 
    
         
            -
                    rescue Errors::EmptyConfigurationFile
         
     | 
| 
       33 
     | 
    
         
            -
                      Bundler.ui.error(build_empty_error_message(build_path))
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                      raise Diffend::Errors::HandledException
         
     | 
| 
       36 
     | 
    
         
            -
                    rescue Errors::MalformedConfigurationFile
         
     | 
| 
       37 
     | 
    
         
            -
                      Bundler.ui.error(build_malformed_error_message(build_path))
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                      raise Diffend::Errors::HandledException
         
     | 
| 
       40 
     | 
    
         
            -
                    rescue *MISSING_KEY_ERRORS => e
         
     | 
| 
       41 
     | 
    
         
            -
                      Bundler.ui.error(build_missing_key_error_message(e))
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
                      raise Diffend::Errors::HandledException
         
     | 
| 
       44 
     | 
    
         
            -
                    end
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
                    private
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
                    # @param build_path [String] path of the current build
         
     | 
| 
       49 
     | 
    
         
            -
                    #
         
     | 
| 
       50 
     | 
    
         
            -
                    # @return [OpenStruct] open struct with config details
         
     | 
| 
       51 
     | 
    
         
            -
                    def build(build_path)
         
     | 
| 
       52 
     | 
    
         
            -
                      content = ERB.new(
         
     | 
| 
       53 
     | 
    
         
            -
                        File.read(
         
     | 
| 
       54 
     | 
    
         
            -
                          FileFinder.call(build_path)
         
     | 
| 
       55 
     | 
    
         
            -
                        )
         
     | 
| 
       56 
     | 
    
         
            -
                      ).result
         
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
                      raise Errors::EmptyConfigurationFile if content.empty?
         
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
                      OpenStruct.new(parse_file(content).merge(build_path: build_path))
         
     | 
| 
       61 
     | 
    
         
            -
                        .tap(&Validator.method(:call))
         
     | 
| 
       62 
     | 
    
         
            -
                    end
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
                    def parse_file(content)
         
     | 
| 
       65 
     | 
    
         
            -
                      YAML.safe_load(content)
         
     | 
| 
       66 
     | 
    
         
            -
                    rescue Psych::SyntaxError
         
     | 
| 
       67 
     | 
    
         
            -
                      raise Errors::MalformedConfigurationFile
         
     | 
| 
       68 
     | 
    
         
            -
                    end
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
                    # @param build_path [String] path of the current build
         
     | 
| 
       71 
     | 
    
         
            -
                    #
         
     | 
| 
       72 
     | 
    
         
            -
                    # @return [String] missing configuration file message
         
     | 
| 
       73 
     | 
    
         
            -
                    def build_missing_error_message(build_path)
         
     | 
| 
       74 
     | 
    
         
            -
                      <<~MSG
         
     | 
| 
       75 
     | 
    
         
            -
                        \nWe were unable to locate Diffend configuration file.\n
         
     | 
| 
       76 
     | 
    
         
            -
                        Please make sure that .diffend.yml is present in #{build_path} folder.\n
         
     | 
| 
       77 
     | 
    
         
            -
                      MSG
         
     | 
| 
       78 
     | 
    
         
            -
                    end
         
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
                    # @return [String] empty configuration file message
         
     | 
| 
       81 
     | 
    
         
            -
                    def build_empty_error_message
         
     | 
| 
       82 
     | 
    
         
            -
                      <<~MSG
         
     | 
| 
       83 
     | 
    
         
            -
                        \nYour Diffend configuration file is empty.\n
         
     | 
| 
       84 
     | 
    
         
            -
                        Please re-setup.\n
         
     | 
| 
       85 
     | 
    
         
            -
                      MSG
         
     | 
| 
       86 
     | 
    
         
            -
                    end
         
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
                    # @return [String] malformed configuration file message
         
     | 
| 
       89 
     | 
    
         
            -
                    def build_malformed_error_message
         
     | 
| 
       90 
     | 
    
         
            -
                      <<~MSG
         
     | 
| 
       91 
     | 
    
         
            -
                        \nYour Diffend configuration file is malformed.\n
         
     | 
| 
       92 
     | 
    
         
            -
                        Please re-setup.\n
         
     | 
| 
       93 
     | 
    
         
            -
                      MSG
         
     | 
| 
       94 
     | 
    
         
            -
                    end
         
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
                    # @return [String] malformed configuration file message
         
     | 
| 
       97 
     | 
    
         
            -
                    def build_missing_key_error_message(exception)
         
     | 
| 
       98 
     | 
    
         
            -
                      missing_key = missing_key_from_exception(exception)
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
                      <<~MSG
         
     | 
| 
       101 
     | 
    
         
            -
                        \nYour Diffend configuration file is missing #{missing_key} key.\n
         
     | 
| 
       102 
     | 
    
         
            -
                        Please re-setup.\n
         
     | 
| 
       103 
     | 
    
         
            -
                      MSG
         
     | 
| 
       104 
     | 
    
         
            -
                    end
         
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
                    def missing_key_from_exception(exception)
         
     | 
| 
       107 
     | 
    
         
            -
                      case exception
         
     | 
| 
       108 
     | 
    
         
            -
                      when Errors::ProjectIdMissingInConfigurationFile then 'project_id'
         
     | 
| 
       109 
     | 
    
         
            -
                      when Errors::ShareableIdMissingInConfigurationFile then 'shareable_id'
         
     | 
| 
       110 
     | 
    
         
            -
                      when Errors::ShareableKeyMissingInConfigurationFile then 'shareable_key'
         
     | 
| 
       111 
     | 
    
         
            -
                      when Errors::BuildPathMissingInConfigurationFile then 'build_path'
         
     | 
| 
       112 
     | 
    
         
            -
                      end
         
     | 
| 
       113 
     | 
    
         
            -
                    end
         
     | 
| 
       114 
     | 
    
         
            -
                  end
         
     | 
| 
       115 
     | 
    
         
            -
                end
         
     | 
| 
       116 
     | 
    
         
            -
              end
         
     | 
| 
       117 
     | 
    
         
            -
            end
         
     |