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.
@@ -1,204 +0,0 @@
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
- config,
29
- commands_url(command, config.project_id),
30
- payload
31
- )
32
-
33
- JSON.parse(response.body)
34
- rescue StandardError => e
35
- Diffend::HandleErrors::Report.call(
36
- exception: e,
37
- payload: payload || {},
38
- config: config,
39
- message: :unhandled_exception,
40
- report: true
41
- )
42
- end
43
-
44
- # Build diffend, host, packages, and platform specific information
45
- #
46
- # @param command [String] either install or update
47
- # @param project_id [String] diffend project_id
48
- # @param definition [Bundler::Definition] definition for your source
49
- #
50
- # @return [Hash] payload for diffend endpoint
51
- def payload(command, project_id, definition)
52
- {
53
- 'diffend' => build_diffend(project_id),
54
- 'host' => build_host,
55
- 'packages' => Local.call(command, definition),
56
- 'platform' => build_platform
57
- }.freeze
58
- end
59
-
60
- # Build diffend information
61
- #
62
- # @param project_id [String, nil] diffend project_id
63
- #
64
- # @return [Hash]
65
- def build_diffend(project_id)
66
- {
67
- 'api_version' => API_VERSION,
68
- 'environment' => build_diffend_environment,
69
- 'project_id' => project_id,
70
- 'type' => PLATFORM_TYPE,
71
- 'version' => Diffend::VERSION
72
- }.freeze
73
- end
74
-
75
- # Build diffend environment information
76
- #
77
- # @return [String]
78
- def build_diffend_environment
79
- ENV['DIFFEND_ENV'] || 'development'
80
- end
81
-
82
- # Build platform information
83
- #
84
- # @return [Hash]
85
- def build_platform
86
- {
87
- 'bundler' => {
88
- 'version' => Bundler::VERSION
89
- },
90
- 'environment' => build_platform_environment,
91
- 'ruby' => build_platform_ruby,
92
- 'rubygems' => {
93
- 'specification_version' => Gem::Specification::CURRENT_SPECIFICATION_VERSION,
94
- 'version' => Gem::VERSION
95
- }
96
- }.freeze
97
- end
98
-
99
- # Build platform ruby information
100
- #
101
- # @return [Hash]
102
- def build_platform_ruby
103
- if defined?(JRUBY_VERSION)
104
- revision = JRUBY_REVISION.to_s
105
- version = JRUBY_VERSION
106
- else
107
- revision = RUBY_REVISION.to_s
108
- version = RUBY_ENGINE_VERSION
109
- end
110
-
111
- {
112
- 'engine' => RUBY_ENGINE,
113
- 'patchlevel' => RUBY_PATCHLEVEL,
114
- 'release_date' => RUBY_RELEASE_DATE,
115
- 'revision' => revision,
116
- 'version' => version
117
- }
118
- end
119
-
120
- # Build platform environment information
121
- #
122
- # @return [String]
123
- def build_platform_environment
124
- ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
125
- end
126
-
127
- # Build host information
128
- #
129
- # @return [Hash]
130
- def build_host
131
- uname = Etc.uname
132
-
133
- {
134
- 'command' => build_host_command,
135
- 'ips' => build_host_ips,
136
- 'name' => uname[:nodename],
137
- 'system' => {
138
- 'machine' => uname[:machine],
139
- 'name' => uname[:sysname],
140
- 'release' => uname[:release],
141
- 'version' => uname[:version]
142
- },
143
- 'tags' => build_host_tags,
144
- 'user' => Etc.getpwuid(Process.uid).name,
145
- 'pid' => Process.pid
146
- }.freeze
147
- end
148
-
149
- # Build host command information
150
- #
151
- # @return [Hash]
152
- def build_host_command
153
- {
154
- 'name' => $PROGRAM_NAME.split('/').last.strip,
155
- 'options' => ARGV.join(' ')
156
- }
157
- end
158
-
159
- # Build host ips, except localhost and loopback
160
- #
161
- # @return [Array<String>]
162
- def build_host_ips
163
- Socket.ip_address_list.map do |ip|
164
- next if ip.ipv4_loopback? || ip.ipv6_loopback? || ip.ipv6_linklocal?
165
-
166
- ip.ip_address
167
- end.compact
168
- end
169
-
170
- # Build host tags
171
- #
172
- # @return [Array]
173
- def build_host_tags
174
- tags = []
175
-
176
- if ENV.key?('GITHUB_ACTIONS')
177
- tags << 'ci'
178
- tags << 'ci-github'
179
- end
180
-
181
- if ENV.key?('CIRCLECI')
182
- tags << 'ci'
183
- tags << 'ci-circle'
184
- end
185
-
186
- tags
187
- end
188
-
189
- # Provides diffend command endpoint url
190
- #
191
- # @param command [String] either install or update
192
- # @param project_id [String] diffend project_id
193
- #
194
- # @return [String] diffend endpoint
195
- def commands_url(command, project_id)
196
- return ENV['DIFFEND_COMMAND_URL'] if ENV.key?('DIFFEND_COMMAND_URL')
197
-
198
- "https://my.diffend.io/api/projects/#{project_id}/bundle/#{command}"
199
- end
200
- end
201
- end
202
- end
203
- end
204
- end