diffend-monitor 0.2.27

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,216 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'etc'
5
+
6
+ module Diffend
7
+ module Voting
8
+ # Module responsible for handling both local and remote gem versions
9
+ module Versions
10
+ # Module responsible for fetching safe/malicious votes
11
+ # for current or current/new versions of gems
12
+ module Remote
13
+ # API version
14
+ API_VERSION = '0.1'
15
+ # Platform type ruby
16
+ PLATFORM_TYPE = 0
17
+
18
+ private_constant :API_VERSION, :PLATFORM_TYPE
19
+
20
+ class << self
21
+ # @param command [String] either install or update
22
+ # @param definition [Bundler::Definition] definition for your source
23
+ # @param config [OpenStruct] diffend config
24
+ def call(command, config, definition)
25
+ payload = payload(command, config.project_id, definition)
26
+
27
+ response = Diffend::Request.call(
28
+ build_request_object(command, config, payload)
29
+ )
30
+
31
+ JSON.parse(response.body)
32
+ rescue StandardError => e
33
+ Diffend::HandleErrors::Report.call(
34
+ exception: e,
35
+ payload: payload || {},
36
+ config: config,
37
+ message: :unhandled_exception,
38
+ report: true
39
+ )
40
+ end
41
+
42
+ # @param command [String] either install or update
43
+ # @param config [OpenStruct] diffend config
44
+ # @param payload [Hash]
45
+ #
46
+ # @return [Diffend::RequestObject]
47
+ def build_request_object(command, config, payload)
48
+ Diffend::RequestObject.new(
49
+ config: config,
50
+ url: commands_url(command, config.project_id),
51
+ payload: payload,
52
+ request_method: :post
53
+ )
54
+ end
55
+
56
+ # Build diffend, host, packages, and platform specific information
57
+ #
58
+ # @param command [String] either install or update
59
+ # @param project_id [String] diffend project_id
60
+ # @param definition [Bundler::Definition] definition for your source
61
+ #
62
+ # @return [Hash] payload for diffend endpoint
63
+ def payload(command, project_id, definition)
64
+ {
65
+ 'diffend' => build_diffend(project_id),
66
+ 'host' => build_host,
67
+ 'packages' => Local.call(command, definition),
68
+ 'platform' => build_platform
69
+ }.freeze
70
+ end
71
+
72
+ # Build diffend information
73
+ #
74
+ # @param project_id [String, nil] diffend project_id
75
+ #
76
+ # @return [Hash]
77
+ def build_diffend(project_id)
78
+ {
79
+ 'api_version' => API_VERSION,
80
+ 'environment' => build_diffend_environment,
81
+ 'project_id' => project_id,
82
+ 'type' => PLATFORM_TYPE,
83
+ 'version' => Diffend::VERSION
84
+ }.freeze
85
+ end
86
+
87
+ # Build diffend environment information
88
+ #
89
+ # @return [String]
90
+ def build_diffend_environment
91
+ ENV['DIFFEND_ENV'] || 'development'
92
+ end
93
+
94
+ # Build platform information
95
+ #
96
+ # @return [Hash]
97
+ def build_platform
98
+ {
99
+ 'bundler' => {
100
+ 'version' => Bundler::VERSION
101
+ },
102
+ 'environment' => build_platform_environment,
103
+ 'ruby' => build_platform_ruby,
104
+ 'rubygems' => {
105
+ 'specification_version' => Gem::Specification::CURRENT_SPECIFICATION_VERSION,
106
+ 'version' => Gem::VERSION
107
+ }
108
+ }.freeze
109
+ end
110
+
111
+ # Build platform ruby information
112
+ #
113
+ # @return [Hash]
114
+ def build_platform_ruby
115
+ if defined?(JRUBY_VERSION)
116
+ revision = JRUBY_REVISION.to_s
117
+ version = JRUBY_VERSION
118
+ else
119
+ revision = RUBY_REVISION.to_s
120
+ version = RUBY_ENGINE_VERSION
121
+ end
122
+
123
+ {
124
+ 'engine' => RUBY_ENGINE,
125
+ 'patchlevel' => RUBY_PATCHLEVEL,
126
+ 'release_date' => RUBY_RELEASE_DATE,
127
+ 'revision' => revision,
128
+ 'version' => version
129
+ }
130
+ end
131
+
132
+ # Build platform environment information
133
+ #
134
+ # @return [String]
135
+ def build_platform_environment
136
+ ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
137
+ end
138
+
139
+ # Build host information
140
+ #
141
+ # @return [Hash]
142
+ def build_host
143
+ uname = Etc.uname
144
+
145
+ {
146
+ 'command' => build_host_command,
147
+ 'ips' => build_host_ips,
148
+ 'name' => uname[:nodename],
149
+ 'system' => {
150
+ 'machine' => uname[:machine],
151
+ 'name' => uname[:sysname],
152
+ 'release' => uname[:release],
153
+ 'version' => uname[:version]
154
+ },
155
+ 'tags' => build_host_tags,
156
+ 'user' => Etc.getpwuid(Process.uid).name,
157
+ 'pid' => Process.pid
158
+ }.freeze
159
+ end
160
+
161
+ # Build host command information
162
+ #
163
+ # @return [Hash]
164
+ def build_host_command
165
+ {
166
+ 'name' => $PROGRAM_NAME.split('/').last.strip,
167
+ 'options' => ARGV.join(' ')
168
+ }
169
+ end
170
+
171
+ # Build host ips, except localhost and loopback
172
+ #
173
+ # @return [Array<String>]
174
+ def build_host_ips
175
+ Socket.ip_address_list.map do |ip|
176
+ next if ip.ipv4_loopback? || ip.ipv6_loopback? || ip.ipv6_linklocal?
177
+
178
+ ip.ip_address
179
+ end.compact
180
+ end
181
+
182
+ # Build host tags
183
+ #
184
+ # @return [Array]
185
+ def build_host_tags
186
+ tags = []
187
+
188
+ if ENV.key?('GITHUB_ACTIONS')
189
+ tags << 'ci'
190
+ tags << 'ci-github'
191
+ end
192
+
193
+ if ENV.key?('CIRCLECI')
194
+ tags << 'ci'
195
+ tags << 'ci-circle'
196
+ end
197
+
198
+ tags
199
+ end
200
+
201
+ # Provides diffend command endpoint url
202
+ #
203
+ # @param command [String] either install or update
204
+ # @param project_id [String] diffend project_id
205
+ #
206
+ # @return [String] diffend endpoint
207
+ def commands_url(command, project_id)
208
+ return ENV['DIFFEND_COMMAND_URL'] if ENV.key?('DIFFEND_COMMAND_URL')
209
+
210
+ "https://my.diffend.io/api/projects/#{project_id}/bundle/#{command}"
211
+ end
212
+ end
213
+ end
214
+ end
215
+ end
216
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'diffend'
4
+
5
+ Diffend.register
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'byebug'
4
+ require 'diffend'
5
+
6
+
7
+ command = 'install'
8
+ project_id = nil
9
+
10
+ gemfile = ARGV[0]
11
+ lockfile = ARGV[1]
12
+
13
+ definition = Diffend::BuildBundlerDefinition.call(command, gemfile lockfile)
14
+
15
+ pp Diffend::Voting::Versions::Remote.payload(command, project_id, definition)
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: diffend-monitor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.27
5
+ platform: ruby
6
+ authors:
7
+ - Tomasz Pajor
8
+ - Maciej Mensfeld
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain:
12
+ - |
13
+ -----BEGIN CERTIFICATE-----
14
+ MIIEODCCAqCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhtYWNp
15
+ ZWovREM9bWVuc2ZlbGQvREM9cGwwHhcNMjAwODExMDkxNTM3WhcNMjEwODExMDkx
16
+ NTM3WjAjMSEwHwYDVQQDDBhtYWNpZWovREM9bWVuc2ZlbGQvREM9cGwwggGiMA0G
17
+ CSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDCpXsCgmINb6lHBXXBdyrgsBPSxC4/
18
+ 2H+weJ6L9CruTiv2+2/ZkQGtnLcDgrD14rdLIHK7t0o3EKYlDT5GhD/XUVhI15JE
19
+ N7IqnPUgexe1fbZArwQ51afxz2AmPQN2BkB2oeQHXxnSWUGMhvcEZpfbxCCJH26w
20
+ hS0Ccsma8yxA6hSlGVhFVDuCr7c2L1di6cK2CtIDpfDaWqnVNJEwBYHIxrCoWK5g
21
+ sIGekVt/admS9gRhIMaIBg+Mshth5/DEyWO2QjteTodItlxfTctrfmiAl8X8T5JP
22
+ VXeLp5SSOJ5JXE80nShMJp3RFnGw5fqjX/ffjtISYh78/By4xF3a25HdWH9+qO2Z
23
+ tx0wSGc9/4gqNM0APQnjN/4YXrGZ4IeSjtE+OrrX07l0TiyikzSLFOkZCAp8oBJi
24
+ Fhlosz8xQDJf7mhNxOaZziqASzp/hJTU/tuDKl5+ql2icnMv5iV/i6SlmvU29QNg
25
+ LCV71pUv0pWzN+OZbHZKWepGhEQ3cG9MwvkCAwEAAaN3MHUwCQYDVR0TBAIwADAL
26
+ BgNVHQ8EBAMCBLAwHQYDVR0OBBYEFImGed2AXS070ohfRidiCEhXEUN+MB0GA1Ud
27
+ EQQWMBSBEm1hY2llakBtZW5zZmVsZC5wbDAdBgNVHRIEFjAUgRJtYWNpZWpAbWVu
28
+ c2ZlbGQucGwwDQYJKoZIhvcNAQELBQADggGBAKiHpwoENVrMi94V1zD4o8/6G3AU
29
+ gWz4udkPYHTZLUy3dLznc/sNjdkJFWT3E6NKYq7c60EpJ0m0vAEg5+F5pmNOsvD3
30
+ 2pXLj9kisEeYhR516HwXAvtngboUcb75skqvBCU++4Pu7BRAPjO1/ihLSBexbwSS
31
+ fF+J5OWNuyHHCQp+kGPLtXJe2yUYyvSWDj3I2//Vk0VhNOIlaCS1+5/P3ZJThOtm
32
+ zJUBI7h3HgovwRpcnmk2mXTmU4Zx/bCzX8EA6VY0khEvnmiq7S6eBF0H9qH8KyQ6
33
+ EkVLpvmUDFcf/uNaBQdazEMB5jYtwoA8gQlANETNGPi51KlkukhKgaIEDMkBDJOx
34
+ 65N7DzmkcyY0/GwjIVIxmRhcrCt1YeCUElmfFx0iida1/YRm6sB2AXqScc1+ECRi
35
+ 2DND//YJUikn1zwbz1kT70XmHd97B4Eytpln7K+M1u2g1pHVEPW4owD/ammXNpUy
36
+ nt70FcDD4yxJQ+0YNiHd0N8IcVBM1TMIVctMNQ==
37
+ -----END CERTIFICATE-----
38
+ date: 2020-09-16 00:00:00.000000000 Z
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: bundler
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: rake
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ description:
69
+ email:
70
+ - contact@diffend.io
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - ".coditsu/ci.yml"
76
+ - ".diffend.yml"
77
+ - ".github/workflows/ci.yml"
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".ruby-version"
81
+ - CHANGELOG.md
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.md
85
+ - README.md
86
+ - bin/bundle
87
+ - bin/byebug
88
+ - bin/htmldiff
89
+ - bin/ldiff
90
+ - bin/rake
91
+ - bin/rspec
92
+ - certs/mensfeld.pem
93
+ - certs/tomaszpajor.pem
94
+ - diffend.gemspec
95
+ - lib/diffend.rb
96
+ - lib/diffend/build_bundler_definition.rb
97
+ - lib/diffend/commands.rb
98
+ - lib/diffend/config/fetcher.rb
99
+ - lib/diffend/config/file_finder.rb
100
+ - lib/diffend/config/validator.rb
101
+ - lib/diffend/errors.rb
102
+ - lib/diffend/handle_errors/build_exception_payload.rb
103
+ - lib/diffend/handle_errors/display_to_stdout.rb
104
+ - lib/diffend/handle_errors/messages.rb
105
+ - lib/diffend/handle_errors/report.rb
106
+ - lib/diffend/monitor.rb
107
+ - lib/diffend/request.rb
108
+ - lib/diffend/request_object.rb
109
+ - lib/diffend/track.rb
110
+ - lib/diffend/voting.rb
111
+ - lib/diffend/voting/versions/local.rb
112
+ - lib/diffend/voting/versions/remote.rb
113
+ - plugins.rb
114
+ - scripts/generate_payload_for_file.rb
115
+ homepage: https://diffend.io
116
+ licenses:
117
+ - Prosperity Public License
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubygems_version: 3.1.4
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: OSS supply chain security and management platform.
138
+ test_files: []
Binary file