judges 0.15.6 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d43bd3ebf5cea4ae2ca7c8d5deb723e01730ea24a2b849e5a7601049b354a3f
4
- data.tar.gz: 5b7e845e02b248d8d3eb6c877ee29e7fa92a423eb472aada3112d4efa772feb4
3
+ metadata.gz: db0130833063b43aab8a1dacec3106566da9c398fe539eea33eb8e76529d9d09
4
+ data.tar.gz: 2ced92ba9c8896742ad493dc75be234864cef5690d0313a6a581ee7e12cb427a
5
5
  SHA512:
6
- metadata.gz: 2e263f81a023f86ac28fd69d122120e29c74adc91ba141d65ec9bfb76266c89b9d072f5134b858c089f43d136ca53fee5fff0c93cf40d453970c8fc8f25a84d0
7
- data.tar.gz: d36e3c2b7e80a15d2194645e8756adfdd6077e1895e6d9e6035c421842be38f04e2ce6188a3672ea3d8c0ef590ff1d5362adc547d31d55c88709ad1dc6dc77cd
6
+ metadata.gz: d4393433a51dfdbabec4e6b8c09d9a02255fc18f76022f571a9633abf73c9f4bc9783ef1b4175dca14f35a939f5cc043f6052f928c5798206d40bda22667e6d7
7
+ data.tar.gz: b4e7653eb03bec4c3ec08a4060c594d1ded0bbe63e24357bce24bab52e4dee1d74615ac7199bbbf09b485c51072c997f513d71011c3fef4147a46c378bf786cd
data/Gemfile.lock CHANGED
@@ -2,17 +2,17 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  judges (0.0.0)
5
- backtrace
5
+ backtrace (~> 0)
6
6
  concurrent-ruby (~> 1.2)
7
- factbase
7
+ factbase (~> 0)
8
8
  gli (~> 2.21)
9
- iri
10
- loog
9
+ iri (~> 0)
10
+ loog (~> 0)
11
11
  moments (~> 0.3)
12
12
  nokogiri (~> 1.10)
13
- others
14
- retries
15
- tago
13
+ others (~> 0)
14
+ retries (~> 0)
15
+ tago (~> 0)
16
16
  typhoeus (~> 1.3)
17
17
 
18
18
  GEM
data/bin/judges CHANGED
@@ -177,6 +177,8 @@ class App
177
177
  c.switch([:ssl], default_value: true)
178
178
  c.desc 'A unique name to use for a lock/unlock'
179
179
  c.flag([:owner], default_value: 'default', type: String)
180
+ c.desc 'Supplementary meta information about the upload (key:value)'
181
+ c.flag([:meta], type: String, multiple: true)
180
182
  c.action do |global, options, args|
181
183
  require_relative '../lib/judges/commands/push'
182
184
  Judges::Push.new(loog).run(options, args)
@@ -6,7 +6,6 @@ Feature: Push
6
6
  Given I make a temp directory
7
7
  Then I run bin/judges with "--verbose eval simple.fb '(0..1000).each { $fb.insert.foo = 42 }'"
8
8
  And Exit code is zero
9
- Then I run bin/judges with "push --token 00000000-0000-0000-0000-000000000000 simple simple.fb"
9
+ Then I run bin/judges with "push --token 00000000-0000-0000-0000-000000000000 --meta a:b --meta foo:bar simple simple.fb"
10
10
  Then Stdout contains "Pushed"
11
11
  And Exit code is zero
12
-
data/judges.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
27
27
  s.required_ruby_version = '>=3.2'
28
28
  s.name = 'judges'
29
- s.version = '0.15.6'
29
+ s.version = '0.16.0'
30
30
  s.license = 'MIT'
31
31
  s.summary = 'Command-Line Tool for a Factbase'
32
32
  s.description =
@@ -42,17 +42,17 @@ Gem::Specification.new do |s|
42
42
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
43
43
  s.rdoc_options = ['--charset=UTF-8']
44
44
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
45
- s.add_dependency 'backtrace'
45
+ s.add_dependency 'backtrace', '~>0'
46
46
  s.add_dependency 'concurrent-ruby', '~>1.2'
47
- s.add_dependency 'factbase'
47
+ s.add_dependency 'factbase', '~>0'
48
48
  s.add_dependency 'gli', '~>2.21'
49
- s.add_dependency 'iri'
50
- s.add_dependency 'loog'
49
+ s.add_dependency 'iri', '~>0'
50
+ s.add_dependency 'loog', '~>0'
51
51
  s.add_dependency 'moments', '~>0.3'
52
52
  s.add_dependency 'nokogiri', '~>1.10'
53
- s.add_dependency 'others'
54
- s.add_dependency 'retries'
55
- s.add_dependency 'tago'
53
+ s.add_dependency 'others', '~>0'
54
+ s.add_dependency 'retries', '~>0'
55
+ s.add_dependency 'tago', '~>0'
56
56
  s.add_dependency 'typhoeus', '~>1.3'
57
57
  s.metadata['rubygems_mfa_required'] = 'true'
58
58
  end
data/lib/judges/baza.rb CHANGED
@@ -24,6 +24,7 @@ require 'typhoeus'
24
24
  require 'retries'
25
25
  require 'iri'
26
26
  require 'loog'
27
+ require 'base64'
27
28
  require_relative '../judges'
28
29
  require_relative '../judges/elapsed'
29
30
 
@@ -43,18 +44,20 @@ class Judges::Baza
43
44
  @loog = loog
44
45
  end
45
46
 
46
- def push(name, data)
47
+ def push(name, data, meta)
47
48
  id = 0
49
+ hdrs = headers.merge(
50
+ 'Content-Type' => 'application/octet-stream',
51
+ 'Content-Length' => data.size
52
+ )
53
+ hdrs = hdrs.merge('X-Zerocracy-Meta' => meta.map { |v| Base64.encode64(v).strip }.join(' ')) unless meta.empty?
48
54
  elapsed(@loog) do
49
55
  ret = with_retries do
50
56
  checked(
51
57
  Typhoeus::Request.put(
52
58
  home.append('push').append(name).to_s,
53
59
  body: data,
54
- headers: headers.merge(
55
- 'Content-Type' => 'application/octet-stream',
56
- 'Content-Length' => data.size
57
- ),
60
+ headers: hdrs,
58
61
  connecttimeout: @timeout,
59
62
  timeout: @timeout
60
63
  )
@@ -203,12 +206,17 @@ class Judges::Baza
203
206
  @loog.debug("#{log}\n #{(ret.headers || {}).map { |k, v| "#{k}: #{v}" }.join("\n ")}")
204
207
  msg =
205
208
  "Invalid response code ##{ret.code} " \
206
- "at #{mtd} #{url} (#{ret.headers['X-Zerocracy-Flash']})"
207
- if ret.code == 503
209
+ "at #{mtd} #{url} (#{ret.headers['X-Zerocracy-Flash'].inspect})"
210
+ case ret.code
211
+ when 500
208
212
  msg +=
209
213
  ', most probably it\'s an internal error on the server, ' \
214
+ 'please report this to https://github.com/zerocracy/baza'
215
+ when 503
216
+ msg +=
217
+ ", most probably it's an internal error on the server (#{ret.headers['X-Zerocracy-Failure'].inspect}), " \
210
218
  'please report this to https://github.com/yegor256/judges'
211
- elsif ret.code == 404
219
+ when 404
212
220
  msg +=
213
221
  ', most probably you are trying to reach a wrong server, which doesn\'t ' \
214
222
  'have the URL that it is expected to have'
@@ -47,7 +47,7 @@ class Judges::Push
47
47
  )
48
48
  elapsed(@loog) do
49
49
  baza.lock(name, opts['owner'])
50
- id = baza.push(name, fb.export)
50
+ id = baza.push(name, fb.export, opts['meta'] || [])
51
51
  baza.unlock(name, opts['owner'])
52
52
  throw :"Pushed #{fb.size} facts, job ID is #{id}"
53
53
  end
data/lib/judges.rb CHANGED
@@ -25,5 +25,5 @@
25
25
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Judges
28
- VERSION = '0.15.6'
28
+ VERSION = '0.16.0'
29
29
  end
data/test/test_baza.rb CHANGED
@@ -40,7 +40,7 @@ class TestBaza < Minitest::Test
40
40
  )
41
41
  assert_equal(
42
42
  42,
43
- Judges::Baza.new('example.org', 443, '000').push('simple', 'hello, world!')
43
+ Judges::Baza.new('example.org', 443, '000').push('simple', 'hello, world!', [])
44
44
  )
45
45
  end
46
46
 
@@ -76,6 +76,22 @@ class TestBaza < Minitest::Test
76
76
  end
77
77
 
78
78
  def test_real_http
79
+ req = with_http_server(200, 'yes') do |baza|
80
+ baza.name_exists?('simple')
81
+ end
82
+ assert(req.include?("User-Agent: judges #{Judges::VERSION}\r\n"))
83
+ end
84
+
85
+ def test_push_with_meta
86
+ req = with_http_server(200, 'yes') do |baza|
87
+ baza.push('simple', 'hello, world!', ['boom!', 'хей!'])
88
+ end
89
+ assert(req.include?("X-Zerocracy-Meta: Ym9vbSE= 0YXQtdC5IQ==\r\n"))
90
+ end
91
+
92
+ private
93
+
94
+ def with_http_server(code, response)
79
95
  WebMock.enable_net_connect!
80
96
  req = []
81
97
  host = '127.0.0.1'
@@ -88,12 +104,12 @@ class TestBaza < Minitest::Test
88
104
  break if line == "\r\n"
89
105
  req << line
90
106
  end
91
- socket.puts "HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nyes"
107
+ socket.puts "HTTP/1.1 #{code} OK\r\nContent-Length: #{response.length}\r\n\r\n#{response}"
92
108
  socket.close
93
109
  end
94
- Judges::Baza.new(host, port, '0000', ssl: false, timeout: 1).name_exists?('simple')
110
+ yield Judges::Baza.new(host, port, '0000', ssl: false, timeout: 1)
95
111
  t.join
96
112
  end
97
- assert(req.include?("User-Agent: judges #{Judges::VERSION}\r\n"))
113
+ req
98
114
  end
99
115
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: judges
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.6
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-11 00:00:00.000000000 Z
11
+ date: 2024-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
@@ -42,14 +42,14 @@ dependencies:
42
42
  name: factbase
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
@@ -70,28 +70,28 @@ dependencies:
70
70
  name: iri
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: loog
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
@@ -126,42 +126,42 @@ dependencies:
126
126
  name: others
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ">="
129
+ - - "~>"
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: retries
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - "~>"
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ">="
150
+ - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: tago
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ">="
157
+ - - "~>"
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ">="
164
+ - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  - !ruby/object:Gem::Dependency