local_pac 0.1.13 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/{LICENSE.txt → LICENSE.md} +0 -0
- data/README.DEVELOPER.md +7 -0
- data/README.md +138 -2
- data/Rakefile +16 -8
- data/app/controllers/application_controller.rb +5 -3
- data/app/controllers/assets_controller.rb +3 -2
- data/app/controllers/file_serve_controller.rb +3 -6
- data/app/controllers/lookup_controller.rb +9 -9
- data/app/locales/en.yml +1 -0
- data/app/views/application.haml +1 -1
- data/bin/local_pac +49 -64
- data/config.ru +24 -7
- data/features/initializer.feature +4 -4
- data/features/show_status.feature +2 -2
- data/files/config.yaml +2 -2
- data/files/example-config.erb +10 -12
- data/files/git-hook.erb +1 -0
- data/lib/local_pac.rb +22 -5
- data/lib/local_pac/actions/create_directory.rb +2 -2
- data/lib/local_pac/actions/create_file.rb +8 -2
- data/lib/local_pac/actions/create_repository.rb +6 -8
- data/lib/local_pac/actions/get_system_information.rb +78 -0
- data/lib/local_pac/actions/print_newline.rb +19 -0
- data/lib/local_pac/actions/print_title.rb +41 -0
- data/lib/local_pac/actions/reload_configuration.rb +21 -0
- data/lib/local_pac/actions/reload_local_storage.rb +22 -0
- data/lib/local_pac/actions/send_signal.rb +32 -0
- data/lib/local_pac/actions/show_config.rb +10 -0
- data/lib/local_pac/actions/show_process_information.rb +94 -0
- data/lib/local_pac/application_status.rb +34 -0
- data/lib/local_pac/cli/helper.rb +34 -0
- data/lib/local_pac/cli/reload.rb +36 -0
- data/lib/local_pac/config.rb +15 -13
- data/lib/local_pac/exceptions.rb +6 -0
- data/lib/local_pac/file.rb +32 -0
- data/lib/local_pac/git.rb +20 -6
- data/lib/local_pac/git_repository.rb +40 -28
- data/lib/local_pac/git_storage.rb +60 -0
- data/lib/local_pac/initializer.rb +8 -5
- data/lib/local_pac/local_storage.rb +3 -4
- data/lib/local_pac/main.rb +2 -2
- data/lib/local_pac/{null_pac_file.rb → null_file.rb} +5 -1
- data/lib/local_pac/server.rb +1 -1
- data/lib/local_pac/spec_helper_file_server.rb +6 -5
- data/lib/local_pac/template_file.rb +1 -1
- data/lib/local_pac/template_repository.rb +3 -3
- data/lib/local_pac/version.rb +1 -1
- data/local_pac.gemspec +13 -9
- data/script/console +1 -1
- data/share/archlinux/PKGBUILD +4 -1
- data/share/archlinux/config.yaml +1 -1
- data/spec/actions/create_directory_spec.rb +3 -3
- data/spec/actions/create_file_spec.rb +23 -2
- data/spec/actions/create_repository_spec.rb +3 -3
- data/spec/actions/get_system_information_spec.rb +22 -0
- data/spec/actions/print_new_line_spec.rb +36 -0
- data/spec/actions/print_title_spec.rb +50 -0
- data/spec/actions/reload_configuration_spec.rb +38 -0
- data/spec/actions/reload_repository_spec.rb +35 -0
- data/spec/actions/send_signal_spec.rb +58 -0
- data/spec/actions/show_config_spec.rb +22 -0
- data/spec/actions/show_process_information_spec.rb +45 -0
- data/spec/application_status_spec.rb +40 -0
- data/spec/config_spec.rb +11 -11
- data/spec/features/fetch_proxy_pac_spec.rb +11 -10
- data/spec/features/lookup_proxy_spec.rb +32 -40
- data/spec/file_spec.rb +56 -0
- data/spec/git_spec.rb +13 -7
- data/spec/git_storage_spec.rb +64 -0
- data/spec/initializer_spec.rb +7 -5
- data/spec/{null_pac_file_spec.rb → null_file_spec.rb} +6 -6
- data/spec/proxy_pac/pac_result_html_stylist_spec.rb +3 -2
- data/spec/runner_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -2
- data/spec/spec_helper_features.rb +2 -2
- data/spec/support/config.rb +5 -0
- data/spec/support/filesystem.rb +1 -1
- data/spec/support/git.rb +23 -2
- data/spec/support/helper_features.rb +23 -0
- data/spec/template_repository_spec.rb +2 -2
- metadata +113 -32
- data/lib/local_pac/git_file.rb +0 -18
- data/lib/local_pac/pac_file.rb +0 -27
- data/spec/git_repository_spec.rb +0 -60
- data/spec/pac_file_spec.rb +0 -44
data/config.ru
CHANGED
@@ -1,14 +1,31 @@
|
|
1
|
-
$LOAD_PATH
|
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
|
-
|
11
|
-
|
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
|
-
|
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
|
18
|
+
| 'data/storage.git' |
|
19
19
|
| 'log' |
|
20
20
|
And the following files should exist:
|
21
21
|
| file |
|
22
|
-
| 'storage
|
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
|
-
|
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
|
-
|
20
|
+
access_log: 'log/access.log'
|
21
21
|
executable: 'bin/local_pac'
|
22
22
|
"""
|
data/files/config.yaml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
---
|
2
|
-
:
|
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
|
data/files/example-config.erb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
|
-
|
2
1
|
---
|
3
|
-
# You might want to copy the following output to one of the
|
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
|
-
|
13
|
-
:
|
14
|
-
:
|
15
|
-
: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
|
|
data/files/git-hook.erb
CHANGED
data/lib/local_pac.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
-
require '
|
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/
|
35
|
-
require 'local_pac/
|
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
|
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
|
-
|
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
|
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
|
-
|
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 =
|
12
|
-
@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
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
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,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
|