Class: Itamae::Resource::HttpRequest
- Inherits:
-
Object
- Object
- Itamae::Resource::HttpRequest
- Defined in:
- lib/itamae-spec/resource/http_request.rb
Instance Method Summary collapse
Instance Method Details
#fetch_content ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/itamae-spec/resource/http_request.rb', line 38 def fetch_content uri = URI.parse(attributes.url) response = nil redirects_followed = 0 loop do http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if uri.scheme == "https" case @current_action when :delete, :get, :options response = http.method(@current_action).call(uri.request_uri, attributes.headers) when :post, :put response = http.method(@current_action).call(uri.request_uri, attributes., attributes.headers) end if response.kind_of?(Net::HTTPRedirection) if redirects_followed < attributes.redirect_limit uri = URI.parse(response["location"]) redirects_followed += 1 ItamaeMitsurin.logger.debug "Following redirect #{redirects_followed}/#{attributes.redirect_limit}" else raise RedirectLimitExceeded end else break end end response.body end |
#pre_action ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/itamae-spec/resource/http_request.rb', line 5 def pre_action attributes.content = fetch_content current.exist = run_specinfra(:check_file_is_file, attributes.path) attributes.exist = true send_tempfile compare_file end |
#show_differences ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/itamae-spec/resource/http_request.rb', line 14 def show_differences current.mode = current.mode.rjust(4, '0') if current.mode attributes.mode = attributes.mode.rjust(4, '0') if attributes.mode @current_attributes.each_pair do |key, current_value| value = @attributes[key] if current_value.nil? && value.nil? # ignore elsif current_value.nil? && !value.nil? Itamae.logger.color :green do Itamae.logger.info "#{resource_type}[#{resource_name}] #{key} will be '#{value}'" end elsif current_value == value || value.nil? Itamae.logger.debug "#{resource_type}[#{resource_name}] #{key} will not change (current value is '#{current_value}')" else Itamae.logger.color :green do Itamae.logger.info "#{resource_type}[#{resource_name}] #{key} will change from '#{current_value}' to '#{value}'" end end end show_content_diff end |