itamae 1.9.2 → 1.9.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba7c43e3ad6a6bfafe1bc42c97b72e9869218f10
4
- data.tar.gz: 6d4c623011615e7bf8220876642479cbddc94fc6
3
+ metadata.gz: 154b1597ae0505eec08966ce87e4481cebc99291
4
+ data.tar.gz: eaed49c1a0352814e22227999385e0668dc99320
5
5
  SHA512:
6
- metadata.gz: ba8d6b72cd15260fc2e0b4b53d8a9774e9a7baa1352cc5ef3aafdfc3be0224848873cafd846c0e44d2650e6aeb6b6a5ae0906f4eb5b92c6251d89669f11137d8
7
- data.tar.gz: f5925dbc882fb1e6b1f654a51ddf7cc77059725bb678404ad11cb522fffcba317d1c09092007102c8f8787d5437749cc019b4eaa725f7ea1f6ffc953c8a21004
6
+ metadata.gz: 749602fb374334e832b70aeadbae91dade0aaa0426747dc11394771c1cb4d4f00d78af4f290907659c15307e773c977e0fd7b4d6eaa72536248a9eca757b005d
7
+ data.tar.gz: 97c15caa14ea44d38898a2ec44c629a25a499855b5d16553e04fa431cc72dff470b7f8844e0b0fc31aff9d9abae51a8509a3263ec8c243b36b86c95baded7bc6
@@ -1,3 +1,11 @@
1
+ ## v1.9.3
2
+
3
+ Improvements
4
+
5
+ - [Support redirect on http_request resource (by @hico-horiuchi)](https://github.com/itamae-kitchen/itamae/pull/190)
6
+ - [Use /bin/bash as default shell if shell is not set (by @hico-horiuchi)](https://github.com/itamae-kitchen/itamae/pull/192)
7
+ - [Stop replacing files which are not updated (by @KitaitiMakoto)](https://github.com/itamae-kitchen/itamae/pull/194)
8
+
1
9
  ## v1.9.2
2
10
 
3
11
  Features
@@ -36,7 +36,7 @@ module Itamae
36
36
 
37
37
  class Base
38
38
  attr_reader :executed_commands
39
-
39
+
40
40
  def initialize(options)
41
41
  @options = options
42
42
  @backend = create_specinfra_backend
@@ -189,7 +189,7 @@ module Itamae
189
189
  end
190
190
 
191
191
  def shell
192
- @options[:shell]
192
+ @options[:shell] || '/bin/sh'
193
193
  end
194
194
 
195
195
  def run_command_with_profiling(command)
@@ -80,7 +80,9 @@ module Itamae
80
80
  updated!
81
81
  end
82
82
 
83
- run_specinfra(:move_file, @temppath, attributes.path)
83
+ if updated?
84
+ run_specinfra(:move_file, @temppath, attributes.path)
85
+ end
84
86
  end
85
87
  end
86
88
 
@@ -1,27 +1,45 @@
1
1
  require 'itamae'
2
2
  require 'uri'
3
- require 'net/http'
3
+ require 'net/https'
4
4
 
5
5
  module Itamae
6
6
  module Resource
7
7
  class HttpRequest < File
8
- UrlNotFoundError = Class.new(StandardError)
8
+ RedirectLimitExceeded = Class.new(StandardError)
9
9
 
10
10
  define_attribute :action, default: :get
11
11
  define_attribute :headers, type: Hash, default: {}
12
12
  define_attribute :message, type: String, default: ""
13
+ define_attribute :redirect_limit, type: Integer, default: 10
13
14
  define_attribute :url, type: String, required: true
14
15
 
15
16
  def pre_action
16
17
  uri = URI.parse(attributes.url)
17
- http = Net::HTTP.new(uri.host, uri.port)
18
- http.use_ssl = true if uri.scheme == "https"
19
-
20
- case attributes.action
21
- when :delete, :get, :options
22
- response = http.method(attributes.action).call(uri.request_uri, attributes.headers)
23
- when :post, :put
24
- response = http.method(attributes.action).call(uri.request_uri, attributes.message, attributes.headers)
18
+ response = nil
19
+ redirects_followed = 0
20
+
21
+ loop do
22
+ http = Net::HTTP.new(uri.host, uri.port)
23
+ http.use_ssl = true if uri.scheme == "https"
24
+
25
+ case attributes.action
26
+ when :delete, :get, :options
27
+ response = http.method(attributes.action).call(uri.request_uri, attributes.headers)
28
+ when :post, :put
29
+ response = http.method(attributes.action).call(uri.request_uri, attributes.message, attributes.headers)
30
+ end
31
+
32
+ if response.kind_of?(Net::HTTPRedirection)
33
+ if redirects_followed < attributes.redirect_limit
34
+ uri = URI.parse(response["location"])
35
+ redirects_followed += 1
36
+ Itamae.logger.debug "Following redirect #{redirects_followed}/#{attributes.redirect_limit}"
37
+ else
38
+ raise RedirectLimitExceeded
39
+ end
40
+ else
41
+ break
42
+ end
25
43
  end
26
44
 
27
45
  attributes.content = response.body
@@ -1 +1 @@
1
- 1.9.2
1
+ 1.9.3
@@ -101,6 +101,11 @@ describe file('/tmp/http_request_headers.html') do
101
101
  its(:content) { should match(/"User-Agent": "Itamae"/) }
102
102
  end
103
103
 
104
+ describe file('/tmp/http_request_redirect.html') do
105
+ it { should be_file }
106
+ its(:content) { should match(/"from": "itamae"/) }
107
+ end
108
+
104
109
  describe file('/tmp/notifies') do
105
110
  it { should be_file }
106
111
  its(:content) { should eq("2431") }
@@ -186,6 +186,11 @@ http_request "/tmp/http_request_headers.html" do
186
186
  url "https://httpbin.org/get"
187
187
  end
188
188
 
189
+ http_request "/tmp/http_request_redirect.html" do
190
+ redirect_limit 1
191
+ url "https://httpbin.org/redirect-to?url=https%3A%2F%2Fhttpbin.org%2Fget%3Ffrom%3Ditamae"
192
+ end
193
+
189
194
  ######
190
195
 
191
196
  service "cron" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itamae
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.2
4
+ version: 1.9.3
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-12-31 00:00:00.000000000 Z
11
+ date: 2016-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor