zold 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zold/copies.rb +4 -0
- data/lib/zold/key.rb +5 -97
- data/lib/zold/node/front.rb +6 -11
- data/lib/zold/version.rb +1 -1
- data/resources/remotes +1 -0
- data/zold.gemspec +0 -1
- metadata +1 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 310bfd7583912cdc9abc3b2bb8ff1c3a2d8bdc9a
|
4
|
+
data.tar.gz: 6b9c43db3c2534bedf560a2baf8519596e52d187
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34802e906d21aec4e14ba10f01e4625df22c2e767c470b0167d9879bd7337a83018ea4d7bc506dc9e3deda52c4bbf32624bcd01d8cb4f406bbfd539a82b533e9
|
7
|
+
data.tar.gz: 6a4f768f29cea3a6246e7c55261ade7444e3149cfccac4a367a361484b695be2170fabd8e3e9246640ed7bfebf68c15ef41e303d780b78268ab32c73ae38a07f
|
data/lib/zold/copies.rb
CHANGED
@@ -49,6 +49,10 @@ module Zold
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
def remove(host, port)
|
53
|
+
save(load.reject! { |s| s[:host] == host && s[:port] == port })
|
54
|
+
end
|
55
|
+
|
52
56
|
def add(content, host, port, score, time = Time.now)
|
53
57
|
raise "Content can't be empty" if content.empty?
|
54
58
|
raise 'TCP port must be of type Integer' unless port.is_a?(Integer)
|
data/lib/zold/key.rb
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
gem 'openssl'
|
22
22
|
require 'openssl'
|
23
23
|
require 'base64'
|
24
|
+
require 'tempfile'
|
24
25
|
|
25
26
|
# The RSA key (either private or public).
|
26
27
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -70,7 +71,10 @@ module Zold
|
|
70
71
|
def rsa
|
71
72
|
text = @body.call.strip
|
72
73
|
unless text.start_with?('-----BEGIN')
|
73
|
-
|
74
|
+
Tempfile.open do |f|
|
75
|
+
File.write(f.path, text)
|
76
|
+
text = `ssh-keygen -f #{f.path} -e -m pem`
|
77
|
+
end
|
74
78
|
end
|
75
79
|
begin
|
76
80
|
OpenSSL::PKey::RSA.new(text)
|
@@ -80,99 +84,3 @@ module Zold
|
|
80
84
|
end
|
81
85
|
end
|
82
86
|
end
|
83
|
-
|
84
|
-
# Stolen from: https://gist.github.com/tombh/f66de84fd3a63e670ad9
|
85
|
-
module OpenSSHKeyConverter
|
86
|
-
# The components in a openssh .pub / known_host RSA public key.
|
87
|
-
RSA_COMPONENTS = ['ssh-rsa', :e, :n].freeze
|
88
|
-
# The components in a openssh .pub / known_host DSA public key.
|
89
|
-
DSA_COMPONENTS = ['ssh-dss', :p, :q, :g, :pub_key].freeze
|
90
|
-
|
91
|
-
# Encodes a key's public part in the format found in .pub & known_hosts files.
|
92
|
-
def self.encode_pubkey(key)
|
93
|
-
case key
|
94
|
-
when OpenSSL::PKey::RSA
|
95
|
-
components = RSA_COMPONENTS
|
96
|
-
when OpenSSL::PKey::DSA
|
97
|
-
components = DSA_COMPONENTS
|
98
|
-
else
|
99
|
-
raise "Unsupported key type #{key.class.name}"
|
100
|
-
end
|
101
|
-
components.map! { |c| c.is_a?(Symbol) ? encode_mpi(key.send(c)) : c }
|
102
|
-
# ruby tries to be helpful and adds new lines every 60 bytes :(
|
103
|
-
[pack_pubkey_components(components)].pack('m').delete("\n")
|
104
|
-
end
|
105
|
-
|
106
|
-
# Decodes an openssh public key from the format of .pub & known_hosts files.
|
107
|
-
def self.decode_pubkey(string)
|
108
|
-
components = unpack_pubkey_components Base64.decode64(string)
|
109
|
-
case components.first
|
110
|
-
when RSA_COMPONENTS.first
|
111
|
-
ops = RSA_COMPONENTS.zip components
|
112
|
-
key = OpenSSL::PKey::RSA.new
|
113
|
-
when DSA_COMPONENTS.first
|
114
|
-
ops = DSA_COMPONENTS.zip components
|
115
|
-
key = OpenSSL::PKey::DSA.new
|
116
|
-
else
|
117
|
-
raise "Unsupported key type #{components.first}"
|
118
|
-
end
|
119
|
-
ops.each do |o|
|
120
|
-
next unless o.first.is_a? Symbol
|
121
|
-
key.send "#{o.first}=", decode_mpi(o.last)
|
122
|
-
end
|
123
|
-
key
|
124
|
-
end
|
125
|
-
|
126
|
-
# Loads a serialized key from an IO instance (File, StringIO).
|
127
|
-
def self.load_key(io)
|
128
|
-
key_from_string io.read
|
129
|
-
end
|
130
|
-
|
131
|
-
# Reads a serialized key from a string.
|
132
|
-
def self.key_from_string(serialized_key)
|
133
|
-
header = first_line serialized_key
|
134
|
-
if header.index 'RSA'
|
135
|
-
OpenSSL::PKey::RSA.new serialized_key
|
136
|
-
elsif header.index 'DSA'
|
137
|
-
OpenSSL::PKey::DSA.new serialized_key
|
138
|
-
else
|
139
|
-
raise 'Unknown key type'
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
# Extracts the first line of a string.
|
144
|
-
def self.first_line(string)
|
145
|
-
string[0, string.index(/\r|\n/) || string.len]
|
146
|
-
end
|
147
|
-
|
148
|
-
# Unpacks the string components in an openssh-encoded pubkey.
|
149
|
-
def self.unpack_pubkey_components(str)
|
150
|
-
cs = []
|
151
|
-
i = 0
|
152
|
-
while i < str.length
|
153
|
-
len = str[i, 4].unpack('N').first
|
154
|
-
cs << str[i + 4, len]
|
155
|
-
i += 4 + len
|
156
|
-
end
|
157
|
-
cs
|
158
|
-
end
|
159
|
-
|
160
|
-
# Packs string components into an openssh-encoded pubkey.
|
161
|
-
def self.pack_pubkey_components(strings)
|
162
|
-
(strings.map { |s| [s.length].pack('N') }).zip(strings).flatten.join
|
163
|
-
end
|
164
|
-
|
165
|
-
# Decodes an openssh-mpi-encoded integer.
|
166
|
-
def self.decode_mpi(mpi_str)
|
167
|
-
mpi_str.unpack('C*').inject(0) { |a, e| (a << 8) | e }
|
168
|
-
end
|
169
|
-
|
170
|
-
# Encodes an openssh-mpi-encoded integer.
|
171
|
-
def self.encode_mpi(n)
|
172
|
-
chars = []
|
173
|
-
n = n.to_i
|
174
|
-
chars << (n & 0xff) && n >>= 8 while n != 0
|
175
|
-
chars << 0 if chars.empty? || chars.last >= 0x80
|
176
|
-
chars.reverse.pack('C*')
|
177
|
-
end
|
178
|
-
end
|
data/lib/zold/node/front.rb
CHANGED
@@ -21,7 +21,6 @@
|
|
21
21
|
STDOUT.sync = true
|
22
22
|
|
23
23
|
require 'slop'
|
24
|
-
require 'facter'
|
25
24
|
require 'json'
|
26
25
|
require 'sinatra/base'
|
27
26
|
require 'webrick'
|
@@ -34,7 +33,6 @@ require_relative '../log'
|
|
34
33
|
require_relative '../remotes'
|
35
34
|
require_relative '../id'
|
36
35
|
require_relative '../http'
|
37
|
-
require_relative '../commands/merge'
|
38
36
|
|
39
37
|
# The web front of the node.
|
40
38
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -84,15 +82,8 @@ module Zold
|
|
84
82
|
JSON.pretty_generate(
|
85
83
|
version: VERSION,
|
86
84
|
score: score.to_h,
|
87
|
-
|
88
|
-
|
89
|
-
# see https://docs.puppet.com/facter/3.3/core_facts.html
|
90
|
-
kernel: Facter.value(:kernel),
|
91
|
-
processors: Facter.value(:processors)['count']
|
92
|
-
},
|
93
|
-
wallets: {
|
94
|
-
total: wallets.all.count
|
95
|
-
},
|
85
|
+
uptime: `uptime`.strip,
|
86
|
+
wallets: wallets.all.count,
|
96
87
|
farm: settings.farm.to_json,
|
97
88
|
date: `date --iso-8601=seconds -u`.strip,
|
98
89
|
age: (Time.now - settings.start) / (60 * 60),
|
@@ -118,7 +109,11 @@ module Zold
|
|
118
109
|
request.body.rewind
|
119
110
|
cps = copies(id)
|
120
111
|
cps.add(request.body.read, 'remote', Remotes::PORT, 0)
|
112
|
+
require_relative '../commands/fetch'
|
113
|
+
Zold::Fetch.new(remotes: remotes, copies: cps.root).run([id.to_s])
|
114
|
+
require_relative '../commands/merge'
|
121
115
|
Zold::Merge.new(wallets: wallets, copies: cps.root).run([id.to_s])
|
116
|
+
cps.remove('remote', Remotes::PORT)
|
122
117
|
"Success, #{wallet.id} balance is #{wallet.balance}"
|
123
118
|
end
|
124
119
|
|
data/lib/zold/version.rb
CHANGED
data/resources/remotes
CHANGED
data/zold.gemspec
CHANGED
@@ -46,7 +46,6 @@ Gem::Specification.new do |s|
|
|
46
46
|
s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
|
47
47
|
s.add_runtime_dependency 'cucumber', '1.3.17'
|
48
48
|
s.add_runtime_dependency 'diffy', '3.2.0'
|
49
|
-
s.add_runtime_dependency 'facter', '2.5.1'
|
50
49
|
s.add_runtime_dependency 'openssl', '2.0.1'
|
51
50
|
s.add_runtime_dependency 'rainbow', '~>3.0'
|
52
51
|
s.add_runtime_dependency 'rake', '12.0.0'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 3.2.0
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: facter
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - '='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 2.5.1
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - '='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 2.5.1
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: openssl
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|