local_pac 0.1.13 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/{LICENSE.txt → LICENSE.md} +0 -0
  2. data/README.DEVELOPER.md +7 -0
  3. data/README.md +138 -2
  4. data/Rakefile +16 -8
  5. data/app/controllers/application_controller.rb +5 -3
  6. data/app/controllers/assets_controller.rb +3 -2
  7. data/app/controllers/file_serve_controller.rb +3 -6
  8. data/app/controllers/lookup_controller.rb +9 -9
  9. data/app/locales/en.yml +1 -0
  10. data/app/views/application.haml +1 -1
  11. data/bin/local_pac +49 -64
  12. data/config.ru +24 -7
  13. data/features/initializer.feature +4 -4
  14. data/features/show_status.feature +2 -2
  15. data/files/config.yaml +2 -2
  16. data/files/example-config.erb +10 -12
  17. data/files/git-hook.erb +1 -0
  18. data/lib/local_pac.rb +22 -5
  19. data/lib/local_pac/actions/create_directory.rb +2 -2
  20. data/lib/local_pac/actions/create_file.rb +8 -2
  21. data/lib/local_pac/actions/create_repository.rb +6 -8
  22. data/lib/local_pac/actions/get_system_information.rb +78 -0
  23. data/lib/local_pac/actions/print_newline.rb +19 -0
  24. data/lib/local_pac/actions/print_title.rb +41 -0
  25. data/lib/local_pac/actions/reload_configuration.rb +21 -0
  26. data/lib/local_pac/actions/reload_local_storage.rb +22 -0
  27. data/lib/local_pac/actions/send_signal.rb +32 -0
  28. data/lib/local_pac/actions/show_config.rb +10 -0
  29. data/lib/local_pac/actions/show_process_information.rb +94 -0
  30. data/lib/local_pac/application_status.rb +34 -0
  31. data/lib/local_pac/cli/helper.rb +34 -0
  32. data/lib/local_pac/cli/reload.rb +36 -0
  33. data/lib/local_pac/config.rb +15 -13
  34. data/lib/local_pac/exceptions.rb +6 -0
  35. data/lib/local_pac/file.rb +32 -0
  36. data/lib/local_pac/git.rb +20 -6
  37. data/lib/local_pac/git_repository.rb +40 -28
  38. data/lib/local_pac/git_storage.rb +60 -0
  39. data/lib/local_pac/initializer.rb +8 -5
  40. data/lib/local_pac/local_storage.rb +3 -4
  41. data/lib/local_pac/main.rb +2 -2
  42. data/lib/local_pac/{null_pac_file.rb → null_file.rb} +5 -1
  43. data/lib/local_pac/server.rb +1 -1
  44. data/lib/local_pac/spec_helper_file_server.rb +6 -5
  45. data/lib/local_pac/template_file.rb +1 -1
  46. data/lib/local_pac/template_repository.rb +3 -3
  47. data/lib/local_pac/version.rb +1 -1
  48. data/local_pac.gemspec +13 -9
  49. data/script/console +1 -1
  50. data/share/archlinux/PKGBUILD +4 -1
  51. data/share/archlinux/config.yaml +1 -1
  52. data/spec/actions/create_directory_spec.rb +3 -3
  53. data/spec/actions/create_file_spec.rb +23 -2
  54. data/spec/actions/create_repository_spec.rb +3 -3
  55. data/spec/actions/get_system_information_spec.rb +22 -0
  56. data/spec/actions/print_new_line_spec.rb +36 -0
  57. data/spec/actions/print_title_spec.rb +50 -0
  58. data/spec/actions/reload_configuration_spec.rb +38 -0
  59. data/spec/actions/reload_repository_spec.rb +35 -0
  60. data/spec/actions/send_signal_spec.rb +58 -0
  61. data/spec/actions/show_config_spec.rb +22 -0
  62. data/spec/actions/show_process_information_spec.rb +45 -0
  63. data/spec/application_status_spec.rb +40 -0
  64. data/spec/config_spec.rb +11 -11
  65. data/spec/features/fetch_proxy_pac_spec.rb +11 -10
  66. data/spec/features/lookup_proxy_spec.rb +32 -40
  67. data/spec/file_spec.rb +56 -0
  68. data/spec/git_spec.rb +13 -7
  69. data/spec/git_storage_spec.rb +64 -0
  70. data/spec/initializer_spec.rb +7 -5
  71. data/spec/{null_pac_file_spec.rb → null_file_spec.rb} +6 -6
  72. data/spec/proxy_pac/pac_result_html_stylist_spec.rb +3 -2
  73. data/spec/runner_spec.rb +1 -1
  74. data/spec/spec_helper.rb +2 -2
  75. data/spec/spec_helper_features.rb +2 -2
  76. data/spec/support/config.rb +5 -0
  77. data/spec/support/filesystem.rb +1 -1
  78. data/spec/support/git.rb +23 -2
  79. data/spec/support/helper_features.rb +23 -0
  80. data/spec/template_repository_spec.rb +2 -2
  81. metadata +113 -32
  82. data/lib/local_pac/git_file.rb +0 -18
  83. data/lib/local_pac/pac_file.rb +0 -27
  84. data/spec/git_repository_spec.rb +0 -60
  85. data/spec/pac_file_spec.rb +0 -44
data/config.ru CHANGED
@@ -1,14 +1,31 @@
1
- $LOAD_PATH << File.expand_path('../lib/', __FILE__)
2
-
3
- #require 'rack/contrib'
1
+ $LOAD_PATH <<::File.expand_path('../lib/', __FILE__)
4
2
 
5
3
  require 'local_pac'
6
4
 
7
5
  require File.expand_path('../app/controllers/application_controller.rb', __FILE__)
8
- Dir.glob(File.expand_path('../app/controllers/*.rb', __FILE__)).each { |f| require f }
9
- #
10
- #logger = LocalPac::AccessLogger.new ENV['ACCESS_LOG'] || File.expand_path(File.join(LocalPac.config.access_log))
11
- #use Rack::CommonLogger, logger
6
+ Dir.glob(::File.expand_path('../app/controllers/*.rb', __FILE__)).each { |f| require f }
7
+
8
+ LocalPac.ui_logger.level = ::Logger::INFO
9
+
10
+ trap LocalPac.config.reload_config_signal do
11
+ begin
12
+ LocalPac.ui_logger.warn 'Reload of configuration requested'
13
+ LocalPac::Actions::ReloadConfiguration.new.run
14
+ LocalPac.ui_logger.info 'Reload of configuration successful'
15
+ rescue => e
16
+ LocalPac.ui_logger.fatal "Reload of configuration failed: #{e.message}"
17
+ end
18
+ end
19
+
20
+ trap LocalPac.config.reload_storage_signal do
21
+ begin
22
+ LocalPac.ui_logger.warn 'Reload of local storage requested'
23
+ LocalPac::Actions::ReloadLocalStorage.new([LocalPac::App::FileServeController, LocalPac::App::LookupController]).run
24
+ LocalPac.ui_logger.info 'Reload of local storage successful'
25
+ rescue => e
26
+ LocalPac.ui_logger.fatal "Reload of local storage failed: #{e.message}"
27
+ end
28
+ end
12
29
 
13
30
  map '/' do
14
31
  run LocalPac::App::FileServeController
@@ -7,16 +7,16 @@ Feature: Initialize environment
7
7
  Given a file named "config.yaml" with:
8
8
  """
9
9
  pid_file: 'run/pid'
10
- local_storage: 'storage'
11
- log_sink: 'log'
10
+ local_storage: 'data/storage.git'
11
+ access_log: 'log/access_log'
12
12
  executable: 'bin/local_pac'
13
13
  """
14
14
  When I successfully run `local_pac init --config-file config.yaml`
15
15
  Then the following directories should exist:
16
16
  | directory |
17
17
  | 'run' |
18
- | 'storage/cache.git' |
18
+ | 'data/storage.git' |
19
19
  | 'log' |
20
20
  And the following files should exist:
21
21
  | file |
22
- | 'storage/cache.git/hooks/pre-receive' |
22
+ | 'data/storage.git/hooks/pre-receive' |
@@ -9,7 +9,7 @@ Feature: Show status
9
9
  """
10
10
  pid_file: 'run/pid'
11
11
  local_storage: 'storage'
12
- log_sink: 'log'
12
+ access_log: 'log/access.log'
13
13
  executable: 'bin/local_pac'
14
14
  """
15
15
  When I successfully run `local_pac status`
@@ -17,6 +17,6 @@ Feature: Show status
17
17
  """
18
18
  pid_file: 'run/pid'
19
19
  local_storage: 'storage'
20
- log_sink: 'log'
20
+ access_log: 'log/access.log'
21
21
  executable: 'bin/local_pac'
22
22
  """
@@ -1,5 +1,5 @@
1
1
  ---
2
- :log_sink: ~/.local/share/local_pac/log
3
- :local_storage: ~/.local/share/local_pac/data
2
+ :local_storage: ~/.local/share/local_pac/data/storage.git
4
3
  :pid_file: ~/.local/share/local_pac/run/pid
5
4
  :access_log: ~/.local/share/local_pac/log/access.log
5
+ :config_file: ~/.config/local_pac/config.yaml
@@ -1,16 +1,14 @@
1
-
2
1
  ---
3
- # You might want to copy the following output to one of the searched config
4
- # file paths - in the given order.
2
+ # You might want to copy the following output to one of the allowed config
3
+ # file paths - in the given order. But be aware that at
4
+ # <%= lookup('config_file') -%>, there might be a
5
+ # config file created during initialization.
5
6
  <% Array(lookup('allowed_config_file_paths')).each do |p| -%>
6
- # <%= p %>
7
- <% end -%>
8
- :gem_path:
9
- <% Array(lookup('gem_path')).collect { |p| File.expand_path(p) }.each do |p| -%>
10
- - <%= p %>
7
+ # * <%= p %>
11
8
  <% end -%>
12
- :log_sink: <%= File.expand_path(lookup('log_sink')) %>
13
- :local_storage: <%= File.expand_path(lookup('local_storage')) %>
14
- :executable: <%= File.expand_path(lookup('executable')) %>
15
- :pid_file: <%= File.expand_path(lookup('pid_file')) %>
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')) %>
16
14
 
@@ -6,6 +6,7 @@ $LOAD_PATH.unshift '<%= p %>'
6
6
 
7
7
  require 'git_hook-pre_receive'
8
8
  require 'pac'
9
+ require 'uri'
9
10
 
10
11
  class PacFileSyntaxChecker
11
12
  def check(files)
@@ -1,7 +1,13 @@
1
- require 'sinatra'
1
+ require 'thor'
2
+ require 'sys/proctable'
3
+ require 'facter'
2
4
  require 'fileutils'
5
+ require 'pathname'
6
+ require 'rugged'
7
+ require 'timeout'
3
8
  require 'logger'
4
9
  require 'uglifier'
10
+ require 'pager'
5
11
  require 'pac'
6
12
  require 'ostruct'
7
13
  require 'psych'
@@ -10,7 +16,7 @@ require 'thread'
10
16
  require 'open3'
11
17
  require 'addressable/uri'
12
18
  require 'securerandom'
13
- require 'fedux_org/stdlib/filesystem'
19
+ #require 'fedux_org/stdlib/filesystem'
14
20
 
15
21
  require 'active_support/cache'
16
22
  require 'active_support/core_ext/string/inflections'
@@ -24,24 +30,35 @@ require 'local_pac/ui_logger'
24
30
  LocalPac.ui_logger.level = ::Logger::UNKNOWN
25
31
 
26
32
  require 'local_pac/git'
27
- require 'local_pac/git_file'
28
33
  require 'local_pac/git_repository'
34
+ require 'local_pac/git_storage'
29
35
  require 'local_pac/config'
30
36
  require 'local_pac/runner'
31
37
  require 'local_pac/erb_generator'
32
38
  require 'local_pac/data'
33
39
  require 'local_pac/version'
34
- require 'local_pac/pac_file'
35
- require 'local_pac/null_pac_file'
40
+ require 'local_pac/file'
41
+ require 'local_pac/null_file'
36
42
  require 'local_pac/java_script_compressor'
37
43
  require 'local_pac/template_repository'
38
44
  require 'local_pac/template_file'
39
45
  require 'local_pac/pac_file_validator'
46
+ require 'local_pac/actions/get_system_information'
47
+ require 'local_pac/actions/send_signal'
40
48
  require 'local_pac/actions/create_repository'
41
49
  require 'local_pac/actions/create_output'
42
50
  require 'local_pac/actions/create_directory'
43
51
  require 'local_pac/actions/create_file'
52
+ require 'local_pac/actions/show_config'
53
+ require 'local_pac/actions/print_newline'
54
+ require 'local_pac/actions/show_process_information'
55
+ require 'local_pac/actions/print_title'
56
+ require 'local_pac/actions/reload_configuration'
57
+ require 'local_pac/actions/reload_local_storage'
58
+ require 'local_pac/cli/helper'
59
+ require 'local_pac/cli/reload'
44
60
  require 'local_pac/initializer'
61
+ require 'local_pac/application_status'
45
62
  require 'local_pac/local_storage'
46
63
  require 'local_pac/server'
47
64
  require 'local_pac/proxy_pac/html_table_style'
@@ -9,7 +9,7 @@ module LocalPac
9
9
  public
10
10
 
11
11
  def initialize(path, options = {}, fs_engine = FileUtils)
12
- @path = File.expand_path(path)
12
+ @path =::File.expand_path(path)
13
13
  @options = options
14
14
  @fs_engine = fs_engine
15
15
  end
@@ -26,7 +26,7 @@ module LocalPac
26
26
  private
27
27
 
28
28
  def need_to_run?
29
- !File.exists?(path)
29
+ !::File.exists?(path)
30
30
  end
31
31
  end
32
32
  end
@@ -10,7 +10,7 @@ module LocalPac
10
10
 
11
11
  def initialize(name, destination, data, options = {}, engine = ErbGenerator, repository = TemplateRepository.new)
12
12
  @name = name
13
- @destination = File.expand_path(destination)
13
+ @destination =::File.expand_path(destination)
14
14
  @data = data
15
15
  @options = options
16
16
  @engine = engine
@@ -21,6 +21,8 @@ module LocalPac
21
21
  if need_to_run? || options[:force] == true
22
22
  LocalPac.ui_logger.warn "Creating file \"#{destination}\"."
23
23
 
24
+ create_directories if options[:create_directories] == true
25
+
24
26
  file = template(name, ::File.new(destination, 'w'), data)
25
27
  FileUtils.chmod('+x', file) if options[:executable] == true
26
28
  else
@@ -30,6 +32,10 @@ module LocalPac
30
32
 
31
33
  private
32
34
 
35
+ def create_directories
36
+ FileUtils.mkdir_p(::File.dirname(destination))
37
+ end
38
+
33
39
  def template(local_name, local_destination, local_data)
34
40
  template = repository.find(local_name)
35
41
 
@@ -42,7 +48,7 @@ module LocalPac
42
48
  end
43
49
 
44
50
  def need_to_run?
45
- !File.exists?(destination)
51
+ !::File.exists?(destination)
46
52
  end
47
53
  end
48
54
  end
@@ -8,8 +8,8 @@ module LocalPac
8
8
 
9
9
  public
10
10
 
11
- def initialize(path, options = {}, vcs_engine = LocalPac::Git)
12
- @path = File.expand_path(path)
11
+ def initialize(path, options = {}, vcs_engine = GitRepository)
12
+ @path =::File.expand_path(path)
13
13
  @options = options
14
14
  @vcs_engine = vcs_engine
15
15
  end
@@ -18,11 +18,9 @@ module LocalPac
18
18
  if need_to_run? || options[:force] == true
19
19
  LocalPac.ui_logger.warn "Creating repository \"#{path}\"."
20
20
 
21
- if options[:bare] == true
22
- vcs_engine.init(path, true)
23
- else
24
- vcs_engine.init(path)
25
- end
21
+ repo = vcs_engine.create(path)
22
+ repo.add_content('README.md', 'Please place your proxy.pac-files here.')
23
+
26
24
  else
27
25
  LocalPac.ui_logger.warn "Repository \"#{path}\" already exists. Do not create it again!."
28
26
  end
@@ -31,7 +29,7 @@ module LocalPac
31
29
  private
32
30
 
33
31
  def need_to_run?
34
- !File.exists?(path)
32
+ !::File.exists?(path)
35
33
  end
36
34
  end
37
35
  end
@@ -0,0 +1,78 @@
1
+ # encoding: utf-8
2
+ module LocalPac
3
+ module Actions
4
+ class GetSystemInformation
5
+ private
6
+
7
+ attr_reader :options
8
+
9
+ public
10
+
11
+ def initialize(options = {})
12
+ @options = options
13
+ end
14
+
15
+ def run
16
+ printf( "%#{max_field_length}s | %s\n", 'Information', 'Value')
17
+ printf( "%s + %s\n", '-' * max_field_length, '-' * 40)
18
+ data.sort_by { |key, value| key }.each { |key, value| printf( "%#{max_field_length}s | %s\n", key, value) }
19
+ end
20
+
21
+ private
22
+
23
+ def data
24
+ Timeout::timeout(5) do
25
+ Facter.to_hash.keep_if { |key,_| fields.include?(key.to_s) }
26
+ end
27
+ rescue Timeout::Error
28
+ LocalPac.ui_logger.warn 'Getting environment information took to long. Please make sure the name resolver is avaiable. This might cause the latency.'
29
+ {}
30
+ end
31
+
32
+ def max_field_length
33
+ fields.inject(0) { |memo, f| memo = f.size if f.size > memo ; memo}
34
+ end
35
+
36
+ def fields
37
+ %w[
38
+ architecture
39
+ filesystems
40
+ hardwareisa
41
+ hardwaremodel
42
+ is_virtual
43
+ kernel
44
+ kernelmajversion
45
+ kernelrelease
46
+ kernelversion
47
+ memoryfree
48
+ memoryfree_mb
49
+ memorysize
50
+ memorysize_mb
51
+ memorytotal
52
+ operatingsystem
53
+ operatingsystemrelease
54
+ osfamily
55
+ path
56
+ physicalprocessorcount
57
+ processor0
58
+ processor1
59
+ processorcount
60
+ ps
61
+ rubysitedir
62
+ rubyversion
63
+ selinux
64
+ swapfree
65
+ swapfree_mb
66
+ swapsize
67
+ swapsize_mb
68
+ timezone
69
+ uptime
70
+ uptime_days
71
+ uptime_hours
72
+ uptime_seconds
73
+ virtual
74
+ ]
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,19 @@
1
+ module LocalPac
2
+ module Actions
3
+ class PrintNewline
4
+ private
5
+
6
+ attr_reader :count
7
+
8
+ public
9
+
10
+ def initialize(count = 1)
11
+ @count = count
12
+ end
13
+
14
+ def run
15
+ print "\n" * count
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,41 @@
1
+ module LocalPac
2
+ module Actions
3
+ class PrintTitle
4
+ private
5
+
6
+ attr_reader :title, :width
7
+
8
+ public
9
+
10
+ def initialize(title, width = 0)
11
+ @title = title
12
+ @width = width
13
+ end
14
+
15
+ def run
16
+ puts long_line
17
+ puts full_title
18
+ puts long_line
19
+ print "\n"
20
+ end
21
+
22
+ private
23
+
24
+ def long_line
25
+ '#' * full_title.size
26
+ end
27
+
28
+ def full_title
29
+ header + ' ' + title + ' ' + header
30
+ end
31
+
32
+ def header
33
+ if width > title.size
34
+ '#' * ((width - title.size) / 2)
35
+ else
36
+ '#'
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ module LocalPac
3
+ module Actions
4
+ class ReloadConfiguration
5
+
6
+ private
7
+
8
+ attr_reader :config
9
+
10
+ public
11
+
12
+ def initialize(config = Config.new)
13
+ @config = config
14
+ end
15
+
16
+ def run
17
+ LocalPac.config = config
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ module LocalPac
3
+ module Actions
4
+ class ReloadLocalStorage
5
+
6
+ private
7
+
8
+ attr_reader :local_storage, :sinatra_apps
9
+
10
+ public
11
+
12
+ def initialize(sinatra_apps, local_storage = LocalStorage.new)
13
+ @sinatra_apps = Array(sinatra_apps)
14
+ @local_storage = local_storage
15
+ end
16
+
17
+ def run
18
+ sinatra_apps.each { |app| app.set :local_storage, local_storage }
19
+ end
20
+ end
21
+ end
22
+ end