diffend 0.2.26 → 0.2.31
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 +27 -2
- data/Gemfile.lock +1 -1
- data/diffend.gemspec +2 -3
- data/lib/diffend.rb +0 -127
- data/lib/diffend/commands.rb +4 -2
- data/lib/diffend/config.rb +19 -0
- data/lib/diffend/config/fetcher.rb +8 -4
- data/lib/diffend/errors.rb +4 -0
- data/lib/diffend/{voting.rb → execute.rb} +19 -7
- data/lib/diffend/handle_errors/report.rb +17 -5
- data/lib/diffend/local_context.rb +24 -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/monitor.rb +36 -0
- data/lib/diffend/plugin.rb +124 -0
- data/lib/diffend/request.rb +38 -18
- data/lib/diffend/request_object.rb +6 -0
- data/lib/diffend/request_verdict.rb +59 -0
- data/lib/diffend/track.rb +85 -0
- data/lib/diffend/version.rb +6 -0
- data/plugins.rb +2 -2
- data/scripts/generate_payload_for_file.rb +1 -2
- metadata +16 -6
- metadata.gz.sig +0 -0
- data/lib/diffend/voting/versions/local.rb +0 -304
- data/lib/diffend/voting/versions/remote.rb +0 -204
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7b14e2973870903bee26272a50713c543934f7dbe5c0f2aab495dba99d6ee177
|
|
4
|
+
data.tar.gz: 900edb2cd152dce431f81029becec9e76662ef2bd5f19a7b082f9276bf9050cc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 33eb4745a8a8e909c266efdbd6a06647c7377e480886eb5d03aa6dbc78a65ce567ad3533df24c85e93cef714094c528f6f15c2738cd512874af4d09bbbe74173
|
|
7
|
+
data.tar.gz: ee68d0977516bce252304aa150ff2b6bde0788b06a135e9485ad5b22a351637f293fe533ea771e09f81446bac1a39b06427b0bf305ab575ce3f41ecbd0b97608
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data.tar.gz.sig
CHANGED
|
Binary file
|
data/CHANGELOG.md
CHANGED
|
@@ -2,8 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased][master]
|
|
4
4
|
|
|
5
|
+
## [0.2.31] (2020-09-24)
|
|
6
|
+
- change request timeout to 15 seconds ([#53](https://github.com/diffend-io/diffend-ruby/pull/53))
|
|
7
|
+
- report request issues as warnings ([#54](https://github.com/diffend-io/diffend-ruby/pull/54))
|
|
8
|
+
|
|
9
|
+
## [0.2.30] (2020-09-21)
|
|
10
|
+
- handle dependencies resolve issues ([#51](https://github.com/diffend-io/diffend-ruby/pull/51))
|
|
11
|
+
- better detection when to start `Diffend::Monitor` ([#50](https://github.com/diffend-io/diffend-ruby/pull/50))
|
|
12
|
+
- cleanup structure ([#47](https://github.com/diffend-io/diffend-ruby/pull/47))
|
|
13
|
+
|
|
14
|
+
## [0.2.29] (2020-09-21)
|
|
15
|
+
- fix command reporting on jruby ([#48](https://github.com/diffend-io/diffend-ruby/pull/48))
|
|
16
|
+
|
|
17
|
+
## [0.2.28] (2020-09-19)
|
|
18
|
+
- start `Diffend::Monitor` only if not in development or test ([#44](https://github.com/diffend-io/diffend-ruby/pull/44))
|
|
19
|
+
- better host command expose ([#45](https://github.com/diffend-io/diffend-ruby/pull/45))
|
|
20
|
+
|
|
21
|
+
## [0.2.27] (2020-09-16)
|
|
22
|
+
- introduce `Diffend::RequestObject` ([#40](https://github.com/diffend-io/diffend-ruby/pull/40))
|
|
23
|
+
- clean up error codes and introduce `DIFFEND_INGORE_EXCEPTIONS` ([#41](https://github.com/diffend-io/diffend-ruby/pull/41))
|
|
24
|
+
- introduce `Diffend::Monitor` and `Diffend::Track` ([#15](https://github.com/diffend-io/diffend-ruby/pull/15))
|
|
25
|
+
|
|
5
26
|
## [0.2.26] (2020-09-10)
|
|
6
|
-
- introduce DIFFEND_DEVELOPMENT environment variable ([#36](https://github.com/diffend-io/diffend-ruby/pull/36))
|
|
27
|
+
- introduce `DIFFEND_DEVELOPMENT` environment variable ([#36](https://github.com/diffend-io/diffend-ruby/pull/36))
|
|
7
28
|
- adjust message for allow verdict ([#37](https://github.com/diffend-io/diffend-ruby/pull/37))
|
|
8
29
|
- do not run the plugin when it is not enabled ([#38](https://github.com/diffend-io/diffend-ruby/pull/38))
|
|
9
30
|
|
|
@@ -55,7 +76,11 @@
|
|
|
55
76
|
|
|
56
77
|
- initial release
|
|
57
78
|
|
|
58
|
-
[master]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.
|
|
79
|
+
[master]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.30...HEAD
|
|
80
|
+
[0.2.30]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.29...v0.2.30
|
|
81
|
+
[0.2.29]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.28...v0.2.29
|
|
82
|
+
[0.2.28]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.27...v0.2.28
|
|
83
|
+
[0.2.27]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.26...v0.2.27
|
|
59
84
|
[0.2.26]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.25...v0.2.26
|
|
60
85
|
[0.2.25]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.24...v0.2.25
|
|
61
86
|
[0.2.24]: https://github.com/diffend-io/diffend-ruby/compare/v0.2.23...v0.2.24
|
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,131 +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
|
|
19
|
-
voting
|
|
20
|
-
].each { |file| require "diffend/#{file}" }
|
|
21
|
-
|
|
22
|
-
%w[
|
|
23
|
-
versions/local
|
|
24
|
-
versions/remote
|
|
25
|
-
].each { |file| require "diffend/voting/#{file}" }
|
|
26
|
-
|
|
27
|
-
# Diffend main namespace
|
|
28
3
|
module Diffend
|
|
29
|
-
# Current plugin version
|
|
30
|
-
VERSION = '0.2.26'
|
|
31
|
-
# Diffend homepage
|
|
32
|
-
HOMEPAGE = 'https://diffend.io'
|
|
33
|
-
|
|
34
|
-
class << self
|
|
35
|
-
# Registers the plugin and add before install all hook
|
|
36
|
-
def register
|
|
37
|
-
Bundler::Plugin.add_hook('before-install-all') do |_|
|
|
38
|
-
execute
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# Execute diffend plugin
|
|
43
|
-
def execute
|
|
44
|
-
return unless enabled?
|
|
45
|
-
|
|
46
|
-
verify_version
|
|
47
|
-
|
|
48
|
-
config = fetch_config
|
|
49
|
-
|
|
50
|
-
Diffend::Voting.call(
|
|
51
|
-
command,
|
|
52
|
-
config,
|
|
53
|
-
Diffend::BuildBundlerDefinition.call(
|
|
54
|
-
command,
|
|
55
|
-
Bundler.default_gemfile,
|
|
56
|
-
Bundler.default_lockfile
|
|
57
|
-
)
|
|
58
|
-
)
|
|
59
|
-
rescue StandardError => e
|
|
60
|
-
Diffend::HandleErrors::Report.call(
|
|
61
|
-
exception: e,
|
|
62
|
-
config: config,
|
|
63
|
-
message: :unhandled_exception,
|
|
64
|
-
report: true
|
|
65
|
-
)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def verify_version
|
|
69
|
-
return if ENV['DIFFEND_DEVELOPMENT'] == 'true'
|
|
70
|
-
return if installed_version == VERSION
|
|
71
|
-
|
|
72
|
-
build_outdated_version_message(installed_version)
|
|
73
|
-
.tap(&Bundler.ui.method(:error))
|
|
74
|
-
|
|
75
|
-
exit 1
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
# @return [String] installed plugin version
|
|
79
|
-
def installed_version
|
|
80
|
-
Bundler::Plugin
|
|
81
|
-
.index
|
|
82
|
-
.plugin_path('diffend')
|
|
83
|
-
.basename
|
|
84
|
-
.to_s
|
|
85
|
-
.split('-')
|
|
86
|
-
.last
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
# Checks if plugin is enabled
|
|
90
|
-
#
|
|
91
|
-
# @return [Boolean] true if enabled, false otherwise
|
|
92
|
-
def enabled?
|
|
93
|
-
Bundler
|
|
94
|
-
.default_gemfile
|
|
95
|
-
.read
|
|
96
|
-
.split("\n")
|
|
97
|
-
.reject(&:empty?)
|
|
98
|
-
.map(&:strip)
|
|
99
|
-
.select { |line| line.start_with?('plugin') }
|
|
100
|
-
.any? { |line| line.include?('diffend') }
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
# @param version [Hash] installed version
|
|
104
|
-
#
|
|
105
|
-
# @return [String]
|
|
106
|
-
def build_outdated_version_message(version)
|
|
107
|
-
<<~MSG
|
|
108
|
-
\nYou are running an outdated version (#{version}) of the plugin, which will lead to issues.
|
|
109
|
-
\nPlease upgrade to the latest one (#{VERSION}) by executing "rm -rf .bundle/plugin".\n
|
|
110
|
-
MSG
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
# Command that was run with bundle
|
|
114
|
-
#
|
|
115
|
-
# @return [String]
|
|
116
|
-
def command
|
|
117
|
-
ARGV.first || Bundler.feature_flag.default_cli_command.to_s
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
# Fetch diffend config file
|
|
121
|
-
#
|
|
122
|
-
# @return [OpenStruct, nil] configuration object
|
|
123
|
-
#
|
|
124
|
-
# @raise [Errors::MissingConfigurationFile] when no config file
|
|
125
|
-
def fetch_config
|
|
126
|
-
Config::Fetcher.call(
|
|
127
|
-
File.expand_path('..', Bundler.bin_path)
|
|
128
|
-
)
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
4
|
end
|
data/lib/diffend/commands.rb
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
module Diffend
|
|
4
4
|
# Modules grouping supported bundler commands
|
|
5
5
|
module Commands
|
|
6
|
-
#
|
|
6
|
+
# Bundler install command
|
|
7
7
|
INSTALL = 'install'
|
|
8
|
-
#
|
|
8
|
+
# Bundler update command
|
|
9
9
|
UPDATE = 'update'
|
|
10
|
+
# Bundler exec command
|
|
11
|
+
EXEC = 'exec'
|
|
10
12
|
end
|
|
11
13
|
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
|
|
@@ -27,16 +27,20 @@ module Diffend
|
|
|
27
27
|
build(build_path)
|
|
28
28
|
rescue Errors::MissingConfigurationFile
|
|
29
29
|
Bundler.ui.error(build_missing_error_message(build_path))
|
|
30
|
-
|
|
30
|
+
|
|
31
|
+
raise Diffend::Errors::HandledException
|
|
31
32
|
rescue Errors::EmptyConfigurationFile
|
|
32
33
|
Bundler.ui.error(build_empty_error_message(build_path))
|
|
33
|
-
|
|
34
|
+
|
|
35
|
+
raise Diffend::Errors::HandledException
|
|
34
36
|
rescue Errors::MalformedConfigurationFile
|
|
35
37
|
Bundler.ui.error(build_malformed_error_message(build_path))
|
|
36
|
-
|
|
38
|
+
|
|
39
|
+
raise Diffend::Errors::HandledException
|
|
37
40
|
rescue *MISSING_KEY_ERRORS => e
|
|
38
41
|
Bundler.ui.error(build_missing_key_error_message(e))
|
|
39
|
-
|
|
42
|
+
|
|
43
|
+
raise Diffend::Errors::HandledException
|
|
40
44
|
end
|
|
41
45
|
|
|
42
46
|
private
|
data/lib/diffend/errors.rb
CHANGED
|
@@ -21,5 +21,9 @@ module Diffend
|
|
|
21
21
|
BuildPathMissingInConfigurationFile = Class.new(BaseError)
|
|
22
22
|
# Raised when server-side error occurs
|
|
23
23
|
RequestServerError = Class.new(BaseError)
|
|
24
|
+
# Raised when we had an exception that we know how to handle
|
|
25
|
+
HandledException = Class.new(BaseError)
|
|
26
|
+
# Raised when we are unable to resolve dependencies
|
|
27
|
+
DependenciesResolveException = Class.new(BaseError)
|
|
24
28
|
end
|
|
25
29
|
end
|
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Diffend
|
|
4
|
-
#
|
|
5
|
-
module
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
@@ -38,7 +50,7 @@ module Diffend
|
|
|
38
50
|
build_error_message(response)
|
|
39
51
|
.tap(&Bundler.ui.method(:error))
|
|
40
52
|
|
|
41
|
-
|
|
53
|
+
raise Diffend::Errors::HandledException
|
|
42
54
|
end
|
|
43
55
|
|
|
44
56
|
# @param command [String] either install or update
|
|
@@ -12,9 +12,10 @@ module Diffend
|
|
|
12
12
|
# @param config [OpenStruct] Diffend config
|
|
13
13
|
# @param message [Symbol] message that we want to display
|
|
14
14
|
# @param report [Boolean] if true we will report the issue to diffend
|
|
15
|
+
# @param raise_exception [Boolean] if true we will raise an exception
|
|
15
16
|
#
|
|
16
17
|
# @return [Net::HTTPResponse] response from Diffend
|
|
17
|
-
def call(config:, message:, exception: nil, payload: {}, report: false)
|
|
18
|
+
def call(config:, message:, exception: nil, payload: {}, report: false, raise_exception: true)
|
|
18
19
|
exception_payload = prepare_exception_payload(exception, payload)
|
|
19
20
|
|
|
20
21
|
Bundler.ui.error(Diffend::HandleErrors::Messages::PAYLOAD_DUMP)
|
|
@@ -22,13 +23,24 @@ module Diffend
|
|
|
22
23
|
|
|
23
24
|
if report
|
|
24
25
|
Diffend::Request.call(
|
|
25
|
-
config,
|
|
26
|
-
errors_url(config.project_id),
|
|
27
|
-
exception_payload
|
|
26
|
+
build_request_object(config, exception_payload)
|
|
28
27
|
)
|
|
29
28
|
end
|
|
30
29
|
|
|
31
|
-
|
|
30
|
+
raise Diffend::Errors::HandledException if raise_exception
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# @param config [OpenStruct] diffend config
|
|
34
|
+
# @param payload [Hash]
|
|
35
|
+
#
|
|
36
|
+
# @return [Diffend::RequestObject]
|
|
37
|
+
def build_request_object(config, payload)
|
|
38
|
+
Diffend::RequestObject.new(
|
|
39
|
+
config: config,
|
|
40
|
+
url: errors_url(config.project_id),
|
|
41
|
+
payload: payload,
|
|
42
|
+
request_method: :post
|
|
43
|
+
)
|
|
32
44
|
end
|
|
33
45
|
|
|
34
46
|
# Prepare exception payload and display it to stdout
|
|
@@ -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
|