diffend 0.2.36 → 0.2.37

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76c744c4aef5eaa735b131f3f866f9e89d01b9ae79e04cfa1a922419f4be4a3c
4
- data.tar.gz: 3ebbd02c2a0b693e57d9b4d7d73c8c9e490236189983a30e7c24caaffb7b5843
3
+ metadata.gz: 6882244ccac8c68c4b0eef0e1ffceeda710c6202b28a7608e7b6502dc9c8f694
4
+ data.tar.gz: efd83185b8af53f813204f3265567ed2ed44b6d9e40328d13f613254e3865857
5
5
  SHA512:
6
- metadata.gz: a166de7306a536d75d20d50c5fe27f27fe77cc4a3332446a85543f42a617b180d3bc97a1a0800c5ada0189eb59d923e8d0a7bd823d3f2f9e31ef2113263a616f
7
- data.tar.gz: 5b1890d48842a54166c3eae9d500d43f8c81172f66df9b5f768460fd65e97a2460f542eba99970db8fceb630c97a6fd71f1dd9fe7170c425d5f89b06f448499c
6
+ metadata.gz: 82509d763d303aad433d329c761d1c36e422314dfb0f55999793829a5c1d1e0a9bdcc4e23a3b4b47dd340fd97129eef567eee23320a5249c0cea956a5fd05468
7
+ data.tar.gz: bfff54f76c8d02c108c4416756be710991948cd3cebf35143c8ecd98e0a13777a8d445963d2986388db5a480a31094250a2ef9334bd3e58558acdd36bb12e0a7
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -8,10 +8,14 @@ jobs:
8
8
  fail-fast: false
9
9
  matrix:
10
10
  ruby:
11
+ - '3.0'
11
12
  - '2.7'
12
13
  - '2.6'
13
14
  - '2.5'
14
- - 'jruby'
15
+ - 'jruby-9.2.13.0'
16
+ bundler:
17
+ - '2.1.4'
18
+ - '2.2.4'
15
19
  include:
16
20
  - ruby: '2.7'
17
21
  coverage: 'true'
@@ -30,19 +34,17 @@ jobs:
30
34
  uses: ruby/setup-ruby@v1
31
35
  with:
32
36
  ruby-version: ${{matrix.ruby}}
33
- - name: Install latest bundler
34
- run: |
35
- gem install bundler --no-document
37
+ bundler: ${{matrix.bundler}}
36
38
  - name: Bundle install
37
39
  env:
38
40
  DIFFEND_DEVELOPMENT: true
39
41
  run: |
40
- bundle config path vendor/bundle
41
- bundle install --jobs 4 --retry 3
42
+ bundle _${{matrix.bundler}}_ config path vendor/bundle
43
+ bundle _${{matrix.bundler}}_ install --jobs 4 --retry 3
42
44
  - name: Run all tests
43
45
  env:
44
46
  GITHUB_COVERAGE: ${{matrix.coverage}}
45
- run: bundle exec rspec
47
+ run: bundle _${{matrix.bundler}}_ exec rspec
46
48
 
47
49
  coditsu:
48
50
  runs-on: ubuntu-latest
@@ -1 +1 @@
1
- 2.7.2
1
+ 3.0.0
@@ -2,6 +2,18 @@
2
2
 
3
3
  ## [Unreleased][master]
4
4
 
5
+ ## [0.2.37] (2021-01-05)
6
+ - add support for ENV loaded at runtime ([#92](https://github.com/diffend-io/diffend-ruby/pull/92))
7
+ - allow us to have more control over config errors ([#91](https://github.com/diffend-io/diffend-ruby/pull/91))
8
+ - add `bundle secure` command ([#90](https://github.com/diffend-io/diffend-ruby/pull/90))
9
+ - test against bundler 2.1 and 2.2 ([#83](https://github.com/diffend-io/diffend-ruby/pull/83))
10
+ - test against ruby 3.0.0 ([#89](https://github.com/diffend-io/diffend-ruby/pull/89))
11
+ - simplify how we build full json in specs ([#82](https://github.com/diffend-io/diffend-ruby/pull/82))
12
+ - simplify how we build bundler json in specs ([#84](https://github.com/diffend-io/diffend-ruby/pull/84))
13
+ - simplify how we build diffend json in specs ([#85](https://github.com/diffend-io/diffend-ruby/pull/85))
14
+ - simplify how we build rubygems json in specs ([#86](https://github.com/diffend-io/diffend-ruby/pull/86))
15
+ - simplify how we build packages platforms json in specs ([#87](https://github.com/diffend-io/diffend-ruby/pull/87))
16
+
5
17
  ## [0.2.36] (2020-12-06)
6
18
  - handle `Bundler::PermissionError` ([#79](https://github.com/diffend-io/diffend-ruby/pull/79))
7
19
  - use cache to resolve dependencies in exec mode ([#78](https://github.com/diffend-io/diffend-ruby/pull/78))
data/Gemfile CHANGED
@@ -7,5 +7,6 @@ plugin 'diffend'
7
7
  gemspec
8
8
 
9
9
  group :development, :test do
10
+ gem 'byebug', platform: :ruby
10
11
  gem 'rspec'
11
12
  end
@@ -1,36 +1,40 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- diffend (0.2.36)
4
+ diffend (0.2.37)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ byebug (11.1.3)
9
10
  diff-lcs (1.4.4)
10
- rake (13.0.1)
11
+ rake (13.0.3)
11
12
  rspec (3.10.0)
12
13
  rspec-core (~> 3.10.0)
13
14
  rspec-expectations (~> 3.10.0)
14
15
  rspec-mocks (~> 3.10.0)
15
- rspec-core (3.10.0)
16
+ rspec-core (3.10.1)
16
17
  rspec-support (~> 3.10.0)
17
- rspec-expectations (3.10.0)
18
+ rspec-expectations (3.10.1)
18
19
  diff-lcs (>= 1.2.0, < 2.0)
19
20
  rspec-support (~> 3.10.0)
20
- rspec-mocks (3.10.0)
21
+ rspec-mocks (3.10.1)
21
22
  diff-lcs (>= 1.2.0, < 2.0)
22
23
  rspec-support (~> 3.10.0)
23
- rspec-support (3.10.0)
24
+ rspec-support (3.10.1)
24
25
 
25
26
  PLATFORMS
26
27
  java
27
28
  ruby
29
+ universal-java-13
30
+ x86_64-darwin-19
28
31
 
29
32
  DEPENDENCIES
30
33
  bundler
34
+ byebug
31
35
  diffend!
32
36
  rake
33
37
  rspec
34
38
 
35
39
  BUNDLED WITH
36
- 2.1.4
40
+ 2.2.4
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Diffend
4
+ # Extend bundler with a new secure command to be able to run Diffend separately
5
+ class BundleSecure
6
+ Bundler::Plugin::API.command(Diffend::Commands::SECURE, self)
7
+
8
+ # Execute diffend check
9
+ #
10
+ # @param _name [String] command name
11
+ # @param _args [Array] arguments from ARGV
12
+ def exec(_name, _args)
13
+ return unless Diffend::Enabled.call
14
+
15
+ config = Diffend::Config.new(
16
+ command: Diffend::Commands::SECURE,
17
+ severity: Diffend::Logger::INFO
18
+ )
19
+
20
+ Diffend::LatestVersion.call(config)
21
+
22
+ Diffend::Execute.call(config)
23
+ end
24
+ end
25
+ end
@@ -9,5 +9,7 @@ module Diffend
9
9
  UPDATE = 'update'
10
10
  # Bundler exec command
11
11
  EXEC = 'exec'
12
+ # Bundler secure command introduced by diffend plugin
13
+ SECURE = 'secure'
12
14
  end
13
15
  end
@@ -3,29 +3,50 @@
3
3
  module Diffend
4
4
  # Diffend config object
5
5
  class Config
6
- attr_reader :project_id, :shareable_id, :shareable_key, :build_path, :env, :command
6
+ # Name of the diffend config file
7
+ FILENAME = '.diffend.yml'
8
+
9
+ attr_reader :project_id, :shareable_id, :shareable_key, :build_path, :env, :command, :errors
7
10
 
8
11
  # Build diffend config object
9
12
  #
13
+ # @param command [String] command executed via bundler
14
+ # @param severity [Integer] logging severity threshold
15
+ # @param build_path [String] path of the current build
16
+ #
10
17
  # @return [Diffend::Config]
11
18
  def initialize(command: nil, severity: nil, build_path: nil)
12
19
  @log_level = severity
20
+ @errors = []
13
21
  build(command, build_path)
14
- validate
22
+ Diffend::Configs::Validator.call(self)
15
23
  end
16
24
 
25
+ # Initialize logger
17
26
  def logger
18
27
  @logger ||= Diffend::Logger.new(@log_level)
19
28
  end
20
29
 
30
+ # @return [Boolean] true if config is valid, false otherwise
31
+ def valid?
32
+ @errors.empty?
33
+ end
34
+
35
+ # @return [Boolean] true if we want to ignore errors, false otherwise
21
36
  def ignore_errors?
22
37
  @ignore_errors
23
38
  end
24
39
 
40
+ # @return [Boolean] true if we are in development mode, false otherwise
25
41
  def development?
26
42
  @development
27
43
  end
28
44
 
45
+ # @return [Boolean] true if we are in deployment mode, false otherwise
46
+ def deployment?
47
+ !%w[development test].include?(env)
48
+ end
49
+
29
50
  # Provides diffend commands endpoint url
30
51
  #
31
52
  # @return [String]
@@ -51,19 +72,24 @@ module Diffend
51
72
  "https://my.diffend.io/api/projects/#{project_id}/bundle/#{request_id}/track"
52
73
  end
53
74
 
75
+ # Print config errors
76
+ def print_errors
77
+ @errors.each { |error| logger.fatal(error) }
78
+ end
79
+
54
80
  private
55
81
 
82
+ # @param command [String] command executed via bundler
83
+ # @param build_path [String] path of the current build
56
84
  def build(command, build_path)
57
85
  build_path ||= File.expand_path('..', ::Bundler.bin_path)
58
- hash = Diffend::Configs::Fetcher.call(logger, plugin_path, build_path)
86
+ hash = Diffend::Configs::Fetcher.call(plugin_path, build_path)
59
87
  hash['build_path'] = build_path
60
88
  hash['command'] = command || build_command
61
89
 
62
90
  hash.each { |key, value| instance_variable_set(:"@#{key}", value) }
63
- end
64
-
65
- def validate
66
- Diffend::Configs::Validator.call(self)
91
+ rescue Errors::MalformedConfigurationFile
92
+ @errors << Diffend::Configs::ErrorMessages.malformed_file
67
93
  end
68
94
 
69
95
  # Command that was run with bundle
@@ -73,6 +99,7 @@ module Diffend
73
99
  ARGV.first || ::Bundler.feature_flag.default_cli_command.to_s
74
100
  end
75
101
 
102
+ # @return [String] path to the plugin
76
103
  def plugin_path
77
104
  Pathname.new(File.expand_path('../..', __dir__))
78
105
  end
@@ -0,0 +1,38 @@
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 config error messages
7
+ module ErrorMessages
8
+ class << self
9
+ # @return [String] malformed configuration file message
10
+ def malformed_file
11
+ 'Your Diffend configuration file is malformed. Please re-setup.'
12
+ end
13
+
14
+ # Missing key message
15
+ #
16
+ # @param key [String] missing key
17
+ #
18
+ # @return [String]
19
+ def missing_key(key)
20
+ "Diffend configuration is missing #{key} key"
21
+ end
22
+
23
+ # Invalid key message
24
+ #
25
+ # @param config [Diffend::Config]
26
+ # @param key [String] invalid key
27
+ #
28
+ # @return [String]
29
+ def invalid_key(config, key)
30
+ <<~MSG
31
+ Diffend configuration value for #{key} is invalid.
32
+ Expected #{Validator::KNOWN_KEYS[key].join(' or ')}, was #{config.public_send(key).class}.
33
+ MSG
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -11,7 +11,6 @@ module Diffend
11
11
  # Class responsible for fetching the config from .diffend.yml
12
12
  module Fetcher
13
13
  class << self
14
- # @param logger [Diffend::Logger]
15
14
  # @param plugin_path [String] path of the plugin
16
15
  # @param build_path [String] path of the current build
17
16
  #
@@ -20,24 +19,9 @@ module Diffend
20
19
  # @example
21
20
  # details = Fetcher.new.call('./')
22
21
  # details.build_path #=> './'
23
- def call(logger, plugin_path, build_path)
24
- build(plugin_path, build_path)
25
- rescue Errors::MalformedConfigurationFile
26
- build_malformed_error_message(build_path)
27
- .tap(&logger.method(:fatal))
28
-
29
- raise Diffend::Errors::HandledException
30
- end
31
-
32
- private
33
-
34
- # @param plugin_path [String] path of the plugin
35
- # @param build_path [String] path of the current build
36
- #
37
- # @return [OpenStruct] open struct with config details
38
- def build(plugin_path, build_path)
22
+ def call(plugin_path, build_path)
39
23
  default_config = File.join(plugin_path, 'config', 'diffend.yml')
40
- project_config = File.join(build_path, '.diffend.yml')
24
+ project_config = File.join(build_path, Diffend::Config::FILENAME)
41
25
 
42
26
  hash = read_file(default_config)
43
27
 
@@ -48,19 +32,18 @@ module Diffend
48
32
  hash
49
33
  end
50
34
 
51
- def read_file(path)
52
- YAML.safe_load(ERB.new(File.read(path)).result)
35
+ private
36
+
37
+ # Load config file
38
+ #
39
+ # @param file_path [String]
40
+ #
41
+ # @return [Hash]
42
+ def read_file(file_path)
43
+ YAML.safe_load(ERB.new(File.read(file_path)).result)
53
44
  rescue Psych::SyntaxError
54
45
  raise Errors::MalformedConfigurationFile
55
46
  end
56
-
57
- # @return [String] malformed configuration file message
58
- def build_malformed_error_message
59
- <<~MSG
60
- \nYour Diffend configuration file is malformed.\n
61
- Please re-setup.\n
62
- MSG
63
- end
64
47
  end
65
48
  end
66
49
  end
@@ -5,6 +5,7 @@ module Diffend
5
5
  module Configs
6
6
  # Class responsible for validating the config from .diffend.yml
7
7
  module Validator
8
+ # List of known config keys
8
9
  KNOWN_KEYS = {
9
10
  project_id: [String],
10
11
  shareable_id: [String],
@@ -21,18 +22,11 @@ module Diffend
21
22
  def call(config)
22
23
  KNOWN_KEYS.each_key do |key|
23
24
  if missing?(config, key)
24
- missing_key_message(key)
25
- .tap(&config.logger.method(:fatal))
26
-
27
- raise Diffend::Errors::HandledException
25
+ config.errors << ErrorMessages.missing_key(key)
26
+ next
28
27
  end
29
28
 
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
29
+ config.errors << ErrorMessages.invalid_key(config, key) if invalid?(config, key)
36
30
  end
37
31
  end
38
32
 
@@ -55,30 +49,6 @@ module Diffend
55
49
  def invalid?(config, key)
56
50
  !KNOWN_KEYS[key].include?(config.public_send(key).class)
57
51
  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
52
  end
83
53
  end
84
54
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Diffend
4
+ # Verify if the plugin is enabled
5
+ module Enabled
6
+ class << self
7
+ # Checks if plugin is enabled
8
+ #
9
+ # @return [Boolean] true if enabled, false otherwise
10
+ def call
11
+ ::Bundler
12
+ .default_gemfile
13
+ .read
14
+ .split("\n")
15
+ .reject(&:empty?)
16
+ .map(&:strip)
17
+ .select { |line| line.start_with?('plugin') }
18
+ .any? { |line| line.include?('diffend') }
19
+ end
20
+ end
21
+ end
22
+ end
@@ -39,7 +39,7 @@ module Diffend
39
39
  Bundler.ui.silence { instance.resolve }
40
40
 
41
41
  case command
42
- when Commands::INSTALL, Commands::EXEC then instance.build_install
42
+ when Commands::INSTALL, Commands::EXEC, Commands::SECURE then instance.build_install
43
43
  when Commands::UPDATE then instance.build_update
44
44
  else
45
45
  raise ArgumentError, "invalid command: #{command}"
@@ -3,17 +3,17 @@
3
3
  module Diffend
4
4
  # Diffend logging
5
5
  class Logger
6
- # Low-level information, mostly for developers.
6
+ # Low-level information, mostly for developers
7
7
  DEBUG = 0
8
- # Generic (useful) information about system operation.
8
+ # Generic (useful) information about system operation
9
9
  INFO = 1
10
- # A warning.
10
+ # A warning
11
11
  WARN = 2
12
- # A handleable error condition.
12
+ # A handleable error condition
13
13
  ERROR = 3
14
- # An unhandleable error that results in a program crash.
14
+ # An error that we are unable to handle that results in a program crash
15
15
  FATAL = 4
16
- # An unknown message that should always be logged.
16
+ # An unknown message that should always be logged
17
17
  UNKNOWN = 5
18
18
 
19
19
  # @param level [Integer] logging severity threshold
@@ -6,6 +6,7 @@
6
6
  errors
7
7
  build_bundler_definition
8
8
  commands
9
+ configs/error_messages
9
10
  config
10
11
  configs/fetcher
11
12
  configs/validator
@@ -25,19 +26,28 @@
25
26
  track
26
27
  ].each { |file| require "diffend/#{file}" }
27
28
 
28
- begin
29
- config = Diffend::Config.new(
30
- command: Diffend::Commands::EXEC,
31
- severity: Diffend::Logger::FATAL
32
- )
33
- rescue Diffend::Errors::HandledException
34
- # we silent exit here because we don't want to break client boot
35
- return
36
- end
29
+ Thread.new do
30
+ config = nil
31
+ config_iterations = 0
37
32
 
38
- return if %w[development test].include?(config.env)
33
+ loop do
34
+ config = Diffend::Config.new(
35
+ command: Diffend::Commands::EXEC,
36
+ severity: Diffend::Logger::FATAL
37
+ )
38
+
39
+ break if config.valid?
40
+
41
+ config_iterations += 1
42
+
43
+ break if config_iterations == 12
44
+
45
+ sleep 5
46
+ end
47
+
48
+ Thread.exit unless config.valid?
49
+ Thread.exit unless config.deployment?
39
50
 
40
- Thread.new do
41
51
  track = Diffend::Track.new(config)
42
52
  track.start
43
53
  end
@@ -7,10 +7,12 @@
7
7
  %w[
8
8
  version
9
9
  logger
10
+ enabled
10
11
  latest_version
11
12
  errors
12
13
  build_bundler_definition
13
14
  commands
15
+ configs/error_messages
14
16
  config
15
17
  configs/fetcher
16
18
  configs/validator
@@ -42,10 +44,16 @@ module Diffend
42
44
 
43
45
  # Execute diffend plugin
44
46
  def execute
45
- return unless enabled?
47
+ return unless Diffend::Enabled.call
46
48
 
47
49
  config = Diffend::Config.new(severity: Diffend::Logger::INFO)
48
50
 
51
+ unless config.valid?
52
+ config.print_errors
53
+
54
+ exit 255
55
+ end
56
+
49
57
  Diffend::LatestVersion.call(config)
50
58
 
51
59
  Diffend::Execute.call(config)
@@ -67,20 +75,6 @@ module Diffend
67
75
 
68
76
  exit 255
69
77
  end
70
-
71
- # Checks if plugin is enabled
72
- #
73
- # @return [Boolean] true if enabled, false otherwise
74
- def enabled?
75
- ::Bundler
76
- .default_gemfile
77
- .read
78
- .split("\n")
79
- .reject(&:empty?)
80
- .map(&:strip)
81
- .select { |line| line.start_with?('plugin') }
82
- .any? { |line| line.include?('diffend') }
83
- end
84
78
  end
85
79
  end
86
80
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Diffend
4
4
  # Current version
5
- VERSION = '0.2.36'
5
+ VERSION = '0.2.37'
6
6
  end
data/plugins.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'diffend/plugin'
4
+ require 'diffend/bundle_secure'
4
5
 
5
6
  Diffend::Plugin.register
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.36
4
+ version: 0.2.37
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-12-06 00:00:00.000000000 Z
37
+ date: 2021-01-05 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: bundler
@@ -94,10 +94,13 @@ files:
94
94
  - diffend.gemspec
95
95
  - lib/diffend.rb
96
96
  - lib/diffend/build_bundler_definition.rb
97
+ - lib/diffend/bundle_secure.rb
97
98
  - lib/diffend/commands.rb
98
99
  - lib/diffend/config.rb
100
+ - lib/diffend/configs/error_messages.rb
99
101
  - lib/diffend/configs/fetcher.rb
100
102
  - lib/diffend/configs/validator.rb
103
+ - lib/diffend/enabled.rb
101
104
  - lib/diffend/errors.rb
102
105
  - lib/diffend/execute.rb
103
106
  - lib/diffend/handle_errors/build_exception_payload.rb
@@ -139,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
142
  - !ruby/object:Gem::Version
140
143
  version: '0'
141
144
  requirements: []
142
- rubygems_version: 3.1.4
145
+ rubygems_version: 3.2.3
143
146
  signing_key:
144
147
  specification_version: 4
145
148
  summary: OSS supply chain security and management platform
metadata.gz.sig CHANGED
Binary file