foreman_rh_cloud 4.0.35 → 4.0.36

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
  SHA256:
3
- metadata.gz: 13d501dcd7ec95a0fc10ed4bd7b0a426e3f485aa3dd7ba597e56dbfd41268977
4
- data.tar.gz: 6c392f1ad04344c887609894b64dac3bbd6add5c4a70cbf4ae1598c2851ac581
3
+ metadata.gz: 224802f19d8eb36625b3d80121e6325d2733920417d1b45d229b448e20cd8164
4
+ data.tar.gz: 3ffe588112a4638c952b7dc11786e811dd484aba2f013b03fd070b09cd5292d0
5
5
  SHA512:
6
- metadata.gz: c5bbe88508a4df1017b05d6dd13adb432040dbad271bc317abc10169decd43f1ab785dfc9733f3c8e4d5f6116ffa46252ace5996a5e133c2c48954da71679464
7
- data.tar.gz: 448308053649ce5001aeb40b53f546a52c92a5a84c870d1bbda392655f579c0f16df61c53da16f58101708fdac855813c5f1adeb2039cf2c6a0f2ea1b4c6f709
6
+ metadata.gz: '08abdef66a17843cec33bf0a6fa84c689ecdceab413df010936c0b9b7226ce9b2ed00d1853c23838b49faa01a96ab86673d59554910ba78ebbfd654ecc439d8e'
7
+ data.tar.gz: 3f432ee32d4d1e81b1f5dddccd98265be4e62422ca28a062264be78dd3ce3c58f657aae55dd572a27cc8d88c38ac8b6250f328f17d9951572340af694644259b
@@ -33,14 +33,25 @@ module InsightsCloud::Api
33
33
  }, status: @cloud_response.code
34
34
  end
35
35
 
36
- if @cloud_response.headers[:content_disposition]
37
- return send_data @cloud_response, disposition: @cloud_response.headers[:content_disposition], type: @cloud_response.headers[:content_type]
36
+ # Append redhat-specific headers
37
+ @cloud_response.headers.each do |key, value|
38
+ assign_header(response, @cloud_response, key, false) if key.to_s.start_with?('x_rh_')
38
39
  end
39
-
40
+ # Append general headers
40
41
  assign_header(response, @cloud_response, :x_resource_count, true)
41
- assign_header(response, @cloud_response, :x_rh_insights_request_id, false)
42
+ headers[Rack::ETAG] = @cloud_response.headers[:etag]
42
43
 
43
- render json: @cloud_response, status: @cloud_response.code
44
+ if @cloud_response.headers[:content_disposition]
45
+ # If there is a Content-Disposition header, it means we are forwarding binary data, send the raw data with proper
46
+ # content type
47
+ send_data @cloud_response, disposition: @cloud_response.headers[:content_disposition], type: @cloud_response.headers[:content_type]
48
+ elsif @cloud_response.headers[:content_type] =~ /zip/
49
+ # if there is no Content-Disposition, but the content type is binary according the content type,
50
+ # forward the request as binry too
51
+ send_data @cloud_response, type: @cloud_response.headers[:content_type]
52
+ else
53
+ render json: @cloud_response, status: @cloud_response.code
54
+ end
44
55
  end
45
56
 
46
57
  def branch_info
@@ -25,11 +25,12 @@ module ForemanRhCloud
25
25
  base_params = {
26
26
  method: original_request.method,
27
27
  payload: forward_payload,
28
- headers: {
29
- params: forward_params,
30
- user_agent: http_user_agent(original_request),
31
- content_type: original_request.media_type.presence || original_request.format.to_s,
32
- },
28
+ headers: original_headers(original_request).merge(
29
+ {
30
+ params: forward_params,
31
+ user_agent: http_user_agent(original_request),
32
+ content_type: original_request.media_type.presence || original_request.format.to_s,
33
+ }),
33
34
  }
34
35
  base_params.merge(path_params(original_request.path, certs))
35
36
  end
@@ -80,6 +81,16 @@ module ForemanRhCloud
80
81
  end
81
82
  end
82
83
 
84
+ def original_headers(original_request)
85
+ headers = {
86
+ if_none_match: original_request.if_none_match,
87
+ if_modified_since: original_request.if_modified_since,
88
+ }.compact
89
+
90
+ logger.debug("Sending headers: #{headers}")
91
+ headers
92
+ end
93
+
83
94
  def platform_request?
84
95
  ->(request_path) { request_path.include? '/platform' }
85
96
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '4.0.35'.freeze
2
+ VERSION = '4.0.36'.freeze
3
3
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_rh_cloud",
3
- "version": "4.0.35",
3
+ "version": "4.0.36",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -60,6 +60,29 @@ module InsightsCloud::Api
60
60
  assert_equal x_rh_insights_request_id, @response.headers['x_rh_insights_request_id']
61
61
  end
62
62
 
63
+ test "should set etag header to response from cloud" do
64
+ etag = '12345'
65
+ req = RestClient::Request.new(:method => 'GET', :url => 'http://test.theforeman.org', :headers => { "If-None-Match": etag})
66
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, "OK")
67
+ net_http_resp[Rack::ETAG] = etag
68
+ res = RestClient::Response.create(@body, net_http_resp, req)
69
+ ::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:forward_request).returns(res)
70
+
71
+ get :forward_request, params: { "path" => "static/v1/release/insights-core.egg" }
72
+ assert_equal etag, @response.headers[Rack::ETAG]
73
+ end
74
+
75
+ test "should set content type header to response from cloud" do
76
+ req = RestClient::Request.new(:method => 'GET', :url => 'http://test.theforeman.org')
77
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, "OK")
78
+ net_http_resp['Content-Type'] = 'application/zip'
79
+ res = RestClient::Response.create(@body, net_http_resp, req)
80
+ ::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:forward_request).returns(res)
81
+
82
+ get :forward_request, params: { "path" => "static/v1/release/insights-core.egg" }
83
+ assert_equal net_http_resp['Content-Type'], @response.headers['Content-Type']
84
+ end
85
+
63
86
  test "should handle failed authentication to cloud" do
64
87
  net_http_resp = Net::HTTPResponse.new(1.0, 401, "Unauthorized")
65
88
  res = RestClient::Response.create(@body, net_http_resp, @http_req)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_rh_cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.35
4
+ version: 4.0.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman Red Hat Cloud team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-07 00:00:00.000000000 Z
11
+ date: 2022-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: katello
@@ -174,7 +174,6 @@ files:
174
174
  - app/views/layouts/foreman_rh_cloud/application.html.erb
175
175
  - config/Gemfile.lock.gh_test
176
176
  - config/database.yml.example
177
- - config/package-lock.json
178
177
  - config/package-lock.json.gh_test
179
178
  - config/package-lock.json.plugin
180
179
  - config/rh_cert-api_chain.pem
@@ -659,7 +658,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
659
658
  - !ruby/object:Gem::Version
660
659
  version: '0'
661
660
  requirements: []
662
- rubygems_version: 3.2.22
661
+ rubygems_version: 3.3.7
663
662
  signing_key:
664
663
  specification_version: 4
665
664
  summary: Summary of ForemanRhCloud.