vpsmatrix 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 375d8957b222ef315120d03691c37d7dd4612582
4
+ data.tar.gz: 955af47bd16f83401f0d9bc806b87d614b5520f7
5
+ SHA512:
6
+ metadata.gz: 9e8ae55fa79dd785f2dee3a90ff1f2344cb1ede145b620df2c01867896b8148fbe3cc485e3a9e0ee9a84da64eb3e05d8ac68f84e4355a416c31422ba85ea4b25
7
+ data.tar.gz: fc7da70148211841a592092b99f775710b880c861f7ecf02310dfdf1bf25ffe8871c06b877db6e3ca9e958e8bddff716cf3d1970e75e4f2508be2526687d270d
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vpsmatrix.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Vpsmatrix
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/vpsmatrix`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'vpsmatrix'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install vpsmatrix
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vpsmatrix.
36
+
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
3
+ task :console do
4
+ exec "irb -r vpsmatrix -I ./lib"
5
+ end
data/bin/vpsx ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'vpsmatrix'
4
+ Starter.start(ARGV)
@@ -0,0 +1,25 @@
1
+ require 'yaml'
2
+
3
+ class Config
4
+
5
+ def initialize
6
+ @file_path = ".vps_matrix/config.yml"
7
+ unless File.exists? @file_path
8
+ Dir.mkdir ".vpsmatrix"
9
+ File.open(@file_path, 'w') do |file|
10
+ file.write "comment: 'Config file for VPS Matrix services'"
11
+ end
12
+ end
13
+ @content = YAML::load_file(@file_path)
14
+ end
15
+
16
+ def content
17
+ @content
18
+ end
19
+
20
+ # how to write with nested keys
21
+ def write key, value
22
+ @content[key] = value
23
+ File.open(@file_path, 'w') { |f| YAML.dump(@content, f) }
24
+ end
25
+ end
@@ -0,0 +1,134 @@
1
+ require 'thor'
2
+ require 'digest'
3
+ require 'net/http'
4
+ require 'uri'
5
+
6
+ class Starter < Thor
7
+ include Thor::Actions
8
+
9
+ desc 'deploy', 'run deploy to deploy app to VPS Matrix demo server'
10
+ def deploy
11
+
12
+ ##
13
+ # check SSH key in .vpsmatrix dir, else generate new
14
+ # generate ~/.vpsmatrix/config.yml
15
+ # generate ~/.vpsmatrix/id_rsa.pub
16
+
17
+ ## check for .vpsmatrix_config
18
+ ## no?
19
+ # generate .vpsmatrix_config.yml
20
+ # ask for API KEY
21
+ # write it to .vpsmatrix_config.yml
22
+ ## yes?
23
+ # read API KEY
24
+
25
+
26
+ # there should be only one SSH key for all apps right? So dir in home with general config and SSH key
27
+ # then one config file in app folder?
28
+ unless File.exists? ".vpsmatrix/id_rsa.pub"
29
+ # Generate SSH key
30
+ end
31
+
32
+ @app_name = Dir.pwd.split(File::SEPARATOR).last
33
+ unless Config.new.content['api_key']
34
+ # ask for it to server
35
+ api_key = send_get_request "https://api.vpsmatrix.net/uploads/get_api_key", {ssh_key: ssh_key}
36
+ Config.new.write 'api_key', api_key
37
+ end
38
+
39
+ read_files
40
+ stream_file
41
+
42
+ # https://api.vpsmatrix.net/uploads/get_new_files
43
+
44
+ # detect rails? DB in (pg, mysql, sqlite, nodb)?
45
+ # no? - do you wish us to check it?
46
+
47
+ # send SSH key and API KEY to API app
48
+
49
+ # -> OK
50
+ # upload app to API, use rsync or something easy
51
+
52
+
53
+ # -> return error message (no account, etc.)
54
+
55
+ # run deploy on API app
56
+ # receive DONE deploy -> show URL
57
+
58
+ end
59
+
60
+ no_commands do
61
+ def read_files
62
+
63
+ # TODO check size of directory
64
+ working_dir = Dir.pwd
65
+ list_of_files = Dir.glob "#{working_dir}/**/*"
66
+ list_of_files.reject! {|path| path =~ /\/log|\/tmp/}
67
+ File.open("files_to_send", 'w') do |temp_file|
68
+ list_of_files.each do |file|
69
+ if File.file? file
70
+ file_content = File.read(file)
71
+ temp_file.write "#{file}\n"
72
+ temp_file.write "#{file_content}\n"
73
+ temp_file.write "#{Digest::SHA256.hexdigest(file_content)}\n"
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ def stream_file
80
+ uri = URI.parse("https://api.vpsmatrix.net/uploads/send_new_files")
81
+
82
+ # stream version
83
+ Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
84
+ req = Net::HTTP::Put.new(uri)
85
+ req.add_field('Transfer-Encoding', 'chunked')
86
+ request.basic_auth("test_app", "test_app")
87
+ req.body_stream = File.open("files_to_send")
88
+
89
+ http.request request do |response|
90
+ # puts response
91
+ response.read_body do |chunk|
92
+ puts chunk
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ def send_put_request
99
+ uri = URI.parse("https://api.vpsmatrix.net/uploads/send_new_files")
100
+
101
+ # no stream version
102
+ Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
103
+ request = Net::HTTP::Put.new(uri.request_uri)
104
+ request.basic_auth("test_app", "test_app")
105
+ request.set_form_data({"file" => File.read("files_to_send")})
106
+ http.request request
107
+ end
108
+ end
109
+
110
+ def send_get_request endpoint, params={} #https://api.vpsmatrix.net/uploads/get_file_list
111
+ uri = URI.parse(endpoint)
112
+ uri.query = URI.encode_www_form(params)
113
+ http = Net::HTTP.new(uri.host, uri.port)
114
+ http.use_ssl = true
115
+ req = Net::HTTP::Get.new(uri.path)
116
+ req.basic_auth("test_app", "test_app")
117
+ http.request(req)
118
+ #res = Net::HTTP.get_response(uri)
119
+ end
120
+
121
+ def read_dirs
122
+ working_dir = Dir.pwd
123
+ list_of_files = Dir.glob "#{working_dir}/**/*"
124
+ dirs_string = ""
125
+
126
+ list_of_files.map do |file|
127
+ if File.directory file
128
+ dirs_string += "#{file}\n"
129
+ end
130
+ end
131
+ dirs_string
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,3 @@
1
+ module Vpsmatrix
2
+ VERSION = "0.1.0"
3
+ end
data/lib/vpsmatrix.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "vpsmatrix/version"
2
+ require "vpsmatrix/starter"
3
+
4
+ module Vpsmatrix
5
+ # Your code goes here...
6
+ end
data/vpsmatrix.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vpsmatrix/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vpsmatrix"
8
+ spec.version = Vpsmatrix::VERSION
9
+ spec.authors = ["mousse"]
10
+ spec.email = ["mousse@timepress.cz"]
11
+
12
+ spec.summary = %q{Gem for easy deployment to VPS Matrix servers.}
13
+ spec.description = %q{Work in progress}
14
+ spec.homepage = "http://www.vpsmatrix.co.uk"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ #spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ #spec.bindir = "exe"
26
+ spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.11"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_runtime_dependency "thor"
32
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vpsmatrix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mousse
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Work in progress
56
+ email:
57
+ - mousse@timepress.cz
58
+ executables:
59
+ - vpsx
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - Gemfile
64
+ - README.md
65
+ - Rakefile
66
+ - bin/vpsx
67
+ - lib/vpsmatrix.rb
68
+ - lib/vpsmatrix/config.rb
69
+ - lib/vpsmatrix/starter.rb
70
+ - lib/vpsmatrix/version.rb
71
+ - vpsmatrix.gemspec
72
+ homepage: http://www.vpsmatrix.co.uk
73
+ licenses: []
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.6.4
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Gem for easy deployment to VPS Matrix servers.
95
+ test_files: []