diffend 0.2.25 → 0.2.30
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/.github/workflows/ci.yml +2 -0
- data/CHANGELOG.md +28 -1
- data/Gemfile.lock +1 -1
- data/diffend.gemspec +2 -3
- data/lib/diffend.rb +0 -110
- data/lib/diffend/commands.rb +4 -2
- data/lib/diffend/config.rb +19 -0
- data/lib/diffend/config/fetcher.rb +8 -4
- data/lib/diffend/errors.rb +4 -0
- data/lib/diffend/{voting.rb → execute.rb} +23 -11
- data/lib/diffend/handle_errors/report.rb +17 -5
- data/lib/diffend/local_context.rb +24 -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/monitor.rb +36 -0
- data/lib/diffend/plugin.rb +124 -0
- data/lib/diffend/request.rb +35 -15
- data/lib/diffend/request_object.rb +6 -0
- data/lib/diffend/request_verdict.rb +59 -0
- data/lib/diffend/track.rb +85 -0
- data/lib/diffend/version.rb +6 -0
- data/plugins.rb +2 -2
- data/scripts/generate_payload_for_file.rb +1 -2
- metadata +16 -6
- metadata.gz.sig +0 -0
- data/lib/diffend/voting/versions/local.rb +0 -304
- data/lib/diffend/voting/versions/remote.rb +0 -204
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52618cdf40375202e18c1cdaa481554084f3b92f337fd61c089e147f0027e982
|
4
|
+
data.tar.gz: 859f390055e3030d3a357b604067e6c05814f653225a802136563be4bc32f9ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f17436faa3bdabe77c891c930bb9dac01f426ae715d37035d7727112e221526ac003daa44d196dbb056f4c21bca49589a7799e36bef81db6bf8b3c29012adb5
|
7
|
+
data.tar.gz: 232310953c6dc8cd500aac54b0fd8d7f9980457b40032021b46bf7753f62c8a7d6167486c3e15e0d2e940101b47b8b8cdd8af67577eca7ba626b2db9706724c6
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/.github/workflows/ci.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,28 @@
|
|
2
2
|
|
3
3
|
## [Unreleased][master]
|
4
4
|
|
5
|
+
## [0.2.30] (2020-09-21)
|
6
|
+
- handle dependencies resolve issues ([#51](https://github.com/diffend-io/diffend-ruby/pull/51))
|
7
|
+
- better detection when to start `Diffend::Monitor` ([#50](https://github.com/diffend-io/diffend-ruby/pull/50))
|
8
|
+
- cleanup structure ([#47](https://github.com/diffend-io/diffend-ruby/pull/47))
|
9
|
+
|
10
|
+
## [0.2.29] (2020-09-21)
|
11
|
+
- fix command reporting on jruby ([#48](https://github.com/diffend-io/diffend-ruby/pull/48))
|
12
|
+
|
13
|
+
## [0.2.28] (2020-09-19)
|
14
|
+
- start `Diffend::Monitor` only if not in development or test ([#44](https://github.com/diffend-io/diffend-ruby/pull/44))
|
15
|
+
- better host command expose ([#45](https://github.com/diffend-io/diffend-ruby/pull/45))
|
16
|
+
|
17
|
+
## [0.2.27] (2020-09-16)
|
18
|
+
- introduce `Diffend::RequestObject` ([#40](https://github.com/diffend-io/diffend-ruby/pull/40))
|
19
|
+
- clean up error codes and introduce `DIFFEND_INGORE_EXCEPTIONS` ([#41](https://github.com/diffend-io/diffend-ruby/pull/41))
|
20
|
+
- introduce `Diffend::Monitor` and `Diffend::Track` ([#15](https://github.com/diffend-io/diffend-ruby/pull/15))
|
21
|
+
|
22
|
+
## [0.2.26] (2020-09-10)
|
23
|
+
- introduce `DIFFEND_DEVELOPMENT` environment variable ([#36](https://github.com/diffend-io/diffend-ruby/pull/36))
|
24
|
+
- adjust message for allow verdict ([#37](https://github.com/diffend-io/diffend-ruby/pull/37))
|
25
|
+
- do not run the plugin when it is not enabled ([#38](https://github.com/diffend-io/diffend-ruby/pull/38))
|
26
|
+
|
5
27
|
## [0.2.25] (2020-09-09)
|
6
28
|
- add support for a warn verdict ([#34](https://github.com/diffend-io/diffend-ruby/pull/34))
|
7
29
|
|
@@ -50,7 +72,12 @@
|
|
50
72
|
|
51
73
|
- initial release
|
52
74
|
|
53
|
-
[master]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.
|
75
|
+
[master]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.30...HEAD
|
76
|
+
[0.2.30]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.29...v0.2.30
|
77
|
+
[0.2.29]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.28...v0.2.29
|
78
|
+
[0.2.28]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.27...v0.2.28
|
79
|
+
[0.2.27]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.26...v0.2.27
|
80
|
+
[0.2.26]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.25...v0.2.26
|
54
81
|
[0.2.25]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.24...v0.2.25
|
55
82
|
[0.2.24]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.23...v0.2.24
|
56
83
|
[0.2.23]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.22...v0.2.23
|
data/Gemfile.lock
CHANGED
data/diffend.gemspec
CHANGED
@@ -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.
|
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')
|
data/lib/diffend.rb
CHANGED
@@ -1,114 +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
|
19
|
-
voting
|
20
|
-
].each { |file| require "diffend/#{file}" }
|
21
|
-
|
22
|
-
%w[
|
23
|
-
versions/local
|
24
|
-
versions/remote
|
25
|
-
].each { |file| require "diffend/voting/#{file}" }
|
26
|
-
|
27
|
-
# Diffend main namespace
|
28
3
|
module Diffend
|
29
|
-
# Current plugin version
|
30
|
-
VERSION = '0.2.25'
|
31
|
-
# Diffend homepage
|
32
|
-
HOMEPAGE = 'https://diffend.io'
|
33
|
-
|
34
|
-
class << self
|
35
|
-
# Registers the plugin and add before install all hook
|
36
|
-
def register
|
37
|
-
Bundler::Plugin.add_hook('before-install-all') do |_|
|
38
|
-
execute
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# Execute diffend plugin
|
43
|
-
def execute
|
44
|
-
detect_installed_version
|
45
|
-
|
46
|
-
config = fetch_config
|
47
|
-
|
48
|
-
Diffend::Voting.call(
|
49
|
-
command,
|
50
|
-
config,
|
51
|
-
Diffend::BuildBundlerDefinition.call(
|
52
|
-
command,
|
53
|
-
Bundler.default_gemfile,
|
54
|
-
Bundler.default_lockfile
|
55
|
-
)
|
56
|
-
)
|
57
|
-
rescue StandardError => e
|
58
|
-
Diffend::HandleErrors::Report.call(
|
59
|
-
exception: e,
|
60
|
-
config: config,
|
61
|
-
message: :unhandled_exception,
|
62
|
-
report: true
|
63
|
-
)
|
64
|
-
end
|
65
|
-
|
66
|
-
def detect_installed_version
|
67
|
-
return if installed_version == VERSION
|
68
|
-
|
69
|
-
build_outdated_version_message(installed_version)
|
70
|
-
.tap(&Bundler.ui.method(:error))
|
71
|
-
|
72
|
-
exit 1
|
73
|
-
end
|
74
|
-
|
75
|
-
# @param version [Hash] installed version
|
76
|
-
#
|
77
|
-
# @return [String]
|
78
|
-
def build_outdated_version_message(version)
|
79
|
-
<<~MSG
|
80
|
-
\nYou are running an outdated version (#{version}) of the plugin, which will lead to issues.
|
81
|
-
\nPlease upgrade to the latest one (#{VERSION}) by executing "rm -rf .bundle/plugin".\n
|
82
|
-
MSG
|
83
|
-
end
|
84
|
-
|
85
|
-
# @return [String] installed plugin version
|
86
|
-
def installed_version
|
87
|
-
Bundler::Plugin
|
88
|
-
.index
|
89
|
-
.plugin_path('diffend')
|
90
|
-
.basename
|
91
|
-
.to_s
|
92
|
-
.split('-')
|
93
|
-
.last
|
94
|
-
end
|
95
|
-
|
96
|
-
# Command that was run with bundle
|
97
|
-
#
|
98
|
-
# @return [String]
|
99
|
-
def command
|
100
|
-
ARGV.first || Bundler.feature_flag.default_cli_command.to_s
|
101
|
-
end
|
102
|
-
|
103
|
-
# Fetch diffend config file
|
104
|
-
#
|
105
|
-
# @return [OpenStruct, nil] configuration object
|
106
|
-
#
|
107
|
-
# @raise [Errors::MissingConfigurationFile] when no config file
|
108
|
-
def fetch_config
|
109
|
-
Config::Fetcher.call(
|
110
|
-
File.expand_path('..', Bundler.bin_path)
|
111
|
-
)
|
112
|
-
end
|
113
|
-
end
|
114
4
|
end
|
data/lib/diffend/commands.rb
CHANGED
@@ -3,9 +3,11 @@
|
|
3
3
|
module Diffend
|
4
4
|
# Modules grouping supported bundler commands
|
5
5
|
module Commands
|
6
|
-
#
|
6
|
+
# Bundler install command
|
7
7
|
INSTALL = 'install'
|
8
|
-
#
|
8
|
+
# Bundler update command
|
9
9
|
UPDATE = 'update'
|
10
|
+
# Bundler exec command
|
11
|
+
EXEC = 'exec'
|
10
12
|
end
|
11
13
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Diffend
|
4
|
+
# Diffend config object
|
5
|
+
module Config
|
6
|
+
class << self
|
7
|
+
# Build diffend config object
|
8
|
+
#
|
9
|
+
# @return [OpenStruct, nil]
|
10
|
+
#
|
11
|
+
# @raise [Errors::MissingConfigurationFile] when no config file
|
12
|
+
def call
|
13
|
+
Diffend::Config::Fetcher.call(
|
14
|
+
File.expand_path('..', ::Bundler.bin_path)
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -27,16 +27,20 @@ module Diffend
|
|
27
27
|
build(build_path)
|
28
28
|
rescue Errors::MissingConfigurationFile
|
29
29
|
Bundler.ui.error(build_missing_error_message(build_path))
|
30
|
-
|
30
|
+
|
31
|
+
raise Diffend::Errors::HandledException
|
31
32
|
rescue Errors::EmptyConfigurationFile
|
32
33
|
Bundler.ui.error(build_empty_error_message(build_path))
|
33
|
-
|
34
|
+
|
35
|
+
raise Diffend::Errors::HandledException
|
34
36
|
rescue Errors::MalformedConfigurationFile
|
35
37
|
Bundler.ui.error(build_malformed_error_message(build_path))
|
36
|
-
|
38
|
+
|
39
|
+
raise Diffend::Errors::HandledException
|
37
40
|
rescue *MISSING_KEY_ERRORS => e
|
38
41
|
Bundler.ui.error(build_missing_key_error_message(e))
|
39
|
-
|
42
|
+
|
43
|
+
raise Diffend::Errors::HandledException
|
40
44
|
end
|
41
45
|
|
42
46
|
private
|
data/lib/diffend/errors.rb
CHANGED
@@ -21,5 +21,9 @@ module Diffend
|
|
21
21
|
BuildPathMissingInConfigurationFile = Class.new(BaseError)
|
22
22
|
# Raised when server-side error occurs
|
23
23
|
RequestServerError = Class.new(BaseError)
|
24
|
+
# Raised when we had an exception that we know how to handle
|
25
|
+
HandledException = Class.new(BaseError)
|
26
|
+
# Raised when we are unable to resolve dependencies
|
27
|
+
DependenciesResolveException = Class.new(BaseError)
|
24
28
|
end
|
25
29
|
end
|
@@ -1,18 +1,30 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Diffend
|
4
|
-
#
|
5
|
-
module
|
4
|
+
# Executes a check for a given command
|
5
|
+
module Execute
|
6
6
|
class << self
|
7
7
|
# Build verdict
|
8
8
|
#
|
9
9
|
# @param command [String] either install or update
|
10
10
|
# @param config [OpenStruct] diffend config
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
.call(command, config, definition)
|
11
|
+
def call(command, config)
|
12
|
+
Diffend::RequestVerdict
|
13
|
+
.call(command, config, build_definition(command))
|
15
14
|
.tap { |response| build_message(command, config, response) }
|
15
|
+
rescue Diffend::Errors::DependenciesResolveException
|
16
|
+
# We are unable to resolve dependencies, no message will be printed
|
17
|
+
end
|
18
|
+
|
19
|
+
# Build bundler definition
|
20
|
+
#
|
21
|
+
# @return [Bundler::Definition]
|
22
|
+
def build_definition(command)
|
23
|
+
Diffend::BuildBundlerDefinition.call(
|
24
|
+
command,
|
25
|
+
Bundler.default_gemfile,
|
26
|
+
Bundler.default_lockfile
|
27
|
+
)
|
16
28
|
end
|
17
29
|
|
18
30
|
# @param command [String] either install or update
|
@@ -38,7 +50,7 @@ module Diffend
|
|
38
50
|
build_error_message(response)
|
39
51
|
.tap(&Bundler.ui.method(:error))
|
40
52
|
|
41
|
-
|
53
|
+
raise Diffend::Errors::HandledException
|
42
54
|
end
|
43
55
|
|
44
56
|
# @param command [String] either install or update
|
@@ -84,7 +96,7 @@ module Diffend
|
|
84
96
|
def build_allow_message(command, response)
|
85
97
|
<<~MSG
|
86
98
|
#{build_message_header('an allow', command)}
|
87
|
-
#{build_message_info(response)}
|
99
|
+
#{build_message_info(response)}\n
|
88
100
|
#{response['review_url']}\n
|
89
101
|
MSG
|
90
102
|
end
|
@@ -96,7 +108,7 @@ module Diffend
|
|
96
108
|
def build_warn_message(command, response)
|
97
109
|
<<~MSG
|
98
110
|
#{build_message_header('a warn', command)}
|
99
|
-
#{build_message_info(response)}
|
111
|
+
#{build_message_info(response)} Please go to the url below and review the issues.\n
|
100
112
|
#{response['review_url']}\n
|
101
113
|
MSG
|
102
114
|
end
|
@@ -108,7 +120,7 @@ module Diffend
|
|
108
120
|
def build_deny_message(command, response)
|
109
121
|
<<~MSG
|
110
122
|
#{build_message_header('a deny', command)}
|
111
|
-
#{build_message_info(response)}
|
123
|
+
#{build_message_info(response)} Please go to the url below and review the issues.\n
|
112
124
|
#{response['review_url']}\n
|
113
125
|
MSG
|
114
126
|
end
|
@@ -125,7 +137,7 @@ module Diffend
|
|
125
137
|
#
|
126
138
|
# @return [String]
|
127
139
|
def build_message_info(response)
|
128
|
-
"\nQuality score: #{response['quality_score']}, allows: #{response['allows_count']}, warnings: #{response['warns_count']}, denies: #{response['denies_count']}.
|
140
|
+
"\nQuality score: #{response['quality_score']}, allows: #{response['allows_count']}, warnings: #{response['warns_count']}, denies: #{response['denies_count']}."
|
129
141
|
end
|
130
142
|
end
|
131
143
|
end
|
@@ -12,9 +12,10 @@ module Diffend
|
|
12
12
|
# @param config [OpenStruct] Diffend config
|
13
13
|
# @param message [Symbol] message that we want to display
|
14
14
|
# @param report [Boolean] if true we will report the issue to diffend
|
15
|
+
# @param raise_exception [Boolean] if true we will raise an exception
|
15
16
|
#
|
16
17
|
# @return [Net::HTTPResponse] response from Diffend
|
17
|
-
def call(config:, message:, exception: nil, payload: {}, report: false)
|
18
|
+
def call(config:, message:, exception: nil, payload: {}, report: false, raise_exception: true)
|
18
19
|
exception_payload = prepare_exception_payload(exception, payload)
|
19
20
|
|
20
21
|
Bundler.ui.error(Diffend::HandleErrors::Messages::PAYLOAD_DUMP)
|
@@ -22,13 +23,24 @@ module Diffend
|
|
22
23
|
|
23
24
|
if report
|
24
25
|
Diffend::Request.call(
|
25
|
-
config,
|
26
|
-
errors_url(config.project_id),
|
27
|
-
exception_payload
|
26
|
+
build_request_object(config, exception_payload)
|
28
27
|
)
|
29
28
|
end
|
30
29
|
|
31
|
-
|
30
|
+
raise Diffend::Errors::HandledException if raise_exception
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param config [OpenStruct] diffend config
|
34
|
+
# @param payload [Hash]
|
35
|
+
#
|
36
|
+
# @return [Diffend::RequestObject]
|
37
|
+
def build_request_object(config, payload)
|
38
|
+
Diffend::RequestObject.new(
|
39
|
+
config: config,
|
40
|
+
url: errors_url(config.project_id),
|
41
|
+
payload: payload,
|
42
|
+
request_method: :post
|
43
|
+
)
|
32
44
|
end
|
33
45
|
|
34
46
|
# Prepare exception payload and display it to stdout
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Diffend
|
4
|
+
# Module responsible for building local context
|
5
|
+
module LocalContext
|
6
|
+
class << self
|
7
|
+
# Build diffend, host, packages, and platform specific information
|
8
|
+
#
|
9
|
+
# @param command [String] either install or update
|
10
|
+
# @param project_id [String] diffend project_id
|
11
|
+
# @param definition [Bundler::Definition] definition for your source
|
12
|
+
#
|
13
|
+
# @return [Hash] payload for diffend endpoint
|
14
|
+
def call(command, project_id, definition)
|
15
|
+
{
|
16
|
+
'diffend' => Diffend.call(project_id),
|
17
|
+
'host' => Host.call,
|
18
|
+
'packages' => Packages.call(command, definition),
|
19
|
+
'platform' => Platform.call
|
20
|
+
}.freeze
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Diffend
|
4
|
+
# Module responsible for building local context
|
5
|
+
module LocalContext
|
6
|
+
# Module responsible for building diffend information from local context
|
7
|
+
module Diffend
|
8
|
+
# API version
|
9
|
+
API_VERSION = '0.1'
|
10
|
+
# Platform type ruby
|
11
|
+
PLATFORM_TYPE = 0
|
12
|
+
|
13
|
+
private_constant :API_VERSION, :PLATFORM_TYPE
|
14
|
+
|
15
|
+
class << self
|
16
|
+
# Build diffend information
|
17
|
+
#
|
18
|
+
# @param project_id [String, nil] diffend project_id
|
19
|
+
#
|
20
|
+
# @return [Hash]
|
21
|
+
def call(project_id)
|
22
|
+
{
|
23
|
+
'api_version' => API_VERSION,
|
24
|
+
'environment' => ENV['DIFFEND_ENV'],
|
25
|
+
'project_id' => project_id,
|
26
|
+
'type' => PLATFORM_TYPE,
|
27
|
+
'version' => ::Diffend::VERSION
|
28
|
+
}.freeze
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|