proxy_rb 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env +3 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +1 -0
- data/.travis.yml +8 -2
- data/Gemfile +7 -3
- data/README.md +42 -8
- data/Rakefile +8 -23
- data/bin/bootstrap +10 -0
- data/{script → bin}/console +1 -0
- data/bin/test +3 -0
- data/cucumber.yml +2 -0
- data/fixtures/proxy-config/.rspec +2 -0
- data/fixtures/proxy-config/README.md +18 -0
- data/fixtures/proxy-config/Rakefile +10 -0
- data/fixtures/proxy-config/bin/http_server +14 -0
- data/fixtures/proxy-config/spec/spec_helper.rb +8 -0
- data/fixtures/proxy-config/spec/support/aruba.rb +2 -0
- data/fixtures/proxy-config/spec/support/proxy_rb.rb +2 -0
- data/lib/proxy_rb/basic_configuration/in_config_wrapper.rb +28 -0
- data/lib/proxy_rb/basic_configuration/option.rb +32 -0
- data/lib/proxy_rb/basic_configuration.rb +148 -0
- data/lib/proxy_rb/configuration.rb +42 -0
- data/lib/proxy_rb/credentials.rb +52 -0
- data/lib/proxy_rb/errors.rb +5 -0
- data/lib/proxy_rb/http_downloader.rb +23 -0
- data/lib/proxy_rb/http_proxy.rb +52 -0
- data/lib/proxy_rb/main.rb +8 -2
- data/lib/proxy_rb/no_proxy.rb +26 -0
- data/lib/proxy_rb/password_fetchers/basic_password_fetcher.rb +12 -0
- data/lib/proxy_rb/password_fetchers/environment_password_fetcher.rb +34 -0
- data/lib/proxy_rb/password_fetchers/vault_password_fetcher.rb +47 -0
- data/lib/proxy_rb/password_fetchers.rb +6 -0
- data/lib/proxy_rb/proxy_url.rb +73 -0
- data/lib/proxy_rb/proxy_url_parser.rb +56 -0
- data/lib/proxy_rb/request.rb +36 -0
- data/lib/proxy_rb/resource.rb +28 -0
- data/lib/proxy_rb/response.rb +20 -0
- data/lib/proxy_rb/rspec/helpers/http_proxy.rb +78 -0
- data/lib/proxy_rb/rspec/helpers/passwords.rb +29 -0
- data/lib/proxy_rb/rspec.rb +9 -6
- data/lib/proxy_rb/user_passwords/environment_user_password.rb +30 -0
- data/lib/proxy_rb/user_passwords/vault_user_password.rb +27 -0
- data/lib/proxy_rb/user_passwords.rb +7 -0
- data/lib/proxy_rb/version.rb +2 -1
- data/lib/proxy_rb.rb +2 -0
- data/proxy_rb.gemspec +5 -3
- metadata +40 -9
- data/Gemfile.lock +0 -263
- data/script/bootstrap +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db7176840c8e9a52da91b08248612198aa17f557
|
4
|
+
data.tar.gz: ca4ad19e9d3bad727954e3ed9164cad8ee0e6267
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53f73d13a40222916a1783e2c4ba19bf1ac749ea866f6d81e571baed37a567e29f245a98fc0654dd2817b114faa5bc6e49cacca4a53cdd0baf3a8dcc796b27e1
|
7
|
+
data.tar.gz: c75ebce750ca3f20a8000a498a54208c4f6c5c24b79ceb30427c4a1cd769ee569c8ee39e27c13f6646a77876fe56267824b4d1d501cfa3a4f2d3490feb5d071a
|
data/.env
ADDED
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
+
sudo: false
|
1
2
|
env:
|
2
3
|
- CI=1
|
3
4
|
language: ruby
|
4
5
|
bundler_args: --without development debug profile
|
5
6
|
rvm:
|
6
7
|
- 2.1.5
|
7
|
-
- 2.2.
|
8
|
-
|
8
|
+
- 2.2.3
|
9
|
+
- 2.3.0
|
10
|
+
script: script/test
|
11
|
+
before_install:
|
12
|
+
- curl -o /tmp/vault.zip https://releases.hashicorp.com/vault/0.5.1/vault_0.5.1_linux_amd64.zip
|
13
|
+
- unzip /tmp/vault.zip
|
14
|
+
- install -D -m 0755 /tmp/vault ./bin/vault
|
data/Gemfile
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
source 'https://rubygems.org'
|
2
3
|
|
3
4
|
# Specify your gem's dependencies in local_pac.gemspec
|
@@ -13,7 +14,12 @@ group :debug do
|
|
13
14
|
end
|
14
15
|
|
15
16
|
group :development, :test do
|
16
|
-
|
17
|
+
# Password store
|
18
|
+
gem 'vault'
|
19
|
+
|
20
|
+
# Set env during development/test
|
21
|
+
gem 'dotenv'
|
22
|
+
|
17
23
|
gem 'aruba', require: false
|
18
24
|
gem 'awesome_print', require: 'ap'
|
19
25
|
gem 'bundler', '~> 1.3', require: false
|
@@ -21,7 +27,6 @@ group :development, :test do
|
|
21
27
|
gem 'coveralls', require: false
|
22
28
|
gem 'cucumber', require: false
|
23
29
|
gem 'erubis'
|
24
|
-
gem 'fedux_org-stdlib', '~>0.7.25', require: false
|
25
30
|
gem 'filegen'
|
26
31
|
gem 'foreman', require: false
|
27
32
|
gem 'fuubar', require: false
|
@@ -31,7 +36,6 @@ group :development, :test do
|
|
31
36
|
gem 'license_finder'
|
32
37
|
gem 'rack'
|
33
38
|
gem 'rake', require: false
|
34
|
-
gem 'redcarpet', require: false
|
35
39
|
gem 'rubocop', require: false
|
36
40
|
gem 'simplecov', require: false
|
37
41
|
gem 'sinatra', require: 'sinatra/base'
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# ProxyRb
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
`proxy_rb` makes it easier for you to test your proxy infrastructre.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,8 +20,12 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
23
|
+
### Rspec-Integration
|
24
|
+
|
25
25
|
```ruby
|
26
|
-
|
26
|
+
require 'proxy_rb/rspec'
|
27
|
+
|
28
|
+
RSpec.describe 'Infrastructure A' do
|
27
29
|
describe 'proxy1' do
|
28
30
|
subject { 'proxy1.example.com' }
|
29
31
|
|
@@ -95,14 +97,46 @@ RSpec.describe 'Intfrastructure A' do
|
|
95
97
|
end
|
96
98
|
```
|
97
99
|
|
100
|
+
### Authentication
|
101
|
+
|
102
|
+
Maybe your proxy servers require authentication and you would like to test this
|
103
|
+
as well. You've got several possibilies to use proxy passwords with `proxy_rb`.
|
104
|
+
Please have a look at
|
105
|
+
["features/authentication.feature"](features/authentication.feature) for
|
106
|
+
detailed information.
|
107
|
+
|
108
|
+
|
98
109
|
## Development
|
99
110
|
|
100
|
-
|
101
|
-
|
111
|
+
### Requirements
|
112
|
+
|
113
|
+
Go to [the download site](https://www.vaultproject.io/downloads.html) of the
|
114
|
+
"Vault Project" and download the latest `vault` binary. Make sure you place it
|
115
|
+
into a path which is part of the "PATH"-environment variable - even on Windows.
|
116
|
+
|
117
|
+
*Example for a Linux Distribution*
|
118
|
+
|
119
|
+
~~~bash
|
120
|
+
curl -o /tmp/vault.zip https://releases.hashicorp.com/vault/0.5.1/vault_0.5.1_linux_amd64.zip
|
121
|
+
unzip /tmp/vault.zip
|
122
|
+
install -D /tmp/vault -m 0755 ~/bin/vault
|
123
|
+
~~~
|
124
|
+
|
125
|
+
Maybe you want to add the path `~/bin` to `PATH` via `.bashrc` or `.zshrc`.
|
126
|
+
|
127
|
+
~~~bash
|
128
|
+
export PATH=~/bin:$PATH
|
129
|
+
~~~
|
130
|
+
|
131
|
+
### Scripts
|
132
|
+
|
133
|
+
After checking out the repo, run `script/bootstrap` to install dependencies.
|
134
|
+
Then, run `script/console` for an interactive prompt that will allow you to
|
135
|
+
experiment.
|
102
136
|
|
103
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To
|
137
|
+
To install this gem onto your local machine, run `bundle exec rake gem:install`. To
|
104
138
|
release a new version, update the version number in `version.rb`, and then run
|
105
|
-
`bundle exec rake release` to create a git tag for the version, push git
|
139
|
+
`bundle exec rake gem:release` to create a git tag for the version, push git
|
106
140
|
commits and tags, and push the `.gem` file to
|
107
141
|
[rubygems.org](https://rubygems.org).
|
108
142
|
|
data/Rakefile
CHANGED
@@ -1,25 +1,20 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
namespace :gems do
|
5
|
+
require 'bundler/gem_tasks'
|
6
|
+
end
|
2
7
|
|
3
8
|
# require 'bundler'
|
4
9
|
# Bundler.require :default, :test, :development
|
5
10
|
|
6
|
-
require 'filegen'
|
7
|
-
require 'fedux_org_stdlib/rake_tasks'
|
8
|
-
|
9
11
|
require 'coveralls/rake/task'
|
10
12
|
Coveralls::RakeTask.new
|
11
13
|
|
14
|
+
task default: :test
|
15
|
+
|
12
16
|
desc 'Run test suite'
|
13
|
-
task :test
|
14
|
-
Rake::Task['test:before'].execute
|
15
|
-
|
16
|
-
begin
|
17
|
-
#%w(test:rubocop test:rspec test:cucumber test:after).each { |t| Rake::Task[t].execute }
|
18
|
-
%w(test:rubocop test:rspec test:after).each { |t| Rake::Task[t].execute }
|
19
|
-
ensure
|
20
|
-
Rake::Task['test:after'].execute
|
21
|
-
end
|
22
|
-
end
|
17
|
+
task test: %w(test:rubocop test:rspec test:cucumber)
|
23
18
|
|
24
19
|
namespace :test do
|
25
20
|
desc 'Test with coveralls'
|
@@ -37,14 +32,4 @@ namespace :test do
|
|
37
32
|
task :cucumber do
|
38
33
|
sh 'bundle exec cucumber -p all'
|
39
34
|
end
|
40
|
-
|
41
|
-
desc 'Setup test environment'
|
42
|
-
task :before do
|
43
|
-
@web_server = Process.spawn 'rackup -p 65535 script/config.ru'
|
44
|
-
end
|
45
|
-
|
46
|
-
desc 'Teardown test environment'
|
47
|
-
task :after do
|
48
|
-
sh "kill -9 #{@web_server}"
|
49
|
-
end
|
50
35
|
end
|
data/bin/bootstrap
ADDED
data/{script → bin}/console
RENAMED
data/bin/test
ADDED
data/cucumber.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Simple proxy configuration project
|
2
|
+
|
3
|
+
This is a simple proxy configuration project
|
4
|
+
|
5
|
+
## Boostrap
|
6
|
+
|
7
|
+
Execute:
|
8
|
+
|
9
|
+
$ bundle
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Place files in `spec/` and run `rspec`.
|
14
|
+
|
15
|
+
### Fixture
|
16
|
+
|
17
|
+
This fixture includes files for `rspec`-integration.
|
18
|
+
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
|
4
|
+
if RUBY_VERSION < '1.9.3'
|
5
|
+
::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require File.join(File.dirname(f), File.basename(f, '.rb')) }
|
6
|
+
else
|
7
|
+
::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require_relative f }
|
8
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# ProxyRb
|
3
|
+
module ProxyRb
|
4
|
+
# Basic Configuration
|
5
|
+
class BasicConfiguration
|
6
|
+
# In config wrapper
|
7
|
+
#
|
8
|
+
# Used to make the configuration read only if one needs to access an
|
9
|
+
# configuration option from with `ProxyRb::Config`.
|
10
|
+
#
|
11
|
+
# @private
|
12
|
+
class InConfigWrapper
|
13
|
+
attr_reader :config
|
14
|
+
private :config
|
15
|
+
|
16
|
+
def initialize(config)
|
17
|
+
@config = config.dup
|
18
|
+
end
|
19
|
+
|
20
|
+
def method_missing(name, *args)
|
21
|
+
raise ArgumentError, 'Options take no argument' if args.count > 0
|
22
|
+
raise UnknownOptionError, %(Option "#{name}" is unknown. Please use only earlier defined options) unless config.key? name
|
23
|
+
|
24
|
+
config[name]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# ProxyRb
|
3
|
+
module ProxyRb
|
4
|
+
# Basic Configuration
|
5
|
+
class BasicConfiguration
|
6
|
+
# A configuration option
|
7
|
+
#
|
8
|
+
# @private
|
9
|
+
class Option
|
10
|
+
attr_accessor :name, :value
|
11
|
+
attr_reader :default_value
|
12
|
+
|
13
|
+
# Create option
|
14
|
+
def initialize(opts = {})
|
15
|
+
name = opts[:name]
|
16
|
+
value = opts[:value]
|
17
|
+
|
18
|
+
raise ArgumentError, '"name" is required' unless opts.key? :name
|
19
|
+
raise ArgumentError, '"value" is required' unless opts.key? :value
|
20
|
+
|
21
|
+
@name = name
|
22
|
+
@value = value
|
23
|
+
@default_value = value
|
24
|
+
end
|
25
|
+
|
26
|
+
# Compare option
|
27
|
+
def ==(other)
|
28
|
+
name == other.name && value == other.value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'contracts'
|
3
|
+
require 'proxy_rb/basic_configuration/option'
|
4
|
+
require 'proxy_rb/basic_configuration/in_config_wrapper'
|
5
|
+
|
6
|
+
# ProxyRb
|
7
|
+
module ProxyRb
|
8
|
+
# Basic configuration
|
9
|
+
class BasicConfiguration
|
10
|
+
include Contracts
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def known_options
|
14
|
+
@known_options ||= {}
|
15
|
+
end
|
16
|
+
|
17
|
+
# Define an option reader
|
18
|
+
#
|
19
|
+
# @param [Symbol] name
|
20
|
+
# The name of the reader
|
21
|
+
#
|
22
|
+
# @param [Hash] opts
|
23
|
+
# Options
|
24
|
+
#
|
25
|
+
# @option [Class, Module] contract
|
26
|
+
# The contract for the option
|
27
|
+
#
|
28
|
+
# @option [Object] default
|
29
|
+
# The default value
|
30
|
+
def option_reader(name, opts = {})
|
31
|
+
contract = opts[:contract]
|
32
|
+
default = opts[:default]
|
33
|
+
|
34
|
+
raise ArgumentError, 'Either use block or default value' if block_given? && default
|
35
|
+
raise ArgumentError, 'contract-options is required' if contract.nil?
|
36
|
+
|
37
|
+
Contract contract
|
38
|
+
add_option(name, block_given? ? yield(InConfigWrapper.new(known_options)) : default)
|
39
|
+
|
40
|
+
define_method(name) { find_option(name).value }
|
41
|
+
|
42
|
+
self
|
43
|
+
end
|
44
|
+
|
45
|
+
# Define an option reader and writer
|
46
|
+
#
|
47
|
+
# @param [Symbol] name
|
48
|
+
# The name of the reader
|
49
|
+
#
|
50
|
+
# @param [Hash] opts
|
51
|
+
# Options
|
52
|
+
#
|
53
|
+
# @option [Class, Module] contract
|
54
|
+
# The contract for the option
|
55
|
+
#
|
56
|
+
# @option [Object] default
|
57
|
+
# The default value
|
58
|
+
def option_accessor(name, opts = {})
|
59
|
+
contract = opts[:contract]
|
60
|
+
default = opts[:default]
|
61
|
+
|
62
|
+
raise ArgumentError, 'Either use block or default value' if block_given? && default
|
63
|
+
# fail ArgumentError, 'Either use block or default value' if !block_given? && default.nil? && default.to_s.empty?
|
64
|
+
raise ArgumentError, 'contract-options is required' if contract.nil?
|
65
|
+
|
66
|
+
# Add writer
|
67
|
+
add_option(name, block_given? ? yield(InConfigWrapper.new(known_options)) : default)
|
68
|
+
|
69
|
+
Contract contract
|
70
|
+
define_method("#{name}=") { |v| find_option(name).value = v }
|
71
|
+
|
72
|
+
# Add reader
|
73
|
+
option_reader name, contract: { None => contract.values.first }
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def add_option(name, value = nil)
|
79
|
+
return if known_options.key?(name)
|
80
|
+
|
81
|
+
known_options[name] = Option.new(name: name, value: value)
|
82
|
+
|
83
|
+
self
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
protected
|
88
|
+
|
89
|
+
attr_accessor :local_options
|
90
|
+
|
91
|
+
public
|
92
|
+
|
93
|
+
# Create configuration
|
94
|
+
def initialize
|
95
|
+
initialize_configuration
|
96
|
+
end
|
97
|
+
|
98
|
+
# @yield [Configuration]
|
99
|
+
#
|
100
|
+
# Yields self
|
101
|
+
def configure
|
102
|
+
yield self if block_given?
|
103
|
+
end
|
104
|
+
|
105
|
+
# Reset configuration
|
106
|
+
def reset
|
107
|
+
initialize_configuration
|
108
|
+
end
|
109
|
+
|
110
|
+
# Make deep dup copy of configuration
|
111
|
+
def make_copy
|
112
|
+
obj = dup
|
113
|
+
obj.local_options = Marshal.load(Marshal.dump(local_options))
|
114
|
+
|
115
|
+
obj
|
116
|
+
end
|
117
|
+
|
118
|
+
# Check if <name> is option
|
119
|
+
#
|
120
|
+
# @param [String, Symbol] name
|
121
|
+
# The name of the option
|
122
|
+
def option?(name)
|
123
|
+
local_options.any? { |_, v| v.name == name.to_sym }
|
124
|
+
end
|
125
|
+
|
126
|
+
def ==(other)
|
127
|
+
local_options.values.map(&:value) == other.local_options.values.map(&:value)
|
128
|
+
end
|
129
|
+
|
130
|
+
# Set if name is option
|
131
|
+
def set_if_option(name, *args)
|
132
|
+
send("#{name}=".to_sym, *args) if option? name
|
133
|
+
public_send("#{name}=".to_sym, *args) if option? name
|
134
|
+
end
|
135
|
+
|
136
|
+
private
|
137
|
+
|
138
|
+
def initialize_configuration
|
139
|
+
@local_options = Marshal.load(Marshal.dump(self.class.known_options))
|
140
|
+
end
|
141
|
+
|
142
|
+
def find_option(name)
|
143
|
+
raise NotImplementedError, %(Unknown option "#{name}") unless option? name
|
144
|
+
|
145
|
+
local_options[name]
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'contracts'
|
3
|
+
|
4
|
+
require 'proxy_rb/version'
|
5
|
+
require 'proxy_rb/basic_configuration'
|
6
|
+
require 'proxy_rb/basic_configuration/in_config_wrapper'
|
7
|
+
|
8
|
+
require 'proxy_rb/password_fetchers/basic_password_fetcher'
|
9
|
+
require 'proxy_rb/password_fetchers/environment_password_fetcher'
|
10
|
+
|
11
|
+
# ProxyRb
|
12
|
+
module ProxyRb
|
13
|
+
# ProxyRb Configuration
|
14
|
+
#
|
15
|
+
# This defines the configuration options of proxy_rb
|
16
|
+
class Configuration < BasicConfiguration
|
17
|
+
option_accessor :password_fetcher, contract: { PasswordFetchers::BasicPasswordFetcher => PasswordFetchers::BasicPasswordFetcher }, default: ProxyRb::PasswordFetchers::EnvironmentPasswordFetcher.new(prefix: 'SECRET')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# ProxyRb
|
22
|
+
module ProxyRb
|
23
|
+
@config = Configuration.new
|
24
|
+
|
25
|
+
class << self
|
26
|
+
attr_reader :config
|
27
|
+
|
28
|
+
# Configure proxy_rb
|
29
|
+
#
|
30
|
+
# @example How to configure proxy_rb
|
31
|
+
#
|
32
|
+
# ProxyRb.configure do |config|
|
33
|
+
# config.<option> = <value>
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
def configure(&block)
|
37
|
+
@config.configure(&block)
|
38
|
+
|
39
|
+
self
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'shellwords'
|
3
|
+
|
4
|
+
# ProxyRb
|
5
|
+
module ProxyRb
|
6
|
+
# Hold proxy credentials
|
7
|
+
class Credentials
|
8
|
+
protected
|
9
|
+
|
10
|
+
attr_reader :password
|
11
|
+
|
12
|
+
public
|
13
|
+
|
14
|
+
attr_reader :user_name
|
15
|
+
|
16
|
+
# @param [String] user_name
|
17
|
+
# The user name to use for authentication against proxy
|
18
|
+
#
|
19
|
+
# @param [String] password
|
20
|
+
# The password to use for authentication against proxy
|
21
|
+
def initialize(user_name, password)
|
22
|
+
@user_name = user_name
|
23
|
+
@password = password
|
24
|
+
end
|
25
|
+
|
26
|
+
# Convert to string
|
27
|
+
#
|
28
|
+
# @return [String]
|
29
|
+
# A formatted string <user>:<password>
|
30
|
+
def to_s
|
31
|
+
Shellwords.escape(format('%s:%s', user_name, password))
|
32
|
+
end
|
33
|
+
|
34
|
+
# Is credentials empty
|
35
|
+
#
|
36
|
+
# @return [TrueClass, FalseClass]
|
37
|
+
# Empty if any user_name or password is empty
|
38
|
+
def empty?
|
39
|
+
!(user_name? && password?)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def user_name?
|
45
|
+
!(user_name.nil? || user_name.empty?)
|
46
|
+
end
|
47
|
+
|
48
|
+
def password?
|
49
|
+
!(password.nil? || password.empty?)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'excon'
|
3
|
+
|
4
|
+
# ProxyRb
|
5
|
+
module ProxyRb
|
6
|
+
# Download Content via proxy
|
7
|
+
class HttpDownloader
|
8
|
+
private
|
9
|
+
|
10
|
+
attr_reader :downloader, :proxy
|
11
|
+
|
12
|
+
public
|
13
|
+
|
14
|
+
def initialize(proxy)
|
15
|
+
@downloader = Excon
|
16
|
+
@proxy = proxy
|
17
|
+
end
|
18
|
+
|
19
|
+
def process(resource)
|
20
|
+
resource.content = downloader.get(resource.to_uri, proxy: proxy.to_uri)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|