local_pac 0.2.0 → 0.2.1

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/README.md CHANGED
@@ -5,19 +5,46 @@
5
5
  [![Coverage Status](https://coveralls.io/repos/dg-vrnetze/local_pac/badge.png?branch=master)](https://coveralls.io/r/dg-vrnetze/local_pac?branch=master)
6
6
  [![Gem Version](https://badge.fury.io/rb/local_pac.png)](http://badge.fury.io/rb/local_pac)
7
7
 
8
- `local_pac` serves to purposes:
8
+ `local_pac` *serves two main purposes:*
9
9
 
10
- 1. Serve proxy.pac-files compressed from a vcs repository (git).
10
+ 1. Serve proxy.pac-files compressed from a git repository.
11
11
  2. Lookup of url in proxy.pac to find out which proxy will be used.
12
12
 
13
- Behind the scenes it uses a javascript compressor
14
- ([uglifier](https://github.com/lautis/uglifier)) to make 1. and and a proxy-pac
15
- parser ([ruby-pac](https://github.com/samuelkadolph/ruby-pac)) to make 2.
16
- possible.
13
+ *Behind the scenes it uses ...*
17
14
 
15
+ * a javascript compressor ([uglifier](https://github.com/lautis/uglifier))
16
+ * a proxy-pac parser ([ruby-pac](https://github.com/samuelkadolph/ruby-pac))
17
+ * a vcs library ([rugged](https://github.com/libgit2/rugged))
18
+ * etc.
19
+
20
+ *Possible use cases:*
21
+
22
+ * Administrator serving proxy.pacs to thousands of clients
23
+ * Internal developer using virtual machines on her laptop to develop web
24
+ applications but who still needs access to external web applications via
25
+ internal proxy
26
+ * Developer/Consultant using a vpn connection to her customer + internal
27
+ proxy/socks proxy, but still needs direct access to the internet web
28
+ applications
29
+ * Supporter who needs to support thousand of clients and needs to check which
30
+ internal proxies is used for a given url
31
+ * Curious people loving git and using it for every possible use case ;-)
32
+
33
+ ## Screenshots
34
+
35
+ *Search for a url*
36
+ ![Search for a url](https://raw2.github.com/dg-vrnetze/gh-local_pac/gh-pages/images/screenshot_1.png)
37
+
38
+ *Pretty result for a url*
39
+ ![Pretty result for a url](https://raw2.github.com/dg-vrnetze/gh-local_pac/gh-pages/images/screenshot_2.png)
40
+
41
+ *Raw result for a url*
42
+ ![Raw result for a url](https://raw2.github.com/dg-vrnetze/gh-local_pac/gh-pages/images/screenshot_3.png)
18
43
 
19
44
  ## Installation
20
45
 
46
+ ### RubyGems
47
+
21
48
  Add this line to your application's Gemfile:
22
49
 
23
50
  gem 'local_pac'
@@ -30,11 +57,46 @@ Or install it yourself as:
30
57
 
31
58
  $ gem install local_pac
32
59
 
33
- Additionally you need to install `git` because `local_pac` makes a lot of use
34
- of it.
60
+ ### Arch Linux
61
+
62
+ ```bash
63
+ # Install via yaourt
64
+ yaourt -S local_pac
65
+
66
+ # Install via cower + makepkg
67
+ cower -d local_pac
68
+ cd <dir>
69
+ makepkg -is
70
+ ```
35
71
 
36
72
  ## Usage
37
73
 
74
+ ### Quickstart
75
+
76
+ *Initialize local_pac*
77
+
78
+ ```
79
+ % local_pac init --pre-seed
80
+ ```
81
+
82
+ *Starting Webserver*
83
+
84
+ ```
85
+ % local_pac serve
86
+ ```
87
+
88
+ *Download proxy.pac on commandline*
89
+
90
+ ```
91
+ % curl --noproxy "*" http://localhost:8000/v1/pac/proxy.pac
92
+ ```
93
+
94
+ *Starting webbrowser and open web application*
95
+
96
+ ```
97
+ % firefox http://localhost:8000/v1/lookup/proxy.pac
98
+ ```
99
+
38
100
  ### Getting started
39
101
 
40
102
  Make sure that you place a config file for `local_pac` in one of the following
@@ -11,7 +11,7 @@ $('#navigation a[href="#verbatim"]').click(function (e) {
11
11
  $(this).tab('show')
12
12
  })
13
13
 
14
- $('#reset').click(function(){
14
+ $('#reset').click(function (e){
15
15
  e.preventDefault()
16
16
  $('#url').val('')
17
17
  });
data/bin/local_pac CHANGED
@@ -35,6 +35,7 @@ module LocalPac
35
35
 
36
36
  desc 'init', 'Create files/directories to use local_pac in dir or $PWD'
37
37
  option :force, type: :boolean, default: false, desc: 'Overwrite existing files?'
38
+ option :pre_seed, type: :boolean, default: false, desc: 'Add some example files to git repository'
38
39
  def init
39
40
  LocalPac.config = LocalPac::Config.new(options[:config_file]) if options[:config_file]
40
41
  LocalPac.config.lock
@@ -45,7 +46,7 @@ module LocalPac
45
46
  LocalPac.ui_logger.debug('Options: ' + options.to_s)
46
47
  LocalPac.ui_logger.debug("Config:\n" + LocalPac.config.to_s)
47
48
 
48
- Initializer.new(force: options[:force]).run
49
+ Initializer.new(force: options[:force], pre_seed: options[:pre_seed]).run
49
50
  end
50
51
 
51
52
  desc 'status', 'Show status of local_pac: configuration, known proxy pacs, server running etc.'
@@ -0,0 +1,42 @@
1
+ // Main
2
+ function FindProxyForURL(url, host) {
3
+
4
+ if ( reach_via_socks(url, host, dnsResolve(host))) {
5
+ return socks_proxy();
6
+ }
7
+
8
+ if ( reach_directly(url, host, dnsResolve(host))) {
9
+ return no_proxy();
10
+ }
11
+
12
+ return default_proxy();
13
+ }
14
+
15
+
16
+ // Helper
17
+
18
+ function default_proxy() {
19
+ return "PROXY 127.0.0.1:3128";
20
+ }
21
+
22
+ function no_proxy() {
23
+ return "DIRECT";
24
+ }
25
+
26
+ function socks_proxy() {
27
+ return "SOCKS 127.0.0.1:1080";
28
+ }
29
+
30
+ function reach_directly(url, host, host_ip) {
31
+
32
+ return isPlainHostName(host) ||
33
+ host == "localhost" ||
34
+ shExpMatch(host, "localhost.*") ||
35
+ host == "127.0.0.1" ||
36
+ dnsDomainIs ( host , ".example.org") ||
37
+ dnsDomainIs ( host , ".in.example.org");
38
+ }
39
+
40
+ function reach_via_socks(url, host, host_ip) {
41
+ return host == "server.example.org");
42
+ }
@@ -0,0 +1,51 @@
1
+ // Taken from http://findproxyforurl.com/pac-functions/. Please see this site
2
+ // for an explanation for the snippets found below.
3
+
4
+ function FindProxyForURL(url, host) {
5
+ if (dnsDomainIs(host, ".google.com"))
6
+ return "DIRECT";
7
+
8
+ if (shExpMatch(url, "*.local"))
9
+ return "DIRECT";
10
+
11
+ if (shExpMatch(host, "vpn.domain.com") ||
12
+ shExpMatch(url, "http://abcdomain.com/folder/*"))
13
+ return "DIRECT";
14
+
15
+ if (isInNet(dnsResolve(host), "172.16.0.0", "255.240.0.0"))
16
+ return "DIRECT";
17
+
18
+
19
+ if (isInNet(myIpAddress(), "10.10.1.0", "255.255.255.0"))
20
+ return "PROXY 10.10.5.1:8080";
21
+
22
+ if (isInNet(dnsResolve(host), "10.0.0.0", "255.0.0.0") ||
23
+ isInNet(dnsResolve(host), "172.16.0.0", "255.240.0.0") ||
24
+ isInNet(dnsResolve(host), "192.168.0.0", "255.255.0.0") ||
25
+ isInNet(dnsResolve(host), "127.0.0.0", "255.255.255.0"))
26
+ return "DIRECT";
27
+
28
+ if (isPlainHostName(host))
29
+ return "DIRECT";
30
+
31
+ if (localHostOrDomainIs(host, "www.google.com"))
32
+ return "DIRECT";
33
+
34
+ if (localHostOrDomainIs(host, ".google.com"))
35
+ return "DIRECT";
36
+
37
+
38
+ if (isResolvable(host))
39
+ return "PROXY proxy1.example.com:8080";
40
+ if (dnsDomainLevels(host) > 0)
41
+ return "PROXY proxy1.example.com:8080";
42
+ else return "DIRECT";
43
+
44
+ if (weekdayRange("MON", "FRI")) return "PROXY proxy1.example.com:8080";
45
+ else return "DIRECT";
46
+ if (dateRange("JAN", "MAR")) return "PROXY proxy1.example.com:8080";
47
+ else return "DIRECT";
48
+ if (timeRange(8, 18)) return "PROXY proxy1.example.com:8080";
49
+ else return "DIRECT";
50
+
51
+ }
@@ -0,0 +1,3 @@
1
+ function FindProxyForURL(url, host) {
2
+ return "DIRECT";
3
+ }
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+ module LocalPac
3
+ module Actions
4
+ class AddExamplesToLocalStorage
5
+
6
+ private
7
+
8
+ attr_reader :repo, :files, :options, :vcs_engine, :storage_path
9
+
10
+ public
11
+
12
+ def initialize(storage_path, options = {}, vcs_engine = GitRepository)
13
+ @options = options
14
+ @vcs_engine = vcs_engine
15
+ @storage_path = storage_path
16
+ end
17
+
18
+ def run
19
+ @files = Dir.glob(::File.expand_path('../../../../files/examples/*', __FILE__)).collect do |f|
20
+ OpenStruct.new(repo_path: "examples/#{::File.basename(f)}", name: "examples::#{::File.basename(f).sub(/\.[^.]+$/, '')}".to_sym, content: ::File.read(f))
21
+ end
22
+ @files << OpenStruct.new(repo_path: 'proxy.pac', name: :proxy, content: ::File.read(::File.expand_path('../../../../files/proxy.pac', __FILE__)))
23
+
24
+ begin
25
+ @repo = vcs_engine.new(storage_path)
26
+ rescue Rugged::OSError
27
+ raise Exceptions::RepositoryDoesNotExist, "Sorry, but the repository at #{storage_path} does not exist" unless ::Dir.exists? storage_path
28
+ end
29
+
30
+ if need_to_run? || options[:force] == true
31
+ files.each { |f| repo.add_content(f.repo_path, f.content) }
32
+ repo.add_content('proxy.pac', ::File.read(::File.expand_path('../../../../files/proxy.pac', __FILE__)))
33
+ else
34
+ LocalPac.ui_logger.warn "Example files already exists. Do not create them again!."
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def need_to_run?
41
+ files.any? { |f| repo.find_file(f.name).nil? }
42
+ end
43
+ end
44
+ end
45
+ end
@@ -13,7 +13,7 @@ module LocalPac
13
13
  def initialize(path, content = '')
14
14
  @path = path
15
15
  @extension = ::File.extname(path)
16
- @name = path.sub(/\..*$/, '').camelize.downcase.to_sym
16
+ @name = path.sub(/\.[^.]+$/, '').gsub(%r{/}, '::').downcase.to_sym
17
17
  @content = content
18
18
  end
19
19
 
@@ -3,15 +3,18 @@ module LocalPac
3
3
  class GitRepository
4
4
  private
5
5
 
6
- attr_reader :repository, :root_commit
6
+ attr_reader :repository, :root_commit, :null_file, :file_creator
7
7
 
8
8
  public
9
9
 
10
10
  attr_reader :storage_path
11
11
 
12
- def initialize(storage_path)
12
+ def initialize(storage_path, file_creator = LocalPac::File, null_file = LocalPac::NullFile.new)
13
13
  @storage_path = ::File.expand_path(storage_path)
14
14
  @repository = Rugged::Repository.new(storage_path)
15
+ @file_creator = file_creator
16
+ @null_file = null_file
17
+
15
18
  rescue Rugged::RepositoryError
16
19
  raise Exceptions::RepositoryDoesNotExist, "Sorry, but #{storage_path} is not a git repository."
17
20
  end
@@ -48,8 +51,41 @@ module LocalPac
48
51
  Rugged::Commit.create(repository, options)
49
52
  end
50
53
 
54
+ def find_file(name)
55
+ files.fetch(name, null_file)
56
+ end
57
+
58
+ def all_files
59
+ files
60
+ end
61
+
62
+ def each_file(&block)
63
+ files.each(&block)
64
+ end
65
+
51
66
  private
52
67
 
68
+ def files
69
+ files_in_repository.reduce({}) do |memo, file|
70
+ memo[file.name.to_sym] = file
71
+
72
+ memo
73
+ end
74
+ end
75
+
76
+ def files_in_repository
77
+ return [] if repository.empty?
78
+
79
+ head_commit = repository.lookup(repository.head.target)
80
+
81
+ files = []
82
+ head_commit.tree.walk_blobs(:postorder) do |root, entry|
83
+ files << file_creator.new("#{root}#{entry[:name]}", repository.lookup(entry[:oid]).content )
84
+ end
85
+
86
+ files
87
+ end
88
+
53
89
  def default_commit_info
54
90
  options = {}
55
91
  options[:author] = { :email => 'local_pac@local_pac', :name => 'Local Pac', :time => Time.now }
@@ -3,7 +3,7 @@ module LocalPac
3
3
 
4
4
  private
5
5
 
6
- attr_reader :config, :vcs, :options
6
+ attr_reader :config, :options
7
7
 
8
8
  public
9
9
 
@@ -31,7 +31,12 @@ module LocalPac
31
31
  LocalPac.ui_logger.info "Creating config file at \"#{config.config_file}\"."
32
32
  Actions::CreateFile.new(:'example-config', config.config_file, Data.new(config), force: options[:force], create_directories: true).run
33
33
 
34
- LocalPac.ui_logger.warn "Showing the configuration of local_pac on your system."
34
+ if options[:pre_seed]
35
+ LocalPac.ui_logger.info "Adding examples to repository at #{config.local_storage}/examples"
36
+ Actions::AddExamplesToLocalStorage.new(config.local_storage).run
37
+ end
38
+
39
+ LocalPac.ui_logger.info "Showing the configuration of local_pac on your system."
35
40
  Actions::CreateOutput.new(:'example-config', $stdout, Data.new(config)).run
36
41
  end
37
42
  end
@@ -1,4 +1,4 @@
1
1
  #main LocalPac
2
2
  module LocalPac
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.1'
4
4
  end
data/lib/local_pac.rb CHANGED
@@ -29,7 +29,6 @@ require 'local_pac/ui_logger'
29
29
 
30
30
  LocalPac.ui_logger.level = ::Logger::UNKNOWN
31
31
 
32
- require 'local_pac/git'
33
32
  require 'local_pac/git_repository'
34
33
  require 'local_pac/git_storage'
35
34
  require 'local_pac/config'
@@ -55,6 +54,7 @@ require 'local_pac/actions/show_process_information'
55
54
  require 'local_pac/actions/print_title'
56
55
  require 'local_pac/actions/reload_configuration'
57
56
  require 'local_pac/actions/reload_local_storage'
57
+ require 'local_pac/actions/add_examples_to_local_storage'
58
58
  require 'local_pac/cli/helper'
59
59
  require 'local_pac/cli/reload'
60
60
  require 'local_pac/initializer'
@@ -1,7 +1,7 @@
1
1
  # Maintainer: Max Meyer <dev@fedux.org>
2
2
  pkgname=local_pac
3
- pkgver=0.1.11
4
- pkgrel=2
3
+ pkgver=0.2.0
4
+ pkgrel=1
5
5
  pkgdesc="local pacfile serving server"
6
6
  arch=(i686 x86_64)
7
7
  url="https://github.com/dg-vrnetze/${pkgname}"
@@ -11,10 +11,7 @@ install=${pkgname}.install
11
11
  makedepends=(rubygems filegen phantomjs)
12
12
  source=(http://gems.rubyforge.org/gems/$pkgname-$pkgver.gem)
13
13
  noextract=($pkgname-$pkgver.gem)
14
- sha256sums=('cc2695dd44527e942a1d4cc3370480e1fbb44ff2eb3a050fe8714e371178ac39')
15
-
16
- test() {
17
- }
14
+ sha256sums=('1ed00dd8054c57beb92ccbd7fc91e1698e3d673f16d79bf565760ac12136c823')
18
15
 
19
16
  package() {
20
17
  cd "$srcdir"
@@ -35,7 +32,7 @@ package() {
35
32
  install -d ${pkgdir}$_log_dir
36
33
  install -d ${pkgdir}$_config_dir
37
34
 
38
- msg "Starting download of gems. Don't get alert that the download takes a lot of time. Since rubygems 2.2.0 a new algorithm to resolve dependencies is used. Upgrade to > 2.2.0 via sudo /usr/bin/gem update --system to improve performance."
35
+ msg "Starting download of gems. Don't get alert if the download takes a lot of time. Since rubygems 2.2.0 a new algorithm to resolve dependencies is used. Upgrade to > 2.2.0 via sudo /usr/bin/gem update --system to improve performance."
39
36
 
40
37
  GEM_HOME="${pkgdir}${_library_dir}" GEM_ROOT="${pkgdir}${_library_dir}" GEM_PATH="${pkgdir}${_library_dir}" /usr/bin/gem install --env-shebang --wrappers --no-ri --no-rdoc --no-prerelease --install-dir ${pkgdir}${_library_dir} $pkgname puma
41
38
 
@@ -51,7 +48,7 @@ package() {
51
48
  install -D -m644 ${pkgdir}/$_share_dir/systemd/${pkgname}@.service ${pkgdir}/$_systemd_dir/${pkgname}@.service
52
49
  #install -D -m644 ${pkgdir}/$_share_dir/systemd/${pkgname}.socket ${pkgdir}/$_systemd_dir
53
50
 
54
- install -D -m644 ${pkgdir}${_share_dir}/../LICENSE.txt "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
51
+ install -D -m644 ${pkgdir}${_share_dir}/../../LICENSE.md "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
55
52
  }
56
53
 
57
54
  # vim:set ts=2 sw=2 et:
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Actions::AddExamplesToLocalStorage do
5
+ context '#initialize' do
6
+ it 'requires a path to local storage' do
7
+ repo = GitRepository.create(working_directory)
8
+
9
+ expect {
10
+ Actions::AddExamplesToLocalStorage.new(working_directory)
11
+ }.not_to raise_error
12
+ end
13
+ end
14
+
15
+ context '#run' do
16
+ it 'fails if Storage path does not exist' do
17
+ action = Actions::AddExamplesToLocalStorage.new('local_storage')
18
+ expect {
19
+ action.run
20
+ }.to raise_error Exceptions::RepositoryDoesNotExist
21
+ end
22
+
23
+ it 'creates files' do
24
+ repo = GitRepository.create(working_directory)
25
+ action = Actions::AddExamplesToLocalStorage.new(working_directory)
26
+ action.run
27
+
28
+ expect(repo.find_file('examples::proxy-complex.pac'.to_sym).name).to eq(:'examples::proxy-complex.pac')
29
+ end
30
+
31
+ it 'forces creation' do
32
+ repo = GitRepository.create(working_directory)
33
+ action = Actions::AddExamplesToLocalStorage.new(working_directory)
34
+ action.run
35
+
36
+ result = capture(:stderr) do
37
+ LocalPac.ui_logger.level = ::Logger::INFO
38
+ action.run
39
+ end
40
+
41
+ expect(result).to include('already')
42
+ end
43
+ end
44
+ end
@@ -12,14 +12,11 @@ describe 'Fetch proxy pac', :type => :feature do
12
12
 
13
13
  let(:compressed_valid_pac_file) { "function FindProxyForURL(){return\"DIRECT\"}" }
14
14
 
15
- let(:git_repo) { 'git_repo' }
15
+ let(:git_repo) { File.join(working_directory, 'git_repo.git') }
16
16
 
17
17
  before :each do
18
- git_init(git_repo)
19
- git_set_author(git_repo)
20
- create_file(::File.join(git_repo, 'file.pac'), valid_pac_file)
21
- git_add(git_repo, 'file.pac')
22
- git_commit(git_repo)
18
+ repo = GitRepository.create(git_repo)
19
+ repo.add_content('file.pac', valid_pac_file)
23
20
  end
24
21
 
25
22
  before :each do
@@ -31,7 +28,7 @@ describe 'Fetch proxy pac', :type => :feature do
31
28
  end
32
29
 
33
30
  def local_storage
34
- ::File.join(working_directory, 'git_repo', '.git')
31
+ ::File.join(working_directory, 'git_repo.git')
35
32
  end
36
33
  end.new
37
34
 
@@ -59,7 +56,7 @@ describe 'Fetch proxy pac', :type => :feature do
59
56
  end
60
57
 
61
58
  def local_storage
62
- ::File.join(working_directory, 'git_repo', '.git')
59
+ ::File.join(working_directory, 'git_repo.git')
63
60
  end
64
61
  end.new
65
62
 
@@ -83,7 +80,7 @@ describe 'Fetch proxy pac', :type => :feature do
83
80
  end
84
81
 
85
82
  def local_storage
86
- ::File.join(working_directory, 'git_repo', '.git')
83
+ ::File.join(working_directory, 'git_repo.git')
87
84
  end
88
85
  end.new
89
86
 
@@ -25,14 +25,11 @@ describe 'Lookup proxy for url' do
25
25
  EOS
26
26
  end
27
27
 
28
- let(:git_repo) { 'git_repo' }
29
-
30
- before(:each) do
31
- git_init(git_repo)
32
- git_set_author(git_repo)
33
- create_file(::File.join(git_repo, 'file.pac'), valid_pac_file)
34
- git_add(git_repo, 'file.pac')
35
- git_commit(git_repo)
28
+ let(:git_repo) { File.join(working_directory, 'git_repo.git') }
29
+
30
+ before :each do
31
+ repo = GitRepository.create(git_repo)
32
+ repo.add_content('file.pac', valid_pac_file)
36
33
  end
37
34
 
38
35
  before :each do
@@ -44,7 +41,7 @@ describe 'Lookup proxy for url' do
44
41
  end
45
42
 
46
43
  def local_storage
47
- ::File.join(working_directory, 'git_repo', '.git')
44
+ ::File.join(working_directory, 'git_repo.git')
48
45
  end
49
46
  end.new
50
47
 
@@ -0,0 +1,64 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe GitRepository do
5
+ context '#initialize' do
6
+ it 'requires a storage path' do
7
+ file_creator = double('file_creator')
8
+ null_file = double('null_file')
9
+
10
+ Rugged::Repository.init_at(File.join(working_directory, 'git_repo'))
11
+
12
+ expect {
13
+ GitRepository.new(File.join(working_directory, 'git_repo'), file_creator, null_file)
14
+ }.not_to raise_error
15
+ end
16
+ end
17
+
18
+ context '#find_file' do
19
+ it 'returns a file if exists in repository' do
20
+ repo_path = File.join(working_directory, 'git_repo')
21
+ Rugged::Repository.init_at(repo_path)
22
+
23
+ file = double('file')
24
+ allow(file).to receive(:name).and_return(:file)
25
+
26
+ file_creator = double('file_creator')
27
+ allow(file_creator).to receive(:new).with('file.txt', 'asdf').and_return(file)
28
+
29
+ null_file = double('null_file')
30
+
31
+ repo = GitRepository.new(repo_path, file_creator, null_file)
32
+ repo.add_content('file.txt', 'asdf')
33
+ f = repo.find_file(:file)
34
+
35
+ expect(f).to be(file)
36
+ end
37
+
38
+ it 'returns a null file if does not exist in repository' do
39
+ repo_path = File.join(working_directory, 'git_repo')
40
+ Rugged::Repository.init_at(repo_path)
41
+
42
+ file_creator = double('file_creator')
43
+ null_file = double('null_file')
44
+
45
+ repo = GitRepository.new(repo_path, file_creator, null_file)
46
+ f = repo.find_file(:file)
47
+
48
+ expect(f).to be(null_file)
49
+ end
50
+
51
+ it 'handles uninitialized repositories' do
52
+ repo_path = File.join(working_directory, 'git_repo')
53
+ Rugged::Repository.init_at(repo_path)
54
+
55
+ file_creator = double('file_creator')
56
+ null_file = double('null_file')
57
+
58
+ repo = GitRepository.new(repo_path, file_creator, null_file)
59
+ f = repo.find_file(:file)
60
+
61
+ expect(f).to be(null_file)
62
+ end
63
+ end
64
+ end
@@ -14,7 +14,7 @@ describe Initializer do
14
14
  :config_file: #{File.join(working_directory, 'config', 'config.yaml')}
15
15
  :gem_path: []
16
16
  EOS
17
- config_file = create_file('config.yaml', config_string)
17
+ config_file = create_file('config_spec.yaml', config_string)
18
18
 
19
19
  config = LocalPac::Config.new(config_file)
20
20
  initializer = Initializer.new({}, config)
@@ -32,5 +32,29 @@ describe Initializer do
32
32
  expect(path_exists?('run')).to be_true
33
33
  expect(result).to include("access_log: #{File.expand_path(::File.join(working_directory, 'log', 'access.log'))}")
34
34
  end
35
+
36
+ it 'adds examples on request' do
37
+ config_string = <<-EOS.strip_heredoc
38
+ :access_log: #{File.join(working_directory, 'log', 'access.log')}
39
+ :local_storage: #{File.join(working_directory, 'data', 'storage.git')}
40
+ :executable: #{File.join(working_directory, 'bin', 'local_pac')}
41
+ :pid_file: #{File.join(working_directory, 'run', 'pid')}
42
+ :sass_cache: #{File.join(working_directory, 'cache', 'sass')}
43
+ :config_file: #{File.join(working_directory, 'config', 'config.yaml')}
44
+ :gem_path: []
45
+ EOS
46
+ config_file = create_file('config_spec.yaml', config_string)
47
+
48
+ config = LocalPac::Config.new(config_file)
49
+ initializer = Initializer.new({pre_seed: true}, config)
50
+ silence(:stdout) do
51
+ silence(:stderr) do
52
+ initializer.run
53
+ end
54
+ end
55
+
56
+ repo = GitRepository.new(config.local_storage)
57
+ expect(repo.find_file(:proxy).name).to eq(:proxy)
58
+ end
35
59
  end
36
60
  end
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.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-20 00:00:00.000000000 Z
12
+ date: 2014-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -428,17 +428,21 @@ files:
428
428
  - app/views/lookup_result.haml
429
429
  - bin/local_pac
430
430
  - config.ru
431
- - features/fetch_proxy_pac.feature
432
- - features/initializer.feature
433
- - features/show_status.feature
431
+ - features/fetch_proxy_pac.feature_
432
+ - features/initializer.feature_
433
+ - features/show_status.feature_
434
434
  - features/step_definitions.rb
435
435
  - features/support/env.rb
436
436
  - files/config.yaml
437
437
  - files/example-config.erb
438
+ - files/examples/proxy-complex.pac.example
439
+ - files/examples/proxy-function_demo.pac.example
440
+ - files/examples/proxy.pac.example
438
441
  - files/git-hook.erb
439
442
  - files/proxy.pac
440
443
  - lib/local_pac.rb
441
444
  - lib/local_pac/access_logger.rb
445
+ - lib/local_pac/actions/add_examples_to_local_storage.rb
442
446
  - lib/local_pac/actions/create_directory.rb
443
447
  - lib/local_pac/actions/create_file.rb
444
448
  - lib/local_pac/actions/create_output.rb
@@ -459,7 +463,6 @@ files:
459
463
  - lib/local_pac/erb_generator.rb
460
464
  - lib/local_pac/exceptions.rb
461
465
  - lib/local_pac/file.rb
462
- - lib/local_pac/git.rb
463
466
  - lib/local_pac/git_repository.rb
464
467
  - lib/local_pac/git_storage.rb
465
468
  - lib/local_pac/initializer.rb
@@ -498,6 +501,7 @@ files:
498
501
  - share/systemd/local_pac.service
499
502
  - share/systemd/local_pac.socket
500
503
  - share/systemd/local_pac@.service
504
+ - spec/actions/add_examples_to_local_storage_spec.rb
501
505
  - spec/actions/create_directory_spec.rb
502
506
  - spec/actions/create_file_spec.rb
503
507
  - spec/actions/create_output_spec.rb
@@ -517,7 +521,7 @@ files:
517
521
  - spec/features/fetch_proxy_pac_spec.rb
518
522
  - spec/features/lookup_proxy_spec.rb
519
523
  - spec/file_spec.rb
520
- - spec/git_spec.rb
524
+ - spec/git_repository_spec.rb
521
525
  - spec/git_storage_spec.rb
522
526
  - spec/initializer_spec.rb
523
527
  - spec/java_script_compressor_spec.rb
@@ -539,7 +543,6 @@ files:
539
543
  - spec/support/config.rb
540
544
  - spec/support/environment.rb
541
545
  - spec/support/filesystem.rb
542
- - spec/support/git.rb
543
546
  - spec/support/helper_features.rb
544
547
  - spec/support/rack_test.rb
545
548
  - spec/support/reporting.rb
@@ -573,11 +576,12 @@ signing_key:
573
576
  specification_version: 3
574
577
  summary: Serve local proxy pac
575
578
  test_files:
576
- - features/fetch_proxy_pac.feature
577
- - features/initializer.feature
578
- - features/show_status.feature
579
+ - features/fetch_proxy_pac.feature_
580
+ - features/initializer.feature_
581
+ - features/show_status.feature_
579
582
  - features/step_definitions.rb
580
583
  - features/support/env.rb
584
+ - spec/actions/add_examples_to_local_storage_spec.rb
581
585
  - spec/actions/create_directory_spec.rb
582
586
  - spec/actions/create_file_spec.rb
583
587
  - spec/actions/create_output_spec.rb
@@ -597,7 +601,7 @@ test_files:
597
601
  - spec/features/fetch_proxy_pac_spec.rb
598
602
  - spec/features/lookup_proxy_spec.rb
599
603
  - spec/file_spec.rb
600
- - spec/git_spec.rb
604
+ - spec/git_repository_spec.rb
601
605
  - spec/git_storage_spec.rb
602
606
  - spec/initializer_spec.rb
603
607
  - spec/java_script_compressor_spec.rb
@@ -619,7 +623,6 @@ test_files:
619
623
  - spec/support/config.rb
620
624
  - spec/support/environment.rb
621
625
  - spec/support/filesystem.rb
622
- - spec/support/git.rb
623
626
  - spec/support/helper_features.rb
624
627
  - spec/support/rack_test.rb
625
628
  - spec/support/reporting.rb
data/lib/local_pac/git.rb DELETED
@@ -1,77 +0,0 @@
1
- module LocalPac
2
- class Git
3
- def self.ls_files(filter = nil)
4
- cmd = ['git ls-files']
5
- cmd << filter if filter
6
-
7
- runner = Runner.new(cmd.join(" "))
8
- runner.result
9
- end
10
-
11
- def self.config(option, value, git_dir, is_global = true)
12
- cmd = ['git']
13
- cmd << "--git-dir #{git_dir}" if git_dir
14
- cmd << 'config'
15
- cmd << option
16
- cmd << "\"#{value}\""
17
- cmd << "--global" if is_global
18
-
19
- runner = Runner.new(cmd.join(" "))
20
- runner.result
21
- end
22
-
23
-
24
- def self.ls_tree(git_dir = nil, filter = nil)
25
- cmd = ['git']
26
- cmd << "--git-dir #{git_dir}" if git_dir
27
- cmd << 'ls-tree -r HEAD'
28
- cmd << filter if filter
29
-
30
- runner = Runner.new(cmd.join(" "))
31
- runner.result
32
- end
33
-
34
- def self.init(path, is_bare = false)
35
- if is_bare
36
- Rugged::Repository.init_at(path, :bare)
37
- else
38
- Rugged::Repository.init_at(path)
39
- end
40
- end
41
-
42
- def self.add(object)
43
- runner = Runner.new("git add #{object}")
44
- runner.result
45
- end
46
-
47
- def self.commit(message)
48
- runner = Runner.new("git commit -m \"#{message}\"")
49
- runner.result
50
- end
51
-
52
- def self.status
53
- runner = Runner.new('git status')
54
- runner.result
55
- end
56
-
57
- def self.show(sha = nil, git_dir = nil)
58
- cmd = ['git']
59
- cmd << "--git-dir #{git_dir}" if git_dir
60
- cmd << 'show'
61
- cmd << " #{sha}" if sha
62
-
63
- runner = Runner.new(cmd.join(" "))
64
- runner.result
65
- end
66
-
67
- def self.cat_file(sha, git_dir = nil)
68
- cmd = ['git']
69
- cmd << "--git-dir #{git_dir}" if git_dir
70
- cmd << 'cat-file -p'
71
- cmd << sha
72
-
73
- runner = Runner.new(cmd.join(" "))
74
- runner.result
75
- end
76
- end
77
- end
data/spec/git_spec.rb DELETED
@@ -1,106 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Git do
5
- let(:git_repo) { 'git_repo' }
6
-
7
- context '#init' do
8
- it 'creates a new repository' do
9
- switch_to_working_directory do
10
- Git.init(git_repo)
11
- end
12
-
13
- expect(path_exists?(git_repo)).to be_true
14
- end
15
- end
16
-
17
- context '#ls_tree' do
18
- it 'list files in repo' do
19
- git_init(git_repo)
20
- git_set_author(git_repo)
21
- create_file(::File.join(git_repo, 'file.txt'))
22
- git_add(git_repo, 'file.txt')
23
- git_commit(git_repo)
24
-
25
- Dir.chdir(::File.join(working_directory, git_repo)) do
26
- expect(Git.ls_tree.first).to include('file.txt')
27
- end
28
- end
29
- end
30
-
31
- context '#ls_files' do
32
- it 'list files in repo' do
33
- git_init(git_repo)
34
- git_set_author(git_repo)
35
- create_file(::File.join(git_repo, 'file.txt'))
36
- git_add(git_repo, 'file.txt')
37
- git_commit(git_repo)
38
-
39
- Dir.chdir(::File.join(working_directory, git_repo)) do
40
- expect(Git.ls_files).to include('file.txt')
41
- end
42
- end
43
-
44
- it 'list files in repo and filter' do
45
- git_init(git_repo)
46
- git_set_author(git_repo)
47
- create_file(::File.join(git_repo, 'file1.txt'))
48
- git_add(git_repo, 'file1.txt')
49
-
50
- create_file(::File.join(git_repo, 'file2.txt'))
51
- git_add(git_repo, 'file2.txt')
52
-
53
- git_commit(git_repo)
54
-
55
- Dir.chdir(::File.join(working_directory, git_repo)) do
56
- expect(Git.ls_files('file1.txt')).to eq(['file1.txt'])
57
- end
58
- end
59
- end
60
-
61
- context '#add' do
62
- it 'add dir/file to repository' do
63
- git_init(git_repo)
64
- git_set_author(git_repo)
65
- create_file(::File.join(git_repo, 'file.txt'))
66
-
67
- Dir.chdir(::File.join(working_directory, git_repo)) do
68
- Git.add('file.txt')
69
- end
70
-
71
- expect(git_status(git_repo)).to include("\tnew file: file.txt")
72
- end
73
- end
74
-
75
- context '#commit' do
76
- it 'commit dir/file to repository' do
77
-
78
- git_init(git_repo)
79
- git_set_author(git_repo)
80
-
81
- create_file(::File.join(git_repo, 'file.txt'))
82
-
83
- git_add(git_repo, 'file.txt')
84
-
85
- Dir.chdir(::File.join(working_directory, git_repo)) do
86
- Git.commit('file.txt')
87
- end
88
-
89
- expect(git_status(git_repo)).to include('nothing to commit, working directory clean')
90
- end
91
- end
92
-
93
- context '#show' do
94
- it 'show ref/sha in repository' do
95
- git_init(git_repo)
96
- git_set_author(git_repo)
97
- create_file(::File.join(git_repo, 'file.txt'))
98
- git_add(git_repo, 'file.txt')
99
- git_commit(git_repo)
100
-
101
- Dir.chdir(::File.join(working_directory, git_repo)) do
102
- expect(Git.show.first).to include('commit')
103
- end
104
- end
105
- end
106
- end
data/spec/support/git.rb DELETED
@@ -1,73 +0,0 @@
1
- require 'fedux_org/stdlib/filesystem'
2
-
3
- module LocalPac
4
- module SpecHelper
5
- module GitHelper
6
- include FeduxOrg::Stdlib::Filesystem
7
-
8
- def root_directory
9
- ::File.expand_path('../../../', __FILE__)
10
- end
11
-
12
- def git_init(path)
13
- switch_to_working_directory do
14
- Git.init(path)
15
- end
16
-
17
- ::File.join(working_directory, path)
18
- end
19
-
20
- def git_add(repo, object)
21
- Dir.chdir(::File.join(working_directory, repo)) do
22
- Git.add(object)
23
- end
24
-
25
- ::File.join(working_directory, repo, object)
26
- end
27
-
28
- def git_status(repo)
29
- Dir.chdir(::File.join(working_directory, repo)) do
30
- Git.status
31
- end
32
- end
33
-
34
- def git_commit(repo, message = 'Yay... Added objects')
35
- Dir.chdir(::File.join(working_directory, repo)) do
36
- Git.commit(message)
37
- end
38
- end
39
-
40
- def git_show(repo, sha)
41
- Dir.chdir(::File.join(working_directory, repo)) do
42
- Git.show(sha)
43
- end
44
- end
45
-
46
- def git_ls_tree(repo)
47
- Dir.chdir(::File.join(working_directory, repo)) do
48
- Git.ls_tree
49
- end
50
- end
51
-
52
- def git_config(repo, option, value, is_global = false)
53
- if is_global
54
- Git.config(option, value, is_global)
55
- else
56
- Dir.chdir(::File.join(working_directory, repo)) do
57
- Git.config(option, value, is_global)
58
- end
59
- end
60
- end
61
-
62
- def git_set_author(repo)
63
- git_config(repo, 'user.email', 'user@local_pac')
64
- git_config(repo, 'user.name', 'local_pac')
65
- end
66
- end
67
- end
68
- end
69
-
70
- # encoding: utf-8
71
- RSpec.configure do |c|
72
- c.include LocalPac::SpecHelper::GitHelper
73
- end