vpsmatrix 0.1.5 → 0.1.7

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
  SHA1:
3
- metadata.gz: 72c161a134c74fe3af5b21abcfcde1975f95e017
4
- data.tar.gz: d41715644f3009c2c67b1e9a808f49bf9dd32ab1
3
+ metadata.gz: e5c44d6702d8412d093a5ad411a7af24fd932fb2
4
+ data.tar.gz: 1b911c4a5e518261526e17ca1ef4f5b70336dc6e
5
5
  SHA512:
6
- metadata.gz: 5d83c10ad596f91a2af58b9ad9af19c2954d6ba403955bf3455dbdca429b12f9d4a4ecacbefe6c75f645c26796a1b22d1415cb0ffdd8ef95fbfa3b2a2ae6dd9b
7
- data.tar.gz: cc07abe804ff98f2a43ab1694a557984cd009433e29750c066a03b7763c2fac2139e5e2aa063afa99e8199059e18231ad9f2992db57e12cc2d566ab82f83ca5c
6
+ metadata.gz: c6ae55af26be0c293572570600c5c4ad3cedeae4928fa5f3857e38f4c9cbfa92d2ec7cce3c9a673012d9466772701521cad056edc433dd10ef424b21ffb138f0
7
+ data.tar.gz: c3634168223dcfeb6a67fddc1d198ab212c546aad961517a67fef794d773a2622b297afef28917e169d94e9690e237e1912c3d13038cf953ad436e0a2b578dcb
@@ -3,9 +3,9 @@ require 'yaml'
3
3
  class Config
4
4
 
5
5
  def initialize
6
- @file_path = ".vps_matrix/config.yml"
6
+ @file_path = "config/vpsx.yml"
7
7
  unless File.exists? @file_path
8
- Dir.mkdir ".vps_matrix"
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
@@ -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
- # check SSH key in .vpsmatrix dir, else generate new
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", {ssh_key: ssh_key}
54
- Config.new.write 'api_key', api_key
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
- req.body_stream = File.open("tmp/files_to_send")
119
-
120
- http.request req do |response|
121
- # puts response
122
- response.read_body do |chunk|
123
- puts chunk
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
@@ -1,3 +1,3 @@
1
1
  module Vpsmatrix
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.7"
3
3
  end
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.5
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-08-30 00:00:00.000000000 Z
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.5.1
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.