diffend 0.2.31 → 0.2.36
Sign up to get free protection for your applications and to get access to all the features.
- 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 +12 -24
- data/config/diffend.yml +6 -0
- data/lib/diffend/build_bundler_definition.rb +1 -1
- data/lib/diffend/config.rb +73 -12
- data/lib/diffend/configs/fetcher.rb +67 -0
- data/lib/diffend/configs/validator.rb +85 -0
- data/lib/diffend/errors.rb +0 -4
- data/lib/diffend/execute.rb +21 -24
- data/lib/diffend/handle_errors/report.rb +9 -17
- data/lib/diffend/latest_version.rb +50 -0
- data/lib/diffend/local_context.rb +4 -5
- data/lib/diffend/local_context/diffend.rb +4 -4
- data/lib/diffend/local_context/host.rb +10 -2
- data/lib/diffend/local_context/packages.rb +14 -11
- data/lib/diffend/logger.rb +66 -0
- data/lib/diffend/monitor.rb +15 -8
- data/lib/diffend/plugin.rb +10 -48
- data/lib/diffend/request.rb +10 -9
- data/lib/diffend/request_verdict.rb +16 -22
- data/lib/diffend/track.rb +7 -20
- data/lib/diffend/version.rb +1 -1
- metadata +8 -6
- 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/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
|
@@ -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
|
|
@@ -5,19 +5,26 @@ require 'json'
|
|
5
5
|
module Diffend
|
6
6
|
# Module responsible for fetching diffend verdict on local context
|
7
7
|
module RequestVerdict
|
8
|
+
# Exceptions that we handle when there is a resolve issue
|
9
|
+
RESOLVE_EXCEPTIONS = [
|
10
|
+
Bundler::GemNotFound,
|
11
|
+
Bundler::GitError,
|
12
|
+
Bundler::PermissionError,
|
13
|
+
Bundler::VersionConflict
|
14
|
+
].freeze
|
15
|
+
|
8
16
|
class << self
|
9
|
-
# @param
|
17
|
+
# @param config [Diffend::Config]
|
10
18
|
# @param definition [Bundler::Definition] definition for your source
|
11
|
-
|
12
|
-
|
13
|
-
payload = Diffend::LocalContext.call(command, config.project_id, definition)
|
19
|
+
def call(config, definition)
|
20
|
+
payload = Diffend::LocalContext.call(config, definition)
|
14
21
|
|
15
22
|
response = Diffend::Request.call(
|
16
|
-
build_request_object(
|
23
|
+
build_request_object(config, payload)
|
17
24
|
)
|
18
25
|
|
19
26
|
JSON.parse(response.body)
|
20
|
-
rescue
|
27
|
+
rescue *RESOLVE_EXCEPTIONS
|
21
28
|
raise ::Diffend::Errors::DependenciesResolveException
|
22
29
|
rescue StandardError => e
|
23
30
|
Diffend::HandleErrors::Report.call(
|
@@ -29,31 +36,18 @@ module Diffend
|
|
29
36
|
)
|
30
37
|
end
|
31
38
|
|
32
|
-
# @param
|
33
|
-
# @param config [OpenStruct] diffend config
|
39
|
+
# @param config [Diffend::Config]
|
34
40
|
# @param payload [Hash]
|
35
41
|
#
|
36
42
|
# @return [Diffend::RequestObject]
|
37
|
-
def build_request_object(
|
43
|
+
def build_request_object(config, payload)
|
38
44
|
Diffend::RequestObject.new(
|
39
45
|
config: config,
|
40
|
-
url:
|
46
|
+
url: config.commands_url,
|
41
47
|
payload: payload,
|
42
48
|
request_method: :post
|
43
49
|
)
|
44
50
|
end
|
45
|
-
|
46
|
-
# Provides diffend command endpoint url
|
47
|
-
#
|
48
|
-
# @param command [String] either install or update
|
49
|
-
# @param project_id [String] diffend project_id
|
50
|
-
#
|
51
|
-
# @return [String] diffend endpoint
|
52
|
-
def commands_url(command, project_id)
|
53
|
-
return ENV['DIFFEND_COMMAND_URL'] if ENV.key?('DIFFEND_COMMAND_URL')
|
54
|
-
|
55
|
-
"https://my.diffend.io/api/projects/#{project_id}/bundle/#{command}"
|
56
|
-
end
|
57
51
|
end
|
58
52
|
end
|
59
53
|
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,19 +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::Execute.call(Diffend::Commands::EXEC, @config)
|
54
|
-
end
|
55
|
-
|
56
51
|
# Perform a track request
|
57
52
|
#
|
58
53
|
# @param request_id [String]
|
@@ -68,18 +63,10 @@ module Diffend
|
|
68
63
|
def build_request_object(request_id)
|
69
64
|
Diffend::RequestObject.new(
|
70
65
|
config: @config,
|
71
|
-
url:
|
66
|
+
url: @config.track_url(request_id),
|
72
67
|
payload: { id: request_id }.freeze,
|
73
68
|
request_method: :put
|
74
69
|
).freeze
|
75
70
|
end
|
76
|
-
|
77
|
-
# @param project_id [String] diffend project_id
|
78
|
-
# @param request_id [String]
|
79
|
-
#
|
80
|
-
# @return [String]
|
81
|
-
def track_url(project_id, request_id)
|
82
|
-
"https://my.diffend.io/api/projects/#{project_id}/bundle/#{request_id}/track"
|
83
|
-
end
|
84
71
|
end
|
85
72
|
end
|
data/lib/diffend/version.rb
CHANGED
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.36
|
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-12-06 00:00:00.000000000 Z
|
38
38
|
dependencies:
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: bundler
|
@@ -90,25 +90,27 @@ 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
98
|
- lib/diffend/config.rb
|
98
|
-
- lib/diffend/
|
99
|
-
- lib/diffend/
|
100
|
-
- lib/diffend/config/validator.rb
|
99
|
+
- lib/diffend/configs/fetcher.rb
|
100
|
+
- lib/diffend/configs/validator.rb
|
101
101
|
- lib/diffend/errors.rb
|
102
102
|
- lib/diffend/execute.rb
|
103
103
|
- lib/diffend/handle_errors/build_exception_payload.rb
|
104
104
|
- lib/diffend/handle_errors/display_to_stdout.rb
|
105
105
|
- lib/diffend/handle_errors/messages.rb
|
106
106
|
- lib/diffend/handle_errors/report.rb
|
107
|
+
- lib/diffend/latest_version.rb
|
107
108
|
- lib/diffend/local_context.rb
|
108
109
|
- lib/diffend/local_context/diffend.rb
|
109
110
|
- lib/diffend/local_context/host.rb
|
110
111
|
- lib/diffend/local_context/packages.rb
|
111
112
|
- lib/diffend/local_context/platform.rb
|
113
|
+
- lib/diffend/logger.rb
|
112
114
|
- lib/diffend/monitor.rb
|
113
115
|
- lib/diffend/plugin.rb
|
114
116
|
- lib/diffend/request.rb
|
@@ -137,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
139
|
- !ruby/object:Gem::Version
|
138
140
|
version: '0'
|
139
141
|
requirements: []
|
140
|
-
rubygems_version: 3.1.
|
142
|
+
rubygems_version: 3.1.4
|
141
143
|
signing_key:
|
142
144
|
specification_version: 4
|
143
145
|
summary: OSS supply chain security and management platform
|
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
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Diffend
|
4
|
-
module Config
|
5
|
-
# Class used to figure out the file from which we should load the settings
|
6
|
-
module FileFinder
|
7
|
-
# Names of the files or paths where we will look for the settings
|
8
|
-
#
|
9
|
-
# @note We do the double dot trick, to look outside of the current dir because when
|
10
|
-
# executed from a docker container, we copy the local uncommitted settings into the
|
11
|
-
# dir above the app location not to pollute the reset state of the git repo
|
12
|
-
#
|
13
|
-
# @note Order is important, as for local env we should load from
|
14
|
-
# local file (if present first)
|
15
|
-
FILE_NAMES = %w[
|
16
|
-
.diffend.yml
|
17
|
-
].map { |name| ["../#{name}", name] }.tap(&:flatten!).freeze
|
18
|
-
|
19
|
-
private_constant :FILE_NAMES
|
20
|
-
|
21
|
-
class << self
|
22
|
-
# Looks for Diffend settings file for a given env
|
23
|
-
#
|
24
|
-
# @param build_path [String] path of the current build
|
25
|
-
#
|
26
|
-
# @return [String] path to the file from which we should load all the settings
|
27
|
-
def call(build_path)
|
28
|
-
FILE_NAMES
|
29
|
-
.map { |name| File.join(build_path, name) }
|
30
|
-
.map { |name| Dir[name] }
|
31
|
-
.find { |selection| !selection.empty? }
|
32
|
-
.tap { |path| path || raise(Errors::MissingConfigurationFile) }
|
33
|
-
.first
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Diffend
|
4
|
-
# Module for all the components related to setting up the config
|
5
|
-
module Config
|
6
|
-
# Class responsible for validating the config from .diffend.yml
|
7
|
-
module Validator
|
8
|
-
class << self
|
9
|
-
# @param config [OpenStruct] path of the current build
|
10
|
-
def call(config)
|
11
|
-
raise Errors::ProjectIdMissingInConfigurationFile if missing?(config, 'project_id')
|
12
|
-
raise Errors::ShareableIdMissingInConfigurationFile if missing?(config, 'shareable_id')
|
13
|
-
raise Errors::ShareableKeyMissingInConfigurationFile if missing?(config, 'shareable_key')
|
14
|
-
raise Errors::BuildPathMissingInConfigurationFile if missing?(config, 'build_path')
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def missing?(config, key)
|
20
|
-
config.public_send(key).nil? || config.public_send(key).empty?
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|