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_ips ⇒ Object
- .build_host_tags ⇒ Object
-
.build_platform ⇒ Hash
Build platform information.
-
.build_platform_environment ⇒ String
Build platform environment information.
- .build_platform_ruby ⇒ Object
- .call(command, definition) ⇒ Object
-
.fetch_config ⇒ OpenStruct?
Fetch coditsu config file.
-
.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
54 55 56 57 58 59 60 61 62 |
# File 'lib/diffend/voting/versions/remote.rb', line 54 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
67 68 69 |
# File 'lib/diffend/voting/versions/remote.rb', line 67 def build_diffend_environment ENV['DIFFEND_ENV'] || 'development' end |
.build_host ⇒ Hash
Build host information
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/diffend/voting/versions/remote.rb', line 116 def build_host uname = Etc.uname { 'command' => { 'name' => '', 'options' => '' }, 'ips' => build_host_ips, 'name' => uname[:nodename], 'system' => { 'machine' => uname[:machine], 'name' => uname[:sysname], 'release' => uname[:release], 'version' => uname[:version] }, 'tags' => , 'user' => Etc.getlogin }.freeze end |
.build_host_ips ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/diffend/voting/versions/remote.rb', line 134 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 ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/diffend/voting/versions/remote.rb', line 142 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
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/diffend/voting/versions/remote.rb', line 74 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
109 110 111 |
# File 'lib/diffend/voting/versions/remote.rb', line 109 def build_platform_environment ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development' end |
.build_platform_ruby ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/diffend/voting/versions/remote.rb', line 88 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, definition) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/diffend/voting/versions/remote.rb', line 23 def call(command, definition) config = fetch_config response = Request.call( command, payload(command, config&.project_id, definition), config ) JSON.parse(response.body) end |
.fetch_config ⇒ OpenStruct?
Fetch coditsu config file
163 164 165 166 167 168 169 |
# File 'lib/diffend/voting/versions/remote.rb', line 163 def fetch_config Config::Fetcher.call( File.('..', Bundler.bin_path) ) rescue Errors::MissingConfigurationFile nil end |
.payload(command, project_id, definition) ⇒ Hash
Build diffend, host, packages, and platform specific information
40 41 42 43 44 45 46 47 |
# File 'lib/diffend/voting/versions/remote.rb', line 40 def payload(command, project_id, definition) { 'diffend' => build_diffend(project_id), 'host' => build_host, 'packages' => Local.call(command, definition), 'platform' => build_platform }.freeze end |