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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +29 -1
- data/Gemfile.lock +1 -1
- 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 +81 -0
- data/lib/diffend/{config → configs}/fetcher.rb +11 -39
- data/lib/diffend/{config → configs}/file_finder.rb +1 -1
- data/lib/diffend/configs/validator.rb +85 -0
- data/lib/diffend/errors.rb +2 -0
- 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 +21 -10
- data/lib/diffend/plugin.rb +86 -0
- data/lib/diffend/request.rb +10 -10
- data/lib/diffend/request_verdict.rb +45 -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 +18 -9
- metadata.gz.sig +0 -0
- 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 -216
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8e0efaea5a8bb4c724e24057821578b6c257a5eb313c472ac17dd60747fe10e4
|
|
4
|
+
data.tar.gz: af3b702fa128eabcc8f6f054895c0e64097f38672b650697e292ab705b749b69
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 00e60e3f610e03cad43a65b11c1b7f17d839d4b43009dde4436b9eebd96b82bdbf0035860eb85fb0e57c7042221403894a1aaf5f89cb606a86dd15e94f65bc58
|
|
7
|
+
data.tar.gz: f45b310e0e376b50e27b7a1876f3704a3f282dbadac5c868b4548a4a6a2d582632aeb3f204e47fda5545f47807446e648b0bf2fe70b4a0abdefb17ea40cf1ff1
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data.tar.gz.sig
CHANGED
|
Binary file
|
data/CHANGELOG.md
CHANGED
|
@@ -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.
|
|
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
|
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,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]
|
|
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
|
|
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 [
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
@@ -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
|