infrataster 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b02e1a94765dc0d775d830797454180472654009
4
- data.tar.gz: 29d0856e7cdce1920a7df6690b5f57f145cb2fc1
3
+ metadata.gz: edd8224440be0202f0981f08c84d41d96452ced1
4
+ data.tar.gz: 22738c41f609c5a5975251c41aaf4405fb2a451b
5
5
  SHA512:
6
- metadata.gz: 37fd588b2774e7219915bddd22016bfe7158ffd09bad938259f526e4ace64fc21abfda87884bd0dbb925aef07002f36dcec005cb7fde760dc23b8182e0b2ab20
7
- data.tar.gz: 7b10de04e16a5a507f9119aacd8c35f72948a595907c25f96ab7c61a004a69b812f67c3fa2d724c3405f2a91715a9eb2b1b6410e46b1936eafcedd0e09e5503a
6
+ metadata.gz: 0afc168b4efdf3c99d69f8780061c0d4276873c03801ef49394d56922a73e23a15da02a1376c6ff136c90cb5eca7b71e029d9351200b20713b3c4f4b08ebb11e
7
+ data.tar.gz: f737fd8a7ea09bdda40fffb1fc0e9165a3fe8369d7779a055b6c4b3b56be6ffd1568214e7996784cdbfd89db110138458bdb9e4e7e367492488bc0232eef52c5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Infrataster Changelog
2
2
 
3
+ ## v0.1.8
4
+
5
+ * Use Poltergeist's header manipulation instead of BrowserMob Proxy. Remove BrowserMob Proxy dependency.
6
+
3
7
  ## v0.1.7
4
8
 
5
9
  * Fix a key name in a config passed to Net::SSH.start. (by @rrreeeyyy)
data/README.md CHANGED
@@ -219,15 +219,6 @@ describe server(:app) do
219
219
  end
220
220
  ```
221
221
 
222
- If you use `capybara`, you should download and extract [BrowserMob Proxy](http://bmp.lightbody.net/) and set `Infrataster::BrowsermobProxy.bin_path` to binary path in `spec/spec_helper.rb`:
223
-
224
- ```ruby
225
- # spec/spec_helper.rb
226
- Infrataster::BrowsermobProxy.bin_path = '/path/to/browsermob/bin/browsermob'
227
- ```
228
-
229
- (BrowserMob Proxy is needed to manipulate Host HTTP header.)
230
-
231
222
  ### `mysql_query` resource
232
223
 
233
224
  `mysql_query` resource is now in [infrataster-plugin-mysql](https://github.com/ryotarai/infrataster-plugin-mysql).
data/Rakefile CHANGED
@@ -29,25 +29,7 @@ namespace :spec do
29
29
  end
30
30
 
31
31
  desc 'Prepare'
32
- task :prepare => ['download_browsermob', 'start_vm'] do
33
- end
34
-
35
- task :download_browsermob do
36
- dir = File.join(integration_dir, 'vm/vendor/browsermob')
37
- unless Dir.exist?(dir)
38
- puts yellow("Downloading browsermob...")
39
- Dir.mktmpdir do |tmp|
40
- open('https://s3-us-west-1.amazonaws.com/lightbody-bmp/browsermob-proxy-2.0-beta-9-bin.zip') do |remote|
41
- open(File.join(tmp, 'browsermob-proxy.zip'), 'wb') do |f|
42
- f.write(remote.read)
43
- end
44
- end
45
- Dir.chdir(tmp) do
46
- system "unzip browsermob-proxy.zip"
47
- end
48
- FileUtils.mv(File.join(tmp, 'browsermob-proxy-2.0-beta-9'), dir)
49
- end
50
- end
32
+ task :prepare => ['start_vm'] do
51
33
  end
52
34
 
53
35
  task :berks_vendor do
data/infrataster.gemspec CHANGED
@@ -24,7 +24,6 @@ Gem::Specification.new do |spec|
24
24
  spec.add_runtime_dependency "net-ssh-gateway"
25
25
  spec.add_runtime_dependency "capybara"
26
26
  spec.add_runtime_dependency "poltergeist"
27
- spec.add_runtime_dependency "browsermob-proxy"
28
27
  spec.add_runtime_dependency "faraday"
29
28
 
30
29
  spec.add_development_dependency "bundler", "~> 1.5"
@@ -12,11 +12,9 @@ module Infrataster
12
12
  end
13
13
 
14
14
  def self.prepare_session
15
- proxy = BrowsermobProxy.proxy
16
15
  Capybara.register_driver CAPYBARA_DRIVER_NAME do |app|
17
16
  Capybara::Poltergeist::Driver.new(
18
17
  app,
19
- phantomjs_options: ["--proxy=http://#{proxy.host}:#{proxy.port}"],
20
18
  )
21
19
  end
22
20
  Capybara::Session.new(CAPYBARA_DRIVER_NAME)
@@ -37,18 +35,12 @@ module Infrataster
37
35
  def before_each(example)
38
36
  example.example_group_instance.extend(Capybara::RSpecMatchers)
39
37
 
40
- proxy = BrowsermobProxy.proxy
41
- proxy.header({"Host" => resource.uri.host})
38
+ session.driver.headers = {"Host" => resource.uri.host}
42
39
 
43
- address, port, @gateway_finalize_proc =
44
- server.open_gateway_on_from_server(resource.uri.port)
40
+ address, port = server.forward_port(resource.uri.port)
45
41
  Capybara.app_host = "http://#{address}:#{port}"
46
42
  end
47
43
 
48
- def after_each(example)
49
- @gateway_finalize_proc.call if @gateway_finalize_proc
50
- end
51
-
52
44
  Capybara::Session::DSL_METHODS.each do |method|
53
45
  define_method method do |*args, &block|
54
46
  page.send method, *args, &block
@@ -4,7 +4,7 @@ module Infrataster
4
4
  module Contexts
5
5
  class HttpContext < BaseContext
6
6
  def response
7
- server.open_gateway_on_from_server(resource.uri.port) do |address, port|
7
+ server.forward_port(resource.uri.port) do |address, port|
8
8
  url = "#{resource.uri.scheme}://#{address}:#{port}"
9
9
 
10
10
  conn = Faraday.new(:url => url) do |faraday|
@@ -13,5 +13,11 @@ RSpec.configure do |config|
13
13
  config.after(:each) do
14
14
  @infrataster_context.after_each(example) if @infrataster_context.respond_to?(:after_each)
15
15
  end
16
+
17
+ config.after(:all) do
18
+ Infrataster::Server.defined_servers.each do |server|
19
+ server.shutdown_gateway
20
+ end
21
+ end
16
22
  end
17
23
 
@@ -45,63 +45,34 @@ module Infrataster
45
45
  end
46
46
  end
47
47
 
48
- def ssh_gateway
49
- gateway = Net::SSH::Gateway.new(*ssh_start_args)
50
- finalize_proc = Proc.new do
51
- gateway.shutdown!
52
- end
48
+ def find_available_port
49
+ # find available local port
50
+ server = TCPServer.new('127.0.0.1', 0)
51
+ available_port = server.addr[1]
52
+ server.close
53
53
 
54
- [gateway, finalize_proc]
54
+ available_port
55
55
  end
56
56
 
57
- def with_ssh_gateway
58
- gateway, finalize_proc = ssh_gateway
59
- yield gateway
60
- ensure
61
- finalize_proc.call
57
+ def gateway
58
+ @gateway ||= Net::SSH::Gateway.new(*ssh_start_args)
62
59
  end
63
60
 
64
- def gateway_open(host, port)
65
- # find available local port
66
- server = TCPServer.new('127.0.0.1', 0)
67
- local_port = server.addr[1]
68
- server.close
69
-
70
- if block_given?
71
- with_ssh_gateway do |gateway|
72
- gateway.open(host, port, local_port) do |port|
73
- yield port
74
- end
75
- end
76
- else
77
- gateway, gateway_finalize_proc = ssh_gateway
78
- port = gateway.open(host, port, local_port)
79
- finalize_proc = Proc.new do
80
- gateway.close(port)
81
- gateway_finalize_proc.call
82
- end
83
- [port, finalize_proc]
61
+ def shutdown_gateway
62
+ if @gateway
63
+ @gateway.shutdown!
64
+ @gateway = nil
84
65
  end
85
66
  end
86
67
 
87
- def open_gateway_on_from_server(port)
68
+ def forward_port(port, &block)
69
+ host, forwarded_port = _forward_port(port)
88
70
  if block_given?
89
- if from
90
- from.gateway_open(@address, port) do |new_port|
91
- Logger.debug("tunnel: localhost:#{new_port} -> #{from.address} -> #{@address}:#{port}")
92
- yield '127.0.0.1', new_port
93
- end
94
- else
95
- yield @address, port
96
- end
71
+ return_value = block.call(host, forwarded_port)
72
+ from.gateway.close(forwarded_port) if from
73
+ return_value
97
74
  else
98
- if from
99
- new_port, finalize_proc = from.gateway_open(@address, port)
100
- Logger.debug("tunnel: localhost:#{new_port} -> #{from.address} -> #{@address}:#{port}")
101
- ['127.0.0.1', new_port, finalize_proc]
102
- else
103
- [@address, port, nil]
104
- end
75
+ [host, forwarded_port]
105
76
  end
106
77
  end
107
78
 
@@ -119,6 +90,16 @@ module Infrataster
119
90
 
120
91
  private
121
92
 
93
+ def _forward_port(port)
94
+ if from
95
+ local_port = from.gateway.open(@address, port, find_available_port)
96
+ ['127.0.0.1', local_port]
97
+ else
98
+ # no need to forward port
99
+ [@address, port]
100
+ end
101
+ end
102
+
122
103
  def _ssh_start_args
123
104
  config = {}
124
105
 
@@ -1,3 +1,3 @@
1
1
  module Infrataster
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
data/lib/infrataster.rb CHANGED
@@ -2,7 +2,6 @@ require "infrataster/version"
2
2
  require "infrataster/resources"
3
3
  require "infrataster/server"
4
4
  require "infrataster/helpers"
5
- require "infrataster/browsermob_proxy"
6
5
  require "infrataster/contexts"
7
6
  require 'logger'
8
7
 
@@ -12,8 +12,6 @@ Infrataster::Server.define(
12
12
  from: :proxy,
13
13
  )
14
14
 
15
- Infrataster::BrowsermobProxy.bin_path = File.expand_path('../vm/vendor/browsermob/bin/browsermob-proxy', __FILE__)
16
-
17
15
  RSpec.configure do |config|
18
16
  config.treat_symbols_as_metadata_keys_with_true_values = true
19
17
  config.run_all_when_everything_filtered = true
@@ -32,26 +32,13 @@ module Infrataster
32
32
  end
33
33
  end
34
34
 
35
- describe "#ssh_gateway" do
36
- it "returns gateway instance and proc for finalizing" do
37
- server = Server.new('name', 'address', ssh: {host: 'host', user: 'user'})
38
-
39
- gateway_mock = double
40
- expect(gateway_mock).to receive(:shutdown!)
41
- expect(Net::SSH::Gateway).to receive(:new).and_return(gateway_mock)
42
- gateway, finalize_proc = server.ssh_gateway
43
- finalize_proc.call
44
- expect(gateway).to eq(gateway_mock)
45
- end
46
- end
47
-
48
35
  describe "#_ssh_start_args" do
49
36
  context "with ssh option" do
50
37
  context "when options[:ssh][:host] is set" do
51
38
  it 'returns args for SSH.start' do
52
- server = Server.new('name', 'address', ssh: {host: 'host', user: 'user'})
39
+ server = Server.new('name', 'address', ssh: {host_name: 'host', user: 'user'})
53
40
  expect(server.send(:_ssh_start_args)).
54
- to eq(['host', 'user', {host: 'host', user: 'user'}])
41
+ to eq(['host', 'user', {host_name: 'host', user: 'user'}])
55
42
  end
56
43
  end
57
44
 
@@ -59,7 +46,7 @@ module Infrataster
59
46
  it 'returns args for SSH.start' do
60
47
  server = Server.new('name', 'address', ssh: {user: 'user'})
61
48
  expect(server.send(:_ssh_start_args)).
62
- to eq(['address', 'user', {host: 'address', user: 'user'}])
49
+ to eq(['address', 'user', {host_name: 'address', user: 'user'}])
63
50
  end
64
51
  end
65
52
  end
@@ -69,9 +56,9 @@ module Infrataster
69
56
  it 'returns args for SSH.start' do
70
57
  server = Server.new('name', 'address', vagrant: true)
71
58
  expect(server).to receive(:ssh_config_for_vagrant).with('name').
72
- and_return({host: 'host', user: 'user'})
59
+ and_return({host_name: 'host', user: 'user'})
73
60
  expect(server.send(:_ssh_start_args)).
74
- to eq(['host', 'user', {host: 'host', user: 'user'}])
61
+ to eq(['host', 'user', {host_name: 'host', user: 'user'}])
75
62
  end
76
63
  end
77
64
 
@@ -79,9 +66,9 @@ module Infrataster
79
66
  it 'returns args for SSH.start' do
80
67
  server = Server.new('name', 'address', vagrant: 'vagrant_vm_name')
81
68
  expect(server).to receive(:ssh_config_for_vagrant).with('vagrant_vm_name').
82
- and_return({host: 'host', user: 'user'})
69
+ and_return({host_name: 'host', user: 'user'})
83
70
  expect(server.send(:_ssh_start_args)).
84
- to eq(['host', 'user', {host: 'host', user: 'user'}])
71
+ to eq(['host', 'user', {host_name: 'host', user: 'user'}])
85
72
  end
86
73
  end
87
74
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infrataster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-15 00:00:00.000000000 Z
11
+ date: 2014-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: browsermob-proxy
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: faraday
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -167,7 +153,6 @@ files:
167
153
  - ci/jenkins_build
168
154
  - infrataster.gemspec
169
155
  - lib/infrataster.rb
170
- - lib/infrataster/browsermob_proxy.rb
171
156
  - lib/infrataster/contexts.rb
172
157
  - lib/infrataster/contexts/base_context.rb
173
158
  - lib/infrataster/contexts/capybara_context.rb
@@ -1,36 +0,0 @@
1
- require 'browsermob/proxy'
2
-
3
- module Infrataster
4
- module BrowsermobProxy
5
- class << self
6
- def server
7
- @server ||= start_server
8
- end
9
-
10
- def proxy
11
- @proxy ||= server.create_proxy
12
- end
13
-
14
- def bin_path
15
- @bin_path
16
- end
17
-
18
- def bin_path=(path)
19
- @bin_path = path
20
- end
21
-
22
- private
23
- def start_server
24
- BrowserMob::Proxy::Server.new(find_bin, timeout: 60).tap do |server|
25
- server.start
26
- end
27
- end
28
-
29
- def find_bin
30
- return @bin_path if @bin_path
31
- `which browsermob-proxy`
32
- end
33
- end
34
- end
35
- end
36
-