vae 0.8.4 → 0.8.6

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: d689843b072581200ad83cf7b3bbab97d62bd3cb
4
- data.tar.gz: 7cec8550070b14c59de553ed59c64f64be6def74
3
+ metadata.gz: 6c2974493d451a951be87eec5c8909963f7bc8ce
4
+ data.tar.gz: 65a3d3072f97d3afa44a49f88a5316dde1a83b7d
5
5
  SHA512:
6
- metadata.gz: 1b8fd311fd92b6ff5316cd99d46c9dd1513316edd797fed189b5fa71a975f06a40abbc91c84be08fcc1977cf1a9fbb1461f85f4cd4035770112dbb76e3fb900f
7
- data.tar.gz: 918b1413047679ce58c51bc0554848c6e2f9bf1ee4eb828f5e7c92984e6a3cbd9ce3c9c4cb56a58d4b63a6a01017bd52b5cf4cd88442ae7b9fb7f2ae5abf3ad3
6
+ metadata.gz: 4eb6a694232c72d9211f86a947ccbb66019a2638b3f43621d97e3ef28a11e738cea336a115c4855e64f97069b4244c5c89086391401b74e7493142e91caf1877
7
+ data.tar.gz: ca4a4ad054d4397f917dae5cdc2249e5a6d4ae9ce599eb3495b0da6101514e862e1907a8f09b52db76340f27957b4a8c17b3eee4b25c98277cb8d88a647cb0dc
data/bin/vae CHANGED
@@ -16,6 +16,7 @@ require 'net/http'
16
16
  require 'net/https'
17
17
  require 'optparse'
18
18
  require 'ptools'
19
+ require 'rest-client'
19
20
  require 'shellwords'
20
21
  require 'thread'
21
22
  require 'webrick'
data/lib/full_stack.rb CHANGED
@@ -8,33 +8,33 @@ class FullStack
8
8
  @pids = []
9
9
  end
10
10
 
11
- def authenticate
12
- req = Net::HTTP::Post.new("/api/local/v1/authorize")
13
- req.body = "username=#{CGI.escape(@site.username)}&password=#{CGI.escape(@site.password)}"
14
- res = VaeLocal.fetch_from_vaeplatform(@site.subdomain, req)
15
- data = JSON.parse(res.body)
16
- if data['valid'] == "valid"
17
- FileUtils.mkdir_p(@site.data_path)
18
- if !File.exists?(@site.data_path + "/assets/")
19
- FileUtils.ln_s("#{vae_remote_path}/public", @site.data_path + "/assets")
20
- end
21
- @site.secret_key = data['secret_key']
22
- generation = File.exists?("#{@site.data_path}feed_generation") ? File.open("#{@site.data_path}feed_generation").read.to_i : 0
23
- if data['feed_url'] and data['feed_generation'].to_i > generation
24
- puts "Downloading updated Site Data Feed..."
25
- if curl = File.which("curl")
26
- `curl -o #{Shellwords.shellescape(@site.data_path)}feed.xml #{Shellwords.shellescape(data['feed_url'])}`
27
- else
28
- download_feed(data['feed_url'])
29
- end
30
- File.open("#{@site.data_path}feed_generation",'w') { |f| f.write(data['feed_generation']) }
11
+ def run
12
+ write_files
13
+ launch_daemons
14
+ trap("INT") { @stop = true }
15
+ loop { break if @stop; sleep 0.5 }
16
+ puts "Quit signal received, cleaning up ..."
17
+ @pids.map { |pid| Process.kill("TERM", pid) }
18
+ end
19
+
20
+ def write_files
21
+ data = @site.data
22
+ FileUtils.mkdir_p(@site.data_path)
23
+ if !File.exists?(@site.data_path + "/assets/")
24
+ FileUtils.ln_s("#{vae_remote_path}/public", @site.data_path + "/assets")
25
+ end
26
+ @site.secret_key = data['secret_key']
27
+ generation = File.exists?("#{@site.data_path}feed_generation") ? File.open("#{@site.data_path}feed_generation").read.to_i : 0
28
+ if data['feed_url'] and data['feed_generation'].to_i > generation
29
+ puts "Downloading updated Site Data Feed..."
30
+ if curl = File.which("curl")
31
+ `curl -o #{Shellwords.shellescape(@site.data_path)}feed.xml #{Shellwords.shellescape(data['feed_url'])}`
32
+ else
33
+ download_feed(data['feed_url'])
31
34
  end
32
- File.open("#{@site.data_path}settings.php",'w') { |f| f.write(data['settings']) }
33
- else
34
- raise VaeError, "Error Connecting to Vae with the supplied Username and Password. Please make sure this user has Vae Local permissions assigned."
35
+ File.open("#{@site.data_path}feed_generation",'w') { |f| f.write(data['feed_generation']) }
35
36
  end
36
- rescue JSON::ParserError
37
- raise VaeError, "An unknown error occurred signing into Vae Platform. Please email support for help."
37
+ File.open("#{@site.data_path}settings.php",'w') { |f| f.write(data['settings']) }
38
38
  end
39
39
 
40
40
  def download_feed(url)
@@ -49,15 +49,6 @@ class FullStack
49
49
  }
50
50
  end
51
51
 
52
- def run
53
- authenticate
54
- launch_daemons
55
- trap("INT") { @stop = true }
56
- loop { break if @stop; sleep 0.5 }
57
- puts "Quit signal received, cleaning up ..."
58
- @pids.map { |pid| Process.kill("TERM", pid) }
59
- end
60
-
61
52
  def launch_daemons
62
53
  if VaeLocal.port_open?(9092)
63
54
  puts "Starting Vae Frontend Compiler Service using Installation at #{vae_fcs_path}"
data/lib/site.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class Site
2
- attr_reader :password, :root, :session_id, :subdomain, :username, :data_path
2
+ attr_reader :password, :root, :session_id, :subdomain, :username, :data_path, :auth_key, :data
3
3
  attr_accessor :secret_key
4
4
 
5
5
  def initialize(options)
@@ -7,9 +7,10 @@ class Site
7
7
  @subdomain = options[:subdomain] if options[:subdomain]
8
8
  @username = options[:username] if options[:username]
9
9
  @password = options[:password] if options[:password]
10
+ @auth_key = options[:auth_key] if options[:auth_key]
10
11
  @session_id = Digest::MD5.hexdigest(rand.to_s)
11
12
  @data_path = options[:data_path] || "#{@root}/.vae/data/"
12
- login_to_server
13
+ @data = login_to_server
13
14
  end
14
15
 
15
16
  def fetch_from_server(req)
@@ -23,14 +24,26 @@ class Site
23
24
 
24
25
  def login_to_server
25
26
  req = Net::HTTP::Post.new("/")
26
- req.body = "__vae_local=#{session_id}&__local_username=#{CGI.escape(username)}&__local_password=#{CGI.escape(password)}&__local_version=#{VER}"
27
+ body = "__vae_local=#{session_id}&__local_version=#{VER}"
28
+ if auth_key
29
+ req.body = "#{body}&__local_auth_key=#{CGI.escape(auth_key)}"
30
+ else
31
+ req.body = "#{body}&__local_username2=#{CGI.escape(username)}&__local_password=#{CGI.escape(password)}"
32
+ end
27
33
  res = fetch_from_server(req)
28
- if res.body == "BAD"
34
+ data = JSON.parse(res.body)
35
+ if data['auth_key'] and !auth_key
36
+ VaeLocal.write_auth_key(subdomain, data['auth_key'])
37
+ end
38
+ if data == nil
39
+ raise VaeError, "Invalid password or insufficient permissions."
40
+ elsif data['alert']
41
+ puts data['alert']
42
+ elsif data['valid'] != "valid"
29
43
  raise VaeError, "Invalid password or insufficient permissions."
30
- elsif res.body =~ /MSG/
31
- puts res.body.gsub(/MSG/, "")
32
- elsif res.body != "GOOD"
33
- raise VaeError, "Could not connect to Vae servers. Please check your Internet connection."
34
44
  end
45
+ data
46
+ rescue JSON::ParserError
47
+ raise VaeError, "An unknown error occurred signing into Vae Platform. Please email support for help."
35
48
  end
36
49
  end
data/lib/vae_local.rb CHANGED
@@ -3,7 +3,7 @@ class VaeLocal
3
3
 
4
4
  def self.fetch_from_vaeplatform(site, req)
5
5
  local = ENV['VAEPLATFORM_LOCAL']
6
- http = Net::HTTP.new("#{site}." + (local ? "vaeplatform.dev" : "vaeplatform.com"), (local ? 80 : 443))
6
+ http = Net::HTTP.new(vaeplatform_host(site), (local ? 80 : 443))
7
7
  http.use_ssl = true unless local
8
8
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
9
9
  http.start { |http|
@@ -16,6 +16,36 @@ class VaeLocal
16
16
  !system("lsof -i:#{port}", out: '/dev/null')
17
17
  end
18
18
 
19
+ def self.vaeplatform_host(site)
20
+ "#{site}." + (ENV['VAEPLATFORM_LOCAL'] ? "vaeplatform.test" : "vaeplatform.com")
21
+ end
22
+
23
+ def self.vaeplatform_url(site)
24
+ "http#{ENV['VAEPLATFORM_LOCAL'] ? '' : 's'}://#{vaeplatform_host(site)}"
25
+ end
26
+
27
+ def self.read_auth_keys
28
+ if File.exists?(auth_key_path)
29
+ data = YAML::load_file(auth_key_path) || {}
30
+ else
31
+ data = {}
32
+ end
33
+ if !data['site_keys'].is_a?(Hash)
34
+ data['site_keys'] = {}
35
+ end
36
+ data
37
+ end
38
+
39
+ def self.write_auth_key(site, key)
40
+ data = read_auth_keys
41
+ data['site_keys'][site] = key
42
+ File.open(auth_key_path, 'w') { |f| f.write data.to_yaml }
43
+ end
44
+
45
+ def self.auth_key_path
46
+ File.join(Dir.home, ".vae_local_credentials.yml")
47
+ end
48
+
19
49
  def run
20
50
  options = { port: 9999, server: ProxyServer, log_level: "warning" }
21
51
  loop {
@@ -33,6 +63,7 @@ class VaeLocal
33
63
  opts.on("-f","--full-stack [php|hhvm]","Run in Full Stack Mode. Optionally provide 'php' or 'hhvm' to specify your preferred PHP runtime") { |o| options[:server] = FullStack; options[:php_runtime] = o }
34
64
  opts.on("-U","--url <url>","If running stage or stagerelease, provide the URL of a ZIP file to deploy here") { |o| options[:branch] = o }
35
65
  opts.on("-b","--branch <branch>","If running stage or stagerelease, override the Git branch to deploy here") { |o| options[:branch] = o }
66
+ opts.on("-B","--built_path <path>","If running stage or stagerelease, and you want to provide the built files to deploy from a local path, provide that path here") { |o| options[:built_path] = o }
36
67
  opts.on("-d","--data-path <path>","Where to Store Content and Image Data When In Full Stack Mode") { |o| options[:data_path] = o }
37
68
  opts.on("-l","--log-level <level>","Vaedb Log Level (for Full Stack Mode)") { |o| options[:log_level] = o }
38
69
  opts.on_tail("-h","--help", "Show this help message") { puts opts; exit }
@@ -51,23 +82,36 @@ class VaeLocal
51
82
  end
52
83
 
53
84
  raise VaeError, "We could not determine the Vae subdomain for this site. Please specify it manually by using the --site option or create a __vae.yml file within the site root." if options[:site].nil?
54
- raise VaeError, "We could not determine the Vae username that you use. Please specify it manually by using the --username option." if options[:username].nil?
55
- if options[:password].nil?
56
- options[:password] = ask("Please enter the Vae password for username #{options[:username]}:") { |q| q.echo = false }
85
+
86
+ keys = VaeLocal.read_auth_keys
87
+ if key = keys['site_keys'][options[:site]]
88
+ options[:auth_key] = key
89
+ end
90
+
91
+ unless options[:auth_key]
92
+ raise VaeError, "We could not determine the Vae username that you use. Please specify it manually by using the --username option." if options[:username].nil?
93
+ if options[:password].nil?
94
+ options[:password] = ask("Please enter the Vae password for username #{options[:username]}:") { |q| q.echo = false }
95
+ end
57
96
  end
58
97
 
59
98
  if [ "deploy", "release", "rollback", "stage", "stagerelease" ].include?(ARGV.last)
60
- stagerelease(ARGV.last, options[:site], options[:username], options[:password], options[:branch])
61
- exit
99
+ stageaction = true
100
+ else
101
+ raise VaeError, "You did not specify the path to the root of the local copy of your Vae site. Please specify it manually by using the --root option or cd to the site root (and make sure it contains a __vae.yml file)." unless options[:site_root]
102
+ raise VaeError, "You specified an invalid path to the local copy of your Vae site." unless File.exists?(options[:site_root])
62
103
  end
63
104
 
64
- raise VaeError, "You did not specify the path to the root of the local copy of your Vae site. Please specify it manually by using the --root option or cd to the site root (and make sure it contains a __vae.yml file)." unless options[:site_root]
65
- raise VaeError, "You specified an invalid path to the local copy of your Vae site." unless File.exists?(options[:site_root])
105
+ site = Site.new(subdomain: options[:site], root: options[:site_root], username: options[:username], password: options[:password], auth_key: options[:auth_key])
106
+
107
+ if stageaction
108
+ stagerelease(ARGV.last, options[:site], site.auth_key, options[:branch], options[:built_path])
109
+ exit
110
+ end
66
111
 
67
112
  Dir.chdir File.dirname(__FILE__)
68
113
  puts BANNER
69
114
 
70
- site = Site.new(subdomain: options[:site], root: options[:site_root], username: options[:username], password: options[:password])
71
115
  options[:server].new(site, options).run
72
116
  puts "Thanks for using Vae!"
73
117
  end
@@ -99,22 +143,33 @@ class VaeLocal
99
143
  raise VaeError, "An unknown error occurred requesting this operation from Vae Platform. Please email support for help."
100
144
  end
101
145
 
102
- def stagerelease(action, site, username, password, branch)
146
+ def stagerelease(action, site, auth_key, branch, built_path = nil)
103
147
  if action == "deploy"
104
148
  action = "stage"
105
149
  elsif action == "stagerelease"
106
- stagerelease("stage", site, username, password, branch)
107
- stagerelease("release", site, username, password, branch)
150
+ stagerelease("stage", site, auth_key, branch, built_path)
151
+ stagerelease("release", site, auth_key, branch)
108
152
  return
109
153
  end
110
- req = Net::HTTP::Post.new("/api/local/v1/#{action}")
111
- req.body = "username=#{CGI.escape(username)}&password=#{CGI.escape(password)}&branch=#{CGI.escape(branch || "")}&vae_local=1"
112
- res = VaeLocal.fetch_from_vaeplatform(site, req)
154
+ path = "/api/local/v1/#{action}"
155
+ if built_path
156
+ zip_path = "/tmp/vae_local_zip.zip"
157
+ Dir.chdir(built_path)
158
+ `zip -r "#{zip_path}" *`
159
+ res = RestClient.post(VaeLocal.vaeplatform_url(site) + path, file: File.open(zip_path, 'rb'), auth_key: auth_key, vae_local: "1")
160
+ `rm #{zip_path}`
161
+ else
162
+ req = Net::HTTP::Post.new(path)
163
+ req.body = "auth_key=#{CGI.escape(auth_key)}&branch=#{CGI.escape(branch || "")}&vae_local=1"
164
+ res = VaeLocal.fetch_from_vaeplatform(site, req)
165
+ end
113
166
  if res.is_a?(Net::HTTPFound)
114
167
  raise VaeError, "Invalid username/password or insufficient permissions."
115
168
  else
116
169
  show_job_status(res, site)
117
170
  end
171
+ rescue RestClient::Found
172
+ raise VaeError, "Invalid username/password or insufficient permissions."
118
173
  end
119
174
 
120
175
  def self.run_trapping_exceptions
data/lib/version.rb CHANGED
@@ -1 +1 @@
1
- VER = "0.8.4"
1
+ VER = "0.8.6"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vae
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Action Verb, LLC
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-01-25 00:00:00.000000000 Z
12
+ date: 2018-02-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chunky_png
@@ -151,6 +151,20 @@ dependencies:
151
151
  - - "~>"
152
152
  - !ruby/object:Gem::Version
153
153
  version: '1'
154
+ - !ruby/object:Gem::Dependency
155
+ name: rest-client
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - "~>"
159
+ - !ruby/object:Gem::Version
160
+ version: '2'
161
+ type: :runtime
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: '2'
154
168
  - !ruby/object:Gem::Dependency
155
169
  name: sass
156
170
  requirement: !ruby/object:Gem::Requirement