diffend-monitor 0.2.28 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9042954f4e7d0e9dc7aa2e8553711fe078409db7ebaf4371a5f1a35de587ea5c
4
- data.tar.gz: 2887faa65020fbd0b37b049c3338f540f662ca78869d22636f692d1df3b9447a
3
+ metadata.gz: b768ab8543226a138c1094b0f49dc5f9d72814b747433d63b32d6edaa0c91fcc
4
+ data.tar.gz: '085ce87e9324f4c86f7b300dc18ac8b72d2cea5ecbfad8c97c56a5bf91291389'
5
5
  SHA512:
6
- metadata.gz: f828ca7415cb0713688f1b90f9d806ec3f5369b8cf3f34da097b919dcdcbae13dc45f52f0f248af10cdf754ad302f4c9e3a4435d9b319b258e1e0ca10433b7eb
7
- data.tar.gz: a3fbb0e11aff1cabe4e4f443a069b8209854b651c37eff3a794a4b01bb6e92651c1d0a8c6a897a74b68f5bedf41ab3aaa122283977a68e4744e93bdb71b12ad4
6
+ metadata.gz: 71a8aa1b53a0d9784c8a85e81f24322418751b8548dfef0dc07fcc2dd175e93944aad8ef381a9e743e992df58b95431e67fb4f11ac8fd1d82dddac18e32abe0b
7
+ data.tar.gz: aef5a2f90120b7d5d809c2b4afb60192c7b8157626eebc00fb1163a23ec883ce9f66cdd16c86f21c5c532f4f5229785dcd86fe4a82e064bc179dd7e4fbea0366
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -2,6 +2,14 @@
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
+
5
13
  ## [0.2.28] (2020-09-19)
6
14
  - start `Diffend::Monitor` only if not in development or test ([#44](https://github.com/diffend-io/diffend-ruby/pull/44))
7
15
  - better host command expose ([#45](https://github.com/diffend-io/diffend-ruby/pull/45))
@@ -64,7 +72,9 @@
64
72
 
65
73
  - initial release
66
74
 
67
- [master]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.28...HEAD
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
68
78
  [0.2.28]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.27...v0.2.28
69
79
  [0.2.27]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.26...v0.2.27
70
80
  [0.2.26]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.25...v0.2.26
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- diffend (0.2.28)
4
+ diffend (0.2.30)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,25 +1,25 @@
1
1
  -----BEGIN CERTIFICATE-----
2
2
  MIIEODCCAqCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhtYWNp
3
- ZWovREM9bWVuc2ZlbGQvREM9cGwwHhcNMjAwODExMDkxNTM3WhcNMjEwODExMDkx
4
- NTM3WjAjMSEwHwYDVQQDDBhtYWNpZWovREM9bWVuc2ZlbGQvREM9cGwwggGiMA0G
5
- CSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDCpXsCgmINb6lHBXXBdyrgsBPSxC4/
6
- 2H+weJ6L9CruTiv2+2/ZkQGtnLcDgrD14rdLIHK7t0o3EKYlDT5GhD/XUVhI15JE
7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N0aPj3qEFR8mE/YeDD8rLAfruBRTltPNbR7
18
+ xA5eE1gkxY5LfExUtK3b2wPqfmo7mZgfcsMwfYg/tUXw1WpBCnrhAJodpGH6SXmp
19
+ A40qFUZst0vjiOoO+aTblIHPmMJXoZ3K42dTlNKlEiDKUWMRKSgpjjYGEYalFNWI
20
+ hHfCz2r8L2t+dYdMZg1JGbEkq4ADGsAA8ioZIpJd7V4hI17u5TCdi7X5wh/0gN0E
21
+ CgP+nLox3D+l2q0QuQEkayr+auFYkzTCkF+BmEk1D0Ru4mcf3F4CJvEmW4Pzbjqt
22
+ i1tsCWPtJ4E/UUKnKaWKqGbjrjHJ0MuShYzHkodox5IOiCXIQg+1+YSzfXUV6WEK
23
+ KJG/fhg1JV5vVDdVy6x+tv5SQ5ctU0feCsVfESi3rE3zRd+nvzE9HcZ5aXeL1UtJ
24
+ nT5Xrioegu2w1jPyVEgyZgTZC5rvD0nNS5sFNQ==
25
25
  -----END CERTIFICATE-----
@@ -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.summary = 'OSS supply chain security and management platform.'
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')
@@ -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.28'
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
@@ -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
@@ -57,12 +57,8 @@ module Diffend
57
57
 
58
58
  raise Errors::EmptyConfigurationFile if content.empty?
59
59
 
60
- OpenStruct.new(
61
- parse_file(content)
62
- .merge(build_path: build_path)
63
- .merge(diffend_env: ENV['DIFFEND_ENV'] || 'development')
64
- )
65
- .tap(&Validator.method(:call))
60
+ OpenStruct.new(parse_file(content).merge(build_path: build_path))
61
+ .tap(&Validator.method(:call))
66
62
  end
67
63
 
68
64
  def parse_file(content)
@@ -23,5 +23,7 @@ module Diffend
23
23
  RequestServerError = Class.new(BaseError)
24
24
  # Raised when we had an exception that we know how to handle
25
25
  HandledException = Class.new(BaseError)
26
+ # Raised when we are unable to resolve dependencies
27
+ DependenciesResolveException = Class.new(BaseError)
26
28
  end
27
29
  end
@@ -1,18 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Diffend
4
- # Verifies voting verdicts for gems
5
- module Voting
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
- # @param definition [Bundler::Definition] definition for your source
12
- def call(command, config, definition)
13
- Versions::Remote
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
@@ -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
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'etc'
4
+
5
+ module Diffend
6
+ # Module responsible for building local context
7
+ module LocalContext
8
+ # Module responsible for building host information from local context
9
+ module Host
10
+ class << self
11
+ # Build host information
12
+ #
13
+ # @return [Hash]
14
+ def call
15
+ uname = Etc.uname
16
+
17
+ {
18
+ 'command' => command,
19
+ 'ips' => ips,
20
+ 'name' => uname[:nodename],
21
+ 'system' => {
22
+ 'machine' => uname[:machine],
23
+ 'name' => uname[:sysname],
24
+ 'release' => uname[:release],
25
+ 'version' => uname[:version]
26
+ },
27
+ 'tags' => tags,
28
+ 'user' => Etc.getpwuid(Process.uid).name,
29
+ 'pid' => Process.pid
30
+ }.freeze
31
+ end
32
+
33
+ private
34
+
35
+ # Build host command information
36
+ #
37
+ # @return [Hash]
38
+ def command
39
+ if File.exist?($PROGRAM_NAME)
40
+ if defined?(JRUBY_VERSION)
41
+ name = $PROGRAM_NAME.split('/').last.strip
42
+ command = "#{name} #{ARGV.join(' ')}"
43
+ else
44
+ array = `ps -p #{Process.pid} -o command=`.strip.split(' ')
45
+ array.shift if array.first.end_with?('bin/ruby')
46
+ name = array.shift.split('/').last.strip
47
+ command = "#{name} #{array.join(' ')}"
48
+ end
49
+
50
+ { 'name' => command, 'title' => '' }
51
+ else
52
+ { 'name' => ARGV.join(' '), 'title' => $PROGRAM_NAME }
53
+ end
54
+ end
55
+
56
+ # Build host ips, except localhost and loopback
57
+ #
58
+ # @return [Array<String>]
59
+ def ips
60
+ Socket.ip_address_list.map do |ip|
61
+ next if ip.ipv4_loopback? || ip.ipv6_loopback? || ip.ipv6_linklocal?
62
+
63
+ ip.ip_address
64
+ end.compact
65
+ end
66
+
67
+ # Build host tags
68
+ #
69
+ # @return [Array]
70
+ def tags
71
+ tags = []
72
+
73
+ if ENV.key?('GITHUB_ACTIONS')
74
+ tags << 'ci'
75
+ tags << 'ci-github'
76
+ end
77
+
78
+ if ENV.key?('CIRCLECI')
79
+ tags << 'ci'
80
+ tags << 'ci-circle'
81
+ end
82
+
83
+ tags
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end