foreman_rh_cloud 10.0.3 → 10.0.5
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 +4 -4
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +2 -0
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +5 -3
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/package.json +1 -1
- data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +13 -0
- data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +24 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfabc05d2ec5effb2a007e85471ba31e9d0067495fcbf52d07bb37b4f3c1a15c
|
4
|
+
data.tar.gz: c5f0db2ca590193d014d69358882c0abf98adf523158ceec65536391b454ca23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd794c63904449ceb0f7b4b2d02de6e8b97cdde7745c24a5d6a02d52047fc036d3b995e11bca5aa0cf241a8b2def0f6efda15e810cd2dfdb9a5060e1cfe984bf
|
7
|
+
data.tar.gz: 73d24b976d3a00150696e403d5bd5f134faa1c60ca8b75063a0ac12e57da85427c6a301faf96d502e736f515c60e6bb6b25627c056909698b3fe9fac17751da7
|
@@ -18,6 +18,8 @@ module InsightsCloud::Api
|
|
18
18
|
certs = candlepin_id_cert @organization
|
19
19
|
@cloud_response = ::ForemanRhCloud::CloudRequestForwarder.new.forward_request(request, controller_name, @branch_id, certs)
|
20
20
|
|
21
|
+
return render json: { message: @cloud_response.to_s }, status: :gateway_timeout if @cloud_response.is_a?(RestClient::Exceptions::OpenTimeout)
|
22
|
+
|
21
23
|
if @cloud_response.code == 401
|
22
24
|
return render json: {
|
23
25
|
:message => 'Authentication to the Insights Service failed.',
|
@@ -17,8 +17,8 @@ module ForemanRhCloud
|
|
17
17
|
logger.debug("Sending request to: #{request_opts[:url]}")
|
18
18
|
|
19
19
|
execute_cloud_request(request_opts)
|
20
|
-
rescue RestClient::
|
21
|
-
error_response.response
|
20
|
+
rescue RestClient::ExceptionWithResponse => error_response
|
21
|
+
error_response.response.presence || error_response.exception
|
22
22
|
end
|
23
23
|
|
24
24
|
def prepare_request_opts(original_request, forward_payload, forward_params, certs)
|
@@ -51,7 +51,9 @@ module ForemanRhCloud
|
|
51
51
|
|
52
52
|
def prepare_forward_params(original_request, branch_id)
|
53
53
|
forward_params = original_request.query_parameters
|
54
|
-
|
54
|
+
compliance_request = original_request.path.match?(/compliance\/v2(\/.*)?/)
|
55
|
+
user_agent = original_request.user_agent.present? && !original_request.user_agent.include?('redhat_access_cfme')
|
56
|
+
if user_agent && !compliance_request
|
55
57
|
forward_params = forward_params.merge(:branch_id => branch_id)
|
56
58
|
end
|
57
59
|
|
data/package.json
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'test_plugin_helper'
|
2
|
+
require 'rest-client'
|
2
3
|
|
3
4
|
module InsightsCloud::Api
|
4
5
|
class MachineTelemetriesControllerTest < ActionController::TestCase
|
@@ -33,6 +34,18 @@ module InsightsCloud::Api
|
|
33
34
|
assert_equal @body, @response.body
|
34
35
|
end
|
35
36
|
|
37
|
+
test "should handle timeout from cloud" do
|
38
|
+
::ForemanRhCloud::CloudRequestForwarder.any_instance.
|
39
|
+
stubs(:forward_request).
|
40
|
+
raises(RestClient::Exceptions::OpenTimeout.new("Timed out connecting to server"))
|
41
|
+
|
42
|
+
get :forward_request, params: { "path" => "platform/module-update-router/v1/channel" }
|
43
|
+
request_response = JSON.parse(@response.body)
|
44
|
+
# I can't get @response.status to take a nil value so I'm not asserting for that
|
45
|
+
|
46
|
+
assert_equal 'Timed out connecting to server', request_response['error']
|
47
|
+
end
|
48
|
+
|
36
49
|
test "should respond with the same content type" do
|
37
50
|
net_http_resp = Net::HTTPResponse.new(1.0, 200, "OK")
|
38
51
|
net_http_resp.add_field 'Set-Cookie', 'Monster'
|
@@ -112,6 +112,30 @@ class CloudRequestForwarderTest < ActiveSupport::TestCase
|
|
112
112
|
assert_equal params.merge(:branch_id => 74), @forwarder.prepare_forward_params(req, 74)
|
113
113
|
end
|
114
114
|
|
115
|
+
test 'should NOT add branch id into forwarded params for compliance urls' do
|
116
|
+
user_agent = { :foo => :bar }
|
117
|
+
params = { :page => 5, :per_page => 42 }
|
118
|
+
|
119
|
+
uris = [
|
120
|
+
"/redhat_access/r/insights/platform/compliance/v2/systems/MyUUID/policies",
|
121
|
+
"/redhat_access/r/insights/platform/compliance/v2/policies/MyUUID",
|
122
|
+
"/redhat_access/r/insights/platform/compliance/v2/systems/MyUUID",
|
123
|
+
"/redhat_access/r/insights/platform/compliance/v2/policies",
|
124
|
+
"/redhat_access/r/insights/platform/compliance/v2/",
|
125
|
+
]
|
126
|
+
uris.each do |uri|
|
127
|
+
req = ActionDispatch::Request.new(
|
128
|
+
'REQUEST_URI' => uri,
|
129
|
+
'REQUEST_METHOD' => 'GET',
|
130
|
+
'HTTP_USER_AGENT' => user_agent,
|
131
|
+
'rack.input' => ::Puma::NullIO.new,
|
132
|
+
'action_dispatch.request.query_parameters' => params
|
133
|
+
)
|
134
|
+
req.stubs(:path).returns(uri)
|
135
|
+
refute @forwarder.prepare_forward_params(req, 74).key?(:branch_id), "Branch id should not be added for #{uri}"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
115
139
|
test 'should reuse BranchInfo identifiers for user_agent' do
|
116
140
|
user_agent = { :foo => :bar }
|
117
141
|
params = { :page => 5, :per_page => 42 }
|
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: 10.0.
|
4
|
+
version: 10.0.5
|
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:
|
11
|
+
date: 2025-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: foreman_ansible
|