vpsmatrix 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/vpsmatrix/config.rb +2 -2
- data/lib/vpsmatrix/starter.rb +23 -30
- data/lib/vpsmatrix/upload_progress.rb +23 -0
- data/lib/vpsmatrix/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5c44d6702d8412d093a5ad411a7af24fd932fb2
|
4
|
+
data.tar.gz: 1b911c4a5e518261526e17ca1ef4f5b70336dc6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6ae55af26be0c293572570600c5c4ad3cedeae4928fa5f3857e38f4c9cbfa92d2ec7cce3c9a673012d9466772701521cad056edc433dd10ef424b21ffb138f0
|
7
|
+
data.tar.gz: c3634168223dcfeb6a67fddc1d198ab212c546aad961517a67fef794d773a2622b297afef28917e169d94e9690e237e1912c3d13038cf953ad436e0a2b578dcb
|
data/lib/vpsmatrix/config.rb
CHANGED
@@ -3,9 +3,9 @@ require 'yaml'
|
|
3
3
|
class Config
|
4
4
|
|
5
5
|
def initialize
|
6
|
-
@file_path = "
|
6
|
+
@file_path = "config/vpsx.yml"
|
7
7
|
unless File.exists? @file_path
|
8
|
-
Dir.mkdir ".
|
8
|
+
Dir.mkdir "config" unless Dir.exists? "config"
|
9
9
|
File.open(@file_path, 'w') do |file|
|
10
10
|
file.write "comment: 'Config file for VPS Matrix services'"
|
11
11
|
end
|
data/lib/vpsmatrix/starter.rb
CHANGED
@@ -3,6 +3,7 @@ require 'net/http'
|
|
3
3
|
require 'uri'
|
4
4
|
require 'securerandom'
|
5
5
|
require_relative 'config'
|
6
|
+
require_relative 'upload_progress'
|
6
7
|
|
7
8
|
class Starter
|
8
9
|
|
@@ -25,33 +26,18 @@ class Starter
|
|
25
26
|
|
26
27
|
def demo_deploy
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
# generate ~/.vpsmatrix/config.yml
|
31
|
-
# generate ~/.vpsmatrix/id_rsa.pub
|
32
|
-
|
33
|
-
## check for .vpsmatrix_config
|
34
|
-
## no?
|
35
|
-
# generate .vpsmatrix_config.yml
|
36
|
-
# ask for API KEY
|
37
|
-
# write it to .vpsmatrix_config.yml
|
38
|
-
## yes?
|
39
|
-
# read API KEY
|
40
|
-
|
41
|
-
|
42
|
-
# there should be only one SSH key for all apps right? So dir in home with general config and SSH key
|
43
|
-
# then one config file in app folder?
|
44
|
-
unless File.exists? ".vpsmatrix/id_rsa.pub"
|
45
|
-
# Generate SSH key
|
46
|
-
ssh_key = 'HFKNGEWIUHENINHSLN867G5867BDI7BOQ8YWQF9YFN9QWF'
|
29
|
+
unless Config.new.content['ssh_key']
|
30
|
+
Config.new.write 'ssh_key', SecureRandom.hex
|
47
31
|
end
|
48
32
|
|
49
33
|
@app_name = Dir.pwd.split(File::SEPARATOR).last
|
50
|
-
unless Config.new.content['api_key']
|
34
|
+
unless Config.new.content['api_key'] && Config.new.content['api_key'].length == 32
|
51
35
|
# ask for it to server
|
52
36
|
# TODO check if server returns api_key
|
53
|
-
api_key = send_get_request "https://api.vpsmatrix.net/uploads/get_api_key"
|
54
|
-
|
37
|
+
api_key = send_get_request "https://api.vpsmatrix.net/uploads/get_api_key"
|
38
|
+
if api_key.response.code == '200'
|
39
|
+
Config.new.write 'api_key', api_key.response.body
|
40
|
+
end
|
55
41
|
end
|
56
42
|
|
57
43
|
#register_email
|
@@ -112,17 +98,24 @@ class Starter
|
|
112
98
|
# stream version
|
113
99
|
Net::HTTP.start(uri.host, uri.port, use_ssl: true, :read_timeout => 500) do |http|
|
114
100
|
req = Net::HTTP::Put.new(uri)
|
115
|
-
req.add_field("Content-Type","multipart/form-data; boundary=#{@multipart_boundary}")
|
101
|
+
req.add_field("Content-Type","multipart/form-data; boundary=#{@multipart_boundary}; ssh_key=#{Config.new.content['ssh_key']}; api_key=#{Config.new.content['api_key']}")
|
116
102
|
req.add_field('Transfer-Encoding', 'chunked')
|
117
103
|
req.basic_auth("test_app", "test_app")
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
104
|
+
File.open('tmp/files_to_send', 'rb') do |io|
|
105
|
+
req.content_length = io.size
|
106
|
+
req.body_stream = io
|
107
|
+
puts DateTime.now
|
108
|
+
UploadProgress.new(req) do |progress|
|
109
|
+
print "uploaded so far: #{ progress.upload_size }/#{ io.size }\r"
|
110
|
+
$stdout.flush
|
111
|
+
end
|
112
|
+
http.request req do |response|
|
113
|
+
puts ""
|
114
|
+
response.read_body do |chunk|
|
115
|
+
print chunk
|
116
|
+
end
|
117
|
+
puts response.code
|
124
118
|
end
|
125
|
-
puts response.code
|
126
119
|
end
|
127
120
|
end
|
128
121
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#the code is used from gem 'net-http-uploadprogress'
|
2
|
+
|
3
|
+
class UploadProgress
|
4
|
+
attr_reader :upload_size
|
5
|
+
|
6
|
+
def initialize(req, &block)
|
7
|
+
@req = req
|
8
|
+
@callback = block
|
9
|
+
@upload_size = 0
|
10
|
+
@io = req.body_stream
|
11
|
+
req.body_stream = self
|
12
|
+
end
|
13
|
+
|
14
|
+
def readpartial(maxlen, outbuf)
|
15
|
+
begin
|
16
|
+
str = @io.readpartial(maxlen, outbuf)
|
17
|
+
ensure
|
18
|
+
@callback.call(self) unless @upload_size.zero?
|
19
|
+
end
|
20
|
+
@upload_size += str.length
|
21
|
+
str
|
22
|
+
end
|
23
|
+
end
|
data/lib/vpsmatrix/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vpsmatrix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mousse
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- lib/vpsmatrix.rb
|
54
54
|
- lib/vpsmatrix/config.rb
|
55
55
|
- lib/vpsmatrix/starter.rb
|
56
|
+
- lib/vpsmatrix/upload_progress.rb
|
56
57
|
- lib/vpsmatrix/version.rb
|
57
58
|
- vpsmatrix.gemspec
|
58
59
|
homepage: http://www.vpsmatrix.co.uk
|
@@ -74,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
75
|
version: '0'
|
75
76
|
requirements: []
|
76
77
|
rubyforge_project:
|
77
|
-
rubygems_version: 2.4
|
78
|
+
rubygems_version: 2.6.4
|
78
79
|
signing_key:
|
79
80
|
specification_version: 4
|
80
81
|
summary: Gem for easy deployment to VPS Matrix servers.
|