local_pac 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- local_pac (0.2.3)
4
+ local_pac (0.3.0)
5
5
  activesupport
6
6
  addressable
7
7
  bootstrap-sass
@@ -16,6 +16,8 @@ PATH
16
16
  rugged
17
17
  sass
18
18
  sinatra
19
+ sinatra-contrib
20
+ sinatra-param
19
21
  sprockets
20
22
  sprockets-helpers
21
23
  sprockets-sass
@@ -41,6 +43,7 @@ GEM
41
43
  ast (1.1.0)
42
44
  atomic (1.1.14)
43
45
  awesome_print (1.2.0)
46
+ backports (3.6.0)
44
47
  blockenspiel (0.4.5)
45
48
  bond (0.5.1)
46
49
  bootstrap-sass (3.1.1.0)
@@ -184,16 +187,25 @@ GEM
184
187
  rack (~> 1.4)
185
188
  rack-protection (~> 1.4)
186
189
  tilt (~> 1.3, >= 1.3.4)
190
+ sinatra-contrib (1.4.2)
191
+ backports (>= 2.0)
192
+ multi_json
193
+ rack-protection
194
+ rack-test
195
+ sinatra (~> 1.4.0)
196
+ tilt (~> 1.3)
197
+ sinatra-param (1.1.1)
198
+ sinatra (~> 1.3)
187
199
  slop (3.4.7)
188
200
  sparkr (0.4.1)
189
- sprockets (2.10.1)
201
+ sprockets (2.11.0)
190
202
  hike (~> 1.2)
191
203
  multi_json (~> 1.0)
192
204
  rack (~> 1.0)
193
205
  tilt (~> 1.1, != 1.3.0)
194
206
  sprockets-helpers (1.1.0)
195
207
  sprockets (~> 2.0)
196
- sprockets-sass (1.0.2)
208
+ sprockets-sass (1.0.3)
197
209
  sprockets (~> 2.0)
198
210
  tilt (~> 1.1)
199
211
  sys-proctable (0.9.3)
@@ -1,44 +1,64 @@
1
1
  # encoding: utf-8
2
- require 'haml'
3
- require 'i18n'
4
- require 'i18n/backend/fallbacks'
5
- require 'rack/contrib/locale'
6
- require 'sprockets-helpers'
7
- require 'sass'
8
- require 'sinatra'
9
-
10
2
  module LocalPac
11
3
  module App
12
4
  class ApplicationController < Sinatra::Base
5
+
6
+ @local_storage_mutex = Mutex.new
7
+
8
+ class << self
9
+ attr_reader :local_storage_mutex
10
+ end
11
+
13
12
  set :root, ::File.expand_path('../../', __FILE__)
14
13
  set :haml, :format => :html5
15
14
 
16
15
  def local_storage
17
16
  return @local_storage if @local_storage
18
17
 
19
- if settings.respond_to? :local_storage
20
- @local_storage = settings.local_storage
21
- else
22
- @local_storage = LocalPac::LocalStorage.new
18
+ ApplicationController.local_storage_mutex.synchronize do
19
+ if settings.respond_to? :local_storage
20
+ LocalPac.ui_logger.debug 'Using local storage in production mode: loaded once on startup'
21
+ @local_storage = settings.local_storage
22
+ else
23
+ LocalPac.ui_logger.debug 'Using local storage in development mode: reloaded per request'
24
+ @local_storage = LocalPac::LocalStorage.new
25
+ end
23
26
  end
24
27
  end
25
28
 
26
29
  use Rack::Deflater
27
30
  use Rack::Locale
31
+ use Rack::NestedParams
32
+ use Rack::PostBodyContentTypeParser
28
33
 
29
34
  not_found do
30
- I18n.t('errors.not_found', name: env['sinatra.error'].message)
35
+ @error_summary = I18n.t('errors.unknown_proxy_pac.summary')
36
+ @error_details = I18n.t('errors.unknown_proxy_pac.details', name: env['PATH_INFO'])
37
+
38
+ halt 404, haml(:error, layout: :application)
31
39
  end
32
40
 
33
41
  error do
34
- I18n.t('errors.default', message: env['sinatra.error'].message)
42
+ @error_summary = I18n.t('errors.default.summary')
43
+ @error_details = I18n.t('errors.default.details')
44
+
45
+ halt 500, haml(:error, layout: :application)
35
46
  end
36
47
 
37
48
  error Exceptions::GivenUrlInvalid do
38
- @error_summary = I18n.t('errors.invalid_url.summary')
49
+ @error_summary = I18n.t('errors.invalid_url.summary')
39
50
  @error_details = I18n.t('errors.invalid_url.details', url: env['sinatra.error'].message)
40
51
 
41
- haml :error, layout: :application
52
+ halt 401, haml(:error, layout: :application)
53
+ end
54
+
55
+ set :raise_sinatra_param_exceptions, true
56
+
57
+ error Sinatra::Param::InvalidParameterError do
58
+ @error_summary = I18n.t('errors.invalid_parameter.summary')
59
+ @error_details = I18n.t('errors.invalid_parameter.details', parameter: env['sinatra.error'].param)
60
+
61
+ halt 401, haml(:error, layout: :application)
42
62
  end
43
63
 
44
64
  configure :profile do
@@ -58,6 +78,10 @@ module LocalPac
58
78
 
59
79
  configure :development do
60
80
  set :raise_errors, true
81
+
82
+ before do
83
+ LocalPac.ui_logger.debug "Parameters: " + params.to_s
84
+ end
61
85
  end
62
86
 
63
87
  configure :test do
@@ -86,7 +110,6 @@ module LocalPac
86
110
  I18n.t(*args)
87
111
  end
88
112
  end
89
-
90
113
  end
91
114
  end
92
115
  end
@@ -0,0 +1,69 @@
1
+ # encoding: utf-8
2
+ module LocalPac
3
+ module App
4
+ class GitHookController < ApplicationController
5
+
6
+ helpers Sinatra::Param
7
+ helpers Sinatra::JSON
8
+
9
+ not_found do
10
+ halt 404, json(
11
+ error_summary: I18n.t('errors.unknown_git_hook.summary'),
12
+ error_details: I18n.t('errors.unknown_git_hook.details', name: env['PATH_INFO']),
13
+ result: :failure,
14
+ )
15
+ end
16
+
17
+ error do
18
+ halt 500, json(
19
+ error_summary: I18n.t('errors.default.summary'),
20
+ error_details: I18n.t('errors.default.details'),
21
+ result: :failure,
22
+ )
23
+ end
24
+
25
+ error Exceptions::GivenUrlInvalid do
26
+ halt 401, json(
27
+ error_summary: I18n.t('errors.invalid_url.summary'),
28
+ error_details: I18n.t('errors.invalid_url.details', url: env['sinatra.error'].message),
29
+ result: :failure,
30
+ )
31
+ end
32
+
33
+ set :raise_sinatra_param_exceptions, true
34
+
35
+ error Sinatra::Param::InvalidParameterError do
36
+ halt 401, json(
37
+ error_summary: I18n.t('errors.invalid_parameter.summary'),
38
+ error_details: I18n.t('errors.invalid_parameter.details', parameter: env['sinatra.error'].param),
39
+ result: :failure,
40
+ )
41
+ end
42
+
43
+ error Exceptions::PacFileInvalid do
44
+ halt 403, json(
45
+ error_summary: I18n.t('errors.invalid_pac_file.summary'),
46
+ error_details: I18n.t('errors.invalid_pac_file.details', name: env['sinatra.error']),
47
+ result: :failure,
48
+ )
49
+ end
50
+
51
+ post '/pre-receive' do
52
+ param :old_commit_id, String, required: true
53
+ param :new_commit_id, String, required: true
54
+ param :reference, String, required: true
55
+ param :api_key, String, required: true
56
+
57
+ repo = GitRepository.new(LocalPac.config.local_storage)
58
+ files = repo.added_files(params[:old_commit_id], params[:new_commit_id])
59
+ validator = PacFileValidator.new
60
+
61
+ LocalPac.ui_logger.debug "Files found: " + files.to_s
62
+
63
+ fail Exceptions::PacFileInvalid if files.any? { |f| !validator.valid?(f) }
64
+
65
+ json result: :success
66
+ end
67
+ end
68
+ end
69
+ end
data/app/locales/en.yml CHANGED
@@ -2,11 +2,24 @@
2
2
  en:
3
3
  errors:
4
4
  invalid_proxy_pac: The requested proxy.pac-file "%{name}" is invalid.
5
- not_found: Sorry, but I cannot find proxy.pac-file "%{name}".
5
+ unknown_proxy_pac:
6
+ summary: Unknown ProxyPac-file...
7
+ details: Sorry, but I cannot find proxy.pac-file "%{name}".
8
+ unknown_git_hook:
9
+ summary: Unknown git hook...
10
+ details: Sorry, but I cannot find git hook "%{name}".
6
11
  invalid_url:
7
- summary: 'Invalid URL...'
8
- details: 'Sorry, but your request is invalid. The URL "%{url}" is not a correct one. Allowed are URLs like "http://www.example.org" or "www.example.org".'
9
- default: Sorry, but I cannot full your request. %{message}. Please ask your administrator for support.
12
+ summary: Invalid URL...
13
+ details: Sorry, but your request is invalid. The URL "%{url}" is not a correct one. Allowed are URLs like "http://www.example.org" or "www.example.org".
14
+ default:
15
+ summary: Unexpected Error...
16
+ details: Sorry, but I cannot full your request. Please ask your administrator for support.
17
+ invalid_parameter:
18
+ summary: Invalid Parameter...
19
+ details: Sorry, but your request is invalid. The parameter "%{parameter}" is unknown or the format given cannot be accepted.
20
+ invalid_pac_file:
21
+ summary: Invalid PAC-file...
22
+ details: Sorry, but your push request is invalid. The pac-file "%{name}" is invalid.
10
23
  models:
11
24
  data:
12
25
  request_type: Request Type
data/bin/local_pac CHANGED
@@ -7,8 +7,8 @@ module LocalPac
7
7
  module Cli
8
8
  class Main < Thor
9
9
  class_option :config_file, type: :string, desc: 'Config file'
10
- class_option :log_level, type: :string, desc: 'Log level for ui logging'
11
- class_option :debug, type: :boolean, default: false, desc: 'Run application in debug mode'
10
+ class_option :log_level, default: 'info', type: :string, desc: 'Log level for ui logging'
11
+ class_option :debug_mode, type: :boolean, desc: 'Run application in debug mode'
12
12
 
13
13
  no_commands {
14
14
  include LocalPac::Cli::Helper
@@ -16,17 +16,20 @@ module LocalPac
16
16
 
17
17
  desc 'serve', 'Serve pacfiles'
18
18
  option :access_log, type: :string, desc: 'File to write access log to'
19
- option :listen, type: :string, default: 'tcp://localhost:8000', desc: 'Listen for requests'
20
- option :rack_environment, type: :string, default: 'production', desc: 'Rack environment for application'
19
+ option :listen, type: :string, desc: 'Listen for requests'
20
+ option :environment, type: :string, desc: 'Rack environment for application'
21
21
  option :with, type: :string, default: 'puma', desc: 'Server used to serve proxy pac'
22
22
  def serve
23
23
  LocalPac.config = LocalPac::Config.new(options[:config_file]) if options[:config_file]
24
24
  LocalPac.config.access_log = options[:access_log] if options[:access_log]
25
-
25
+ LocalPac.config.log_level = options[:log_level] if options[:log_level]
26
+ LocalPac.config.debug_mode = options[:debug_mode] if options[:debug_mode]
27
+ LocalPac.config.environment = options[:environment] if options[:environment]
28
+ LocalPac.config.listen = options[:listen] if options[:listen]
26
29
  LocalPac.config.lock
27
30
 
28
- set_log_level(options[:log_level])
29
- set_debug(options[:debug])
31
+ LocalPac.ui_logger.level = LocalPac.config.log_level
32
+ LocalPac.enable_debug_mode if LocalPac.config.debug_mode
30
33
 
31
34
  LocalPac.ui_logger.debug('Options: ' + options.to_s)
32
35
  LocalPac.ui_logger.debug("Config:\n" + LocalPac.config.to_s)
@@ -41,36 +44,83 @@ module LocalPac
41
44
  end
42
45
 
43
46
  command = command_klass.new(
44
- listen: options[:listen],
45
- environment: options[:rack_environment],
47
+ listen: LocalPac.config.listen,
48
+ environment: LocalPac.config.environment,
46
49
  )
47
50
 
51
+ ENV['DEBUG'] = LocalPac.config.debug_mode.to_s if LocalPac.config.debug_mode
52
+ ENV['ACCESS_LOG'] = LocalPac.config.access_log.to_s if LocalPac.config.access_log
53
+ ENV['LOG_LEVEL'] = LocalPac.config.log_level.to_s if LocalPac.config.log_level
54
+
48
55
  Server.new(command).start
49
56
  end
50
57
 
51
58
  desc 'init', 'Create files/directories to use local_pac in dir or $PWD'
52
59
  option :force, type: :boolean, default: false, desc: 'Overwrite existing files?'
53
60
  option :pre_seed, type: :boolean, default: false, desc: 'Add some example files to git repository'
61
+ option :config_file, type: :string, desc: 'Path to config file'
62
+
63
+ option :local_storage, type: :string, desc: 'Path to local storage'
64
+ option :pid_file, type: :string, desc: 'Path to pid file'
65
+ option :access_log, type: :string, desc: 'Path to access log'
66
+ option :sass_cache, type: :string, desc: 'Path to sass cache'
67
+ option :reload_config_signal, type: :string, desc: 'Signal to reload config'
68
+ option :reload_storage_signal, type: :string, desc: 'Signal to reload local storage'
69
+ option :api_key, type: :string, desc: 'API key for communication between git hook and web application'
70
+ option :listen, type: :string, desc: 'Listen statement for rack server'
71
+ option :environment, type: :string, desc: 'Default environment for rack server'
72
+
73
+ option :create_pid_directory, type: :boolean, desc: 'Create pid directory', default: true
74
+ option :create_log_directory, type: :boolean, desc: 'Create log directory', default: true
75
+ option :create_sass_cache, type: :boolean, desc: 'Create sass cache directory', default: true
76
+ option :create_local_storage, type: :boolean, desc: 'Create local storage directory', default: true
77
+ option :create_pre_receive_hook, type: :boolean, desc: 'Create pre receive hook', default: true
78
+ option :create_config_file, type: :boolean, desc: 'Create config_directory', default: true
54
79
  def init
55
80
  LocalPac.config = LocalPac::Config.new(options[:config_file]) if options[:config_file]
81
+
82
+ LocalPac.config.log_level = options[:log_level] if options[:log_level]
83
+ LocalPac.config.debug_mode = options[:debug_mode] if options[:debug_mode]
84
+ LocalPac.config.local_storage = options[:local_storage] if options[:local_storage]
85
+ LocalPac.config.pid_file = options[:pid_file] if options[:pid_file]
86
+ LocalPac.config.access_log = options[:access_log] if options[:access_log]
87
+ LocalPac.config.sass_cache = options[:sass_cache] if options[:sass_cache]
88
+ LocalPac.config.reload_config_signal = options[:reload_config_signal] if options[:reload_config_signal]
89
+ LocalPac.config.reload_storage_signal = options[:reload_storage_signal] if options[:reload_storage_signal]
90
+ LocalPac.config.log_level = options[:log_level] if options[:log_level]
91
+ LocalPac.config.api_key = options[:api_key] if options[:api_key]
92
+ LocalPac.config.listen = options[:listen] if options[:listen]
93
+ LocalPac.config.environment = options[:environment] if options[:environment]
94
+
56
95
  LocalPac.config.lock
57
96
 
58
- set_log_level(options[:log_level])
59
- set_debug(options[:debug])
97
+ LocalPac.ui_logger.level = LocalPac.config.log_level
98
+ LocalPac.enable_debug_mode if LocalPac.config.debug_mode
60
99
 
61
100
  LocalPac.ui_logger.debug('Options: ' + options.to_s)
62
101
  LocalPac.ui_logger.debug("Config:\n" + LocalPac.config.to_s)
63
102
 
64
- Initializer.new(force: options[:force], pre_seed: options[:pre_seed]).run
103
+ Initializer.new(
104
+ force: options[:force],
105
+ pre_seed: options[:pre_seed],
106
+ create_pid_directory: options[:create_pid_directory],
107
+ create_log_directory: options[:create_log_directory],
108
+ create_sass_cache: options[:create_sass_cache],
109
+ create_local_storage: options[:create_local_storage],
110
+ create_pre_receive_hook: options[:create_pre_receive_hook],
111
+ create_config_file: options[:create_config_file],
112
+ ).run
65
113
  end
66
114
 
67
115
  desc 'status', 'Show status of local_pac: configuration, known proxy pacs, server running etc.'
68
116
  def status
69
117
  LocalPac.config = LocalPac::Config.new(options[:config_file]) if options[:config_file]
118
+ LocalPac.config.log_level = options[:log_level] if options[:log_level]
119
+ LocalPac.config.debug_mode = options[:debug_mode] if options[:debug_mode]
70
120
  LocalPac.config.lock
71
121
 
72
- set_log_level(options[:log_level])
73
- set_debug(options[:debug])
122
+ LocalPac.ui_logger.level = LocalPac.config.log_level
123
+ LocalPac.enable_debug_mode if LocalPac.config.debug_mode
74
124
 
75
125
  ApplicationStatus.new.show
76
126
  end
data/config.ru CHANGED
@@ -2,10 +2,15 @@ $LOAD_PATH <<::File.expand_path('../lib/', __FILE__)
2
2
 
3
3
  require 'local_pac'
4
4
 
5
+ LocalPac.config.debug_mode = true if ENV['DEBUG']
6
+ LocalPac.config.log_level = ENV['LOG_LEVEL'] if ENV['LOG_LEVEL']
7
+ LocalPac.config.access_log = ENV['ACCESS_LOG'] if ENV['ACCESS_LOG']
8
+
9
+ LocalPac.ui_logger.level = LocalPac.config.log_level
10
+
5
11
  require File.expand_path('../app/controllers/application_controller.rb', __FILE__)
6
12
  Dir.glob(::File.expand_path('../app/controllers/*.rb', __FILE__)).each { |f| require f }
7
13
 
8
- LocalPac.ui_logger.level = ::Logger::INFO
9
14
 
10
15
  trap LocalPac.config.reload_config_signal do
11
16
  begin
@@ -39,6 +44,10 @@ map '/v1/lookup/' do
39
44
  run LocalPac::App::LookupController
40
45
  end
41
46
 
47
+ map '/v1/git_hook/' do
48
+ run LocalPac::App::GitHookController
49
+ end
50
+
42
51
  map LocalPac::App::AssetsController.assets_prefix do
43
52
  run LocalPac::App::AssetsController.assets
44
53
  end
@@ -7,8 +7,6 @@
7
7
  # * <%= p %>
8
8
  <% end -%>
9
9
 
10
- :access_log: <%=::File.expand_path(lookup('access_log')) %>
11
- :local_storage: <%=::File.expand_path(lookup('local_storage')) %>
12
- :pid_file: <%=::File.expand_path(lookup('pid_file')) %>
13
- :sass_cache: <%=::File.expand_path(lookup('sass_cache')) %>
14
-
10
+ <% LocalPac::Config.options.delete_if { |o| [:expand_path, :gem_path].include? o }.each do |o| -%>
11
+ :<%= o %>: <%= lookup(o) %>
12
+ <% end -%>
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'uri'
4
+ require 'json'
5
+ require 'net/http'
6
+ require 'ostruct'
7
+
8
+ class EnvironmentCleaner
9
+ attr_reader :variables
10
+
11
+ def initialize
12
+ @variables = %w{http_proxy https_proxy HTTP_PROXY HTTPS_PROXY}
13
+ end
14
+
15
+ def cleanup
16
+ variables.each { |v| ENV.delete v }
17
+ end
18
+ end
19
+
20
+ class InputParser
21
+ def parse(input)
22
+ change = OpenStruct.new
23
+ change.old_commit_id, change.new_commit_id, change.reference = input.read.chomp.split(/ /)
24
+
25
+ change
26
+ end
27
+ end
28
+
29
+ class Server
30
+
31
+ attr_reader :uri, :api_key, :path, :http_version
32
+
33
+ def initialize(uri, api_key, path = '/v1/git_hook/pre-receive')
34
+ @uri = parse(uri)
35
+ @api_key = api_key
36
+ @path = path
37
+ @http_version = '1.1'
38
+ end
39
+
40
+ def check(change)
41
+ data = {
42
+ old_commit_id: change.old_commit_id,
43
+ new_commit_id: change.new_commit_id,
44
+ reference: change.reference,
45
+ api_key: api_key
46
+ }
47
+
48
+ begin
49
+ response = send_request(data)
50
+ rescue Errno::ECONNREFUSED
51
+ $stderr.puts 'No connection to validator server. Please make sure the server is running before pushing files again.'
52
+ exit 1
53
+ rescue Timeout::Error
54
+ $stderr.puts 'A time out occured. The validation server does not respond in time. Please make sure the server does not hang before pushing files again.'
55
+ exit 1
56
+ end
57
+
58
+ json = JSON.parse(response.body)
59
+
60
+ if json['result'] == 'success'
61
+ $stderr.puts 'New proxy.pac-files accepted'
62
+ exit 0
63
+ else
64
+ $stderr.puts json['error_details']
65
+ exit 1
66
+ end
67
+ end
68
+
69
+ private
70
+
71
+ def send_request(data)
72
+ request = Net::HTTP::Post.new(path)
73
+ request.set_form_data(data)
74
+
75
+ request.exec(socket, http_version, path)
76
+
77
+ begin
78
+ response = Net::HTTPResponse.read_new(socket)
79
+ if RUBY_VERSION >= '2'
80
+ response.decode_content = request.decode_content
81
+ end
82
+ end while response.kind_of?(Net::HTTPContinue)
83
+
84
+ response.reading_body(socket, request.response_body_permitted?) { }
85
+
86
+ if RUBY_VERSION >= '2'
87
+ response.uri = request.uri
88
+ end
89
+
90
+ response
91
+ end
92
+
93
+ def socket
94
+ @socket ||= case uri.scheme
95
+ when 'unix'
96
+ unix_socket
97
+ else
98
+ tcp_socket
99
+ end
100
+ end
101
+
102
+ def unix_socket
103
+ Net::BufferedIO.new(UNIXSocket.new(uri.path))
104
+ end
105
+
106
+ def tcp_socket
107
+ Net::BufferedIO.new(TCPSocket.new(uri.host, uri.port))
108
+ end
109
+
110
+ def parse(local_uri)
111
+ local_uri = URI.parse(local_uri)
112
+ local_uri.scheme = 'http' if local_uri.scheme == 'tcp'
113
+ local_uri.scheme = 'https' if local_uri.scheme == 'ssl'
114
+
115
+ local_uri
116
+ end
117
+ end
118
+
119
+ cleaner = EnvironmentCleaner.new.cleanup
120
+ server = Server.new('<%= lookup('listen') %>', '<%= lookup('api_key') %>')
121
+ server.check(InputParser.new.parse($stdin))
@@ -7,28 +7,6 @@ module LocalPac
7
7
  rescue Errno::ENOENT
8
8
  'Stale PID-file'
9
9
  end
10
-
11
- def set_log_level(requested_level)
12
- case requested_level.to_s.to_sym
13
- when :info
14
- LocalPac.ui_logger.level = ::Logger::INFO
15
- when :debug
16
- LocalPac.ui_logger.level = ::Logger::DEBUG
17
- else
18
- LocalPac.ui_logger.level = ::Logger::WARN
19
- end
20
- end
21
-
22
- def set_debug(request)
23
- if request
24
- LocalPac.ui_logger.info "Activating debug mode."
25
-
26
- require 'pry'
27
- require 'debugger'
28
- end
29
- rescue LoadError
30
- LocalPac.ui_logger.error "You tried to enable debug-mode, but either 'pry'- or 'debugger'-gem are not installed. Please fix that before using the debug-switch again."
31
- end
32
10
  end
33
11
  end
34
12
  end
@@ -1,27 +1,39 @@
1
1
  # encoding: utf-8
2
2
  module LocalPac
3
-
4
3
  class Config
4
+
5
5
  private
6
6
 
7
7
  attr_reader :config
8
8
 
9
- @options = []
9
+ @options = Set.new
10
+
10
11
  class << self
11
12
 
13
+ public
14
+
12
15
  attr_reader :options
13
16
 
14
- def option(option, default_value)
17
+ def option_reader(option, default_value)
15
18
  define_method option.to_sym do
16
19
  config.fetch(option.to_sym, default_value)
17
20
  end
18
21
 
22
+ @options << option
23
+ end
24
+
25
+ def option_writer(option)
19
26
  define_method "#{option}=".to_sym do |value|
20
27
  config[option.to_sym] = value
21
28
  end
22
29
 
23
30
  @options << option
24
31
  end
32
+
33
+ def option(option, default_value)
34
+ option_reader(option, default_value)
35
+ option_writer(option)
36
+ end
25
37
  end
26
38
 
27
39
  public
@@ -54,6 +66,11 @@ module LocalPac
54
66
  option :config_file, ::File.expand_path(::File.join(ENV['HOME'], '.config', 'local_pac', 'config.yaml'))
55
67
  option :reload_config_signal, :USR1
56
68
  option :reload_storage_signal, :USR2
69
+ option :debug_mode, false
70
+ option :log_level, :info
71
+ option :api_key, SecureRandom.hex
72
+ option :listen, 'tcp://127.0.0.1:8000'
73
+ option :environment, 'development'
57
74
 
58
75
  def to_s
59
76
  result = []
@@ -1,30 +1,33 @@
1
1
  module LocalPac
2
2
  module Exceptions
3
3
  # raise if there are template syntax errrors
4
- class ErbTemplateHasSyntaxErrors < Exception; end
4
+ class ErbTemplateHasSyntaxErrors < StandardError; end
5
5
 
6
6
  # raised if Template does not exist
7
- class ErbTemplateIsUnknown < Exception; end
7
+ class ErbTemplateIsUnknown < StandardError; end
8
8
 
9
9
  # raised if Template does not exist
10
- class ConfigFileNotReadable < Exception; end
10
+ class ConfigFileNotReadable < StandardError; end
11
11
 
12
12
  # raised if listen statement is invalid
13
- class ServerListenStatementInvalid < Exception; end
13
+ class ServerListenStatementInvalid < StandardError; end
14
14
 
15
15
  # raised if entered url is invalid
16
- class URLToSearchForInvalid < Exception; end
16
+ class URLToSearchForInvalid < StandardError; end
17
17
 
18
18
  # raised if pac file is invalid
19
- class PacFileInvalid < Exception; end
19
+ class PacFileInvalid < StandardError; end
20
20
 
21
21
  # raised if request is invalid
22
- class GivenUrlInvalid < Exception; end
22
+ class GivenUrlInvalid < StandardError; end
23
23
 
24
24
  # raised if pid file does not exist
25
- class PidFileDoesNotExist < Exception; end
25
+ class PidFileDoesNotExist < StandardError; end
26
26
 
27
27
  # raised if repository does not exist
28
- class RepositoryDoesNotExist < Exception; end
28
+ class RepositoryDoesNotExist < StandardError; end
29
+
30
+ # raised if commit does not exist
31
+ class CommitDoesNotExist < StandardError; end
29
32
  end
30
33
  end