local_pac 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/local_pac/actions/show_available_proxy_pac_files.rb +34 -0
- data/lib/local_pac/application_status.rb +3 -0
- data/lib/local_pac/git_repository.rb +2 -2
- data/lib/local_pac/git_storage.rb +11 -21
- data/lib/local_pac/initializer.rb +48 -34
- data/lib/local_pac/version.rb +1 -1
- data/lib/local_pac.rb +1 -0
- data/spec/actions/show_available_proxy_pac_files_spec.rb +69 -0
- data/spec/application_status_spec.rb +14 -0
- data/spec/git_repository_spec.rb +20 -0
- data/spec/git_storage_spec.rb +27 -9
- data/spec/spec_helper.rb +1 -0
- metadata +4 -1
data/Gemfile.lock
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module LocalPac
|
3
|
+
module Actions
|
4
|
+
class ShowAvailableProxyPacFiles
|
5
|
+
private
|
6
|
+
|
7
|
+
attr_reader :repo, :options, :vcs_engine, :storage_path, :validator
|
8
|
+
|
9
|
+
public
|
10
|
+
|
11
|
+
def initialize(storage_path, options = {}, vcs_engine = GitStorage, validator = PacFileValidator.new)
|
12
|
+
@options = options
|
13
|
+
@vcs_engine = vcs_engine
|
14
|
+
@storage_path = storage_path
|
15
|
+
@validator = validator
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
begin
|
20
|
+
@repo = vcs_engine.new(storage_path)
|
21
|
+
rescue Rugged::OSError
|
22
|
+
raise Exceptions::RepositoryDoesNotExist, "Sorry, but the repository at #{storage_path} does not exist" unless ::Dir.exists? storage_path
|
23
|
+
end
|
24
|
+
|
25
|
+
printf "%20s | %-20s | %-10s\n", 'Name', 'Path', 'Valid?'
|
26
|
+
printf "%20s-+-%-20s-+-%-10s\n", '-' * 20, '-' * 20, '-' * 10
|
27
|
+
|
28
|
+
repo.each_pac_file do |f|
|
29
|
+
printf "%20s | %-20s | %-10s\n", f.name, f.path, validator.valid?(f)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -23,6 +23,9 @@ module LocalPac
|
|
23
23
|
@actions << Actions::PrintNewline.new(2)
|
24
24
|
@actions << Actions::PrintTitle.new('Process Information')
|
25
25
|
@actions << Actions::ShowProcessInformation.new(config.pid_file)
|
26
|
+
@actions << Actions::PrintNewline.new(2)
|
27
|
+
@actions << Actions::PrintTitle.new('Available Proxy.Pac-Files')
|
28
|
+
@actions << Actions::ShowAvailableProxyPacFiles.new(config.local_storage)
|
26
29
|
end
|
27
30
|
|
28
31
|
def show
|
@@ -3,20 +3,19 @@ module LocalPac
|
|
3
3
|
class GitStorage
|
4
4
|
private
|
5
5
|
|
6
|
-
attr_reader :storage_path, :data, :repository, :file_creator, :null_file
|
6
|
+
attr_reader :storage_path, :data, :repository, :file_creator, :null_file, :vcs_engine
|
7
7
|
|
8
8
|
public
|
9
9
|
|
10
|
-
def initialize(storage_path, compressor_engine = JavaScriptCompressor,
|
10
|
+
def initialize(storage_path, compressor_engine = JavaScriptCompressor, vcs_engine = GitRepository, null_file = LocalPac::NullFile.new)
|
11
11
|
@storage_path = ::File.expand_path(storage_path)
|
12
|
-
@file_creator = file_creator
|
13
12
|
@null_file = null_file
|
13
|
+
@vcs_engine = vcs_engine
|
14
14
|
|
15
15
|
begin
|
16
|
-
@repository =
|
17
|
-
rescue
|
18
|
-
|
19
|
-
@repository = Rugged::Repository.new(storage_path)
|
16
|
+
@repository = vcs_engine.new(storage_path)
|
17
|
+
rescue Exceptions::RepositoryDoesNotExist
|
18
|
+
@repository = vcs_engine.create(storage_path)
|
20
19
|
end
|
21
20
|
|
22
21
|
mutex = Mutex.new
|
@@ -34,27 +33,18 @@ module LocalPac
|
|
34
33
|
data.fetch(key, null_file)
|
35
34
|
end
|
36
35
|
|
36
|
+
def each_pac_file(&block)
|
37
|
+
pac_files.each(&block)
|
38
|
+
end
|
39
|
+
|
37
40
|
private
|
38
41
|
|
39
42
|
def pac_files
|
40
43
|
LocalPac.ui_logger.debug "I'm using the following storage path: \"#{storage_path}\"."
|
41
|
-
files =
|
44
|
+
files = repository.all_files.keep_if { |f| f.extension? '.pac' }
|
42
45
|
LocalPac.ui_logger.debug "Found the following files: #{files.collect { |f| "\"#{f.path}\"" }.join(", ")}."
|
43
46
|
|
44
47
|
files
|
45
48
|
end
|
46
|
-
|
47
|
-
def files_in_repository
|
48
|
-
head_commit = repository.lookup(repository.head.target)
|
49
|
-
|
50
|
-
files = []
|
51
|
-
head_commit.tree.walk_blobs(:postorder) do |root, entry|
|
52
|
-
files << file_creator.new("#{root}#{entry[:name]}", repository.lookup(entry[:oid]).content )
|
53
|
-
end
|
54
|
-
|
55
|
-
files
|
56
|
-
rescue Rugged::ReferenceError
|
57
|
-
[]
|
58
|
-
end
|
59
49
|
end
|
60
50
|
end
|
@@ -13,41 +13,55 @@ module LocalPac
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def run
|
16
|
-
if options[:create_pid_directory]
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
if options[:
|
22
|
-
|
23
|
-
Actions::CreateDirectory.new(::File.dirname(config.access_log), force: options[:force]).run
|
24
|
-
end
|
25
|
-
|
26
|
-
if options[:create_sass_cache]
|
27
|
-
LocalPac.ui_logger.info "Creating sass cache #{config.sass_cache}"
|
28
|
-
Actions::CreateDirectory.new(config.sass_cache, force: options[:force]).run
|
29
|
-
end
|
30
|
-
|
31
|
-
if options[:create_local_storage]
|
32
|
-
LocalPac.ui_logger.info "Creating local storage: #{config.local_storage}"
|
33
|
-
Actions::CreateRepository.new(config.local_storage, bare: true, force: options[:force]).run
|
34
|
-
end
|
35
|
-
|
36
|
-
if options[:create_pre_receive_hook]
|
37
|
-
LocalPac.ui_logger.info "Creating pre-receive hook in local storage \"#{config.local_storage}\"."
|
38
|
-
Actions::CreateFile.new(:'git-hook.rb', ::File.join(config.local_storage, 'hooks', 'pre-receive'), Data.new(config), force: options[:force], executable: true).run
|
39
|
-
end
|
40
|
-
|
41
|
-
if options[:create_config_file]
|
42
|
-
LocalPac.ui_logger.info "Creating config file at \"#{config.config_file}\"."
|
43
|
-
Actions::CreateFile.new(:'example-config', config.config_file, Data.new(config), force: options[:force], create_directories: true).run
|
44
|
-
end
|
45
|
-
|
46
|
-
if options[:pre_seed]
|
47
|
-
LocalPac.ui_logger.info "Adding examples to repository at #{config.local_storage}/examples"
|
48
|
-
Actions::AddExamplesToLocalStorage.new(config.local_storage).run
|
49
|
-
end
|
16
|
+
create_pid_directory if options[:create_pid_directory]
|
17
|
+
create_log_directory if options[:create_log_directory]
|
18
|
+
create_sass_cache if options[:create_sass_cache]
|
19
|
+
create_local_storage if options[:create_local_storage]
|
20
|
+
create_pre_receive_hook if options[:create_pre_receive_hook]
|
21
|
+
create_config_file if options[:create_config_file]
|
22
|
+
pre_seed if options[:pre_seed]
|
50
23
|
|
24
|
+
show_example_config
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def create_pid_directory
|
30
|
+
LocalPac.ui_logger.info "Creating pid directory: #{::File.dirname(config.pid_file)}"
|
31
|
+
Actions::CreateDirectory.new(::File.dirname(config.pid_file), force: options[:force]).run
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_log_directory
|
35
|
+
LocalPac.ui_logger.info "Creating log directory: #{::File.dirname(config.access_log)}"
|
36
|
+
Actions::CreateDirectory.new(::File.dirname(config.access_log), force: options[:force]).run
|
37
|
+
end
|
38
|
+
|
39
|
+
def create_sass_cache
|
40
|
+
LocalPac.ui_logger.info "Creating sass cache #{config.sass_cache}"
|
41
|
+
Actions::CreateDirectory.new(config.sass_cache, force: options[:force]).run
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_local_storage
|
45
|
+
LocalPac.ui_logger.info "Creating local storage: #{config.local_storage}"
|
46
|
+
Actions::CreateRepository.new(config.local_storage, bare: true, force: options[:force]).run
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_pre_receive_hook
|
50
|
+
LocalPac.ui_logger.info "Creating pre-receive hook in local storage \"#{config.local_storage}\"."
|
51
|
+
Actions::CreateFile.new(:'git-hook.rb', ::File.join(config.local_storage, 'hooks', 'pre-receive'), Data.new(config), force: options[:force], executable: true).run
|
52
|
+
end
|
53
|
+
|
54
|
+
def create_config_file
|
55
|
+
LocalPac.ui_logger.info "Creating config file at \"#{config.config_file}\"."
|
56
|
+
Actions::CreateFile.new(:'example-config', config.config_file, Data.new(config), force: options[:force], create_directories: true).run
|
57
|
+
end
|
58
|
+
|
59
|
+
def pre_seed
|
60
|
+
LocalPac.ui_logger.info "Adding examples to repository at #{config.local_storage}/examples"
|
61
|
+
Actions::AddExamplesToLocalStorage.new(config.local_storage).run
|
62
|
+
end
|
63
|
+
|
64
|
+
def show_example_config
|
51
65
|
LocalPac.ui_logger.info "Showing the configuration of local_pac on your system."
|
52
66
|
Actions::CreateOutput.new(:'example-config', $stdout, Data.new(config)).run
|
53
67
|
end
|
data/lib/local_pac/version.rb
CHANGED
data/lib/local_pac.rb
CHANGED
@@ -53,6 +53,7 @@ require 'local_pac/java_script_compressor'
|
|
53
53
|
require 'local_pac/template_repository'
|
54
54
|
require 'local_pac/template_file'
|
55
55
|
require 'local_pac/pac_file_validator'
|
56
|
+
require 'local_pac/actions/show_available_proxy_pac_files'
|
56
57
|
require 'local_pac/actions/get_system_information'
|
57
58
|
require 'local_pac/actions/send_signal'
|
58
59
|
require 'local_pac/actions/create_repository'
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Actions::ShowAvailableProxyPacFiles do
|
5
|
+
let(:valid_pac_file) do <<-EOS.strip_heredoc.chomp
|
6
|
+
function FindProxyForURL(url, host) {
|
7
|
+
return "DIRECT";
|
8
|
+
}
|
9
|
+
EOS
|
10
|
+
end
|
11
|
+
|
12
|
+
context '#initialize' do
|
13
|
+
it 'requires a git repository' do
|
14
|
+
expect {
|
15
|
+
Actions::ShowAvailableProxyPacFiles.new(working_directory)
|
16
|
+
}.not_to raise_error
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context '#run' do
|
21
|
+
it 'shows proxy.pac files in repo' do
|
22
|
+
repo = GitRepository.create(working_directory)
|
23
|
+
repo.add_content('proxy.pac', 'asdf()')
|
24
|
+
repo.add_content('proxy1.pac', 'asd1f()')
|
25
|
+
|
26
|
+
action = Actions::ShowAvailableProxyPacFiles.new(working_directory)
|
27
|
+
|
28
|
+
result = capture(:stdout) do
|
29
|
+
LocalPac.ui_logger.level = :info
|
30
|
+
action.run
|
31
|
+
end
|
32
|
+
|
33
|
+
expect(result).to include('proxy.pac')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'checks if pac file is valid' do
|
37
|
+
repo = GitRepository.create(working_directory)
|
38
|
+
repo.add_content('proxy.pac', valid_pac_file)
|
39
|
+
repo.add_content('proxy1.pac', 'asd1f()')
|
40
|
+
|
41
|
+
action = Actions::ShowAvailableProxyPacFiles.new(working_directory)
|
42
|
+
|
43
|
+
result = capture(:stdout) do
|
44
|
+
LocalPac.ui_logger.level = :info
|
45
|
+
action.run
|
46
|
+
end
|
47
|
+
|
48
|
+
expect(result).to include('true')
|
49
|
+
expect(result).to include('false')
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'ignores non-pac-files' do
|
53
|
+
repo = GitRepository.create(working_directory)
|
54
|
+
repo.add_content('proxy.pac', valid_pac_file)
|
55
|
+
repo.add_content('proxy1.txt', 'asd1f()')
|
56
|
+
|
57
|
+
action = Actions::ShowAvailableProxyPacFiles.new(working_directory)
|
58
|
+
|
59
|
+
result = capture(:stdout) do
|
60
|
+
LocalPac.ui_logger.level = :info
|
61
|
+
action.run
|
62
|
+
end
|
63
|
+
|
64
|
+
expect(result).not_to include('proxy1.txt')
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -2,6 +2,13 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe ApplicationStatus do
|
5
|
+
let(:valid_pac_file) do <<-EOS.strip_heredoc.chomp
|
6
|
+
function FindProxyForURL(url, host) {
|
7
|
+
return "DIRECT";
|
8
|
+
}
|
9
|
+
EOS
|
10
|
+
end
|
11
|
+
|
5
12
|
context '#initialize' do
|
6
13
|
it 'has no special requirements' do
|
7
14
|
expect {
|
@@ -18,8 +25,14 @@ describe ApplicationStatus do
|
|
18
25
|
|
19
26
|
context '#show' do
|
20
27
|
it 'show application status' do
|
28
|
+
git_repo = ::File.join(working_directory, 'data', 'storage.git')
|
29
|
+
|
30
|
+
repo = GitRepository.create(git_repo)
|
31
|
+
repo.add_content('proxy.pac', valid_pac_file)
|
32
|
+
|
21
33
|
config_string = <<-EOS.strip_heredoc
|
22
34
|
:pid_file: #{::File.join(working_directory, 'run', 'pid')}
|
35
|
+
:local_storage: #{git_repo}
|
23
36
|
EOS
|
24
37
|
|
25
38
|
config_file = create_file('config.yaml', config_string)
|
@@ -35,6 +48,7 @@ describe ApplicationStatus do
|
|
35
48
|
expect(result).to include('pid_file')
|
36
49
|
expect(result).to include('pid_file')
|
37
50
|
expect(result).to include('cmdline')
|
51
|
+
expect(result).to include('proxy.pac')
|
38
52
|
end
|
39
53
|
end
|
40
54
|
end
|
data/spec/git_repository_spec.rb
CHANGED
@@ -125,4 +125,24 @@ describe GitRepository do
|
|
125
125
|
expect(result.first.path).to eq('file1.txt')
|
126
126
|
end
|
127
127
|
end
|
128
|
+
|
129
|
+
context '#each_file' do
|
130
|
+
it 'iterates over all found files' do
|
131
|
+
repo_path = File.join(working_directory, 'git_repo')
|
132
|
+
Rugged::Repository.init_at(repo_path)
|
133
|
+
|
134
|
+
file = double('file')
|
135
|
+
allow(file).to receive(:name).and_return(:file1)
|
136
|
+
|
137
|
+
file_creator = double('file_creator')
|
138
|
+
allow(file_creator).to receive(:new).with('file1.pac', 'asdf1').and_return(file)
|
139
|
+
|
140
|
+
null_file = double('null_file')
|
141
|
+
|
142
|
+
repo = GitRepository.new(repo_path, file_creator, null_file)
|
143
|
+
repo.add_content('file1.pac', 'asdf1')
|
144
|
+
|
145
|
+
repo.each_file { |file| file.name }
|
146
|
+
end
|
147
|
+
end
|
128
148
|
end
|
data/spec/git_storage_spec.rb
CHANGED
@@ -26,13 +26,13 @@ describe GitStorage do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
context '#
|
30
|
-
it '
|
29
|
+
context '#[]' do
|
30
|
+
it 'finds by name' do
|
31
31
|
repo = GitRepository.create(git_repo)
|
32
32
|
repo.add_content('file1.txt', 'asdf')
|
33
33
|
repo.add_content('file2.pac', 'data file2.pac')
|
34
34
|
|
35
|
-
storage = GitStorage.new(repo.storage_path, compressor
|
35
|
+
storage = GitStorage.new(repo.storage_path, compressor)
|
36
36
|
expect(storage[:file2].content).to eq('data file2.pac')
|
37
37
|
end
|
38
38
|
|
@@ -41,7 +41,7 @@ describe GitStorage do
|
|
41
41
|
repo.add_content('file1.txt', 'asdf')
|
42
42
|
repo.add_content('dir/file2.pac', 'data file2.pac')
|
43
43
|
|
44
|
-
storage = GitStorage.new(repo.storage_path, compressor
|
44
|
+
storage = GitStorage.new(repo.storage_path, compressor)
|
45
45
|
expect(storage['dir::file2'.to_sym].content).to eq('data file2.pac')
|
46
46
|
end
|
47
47
|
|
@@ -50,15 +50,33 @@ describe GitStorage do
|
|
50
50
|
repo.add_content('file1.txt', 'asdf')
|
51
51
|
repo.add_content('dir/dir1/file3.pac', 'data asdf.pac')
|
52
52
|
|
53
|
-
storage = GitStorage.new(repo.storage_path, compressor
|
53
|
+
storage = GitStorage.new(repo.storage_path, compressor)
|
54
54
|
expect(storage['dir::dir1::file3'.to_sym].content).to eq('data asdf.pac')
|
55
55
|
end
|
56
|
+
end
|
56
57
|
|
57
|
-
|
58
|
-
|
58
|
+
context '#each_pac_file' do
|
59
|
+
it 'iterates over all found pac files' do
|
60
|
+
arbitrary_file = double('arbitrary file')
|
61
|
+
expect(arbitrary_file).to receive(:extension?).with('.pac').and_return(false)
|
62
|
+
|
63
|
+
pac_file = double('pac_file')
|
64
|
+
allow(pac_file).to receive(:extension?).with('.pac').and_return(true)
|
65
|
+
allow(pac_file).to receive(:path).and_return('proxy.pac')
|
66
|
+
allow(pac_file).to receive(:name).and_return(:proxy)
|
67
|
+
|
68
|
+
vcs = double('vcs')
|
69
|
+
allow(vcs).to receive(:all_files).and_return([pac_file, arbitrary_file])
|
70
|
+
|
71
|
+
vcs_engine = double('vcs_engine')
|
72
|
+
allow(vcs_engine).to receive(:new).and_return(vcs)
|
73
|
+
|
74
|
+
storage = GitStorage.new(git_repo, compressor, vcs_engine)
|
75
|
+
|
76
|
+
result = []
|
77
|
+
storage.each_pac_file { |file| result << file}
|
59
78
|
|
60
|
-
|
61
|
-
expect(storage['dir::file2'.to_sym].content).to be_nil
|
79
|
+
expect(result).to eq([pac_file])
|
62
80
|
end
|
63
81
|
end
|
64
82
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: local_pac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -487,6 +487,7 @@ files:
|
|
487
487
|
- lib/local_pac/actions/reload_configuration.rb
|
488
488
|
- lib/local_pac/actions/reload_local_storage.rb
|
489
489
|
- lib/local_pac/actions/send_signal.rb
|
490
|
+
- lib/local_pac/actions/show_available_proxy_pac_files.rb
|
490
491
|
- lib/local_pac/actions/show_config.rb
|
491
492
|
- lib/local_pac/actions/show_process_information.rb
|
492
493
|
- lib/local_pac/application_status.rb
|
@@ -548,6 +549,7 @@ files:
|
|
548
549
|
- spec/actions/reload_configuration_spec.rb
|
549
550
|
- spec/actions/reload_repository_spec.rb
|
550
551
|
- spec/actions/send_signal_spec.rb
|
552
|
+
- spec/actions/show_available_proxy_pac_files_spec.rb
|
551
553
|
- spec/actions/show_config_spec.rb
|
552
554
|
- spec/actions/show_process_information_spec.rb
|
553
555
|
- spec/application_status_spec.rb
|
@@ -631,6 +633,7 @@ test_files:
|
|
631
633
|
- spec/actions/reload_configuration_spec.rb
|
632
634
|
- spec/actions/reload_repository_spec.rb
|
633
635
|
- spec/actions/send_signal_spec.rb
|
636
|
+
- spec/actions/show_available_proxy_pac_files_spec.rb
|
634
637
|
- spec/actions/show_config_spec.rb
|
635
638
|
- spec/actions/show_process_information_spec.rb
|
636
639
|
- spec/application_status_spec.rb
|