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.
- .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
65 66 67 68 69 70 71 72 73 |
# File 'lib/diffend/voting/versions/remote.rb', line 65 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
78 79 80 |
# File 'lib/diffend/voting/versions/remote.rb', line 78 def build_diffend_environment ENV['DIFFEND_ENV'] || 'development' end |
.build_host ⇒ Hash
Build host information
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/diffend/voting/versions/remote.rb', line 130 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
152 153 154 155 156 157 |
# File 'lib/diffend/voting/versions/remote.rb', line 152 def build_host_command { 'name' => $PROGRAM_NAME.split('/').last.strip, 'options' => ARGV.join(' ') } end |
.build_host_ips ⇒ Array<String>
Build host ips, except localhost and loopback
162 163 164 165 166 167 168 |
# File 'lib/diffend/voting/versions/remote.rb', line 162 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
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/diffend/voting/versions/remote.rb', line 173 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
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/diffend/voting/versions/remote.rb', line 85 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
123 124 125 |
# File 'lib/diffend/voting/versions/remote.rb', line 123 def build_platform_environment ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development' end |
.build_platform_ruby ⇒ Hash
Build platform ruby information
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/diffend/voting/versions/remote.rb', line 102 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 |
.call(command, config, definition) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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( config, commands_url(command, config.project_id), 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
195 196 197 198 199 |
# File 'lib/diffend/voting/versions/remote.rb', line 195 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
51 52 53 54 55 56 57 58 |
# File 'lib/diffend/voting/versions/remote.rb', line 51 def payload(command, project_id, definition) { 'diffend' => build_diffend(project_id), 'host' => build_host, 'packages' => Local.call(command, definition), 'platform' => build_platform }.freeze end |