diffend 0.2.27 → 0.2.32

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6539b727e33d38eb0b3fb6f38f25c3fd2abda05f337f50af2db1fe135575510
4
- data.tar.gz: c6808082290c195a846117fd4c16a4fa4cb20f65cc289cbadbd71532f8ae5713
3
+ metadata.gz: 8e0efaea5a8bb4c724e24057821578b6c257a5eb313c472ac17dd60747fe10e4
4
+ data.tar.gz: af3b702fa128eabcc8f6f054895c0e64097f38672b650697e292ab705b749b69
5
5
  SHA512:
6
- metadata.gz: 9eb4e7749b9a9a0824770921d150e180ed5b40ba19a7f22d1f65154474347110221dc96049c2b4b5d7136c850c5775c07bc4e840b005dda13043742ac74238d2
7
- data.tar.gz: 427d6b00c913174e535de300020f8fe715bda9b3f946f1fbe25906dfa734bb4dd3c349735470fbacb9740c287dd5252bcf6b481e40120daba3138afda6f334e9
6
+ metadata.gz: 00e60e3f610e03cad43a65b11c1b7f17d839d4b43009dde4436b9eebd96b82bdbf0035860eb85fb0e57c7042221403894a1aaf5f89cb606a86dd15e94f65bc58
7
+ data.tar.gz: f45b310e0e376b50e27b7a1876f3704a3f282dbadac5c868b4548a4a6a2d582632aeb3f204e47fda5545f47807446e648b0bf2fe70b4a0abdefb17ea40cf1ff1
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -2,6 +2,31 @@
2
2
 
3
3
  ## [Unreleased][master]
4
4
 
5
+ ## [0.2.32] (2020-10-02)
6
+ - fix how we build platform from `Gem::Platform` ([#56](https://github.com/diffend-io/diffend-ruby/pull/56))
7
+ - introduce `Diffend::LatestVersion` ([#57](https://github.com/diffend-io/diffend-ruby/pull/57))
8
+ - refactor `Diffend::Config` ([#58](https://github.com/diffend-io/diffend-ruby/pull/58))
9
+ - set command in `Diffend::Config` ([#59](https://github.com/diffend-io/diffend-ruby/pull/59))
10
+ - introduce `Diffend::Logger` ([#60](https://github.com/diffend-io/diffend-ruby/pull/60))
11
+ - set severity to `FATAL` in `Diffend::Monitor` ([#61](https://github.com/diffend-io/diffend-ruby/pull/61))
12
+ - handle `Bundler::VersionConflict` ([#62](https://github.com/diffend-io/diffend-ruby/pull/62))
13
+
14
+ ## [0.2.31] (2020-09-24)
15
+ - change request timeout to 15 seconds ([#53](https://github.com/diffend-io/diffend-ruby/pull/53))
16
+ - report request issues as warnings ([#54](https://github.com/diffend-io/diffend-ruby/pull/54))
17
+
18
+ ## [0.2.30] (2020-09-21)
19
+ - handle dependencies resolve issues ([#51](https://github.com/diffend-io/diffend-ruby/pull/51))
20
+ - better detection when to start `Diffend::Monitor` ([#50](https://github.com/diffend-io/diffend-ruby/pull/50))
21
+ - cleanup structure ([#47](https://github.com/diffend-io/diffend-ruby/pull/47))
22
+
23
+ ## [0.2.29] (2020-09-21)
24
+ - fix command reporting on jruby ([#48](https://github.com/diffend-io/diffend-ruby/pull/48))
25
+
26
+ ## [0.2.28] (2020-09-19)
27
+ - start `Diffend::Monitor` only if not in development or test ([#44](https://github.com/diffend-io/diffend-ruby/pull/44))
28
+ - better host command expose ([#45](https://github.com/diffend-io/diffend-ruby/pull/45))
29
+
5
30
  ## [0.2.27] (2020-09-16)
6
31
  - introduce `Diffend::RequestObject` ([#40](https://github.com/diffend-io/diffend-ruby/pull/40))
7
32
  - clean up error codes and introduce `DIFFEND_INGORE_EXCEPTIONS` ([#41](https://github.com/diffend-io/diffend-ruby/pull/41))
@@ -60,7 +85,10 @@
60
85
 
61
86
  - initial release
62
87
 
63
- [master]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.27...HEAD
88
+ [master]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.30...HEAD
89
+ [0.2.30]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.29...v0.2.30
90
+ [0.2.29]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.28...v0.2.29
91
+ [0.2.28]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.27...v0.2.28
64
92
  [0.2.27]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.26...v0.2.27
65
93
  [0.2.26]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.25...v0.2.26
66
94
  [0.2.25]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.24...v0.2.25
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- diffend (0.2.27)
4
+ diffend (0.2.32)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -2,7 +2,7 @@
2
2
 
3
3
  lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'diffend'
5
+ require 'diffend/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'diffend'
@@ -11,8 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.email = ['contact@diffend.io']
12
12
 
13
13
  spec.summary = 'OSS supply chain security and management platform'
14
- spec.summary = 'OSS supply chain security and management platform.'
15
- spec.homepage = Diffend::HOMEPAGE
14
+ spec.homepage = 'https://diffend.io'
16
15
  spec.license = 'Prosperity Public License'
17
16
 
18
17
  if $PROGRAM_NAME.end_with?('gem')
@@ -1,142 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- %w[
4
- bundler
5
- ].each(&method(:require))
6
-
7
- %w[
8
- build_bundler_definition
9
- errors
10
- config/fetcher
11
- config/file_finder
12
- config/validator
13
- commands
14
- handle_errors/messages
15
- handle_errors/build_exception_payload
16
- handle_errors/display_to_stdout
17
- handle_errors/report
18
- request_object
19
- request
20
- voting
21
- track
22
- ].each { |file| require "diffend/#{file}" }
23
-
24
- %w[
25
- versions/local
26
- versions/remote
27
- ].each { |file| require "diffend/voting/#{file}" }
28
-
29
- # Diffend main namespace
30
3
  module Diffend
31
- # Current plugin version
32
- VERSION = '0.2.27'
33
- # Diffend homepage
34
- HOMEPAGE = 'https://diffend.io'
35
-
36
- class << self
37
- # Registers the plugin and add before install all hook
38
- def register
39
- Bundler::Plugin.add_hook('before-install-all') do |_|
40
- execute
41
- end
42
- end
43
-
44
- # Execute diffend plugin
45
- def execute
46
- return unless enabled?
47
-
48
- verify_version
49
-
50
- config = fetch_config
51
-
52
- Diffend::Voting.call(
53
- command,
54
- config,
55
- Diffend::BuildBundlerDefinition.call(
56
- command,
57
- Bundler.default_gemfile,
58
- Bundler.default_lockfile
59
- )
60
- )
61
- rescue Diffend::Errors::HandledException
62
- return if ENV['DIFFEND_IGNORE_ERRORS'] == 'true'
63
-
64
- exit 255
65
- rescue StandardError => e
66
- Diffend::HandleErrors::Report.call(
67
- exception: e,
68
- config: config,
69
- message: :unhandled_exception,
70
- report: true,
71
- raise_exception: false
72
- )
73
-
74
- return if ENV['DIFFEND_IGNORE_ERRORS'] == 'true'
75
-
76
- exit 255
77
- end
78
-
79
- def verify_version
80
- return if ENV['DIFFEND_DEVELOPMENT'] == 'true'
81
- return if installed_version == VERSION
82
-
83
- build_outdated_version_message(installed_version)
84
- .tap(&Bundler.ui.method(:error))
85
-
86
- exit 2
87
- end
88
-
89
- # @return [String] installed plugin version
90
- def installed_version
91
- Bundler::Plugin
92
- .index
93
- .plugin_path('diffend')
94
- .basename
95
- .to_s
96
- .split('-')
97
- .last
98
- end
99
-
100
- # Checks if plugin is enabled
101
- #
102
- # @return [Boolean] true if enabled, false otherwise
103
- def enabled?
104
- Bundler
105
- .default_gemfile
106
- .read
107
- .split("\n")
108
- .reject(&:empty?)
109
- .map(&:strip)
110
- .select { |line| line.start_with?('plugin') }
111
- .any? { |line| line.include?('diffend') }
112
- end
113
-
114
- # @param version [Hash] installed version
115
- #
116
- # @return [String]
117
- def build_outdated_version_message(version)
118
- <<~MSG
119
- \nYou are running an outdated version (#{version}) of the plugin, which will lead to issues.
120
- \nPlease upgrade to the latest one (#{VERSION}) by executing "rm -rf .bundle/plugin".\n
121
- MSG
122
- end
123
-
124
- # Command that was run with bundle
125
- #
126
- # @return [String]
127
- def command
128
- ARGV.first || Bundler.feature_flag.default_cli_command.to_s
129
- end
130
-
131
- # Fetch diffend config file
132
- #
133
- # @return [OpenStruct, nil] configuration object
134
- #
135
- # @raise [Errors::MissingConfigurationFile] when no config file
136
- def fetch_config
137
- Config::Fetcher.call(
138
- File.expand_path('..', Bundler.bin_path)
139
- )
140
- end
141
- end
142
4
  end
@@ -6,7 +6,7 @@ module Diffend
6
6
  class << self
7
7
  # Build clean instance of bundler definition, as we don't want to pollute the main one
8
8
  #
9
- # @param command [String] bundler command that we are executing
9
+ # @param command [String] command executed via bundler
10
10
  # @param gemfile [String] path to Gemfile
11
11
  # @param lockfile [String] path to Gemfile.lock
12
12
  #
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Diffend
4
+ # Diffend config object
5
+ class Config
6
+ attr_reader :project_id, :shareable_id, :shareable_key, :build_path, :env, :command
7
+
8
+ # Build diffend config object
9
+ #
10
+ # @return [Diffend::Config]
11
+ #
12
+ # @raise [Errors::MissingConfigurationFile] when no config file
13
+ def initialize(command: nil, severity: nil, build_path: nil)
14
+ @log_level = severity
15
+ build(command, build_path)
16
+ validate
17
+ end
18
+
19
+ def logger
20
+ @logger ||= Diffend::Logger.new(@log_level)
21
+ end
22
+
23
+ def ignore_errors?
24
+ @ignore_errors
25
+ end
26
+
27
+ def development?
28
+ @development
29
+ end
30
+
31
+ # Provides diffend commands endpoint url
32
+ #
33
+ # @return [String]
34
+ def commands_url
35
+ return ENV['DIFFEND_COMMANDS_URL'] if ENV.key?('DIFFEND_COMMANDS_URL')
36
+
37
+ "https://my.diffend.io/api/projects/#{project_id}/bundle/#{command}"
38
+ end
39
+
40
+ # Provides diffend errors endpoint url
41
+ #
42
+ # @return [String]
43
+ def errors_url
44
+ return ENV['DIFFEND_ERRORS_URL'] if ENV.key?('DIFFEND_ERRORS_URL')
45
+
46
+ "https://my.diffend.io/api/projects/#{project_id}/errors"
47
+ end
48
+
49
+ # @param request_id [String]
50
+ #
51
+ # @return [String]
52
+ def track_url(request_id)
53
+ "https://my.diffend.io/api/projects/#{project_id}/bundle/#{request_id}/track"
54
+ end
55
+
56
+ private
57
+
58
+ def build(command, build_path)
59
+ build_path ||= File.expand_path('..', ::Bundler.bin_path)
60
+ hash = Diffend::Configs::Fetcher.call(logger, build_path)
61
+ hash['build_path'] = build_path
62
+ hash['env'] = ENV['DIFFEND_ENV'] || 'development'
63
+ hash['ignore_errors'] = ENV['DIFFEND_IGNORE_ERRORS'] == 'true'
64
+ hash['development'] = ENV['DIFFEND_DEVELOPMENT'] == 'true'
65
+ hash['command'] = command || build_command
66
+
67
+ hash.each { |key, value| instance_variable_set(:"@#{key}", value) }
68
+ end
69
+
70
+ def validate
71
+ Diffend::Configs::Validator.call(self)
72
+ end
73
+
74
+ # Command that was run with bundle
75
+ #
76
+ # @return [String]
77
+ def build_command
78
+ ARGV.first || ::Bundler.feature_flag.default_cli_command.to_s
79
+ end
80
+ end
81
+ end
@@ -4,41 +4,33 @@ require 'yaml'
4
4
 
5
5
  module Diffend
6
6
  # Module for all the components related to setting up the config
7
- module Config
7
+ module Configs
8
8
  # Class responsible for fetching the config from .diffend.yml
9
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
10
  class << self
11
+ # @param logger [Diffend::Logger]
19
12
  # @param build_path [String] path of the current build
20
13
  #
21
- # @return [OpenStruct] open struct with config details
14
+ # @return [Hash] details from configuration file
22
15
  #
23
16
  # @example
24
17
  # details = Fetcher.new.call('./')
25
18
  # details.build_path #=> './'
26
- def call(build_path)
19
+ def call(logger, build_path)
27
20
  build(build_path)
28
21
  rescue Errors::MissingConfigurationFile
29
- Bundler.ui.error(build_missing_error_message(build_path))
22
+ build_missing_error_message(build_path)
23
+ .tap(&logger.method(:fatal))
30
24
 
31
25
  raise Diffend::Errors::HandledException
32
26
  rescue Errors::EmptyConfigurationFile
33
- Bundler.ui.error(build_empty_error_message(build_path))
27
+ build_empty_error_message(build_path)
28
+ .tap(&logger.method(:fatal))
34
29
 
35
30
  raise Diffend::Errors::HandledException
36
31
  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))
32
+ build_malformed_error_message(build_path)
33
+ .tap(&logger.method(:fatal))
42
34
 
43
35
  raise Diffend::Errors::HandledException
44
36
  end
@@ -57,8 +49,7 @@ module Diffend
57
49
 
58
50
  raise Errors::EmptyConfigurationFile if content.empty?
59
51
 
60
- OpenStruct.new(parse_file(content).merge(build_path: build_path))
61
- .tap(&Validator.method(:call))
52
+ parse_file(content)
62
53
  end
63
54
 
64
55
  def parse_file(content)
@@ -92,25 +83,6 @@ module Diffend
92
83
  Please re-setup.\n
93
84
  MSG
94
85
  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
86
  end
115
87
  end
116
88
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Diffend
4
- module Config
4
+ module Configs
5
5
  # Class used to figure out the file from which we should load the settings
6
6
  module FileFinder
7
7
  # Names of the files or paths where we will look for the settings
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Diffend
4
+ # Module for all the components related to setting up the config
5
+ module Configs
6
+ # Class responsible for validating the config from .diffend.yml
7
+ module Validator
8
+ KNOWN_KEYS = {
9
+ project_id: [String],
10
+ shareable_id: [String],
11
+ shareable_key: [String],
12
+ build_path: [String],
13
+ env: [String],
14
+ command: [String],
15
+ ignore_errors?: [TrueClass, FalseClass],
16
+ development?: [TrueClass, FalseClass]
17
+ }.freeze
18
+
19
+ class << self
20
+ # @param config [Diffend::Config]
21
+ def call(config)
22
+ KNOWN_KEYS.each_key do |key|
23
+ if missing?(config, key)
24
+ missing_key_message(key)
25
+ .tap(&config.logger.method(:fatal))
26
+
27
+ raise Diffend::Errors::HandledException
28
+ end
29
+
30
+ if invalid?(config, key)
31
+ invalid_key_message(config, key)
32
+ .tap(&config.logger.method(:fatal))
33
+
34
+ raise Diffend::Errors::HandledException
35
+ end
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ # @param config [Diffend::Config]
42
+ # @param key [String]
43
+ #
44
+ # @return [Boolean] true if we are missing a key, false otherwise
45
+ def missing?(config, key)
46
+ value = config.public_send(key)
47
+
48
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
49
+ end
50
+
51
+ # @param config [Diffend::Config]
52
+ # @param key [String]
53
+ #
54
+ # @return [Boolean] true if we are missing a key, false otherwise
55
+ def invalid?(config, key)
56
+ !KNOWN_KEYS[key].include?(config.public_send(key).class)
57
+ end
58
+
59
+ # Missing key message
60
+ #
61
+ # @param key [String] missing key
62
+ #
63
+ # @return [String]
64
+ def missing_key_message(key)
65
+ <<~MSG
66
+ \nDiffend configuration is missing #{key} key.\n
67
+ MSG
68
+ end
69
+
70
+ # Invalid key message
71
+ #
72
+ # @param hash [Hash] config hash
73
+ # @param key [String] invalid key
74
+ #
75
+ # @return [String]
76
+ def invalid_key_message(hash, key)
77
+ <<~MSG
78
+ \nDiffend configuration value for #{key} is invalid.\n
79
+ It should be #{KNOWN_KEYS[key].join(' or ')} but is #{hash.public_send(key).class}.\n
80
+ MSG
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end