infrataster 0.2.5 → 0.2.6

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: 1ddec9ea2e17c599e93bde43dfcb46d4b4e3eec4
4
- data.tar.gz: 542174438bfd08460623954456dabbd72a2d7c01
3
+ metadata.gz: d3ee864e2b8c987050047a121e5393e5e2675064
4
+ data.tar.gz: a08c6f86e0631d0d6446eb7392b72bae06e460c6
5
5
  SHA512:
6
- metadata.gz: ee75a9a51c1da1b37268399e2e444612d934d4f0858299a7b70cbadd5e8d8dc8edad7644a190ab7f343805e6ad91180750982949e6f5b17a3e49fb55ee31e2bb
7
- data.tar.gz: 18323691afd689f840ca58b604edd14913dd25cf6668357dd36936d931f7298130c840926a847cf8f78a14286c42c7291bf2aabd0edf8d10acab0a24a9cd5bc5
6
+ metadata.gz: 7e0dfa862fed932ee874e9a8280df0aac2f22c5c35d6edc67e21c5aedd730f7364e4cdfceab5ea0300d8f53e09c29717c6ab890478eaa7094671aead90f81019
7
+ data.tar.gz: 0e51bd096323609e8b8551b1f0c3794fe9f612131cbec563d1d64a5a860e308a8a6db51de6516ed0156ea021617e4d4ced11164e6ecddd618e6025109572b53d
@@ -1,5 +1,9 @@
1
1
  # Infrataster Changelog
2
2
 
3
+ ## v0.2.6
4
+
5
+ * [Inflate response body by gzip if inflate_gzip of http resource is true.]
6
+
3
7
  ## v0.2.5
4
8
 
5
9
  * [body option of http resource](https://github.com/ryotarai/infrataster/pull/57)
data/README.md CHANGED
@@ -34,11 +34,11 @@ Vagrant.configure("2") do |config|
34
34
 
35
35
  config.vm.define :proxy do |c|
36
36
  c.vm.network "private_network", ip: "192.168.33.10"
37
- c.vm.network "private_network", ip: "171.16.33.10", virtualbox__intnet: "infrataster-example"
37
+ c.vm.network "private_network", ip: "172.16.33.10", virtualbox__intnet: "infrataster-example"
38
38
  end
39
39
 
40
40
  config.vm.define :app do |c|
41
- c.vm.network "private_network", ip: "171.16.33.11", virtualbox__intnet: "infrataster-example"
41
+ c.vm.network "private_network", ip: "172.16.33.11", virtualbox__intnet: "infrataster-example"
42
42
  end
43
43
  end
44
44
  ```
@@ -175,6 +175,7 @@ Infrataster::Server.define(
175
175
  :app,
176
176
  # find IP address matching 172.16.0.0 ~ 172.16.255.255
177
177
  '172.16.0.0/16',
178
+ )
178
179
  ```
179
180
 
180
181
  Of course, you can set fully-specified IP address too.
@@ -185,6 +186,7 @@ Infrataster::Server.define(
185
186
  '172.16.11.22',
186
187
  # or
187
188
  '172.16.11.22/32',
189
+ )
188
190
  ```
189
191
 
190
192
  ### #ssh_exec
@@ -271,10 +273,28 @@ end
271
273
 
272
274
  ### `dns` resource
273
275
 
274
- `dns` resource send query to DNS server.
276
+ `dns` resource sends a query to DNS server.
275
277
 
276
278
  `dns` is provided by [infrataster-plugin-dns](https://github.com/otahi/infrataster-plugin-dns) by [@otahi](https://github.com/otahi).
277
279
 
280
+ ### `memcached` resource
281
+
282
+ `memcached` resource sends a query to memcached server.
283
+
284
+ `memcached` is provided by [infrataster-plugin-memecached](https://github.com/rahulkhengare/infrataster-plugin-memcached) by [@rahulkhengare](https://github.com/rahulkhengare).
285
+
286
+ ### `redis` resource
287
+
288
+ `redis` resource sends a query to redis server.
289
+
290
+ `redis` is provided by [infrataster-plugin-redis](https://github.com/rahulkhengare/infrataster-plugin-redis) by [@rahulkhengare](https://github.com/rahulkhengare).
291
+
292
+ ### `firewall` resource
293
+
294
+ `firewall` resource tests your firewalls.
295
+
296
+ `firewall` is provided by [infrataster-plugin-firewall](https://github.com/otahi/infrataster-plugin-firewall) by [@otahi](https://github.com/otahi).
297
+
278
298
  ## Example
279
299
 
280
300
  * [example](example)
@@ -3,6 +3,7 @@ require "infrataster/resources"
3
3
  require "infrataster/server"
4
4
  require "infrataster/helpers"
5
5
  require "infrataster/contexts"
6
+ require "infrataster/faraday_middleware"
6
7
  require 'logger'
7
8
 
8
9
  module Infrataster
@@ -15,6 +15,9 @@ module Infrataster
15
15
  conn = Faraday.new(options) do |faraday|
16
16
  faraday.request :url_encoded
17
17
  faraday.response :logger, Logger
18
+ if resource.inflate_gzip?
19
+ faraday.use Infrataster::FaradayMiddleware::Gzip
20
+ end
18
21
  faraday.adapter Faraday.default_adapter
19
22
  faraday.basic_auth(*resource.basic_auth) if resource.basic_auth
20
23
  end
@@ -0,0 +1,6 @@
1
+ require 'infrataster/faraday_middleware/gzip'
2
+
3
+ module Infrataster
4
+ module FaradayMiddleware
5
+ end
6
+ end
@@ -0,0 +1,68 @@
1
+ # This module is ported from faraday_middleware:
2
+ # https://github.com/lostisland/faraday_middleware/blob/138766e3d1cfd58b01d1c3ccb453bb8bc7c1633a/lib/faraday_middleware/gzip.rb
3
+ #
4
+ # Copyright (c) 2011 Erik Michaels-Ober, Wynn Netherland, et al.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+ #
8
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+ #
10
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11
+
12
+ require 'faraday'
13
+
14
+ module Infrataster
15
+ module FaradayMiddleware
16
+ # Middleware to automatically decompress response bodies. If the
17
+ # "Accept-Encoding" header wasn't set in the request, this sets it to
18
+ # "gzip,deflate" and appropriately handles the compressed response from the
19
+ # server. This resembles what Ruby 1.9+ does internally in Net::HTTP#get.
20
+ #
21
+ # This middleware is NOT necessary when these adapters are used:
22
+ # - net_http on Ruby 1.9+
23
+ # - net_http_persistent on Ruby 2.0+
24
+ # - em_http
25
+ class Gzip < Faraday::Middleware
26
+ dependency 'zlib'
27
+
28
+ ACCEPT_ENCODING = 'Accept-Encoding'.freeze
29
+ CONTENT_ENCODING = 'Content-Encoding'.freeze
30
+ CONTENT_LENGTH = 'Content-Length'.freeze
31
+ SUPPORTED_ENCODINGS = 'gzip,deflate'.freeze
32
+ RUBY_ENCODING = '1.9'.respond_to?(:force_encoding)
33
+
34
+ def call(env)
35
+ env[:request_headers][ACCEPT_ENCODING] ||= SUPPORTED_ENCODINGS
36
+ @app.call(env).on_complete do |response_env|
37
+ case response_env[:response_headers][CONTENT_ENCODING]
38
+ when 'gzip'
39
+ reset_body(response_env, &method(:uncompress_gzip))
40
+ when 'deflate'
41
+ reset_body(response_env, &method(:inflate))
42
+ end
43
+ end
44
+ end
45
+
46
+ def reset_body(env)
47
+ env[:body] = yield(env[:body])
48
+ env[:response_headers].delete(CONTENT_ENCODING)
49
+ env[:response_headers][CONTENT_LENGTH] = env[:body].length
50
+ end
51
+
52
+ def uncompress_gzip(body)
53
+ io = StringIO.new(body)
54
+ gzip_reader = if RUBY_ENCODING
55
+ Zlib::GzipReader.new(io, :encoding => 'ASCII-8BIT')
56
+ else
57
+ Zlib::GzipReader.new(io)
58
+ end
59
+ gzip_reader.read
60
+ end
61
+
62
+ def inflate(body)
63
+ Zlib::Inflate.inflate(body)
64
+ end
65
+ end
66
+ end
67
+ end
68
+
@@ -52,6 +52,10 @@ module Infrataster
52
52
  def basic_auth
53
53
  @options[:basic_auth]
54
54
  end
55
+
56
+ def inflate_gzip?
57
+ !!@options[:inflate_gzip]
58
+ end
55
59
  end
56
60
  end
57
61
  end
@@ -47,6 +47,7 @@ module Infrataster
47
47
  def initialize(name, address, options = {})
48
48
  @name, @options = name, options
49
49
  @address = determine_address(address)
50
+ @gateway = nil
50
51
  end
51
52
 
52
53
  def from
@@ -1,3 +1,3 @@
1
1
  module Infrataster
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
@@ -14,15 +14,19 @@ describe server(:proxy) do
14
14
  end
15
15
  end
16
16
 
17
- # If accept-encoding is not specified explicitly,
18
- # Net::HTTP (faraday's default adapter) sends request with accept-encoding=gzip
19
- # and inflate response as gzip automaticallly
20
17
  describe http('http://static.example.com', headers: {"Accept-Encoding" => "gzip"}) do
21
18
  it "gets response compressed by gzip" do
22
19
  expect(response.headers['content-encoding']).to eq('gzip')
23
20
  end
24
21
  end
25
22
 
23
+ describe http('http://static.example.com', headers: {"Accept-Encoding" => "gzip"}, inflate_gzip: true) do
24
+ it "gets response inflated by gzip" do
25
+ expect(response.headers['content-encoding']).to be_nil
26
+ expect(response.body).to eq("This is static site.\n")
27
+ end
28
+ end
29
+
26
30
  describe http('http://static.example.com/auth') do
27
31
  it "sends GET request without basic auth" do
28
32
  expect(response.status).to eq 401
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.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-03 00:00:00.000000000 Z
11
+ date: 2015-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -180,6 +180,8 @@ files:
180
180
  - lib/infrataster/contexts/capybara_context.rb
181
181
  - lib/infrataster/contexts/http_context.rb
182
182
  - lib/infrataster/contexts/no_resource_context.rb
183
+ - lib/infrataster/faraday_middleware.rb
184
+ - lib/infrataster/faraday_middleware/gzip.rb
183
185
  - lib/infrataster/fixtures/Gemfile.erb
184
186
  - lib/infrataster/fixtures/Rakefile.erb
185
187
  - lib/infrataster/fixtures/Vagrantfile.erb
@@ -240,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
242
  version: '0'
241
243
  requirements: []
242
244
  rubyforge_project:
243
- rubygems_version: 2.2.2
245
+ rubygems_version: 2.4.5
244
246
  signing_key:
245
247
  specification_version: 4
246
248
  summary: Infrastructure Behavior Testing Framework