Module: Diffend::Voting::Versions::Remote
- Defined in:
- lib/diffend/voting/versions/remote.rb
Overview
Module responsible for fetching safe/malicious votes for current or current/new versions of gems
Class Method Summary collapse
-
.build_diffend(project_id) ⇒ Hash
Build diffend information.
-
.build_diffend_environment ⇒ String
Build diffend environment information.
-
.build_host ⇒ Hash
Build host information.
-
.build_host_command ⇒ Hash
Build host command information.
-
.build_host_ips ⇒ Array<String>
Build host ips, except localhost and loopback.
-
.build_host_tags ⇒ Array
Build host tags.
-
.build_platform ⇒ Hash
Build platform information.
-
.build_platform_environment ⇒ String
Build platform environment information.
-
.build_platform_ruby ⇒ Hash
Build platform ruby information.
- .build_request_object(command, config, payload) ⇒ Diffend::RequestObject
- .call(command, config, definition) ⇒ Object
-
.commands_url(command, project_id) ⇒ String
Provides diffend command endpoint url.
-
.payload(command, project_id, definition) ⇒ Hash
Build diffend, host, packages, and platform specific information.
Class Method Details
.build_diffend(project_id) ⇒ Hash
Build diffend information
77 78 79 80 81 82 83 84 85 |
# File 'lib/diffend/voting/versions/remote.rb', line 77 def build_diffend(project_id) { 'api_version' => API_VERSION, 'environment' => build_diffend_environment, 'project_id' => project_id, 'type' => PLATFORM_TYPE, 'version' => Diffend::VERSION }.freeze end |
.build_diffend_environment ⇒ String
Build diffend environment information
90 91 92 |
# File 'lib/diffend/voting/versions/remote.rb', line 90 def build_diffend_environment ENV['DIFFEND_ENV'] || 'development' end |
.build_host ⇒ Hash
Build host information
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/diffend/voting/versions/remote.rb', line 142 def build_host uname = Etc.uname { 'command' => build_host_command, 'ips' => build_host_ips, 'name' => uname[:nodename], 'system' => { 'machine' => uname[:machine], 'name' => uname[:sysname], 'release' => uname[:release], 'version' => uname[:version] }, 'tags' => , 'user' => Etc.getpwuid(Process.uid).name, 'pid' => Process.pid }.freeze end |
.build_host_command ⇒ Hash
Build host command information
164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/diffend/voting/versions/remote.rb', line 164 def build_host_command if File.exist?($PROGRAM_NAME) array = `ps -p #{Process.pid} -o command=`.strip.split(' ') array.shift if array.first.end_with?('bin/ruby') name = array.shift.split('/').last.strip command = "#{name} #{array.join(' ')}" { 'name' => command, 'title' => '' } else { 'name' => ARGV.join(' '), 'title' => $PROGRAM_NAME } end end |
.build_host_ips ⇒ Array<String>
Build host ips, except localhost and loopback
180 181 182 183 184 185 186 |
# File 'lib/diffend/voting/versions/remote.rb', line 180 def build_host_ips Socket.ip_address_list.map do |ip| next if ip.ipv4_loopback? || ip.ipv6_loopback? || ip.ipv6_linklocal? ip.ip_address end.compact end |
.build_host_tags ⇒ Array
Build host tags
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/diffend/voting/versions/remote.rb', line 191 def = [] if ENV.key?('GITHUB_ACTIONS') << 'ci' << 'ci-github' end if ENV.key?('CIRCLECI') << 'ci' << 'ci-circle' end end |
.build_platform ⇒ Hash
Build platform information
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/diffend/voting/versions/remote.rb', line 97 def build_platform { 'bundler' => { 'version' => Bundler::VERSION }, 'environment' => build_platform_environment, 'ruby' => build_platform_ruby, 'rubygems' => { 'specification_version' => Gem::Specification::CURRENT_SPECIFICATION_VERSION, 'version' => Gem::VERSION } }.freeze end |
.build_platform_environment ⇒ String
Build platform environment information
135 136 137 |
# File 'lib/diffend/voting/versions/remote.rb', line 135 def build_platform_environment ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development' end |
.build_platform_ruby ⇒ Hash
Build platform ruby information
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/diffend/voting/versions/remote.rb', line 114 def build_platform_ruby if defined?(JRUBY_VERSION) revision = JRUBY_REVISION.to_s version = JRUBY_VERSION else revision = RUBY_REVISION.to_s version = RUBY_ENGINE_VERSION end { 'engine' => RUBY_ENGINE, 'patchlevel' => RUBY_PATCHLEVEL, 'release_date' => RUBY_RELEASE_DATE, 'revision' => revision, 'version' => version } end |
.build_request_object(command, config, payload) ⇒ Diffend::RequestObject
47 48 49 50 51 52 53 54 |
# File 'lib/diffend/voting/versions/remote.rb', line 47 def build_request_object(command, config, payload) Diffend::RequestObject.new( config: config, url: commands_url(command, config.project_id), payload: payload, request_method: :post ) end |
.call(command, config, definition) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/diffend/voting/versions/remote.rb', line 24 def call(command, config, definition) payload = payload(command, config.project_id, definition) response = Diffend::Request.call( build_request_object(command, config, payload) ) JSON.parse(response.body) rescue StandardError => e Diffend::HandleErrors::Report.call( exception: e, payload: payload || {}, config: config, message: :unhandled_exception, report: true ) end |
.commands_url(command, project_id) ⇒ String
Provides diffend command endpoint url
213 214 215 216 217 |
# File 'lib/diffend/voting/versions/remote.rb', line 213 def commands_url(command, project_id) return ENV['DIFFEND_COMMAND_URL'] if ENV.key?('DIFFEND_COMMAND_URL') "https://my.diffend.io/api/projects/#{project_id}/bundle/#{command}" end |
.payload(command, project_id, definition) ⇒ Hash
Build diffend, host, packages, and platform specific information
63 64 65 66 67 68 69 70 |
# File 'lib/diffend/voting/versions/remote.rb', line 63 def payload(command, project_id, definition) { 'diffend' => build_diffend(project_id), 'host' => build_host, 'packages' => Local.call(command, definition), 'platform' => build_platform }.freeze end |