diffend 0.2.30 → 0.2.35

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,19 +5,25 @@ 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::VersionConflict,
12
+ Bundler::GitError
13
+ ].freeze
14
+
8
15
  class << self
9
- # @param command [String] either install or update
16
+ # @param config [Diffend::Config]
10
17
  # @param definition [Bundler::Definition] definition for your source
11
- # @param config [OpenStruct] diffend config
12
- def call(command, config, definition)
13
- payload = Diffend::LocalContext.call(command, config.project_id, definition)
18
+ def call(config, definition)
19
+ payload = Diffend::LocalContext.call(config, definition)
14
20
 
15
21
  response = Diffend::Request.call(
16
- build_request_object(command, config, payload)
22
+ build_request_object(config, payload)
17
23
  )
18
24
 
19
25
  JSON.parse(response.body)
20
- rescue Bundler::GemNotFound
26
+ rescue *RESOLVE_EXCEPTIONS
21
27
  raise ::Diffend::Errors::DependenciesResolveException
22
28
  rescue StandardError => e
23
29
  Diffend::HandleErrors::Report.call(
@@ -29,31 +35,18 @@ module Diffend
29
35
  )
30
36
  end
31
37
 
32
- # @param command [String] either install or update
33
- # @param config [OpenStruct] diffend config
38
+ # @param config [Diffend::Config]
34
39
  # @param payload [Hash]
35
40
  #
36
41
  # @return [Diffend::RequestObject]
37
- def build_request_object(command, config, payload)
42
+ def build_request_object(config, payload)
38
43
  Diffend::RequestObject.new(
39
44
  config: config,
40
- url: commands_url(command, config.project_id),
45
+ url: config.commands_url,
41
46
  payload: payload,
42
47
  request_method: :post
43
48
  )
44
49
  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
50
  end
58
51
  end
59
52
  end
@@ -9,14 +9,16 @@ module Diffend
9
9
  RETRY_SLEEP = 15
10
10
 
11
11
  # Initialize tracking
12
- def initialize
12
+ #
13
+ # @param config [Diffend::Config]
14
+ def initialize(config)
13
15
  @mutex = Mutex.new
14
- @config = Diffend::Config.call
16
+ @config = config
15
17
  end
16
18
 
17
19
  # Start tracking
18
20
  def start
19
- response = exec_request
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 do
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: track_url(@config.project_id, request_id),
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Diffend
4
4
  # Current version
5
- VERSION = '0.2.30'
5
+ VERSION = '0.2.35'
6
6
  end
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.30
4
+ version: 0.2.35
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-09-21 00:00:00.000000000 Z
37
+ date: 2020-11-04 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/config/fetcher.rb
99
- - lib/diffend/config/file_finder.rb
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.2
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