brisk 0.1.1 → 0.2.0

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: 4daa16b5c768b4813fe28e5242b265f6d989e929
4
- data.tar.gz: 9340e9f58325c4dea48080d982a75dfa92c75862
3
+ metadata.gz: 399ca02fec584349bbd680f46241c3fbb2ccd460
4
+ data.tar.gz: bd23cd438ac9b8a2565e8e953198bc5ddb4d7144
5
5
  SHA512:
6
- metadata.gz: 823564cfb0b65657dc8e54863307b9f81f61af90fa4bb27f9be4bddb6ec857f9f5365b0c7677cf53946472dc84ef47a5f48ec4b03fd205a52269b5b38c43d908
7
- data.tar.gz: d4f7efb1f0894cc35fd11487ff9a760108d138d368bab952b13d53fb2b760a542639e2b85aefc88c45201517428159e27312043c95285af7e404058b5f2e4e98
6
+ metadata.gz: 1a6c748372dc5f9dcf5353bc9f9fc4a09b9717f1dbf7be9b81e5c956164618ea7b9aecea66bcdaa0c0db9c6e449774208480fc8f83f255eccac21f6ead2252d8
7
+ data.tar.gz: ddce60ca094595a5145a472ca97e68751df3bcec8a4fe43e8aa0b39f8fa1fb85b147d4c530ca5d5739bcbce900d56410247917e29cee95c9c9580632ccbaf255
data/bin/brisk CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  dir = File.dirname(__FILE__)
4
4
 
5
- system "sudo ruby #{dir}/../lib/brisk.rb #{ARGV[0]}"
5
+ system "sudo ruby #{dir}/../lib/brisk.rb #{ARGV[0]} #{ARGV[1]}"
data/lib/brisk.rb CHANGED
@@ -4,7 +4,9 @@ require 'brisk/thin'
4
4
  require 'brisk/dnsmasq'
5
5
  require 'brisk/rerun'
6
6
  require 'brisk/constants'
7
+ require 'brisk/caddy'
7
8
  require 'brisk/server/server'
9
+ require 'brisk/server/site'
8
10
 
9
11
  class Valet < Thor
10
12
 
@@ -12,27 +14,35 @@ class Valet < Thor
12
14
  def install
13
15
  Thin.install
14
16
  Configuration.install
17
+ Caddy.install
15
18
  DnsMasq.install
16
19
  Rerun.install
17
20
  Thin.restart
21
+ Caddy.restart
18
22
  puts "Ruby Valet installed Successfully. Start adding directories by using brisk set".colorize(:green)
19
23
  end
20
24
 
25
+ desc "update", "Update your Brisk. Only use that when you downloaded a newer version"
26
+ def update
27
+ Thin.update
28
+ Thin.restart
29
+ end
30
+
21
31
  desc "set", "Set directory"
22
32
  def set
23
- Configuration.add_path(Dir.pwd)
33
+ Configuration.add('paths', Dir.pwd)
24
34
  puts "Successfully added directory".colorize(:green)
25
35
  end
26
36
 
27
37
  desc "unset", "Unset directory"
28
38
  def unset
29
- Configuration.remove_path(Dir.pwd)
39
+ Configuration.remove('paths', Dir.pwd)
30
40
  puts "Successfully removed directory".colorize(:green)
31
41
  end
32
42
 
33
43
  desc "kill", "Kill web server"
34
44
  def kill
35
- Server.kill(Constants::VALET_HOME)
45
+ Server.kill(Constants.valet_home)
36
46
  end
37
47
 
38
48
  desc "stop", "Stops the server"
@@ -45,9 +55,45 @@ class Valet < Thor
45
55
  Thin.stop
46
56
  end
47
57
 
58
+ desc "domain DOMAIN", "Sets a new domain"
59
+ def domain(value)
60
+ old_domain = Configuration.read['domain']
61
+
62
+ Configuration.update_domain(value)
63
+
64
+ DnsMasq.update_domain(value, old_domain)
65
+ Thin.restart
66
+
67
+ puts "Successfully set your domain to #{value}".colorize(:green)
68
+ end
69
+
70
+ desc "secure", "Secures the site with a SSL connection"
71
+ def secure
72
+ domain = dirname = File.basename(Dir.getwd) + '.' + Configuration.read['domain']
73
+
74
+ Site.secure(domain)
75
+ Configuration.add('secured', File.basename(Dir.getwd))
76
+ Caddy.restart
77
+
78
+ puts "Website successfully secured".colorize(:green)
79
+ end
80
+
81
+ desc "unsecure", "Unsecures the site from a SSL connection"
82
+ def unsecure
83
+ domain = dirname = File.basename(Dir.getwd) + '.' + Configuration.read['domain']
84
+
85
+ Site.unsecure(domain)
86
+ Configuration.remove('secured', File.basename(Dir.getwd))
87
+ Caddy.restart
88
+
89
+ puts "Website successfully unsecured".colorize(:green)
90
+ end
91
+
48
92
  desc "restart", "Restarts the server"
49
93
  def restart
50
94
  Thin.restart
95
+
96
+ puts "Server restarted".colorize(:green)
51
97
  end
52
98
  end
53
99
 
@@ -0,0 +1,63 @@
1
+ require 'brisk/configuration'
2
+ require 'brisk/constants'
3
+ class Caddy
4
+
5
+ def self.install
6
+ unless is_installed?
7
+ puts "Installing Caddy for you...".colorize(:green)
8
+ download
9
+ end
10
+
11
+ install_caddy_file
12
+ install_caddy_directory
13
+ install_caddy_daemon
14
+ end
15
+
16
+ def self.is_installed?
17
+ system "brew list | grep caddy >> /dev/null"
18
+
19
+ $? == 0
20
+ end
21
+
22
+ def self.download
23
+ system "sudo -u #{ENV['SUDO_USER']} brew install caddy"
24
+ end
25
+
26
+ def self.install_caddy_file
27
+ FileUtils.copy(File.expand_path("../../stubs/Caddyfile", __dir__), Constants.valet_home + '/Caddyfile')
28
+ file = File.read(Constants.valet_home + '/Caddyfile')
29
+ new_file = file.gsub("BRISK_HOME_PATH", Constants.valet_home)
30
+ File.open(Constants.valet_home + '/Caddyfile', 'w+') do |file|
31
+ file.write(new_file)
32
+ end
33
+ end
34
+
35
+ def self.install_caddy_directory
36
+ Configuration.create_dir(Constants.valet_home + '/Caddy')
37
+ File.new(Constants.valet_home + '/Caddy/.keep', 'w')
38
+ end
39
+
40
+ def self.install_caddy_daemon
41
+ path = File.expand_path("../../stubs/caddy_daemon.plist", __dir__)
42
+ file = File.read(path)
43
+ new_file = file.gsub("BRISK_HOME_PATH", Constants.valet_home)
44
+ File.open("/Library/LaunchDaemons/com.frankleef.caddyBriskServer.plist", "w+") do |file|
45
+ file.write(new_file)
46
+ end
47
+ end
48
+
49
+ def self.restart
50
+ stop
51
+
52
+ start
53
+ end
54
+
55
+ def self.start
56
+ system "launchctl load /Library/LaunchDaemons/com.frankleef.caddyBriskServer.plist > /dev/null"
57
+ end
58
+
59
+ def self.stop
60
+ system "launchctl unload /Library/LaunchDaemons/com.frankleef.caddyBriskServer.plist > /dev/null"
61
+ end
62
+
63
+ end
@@ -3,35 +3,44 @@ require 'fileutils'
3
3
  require 'json'
4
4
 
5
5
  class Configuration
6
- include Constants
6
+
7
7
  def self.install
8
- unless File.directory?(directory = Constants::VALET_HOME)
9
- FileUtils.mkdir_p(directory, :mode => 0755)
10
- end
8
+ create_dir(Constants.valet_home)
9
+ create_dir(Constants.valet_home + '/Certificates')
11
10
 
12
- unless File.directory?(drivers_directory = Constants::VALET_HOME + '/Drivers')
13
- FileUtils.mkdir_p(drivers_directory, :mode => 0755)
11
+ unless file_exists?(path)
12
+ write({:domain => 'dev', 'paths' => [], 'secured' => []})
14
13
  end
14
+ end
15
15
 
16
- unless File.directory?(path)
17
- write({:domain => 'dev', 'paths' => []})
16
+ def self.create_dir(directory)
17
+ unless dir_exists?(directory)
18
+ FileUtils.mkdir_p(directory, :mode => 0755)
18
19
  end
19
20
  end
20
21
 
21
- def self.add_path(path)
22
+ def self.dir_exists?(directory)
23
+ File.directory?(directory)
24
+ end
25
+
26
+ def self.file_exists?(file)
27
+ File.file?(file)
28
+ end
29
+
30
+ def self.add(key, value)
22
31
  config = read
23
- config['paths'].push(path)
32
+ config[key].push(value)
24
33
  write(config)
25
34
  end
26
35
 
27
- def self.remove_path(path)
36
+ def self.remove(key, value)
28
37
  config = read
29
- config['paths'].delete_if {|i| i == path}
38
+ config[key].delete_if {|i| i == value}
30
39
  write(config)
31
40
  end
32
41
 
33
42
  def self.path
34
- return Constants::VALET_HOME + '/config.json'
43
+ return Constants.valet_home + '/config.json'
35
44
  end
36
45
 
37
46
  def self.read
@@ -43,4 +52,10 @@ class Configuration
43
52
  f.write(config.to_json)
44
53
  end
45
54
  end
55
+
56
+ def self.update_domain(domain)
57
+ config = read
58
+ config['domain'] = domain
59
+ write(config)
60
+ end
46
61
  end
@@ -1,3 +1,13 @@
1
- module Constants
2
- VALET_HOME = ENV["HOME"] + '/.brisk'
1
+ class Constants
2
+
3
+ def self.valet_home
4
+ if ENV["HOME"].nil?
5
+ uid = File.stat(__FILE__).uid
6
+ home_dir = Etc.getpwuid(uid).dir
7
+ home_dir + "/.brisk"
8
+ return home_dir
9
+ end
10
+
11
+ return ENV["HOME"] + '/.brisk'
12
+ end
3
13
  end
data/lib/brisk/dnsmasq.rb CHANGED
@@ -2,15 +2,29 @@ require 'colorize'
2
2
 
3
3
  class DnsMasq
4
4
 
5
- def self.install
5
+ @config_path = '/usr/local/etc/dnsmasq.conf'
6
+ @example_config_path = '/usr/local/opt/dnsmasq/dnsmasq.conf.example'
7
+ @resolver_path = '/etc/resolver'
8
+
9
+
10
+ class << self
11
+ attr_accessor :config_path
12
+ attr_accessor :example_config_path
13
+ attr_accessor :resolver_path
14
+ attr_accessor :dnsmasq_path
15
+ end
16
+
17
+
18
+ def self.install(domain = 'dev')
19
+
6
20
  unless is_installed?
7
21
  puts "Installing DnsMasq...".colorize(:green)
8
22
  download
9
23
  end
10
24
 
11
- create_custom_configuration
25
+ create_custom_configuration(domain)
12
26
 
13
- create_resolver
27
+ create_resolver(domain)
14
28
 
15
29
  system "brew services restart dnsmasq > /dev/null"
16
30
  end
@@ -25,28 +39,37 @@ class DnsMasq
25
39
  system "sudo -u #{ENV['SUDO_USER']} brew install dnsmasq"
26
40
  end
27
41
 
28
- def self.create_custom_configuration
29
- dnsmasq_path = "/Users/#{ENV['SUDO_USER']}/.brisk/dnsmasq.conf"
42
+ def self.create_custom_configuration(domain)
30
43
 
31
- unless File.file?('/usr/local/etc/dnsmasq.conf')
32
- FileUtils.copy('/usr/local/opt/dnsmasq/dnsmasq.conf.example','/usr/local/etc/dnsmasq.conf')
44
+ unless File.file?(config_path)
45
+ FileUtils.copy(example_config_path,config_path)
33
46
  end
34
47
 
35
- if File.read('/usr/local/etc/dnsmasq.conf').index(dnsmasq_path) == nil
36
- File.open('/usr/local/etc/dnsmasq.conf', 'a') { |f| f.puts "conf-file=" + dnsmasq_path }
48
+ if File.read(config_path).index(dnsmasq_path) == nil
49
+ File.open(config_path, 'a') { |f| f.puts "conf-file=" + dnsmasq_path }
37
50
  end
38
51
 
39
- File.write(dnsmasq_path, 'address=/.dev/127.0.0.1')
52
+ File.write(dnsmasq_path, "address=/.#{domain}/127.0.0.1")
40
53
  end
41
54
 
42
- def self.create_resolver
43
- unless File.directory?('/etc/resolver')
44
- FileUtils.mkdir_p('/etc/resolver')
55
+ def self.create_resolver(domain)
56
+ unless File.directory?(resolver_path)
57
+ FileUtils.mkdir_p(resolver_path)
45
58
  end
46
59
 
47
60
  # File.write('etc/resolver/dev', 'nameserver 127.0.0.1')
48
- File.open('/etc/resolver/dev', 'w+') do |f|
61
+ File.open("#{resolver_path}/#{domain}", 'w+') do |f|
49
62
  f.write('nameserver 127.0.0.1')
50
63
  end
51
64
  end
65
+
66
+ def self.update_domain(domain, old_domain)
67
+ File.delete("#{resolver_path}/#{old_domain}")
68
+
69
+ install(domain)
70
+ end
71
+
72
+ def self.dnsmasq_path
73
+ "#{ENV['HOME']}/.brisk/dnsmasq.conf"
74
+ end
52
75
  end
@@ -6,7 +6,7 @@ class BriskRequestHelper
6
6
  end
7
7
 
8
8
  def get_site
9
- @request.host[0..-5]
9
+ @request.host.split('.')[0]
10
10
  end
11
11
 
12
12
  def valet_home_path
@@ -1,5 +1,7 @@
1
1
  require 'brisk/server/proxy'
2
2
  require 'brisk/server/server_middleware'
3
+ require 'brisk/server/https_middleware'
3
4
 
4
5
  use ServerMiddleware
6
+ use HttpsMiddleware
5
7
  run AppProxy.new
@@ -0,0 +1,18 @@
1
+ require 'brisk/server/site'
2
+ require 'brisk/server/brisk_request_helper'
3
+ class HttpsMiddleware
4
+
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ request = BriskRequestHelper.new env
11
+ site = request.get_site
12
+ #
13
+ # return @app.call(env) unless Site.is_secured?(site)
14
+
15
+
16
+ @app.call(env)
17
+ end
18
+ end
@@ -1,7 +1,7 @@
1
1
  class Pid
2
2
 
3
3
  def self.write(path, pid)
4
- File.open("#{path}/pid.txt", 'w') do |f|
4
+ File.open("#{path}/pid.txt", 'w+') do |f|
5
5
  f.write(pid)
6
6
  end
7
7
 
@@ -16,12 +16,21 @@ class AppProxy < Rack::Proxy
16
16
  request = BriskRequestHelper.new env
17
17
  site = request.get_site
18
18
  valet_home_path = request.valet_home_path
19
+ config = request.get_config
20
+ site_path = Site.get_site_paths(config, site)
19
21
 
20
22
  # Kill existing servers, so we don't get conflitcs
21
23
  if Server.is_running(valet_home_path)
22
24
 
23
25
  if Site.read_site(valet_home_path) == site
24
- env["HTTP_HOST"] = "localhost:3000"
26
+ if Site.is_secured?(config, site)
27
+ env["SERVER_PORT"] = "443" if env["SERVER_PORT"] == "80"
28
+ env["rack.url_scheme"] = "https" if env["rack.url_scheme"] == "http"
29
+ env["rack.ssl_verify_none"] = true
30
+ env["HTTP_HOST"] = "localhost:3003"
31
+ return env
32
+ end
33
+ env["HTTP_HOST"] = "localhost:3001"
25
34
  return env
26
35
  end
27
36
 
@@ -29,28 +38,37 @@ class AppProxy < Rack::Proxy
29
38
  Server.shutdown(existing_pid)
30
39
  end
31
40
 
32
- config = request.get_config
33
41
 
34
- valet_site_path = nil
42
+ if Site.is_secured?(config, site)
35
43
 
36
- # Check if we can find a folder based on the URL
37
- config['paths'].each do |path|
38
- if File.directory?("/#{path}/#{site}")
39
- if File.file?("/#{path}/#{site}/config.ru")
40
- valet_site_path = "/#{path}/#{site}"
41
- end
44
+ Server.start_https(site_path)
45
+ # Check if proccess is up and running
46
+ started = Server.is_started(site_path)
47
+
48
+ # Write the pid to a file so we can delete it later on
49
+ if started
50
+ pid = Pid.read(site_path)
51
+ Pid.write(valet_home_path, pid)
52
+ Site.write_site(valet_home_path, site)
42
53
  end
54
+
55
+ env["SERVER_PORT"] = "443" if env["SERVER_PORT"] == "80"
56
+ env["rack.url_scheme"] = "https" if env["rack.url_scheme"] == "http"
57
+ env["rack.ssl_verify_none"] = true
58
+ env["HTTP_HOST"] = "localhost:3003"
59
+ sleep(1)
60
+ return env
43
61
  end
44
62
 
45
63
  # Boot up the server
46
- Server.start(valet_site_path)
64
+ Server.start(site_path)
47
65
 
48
66
  # Check if proccess is up and running
49
- started = Server.is_started(valet_site_path)
67
+ started = Server.is_started(site_path)
50
68
 
51
69
  # Write the pid to a file so we can delete it later on
52
70
  if started
53
- pid = Pid.read(valet_site_path)
71
+ pid = Pid.read(site_path)
54
72
  Pid.write(valet_home_path, pid)
55
73
  Site.write_site(valet_home_path, site)
56
74
  end
@@ -63,12 +81,12 @@ class AppProxy < Rack::Proxy
63
81
  raise Exception.new "Brisk is not able to run the server.. Connection refused" if counter == 10
64
82
 
65
83
  sleep(0.5)
66
- uri = URI('http://localhost:3000')
84
+ uri = URI('http://localhost:3001')
67
85
 
68
86
  begin
69
87
  # Check if the server is up and running. Find a cleaner way to do this
70
88
  Net::HTTP.get(uri)
71
- env['HTTP_HOST'] = 'localhost:3000'
89
+ env['HTTP_HOST'] = 'localhost:3001'
72
90
  return env
73
91
  rescue Errno::ECONNREFUSED
74
92
  run(env, counter + 1)
@@ -18,12 +18,17 @@ class Server
18
18
  end
19
19
 
20
20
  def self.start(path)
21
- spawn "cd #{path} && /usr/local/bin/rerun \"/usr/local/bin/thin -d -R config.ru -a localhost -p 3000 start\""
21
+ spawn "cd #{path} && /usr/local/bin/rerun \"/usr/local/bin/thin -d -R config.ru -a localhost -p 3001 start\""
22
+ end
23
+
24
+ def self.start_https(path)
25
+ spawn "cd #{path} && /usr/local/bin/thin start -d -R config.ru -a localhost -p 3003 --ssl"
22
26
  end
23
27
 
24
28
  def self.is_started(path, counter = 0)
29
+ sleep(0.5)
30
+
25
31
  if Pid.exists?(path)
26
- sleep(0.5)
27
32
  pid = Pid.read(path)
28
33
  if Pid.alive?(pid)
29
34
  return true
@@ -1,4 +1,5 @@
1
1
  require 'brisk/server/brisk_request_helper'
2
+ require 'brisk/server/site'
2
3
 
3
4
  class ServerMiddleware
4
5
  def initialize(app)
@@ -12,17 +13,9 @@ class ServerMiddleware
12
13
 
13
14
  config = request.get_config
14
15
 
15
- valet_site_path = nil
16
+ site_path = Site.get_site_paths(config, site)
16
17
 
17
- config['paths'].each do |path|
18
- if File.directory?("/#{path}/#{site}")
19
- if File.file?("/#{path}/#{site}/config.ru")
20
- valet_site_path = "/#{path}/#{site}"
21
- end
22
- end
23
- end
24
-
25
- if valet_site_path.nil?
18
+ if site_path.nil?
26
19
  return [404, {}, ['Not found']]
27
20
  end
28
21
 
@@ -1,4 +1,70 @@
1
+ require 'brisk/configuration'
2
+ require 'brisk/constants'
3
+
1
4
  class Site
5
+
6
+ def self.secure(url)
7
+ unsecure(url)
8
+
9
+ Configuration.create_dir(certificates_path)
10
+ create_certificate(url)
11
+
12
+ caddy_file = build_secure_caddy_file(url)
13
+
14
+ File.open("#{Constants.valet_home}/Caddy/#{url}", "w+") do |f|
15
+ f.write(caddy_file)
16
+ end
17
+ end
18
+
19
+ def self.create_certificate(url)
20
+ key_path = certificates_path + "/#{url}.key"
21
+ csr_path = certificates_path + "/#{url}.csr"
22
+ crt_path = certificates_path + "/#{url}.crt"
23
+
24
+ create_private_key(key_path)
25
+ create_signing_request(url, key_path, csr_path)
26
+
27
+ system "openssl x509 -req -days 365 -in #{csr_path} -signkey #{key_path} -out #{crt_path}"
28
+
29
+ trust_certificate(crt_path)
30
+ end
31
+
32
+ def self.is_secured?(config, site)
33
+ config['secured'].include?(site)
34
+ end
35
+
36
+ def self.create_private_key(key_path)
37
+ system "openssl genrsa -out #{key_path} 2048"
38
+ end
39
+
40
+ def self.create_signing_request(url, key_path, csr_path)
41
+ system "openssl req -new -subj \"/C=/ST=/O=/localityName=/commonName=#{url}/organizationalUnitName=/emailAddress=/\" -key #{key_path} -out #{csr_path} -passin pass:"
42
+ end
43
+
44
+ def self.trust_certificate(crt_path)
45
+ system "sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain #{crt_path}"
46
+ end
47
+
48
+ def self.build_secure_caddy_file(url)
49
+ path = File.expand_path("../../../stubs/secureCaddyfile", __dir__)
50
+ file = File.read(path)
51
+ new_file = file.gsub("BRISK_SITE", url)
52
+ new_file = new_file.gsub("BRISK_CERT", "#{certificates_path}/#{url}.crt")
53
+ new_file = new_file.gsub("BRISK_KEY", "#{certificates_path}/#{url}.key")
54
+ return new_file
55
+ end
56
+
57
+ def self.unsecure(url)
58
+ if File.exists?("#{certificates_path}/#{url}.crt")
59
+ File.delete("#{Constants.valet_home}/Caddy/#{url}")
60
+
61
+ File.delete("#{certificates_path}/#{url}.key")
62
+ File.delete("#{certificates_path}/#{url}.csr")
63
+ File.delete("#{certificates_path}/#{url}.crt")
64
+ system "sudo security delete-certificate -c #{url} -t"
65
+ end
66
+ end
67
+
2
68
  def self.write_site(path, site)
3
69
  File.open("#{path}/site.txt", "w+") do |f|
4
70
  f.write(site)
@@ -14,4 +80,22 @@ class Site
14
80
  def self.site_file_exists?(path)
15
81
  File.file?("#{path}/site.txt")
16
82
  end
83
+
84
+ def self.get_site_paths(config, site)
85
+ site_path = nil
86
+
87
+ config['paths'].each do |path|
88
+ if File.directory?("/#{path}/#{site}")
89
+ if File.file?("/#{path}/#{site}/config.ru")
90
+ site_path = "/#{path}/#{site}"
91
+ end
92
+ end
93
+ end
94
+
95
+ site_path
96
+ end
97
+
98
+ def self.certificates_path
99
+ Constants.valet_home + '/Certificates'
100
+ end
17
101
  end
data/lib/brisk/thin.rb CHANGED
@@ -14,15 +14,39 @@ class Thin
14
14
  end
15
15
  end
16
16
 
17
- path = File.expand_path("../../stubs/daemon.plist", __dir__)
18
- server = File.expand_path("server/config.ru", __dir__)
17
+ install_daemon
18
+ install_secure_daemon
19
19
 
20
- file = File.read(path)
20
+ end
21
21
 
22
- new_file = file.gsub("SERVER_PATH", server)
23
- File.open("/Library/LaunchDaemons/com.frankleef.briskServer.plist", "w+") do |file|
24
- file.write(new_file)
25
- end
22
+ def self.update
23
+ system "sudo rm /Library/LaunchDaemons/com.frankleef.briskServer.plist >> /dev/null"
24
+ system "sudo rm /Library/LaunchDaemons/com.frankleef.rubyValetServer.plist >> /dev/null"
25
+ install
26
+ end
27
+
28
+ def self.install_daemon
29
+ path = File.expand_path("../../stubs/daemon.plist", __dir__)
30
+ server = File.expand_path("server/config.ru", __dir__)
31
+
32
+ file = File.read(path)
33
+
34
+ new_file = file.gsub("SERVER_PATH", server)
35
+ File.open("/Library/LaunchDaemons/com.frankleef.briskServer.plist", "w+") do |file|
36
+ file.write(new_file)
37
+ end
38
+ end
39
+
40
+ def self.install_secure_daemon
41
+ path = File.expand_path("../../stubs/secure_daemon.plist", __dir__)
42
+ server = File.expand_path("server/config.ru", __dir__)
43
+
44
+ file = File.read(path)
45
+
46
+ new_file = file.gsub("SERVER_PATH", server)
47
+ File.open("/Library/LaunchDaemons/com.frankleef.briskSecureServer.plist", "w+") do |file|
48
+ file.write(new_file)
49
+ end
26
50
  end
27
51
 
28
52
  def self.download
@@ -45,9 +69,11 @@ class Thin
45
69
 
46
70
  def self.start
47
71
  system "launchctl load /Library/LaunchDaemons/com.frankleef.briskServer.plist > /dev/null"
72
+ system "launchctl load /Library/LaunchDaemons/com.frankleef.briskSecureServer.plist > /dev/null"
48
73
  end
49
74
 
50
75
  def self.stop
51
76
  system "launchctl unload /Library/LaunchDaemons/com.frankleef.briskServer.plist > /dev/null"
77
+ system "launchctl unload /Library/LaunchDaemons/com.frankleef.briskSecureServer.plist > /dev/null"
52
78
  end
53
79
  end
data/lib/brisk/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Brisk
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/stubs/Caddyfile ADDED
@@ -0,0 +1,7 @@
1
+ import BRISK_HOME_PATH/Caddy/*
2
+
3
+ :80 {
4
+ proxy / http://localhost:3000 {
5
+ proxy_header Host {host}
6
+ }
7
+ }
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>Label</key>
6
+ <string>com.frankleef.caddyBriskServer</string>
7
+ <key>ProgramArguments</key>
8
+ <array>
9
+ <string>/usr/local/bin/caddy</string>
10
+ <string>--conf=BRISK_HOME_PATH/Caddyfile</string>
11
+ </array>
12
+ <key>RunAtLoad</key>
13
+ <true/>
14
+ <key>StandardOutput</key>
15
+ <string>/tmp/com.frankleef.caddyBriskServer.out</string>
16
+ <key>StandardErrorPath</key>
17
+ <string>/tmp/com.frankleef.caddyBriskServer.err</string>
18
+ </dict>
19
+ </plist>
data/stubs/daemon.plist CHANGED
@@ -3,7 +3,7 @@
3
3
  <plist version="1.0">
4
4
  <dict>
5
5
  <key>Label</key>
6
- <string>com.frankleef.rubyValetServer</string>
6
+ <string>com.frankleef.briskServer</string>
7
7
  <key>ProgramArguments</key>
8
8
  <array>
9
9
  <string>/usr/local/bin/thin</string>
@@ -11,7 +11,7 @@
11
11
  <string>-R</string>
12
12
  <string>SERVER_PATH</string>
13
13
  <string>-p</string>
14
- <string>80</string>
14
+ <string>3000</string>
15
15
  </array>
16
16
  <key>RunAtLoad</key>
17
17
  <true/>
@@ -0,0 +1,12 @@
1
+ http://BRISK_SITE:80 {
2
+ redir https://{host}{uri}
3
+ }
4
+
5
+ https://BRISK_SITE:443 {
6
+ tls BRISK_CERT BRISK_KEY
7
+
8
+ proxy / https://localhost:3002 {
9
+ proxy_header Host {host}
10
+ insecure_skip_verify
11
+ }
12
+ }
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>Label</key>
6
+ <string>com.frankleef.briskSecureServer</string>
7
+ <key>ProgramArguments</key>
8
+ <array>
9
+ <string>/usr/local/bin/thin</string>
10
+ <string>start</string>
11
+ <string>-R</string>
12
+ <string>SERVER_PATH</string>
13
+ <string>-p</string>
14
+ <string>3002</string>
15
+ <string>--ssl</string>
16
+ </array>
17
+ <key>RunAtLoad</key>
18
+ <true/>
19
+ <key>StandardOutput</key>
20
+ <string>/tmp/com.frankleef.briskSecureServer.out</string>
21
+ <key>StandardErrorPath</key>
22
+ <string>/tmp/com.frankleef.briskSecureServer.err</string>
23
+ </dict>
24
+ </plist>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brisk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-15 00:00:00.000000000 Z
11
+ date: 2016-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fakefs
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.1
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: thor
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -104,12 +118,14 @@ extra_rdoc_files: []
104
118
  files:
105
119
  - bin/brisk
106
120
  - lib/brisk.rb
121
+ - lib/brisk/caddy.rb
107
122
  - lib/brisk/configuration.rb
108
123
  - lib/brisk/constants.rb
109
124
  - lib/brisk/dnsmasq.rb
110
125
  - lib/brisk/rerun.rb
111
126
  - lib/brisk/server/brisk_request_helper.rb
112
127
  - lib/brisk/server/config.ru
128
+ - lib/brisk/server/https_middleware.rb
113
129
  - lib/brisk/server/pid.rb
114
130
  - lib/brisk/server/proxy.rb
115
131
  - lib/brisk/server/server.rb
@@ -117,7 +133,11 @@ files:
117
133
  - lib/brisk/server/site.rb
118
134
  - lib/brisk/thin.rb
119
135
  - lib/brisk/version.rb
136
+ - stubs/Caddyfile
137
+ - stubs/caddy_daemon.plist
120
138
  - stubs/daemon.plist
139
+ - stubs/secureCaddyfile
140
+ - stubs/secure_daemon.plist
121
141
  homepage: https://www.github.com/frankieleef/brisk
122
142
  licenses:
123
143
  - MIT