foreman_rh_cloud 12.1.0 → 12.1.1
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/README.md +7 -4
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +26 -22
- data/app/services/foreman_rh_cloud/cloud_request.rb +9 -3
- data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +0 -2
- 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 +35 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a42f6e6437d9d99d173939b6ce360e573d40d4dbd2c99ba6aa71bd7c54ad868a
|
4
|
+
data.tar.gz: 811a4d82f96597e833067ce20b0654b90a99a35dd6c8da289272e479c6e83917
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9d780419f9357ba8a73c40bccb6de50aa892e21ace6d0c5a9ab0c5f49e871e33406ca7b1b2560dd973875b08f229f8d32778699dd2b68aea69e186ce9eba1d8
|
7
|
+
data.tar.gz: 6726d03325a8cf3c5bd1aab3562120252025e4a18d0910d7c3bb08708bd509d8246fe53df87121c3532cb5f1ae2b6debde64b621171af0400b04380ffead6b85
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
[](https://github.com/theforeman/foreman_rh_cloud/actions/workflows/ruby_tests.yml)
|
2
|
+
[](https://github.com/theforeman/foreman_rh_cloud/actions/workflows/js_tests.yml)
|
3
|
+
|
1
4
|
# ForemanRhCloud
|
2
5
|
|
3
|
-
*
|
6
|
+
*Introduction here*
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
@@ -15,7 +18,7 @@ for how to install Foreman plugins
|
|
15
18
|
|
16
19
|
#### Inventory upload
|
17
20
|
|
18
|
-
In UI:
|
21
|
+
In UI: Insights -> Inventory Upload -> select the organization -> Generate and upload report
|
19
22
|
|
20
23
|
From command-line:
|
21
24
|
|
@@ -38,7 +41,7 @@ From command-line:
|
|
38
41
|
|
39
42
|
#### Fetch hosts remediation data
|
40
43
|
|
41
|
-
In UI:
|
44
|
+
In UI: Insights -> Recommendations -> Sync recommendations (under the vertical ellipsis)
|
42
45
|
|
43
46
|
From command-line:
|
44
47
|
|
@@ -46,7 +49,7 @@ From command-line:
|
|
46
49
|
|
47
50
|
#### Synchronize inventory status
|
48
51
|
|
49
|
-
In UI:
|
52
|
+
In UI: Insights -> Inventory Upload -> Sync all inventory status
|
50
53
|
|
51
54
|
From command-line:
|
52
55
|
|
@@ -18,35 +18,39 @@ module InsightsCloud::Api
|
|
18
18
|
certs = candlepin_id_cert @organization
|
19
19
|
begin
|
20
20
|
@cloud_response = ::ForemanRhCloud::CloudRequestForwarder.new.forward_request(request, controller_name, @branch_id, certs)
|
21
|
-
rescue RestClient::
|
22
|
-
|
23
|
-
return render json: { error:
|
24
|
-
rescue RestClient::
|
25
|
-
logger.
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
rescue RestClient::Exceptions::Timeout => e
|
22
|
+
response_obj = e.response.presence || e.exception
|
23
|
+
return render json: { message: response_obj.to_s, error: response_obj.to_s }, status: :gateway_timeout
|
24
|
+
rescue RestClient::Unauthorized => e
|
25
|
+
logger.warn("Forwarding request auth error: #{e}")
|
26
|
+
message = 'Authentication to the Insights Service failed.'
|
27
|
+
return render json: { message: message, error: message }, status: :unauthorized
|
28
|
+
rescue RestClient::NotModified => e
|
29
|
+
logger.info("Forwarding request not modified: #{e}")
|
30
|
+
message = 'Cloud request not modified'
|
31
|
+
return render json: { message: message, error: message }, status: :not_modified
|
32
|
+
rescue RestClient::ExceptionWithResponse => e
|
33
|
+
response_obj = e.response.presence || e.exception
|
34
|
+
code = response_obj.try(:code) || response_obj.try(:http_code) || 500
|
35
|
+
message = 'Cloud request failed'
|
30
36
|
|
31
|
-
if @cloud_response.code == 401
|
32
37
|
return render json: {
|
33
|
-
:message =>
|
38
|
+
:message => message,
|
39
|
+
:error => response_obj.to_s,
|
34
40
|
:headers => {},
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
:headers => {},
|
42
|
-
:response => @cloud_response,
|
43
|
-
}, status: @cloud_response.code
|
41
|
+
:response => response_obj,
|
42
|
+
}, status: code
|
43
|
+
rescue StandardError => e
|
44
|
+
# Catch any other exceptions here, such as Errno::ECONNREFUSED
|
45
|
+
logger.warn("Cloud request failed with exception: #{e}")
|
46
|
+
return render json: { error: e.to_s }, status: :bad_gateway
|
44
47
|
end
|
45
48
|
|
46
49
|
# Append redhat-specific headers
|
47
50
|
@cloud_response.headers.each do |key, value|
|
48
51
|
assign_header(response, @cloud_response, key, false) if key.to_s.start_with?('x_rh_')
|
49
52
|
end
|
53
|
+
|
50
54
|
# Append general headers
|
51
55
|
assign_header(response, @cloud_response, :x_resource_count, true)
|
52
56
|
headers[Rack::ETAG] = @cloud_response.headers[:etag]
|
@@ -56,8 +60,8 @@ module InsightsCloud::Api
|
|
56
60
|
# content type
|
57
61
|
send_data @cloud_response, disposition: @cloud_response.headers[:content_disposition], type: @cloud_response.headers[:content_type]
|
58
62
|
elsif @cloud_response.headers[:content_type] =~ /zip/
|
59
|
-
#
|
60
|
-
#
|
63
|
+
# If there is no Content-Disposition, but the content type is binary according to Content-Type, send the raw data
|
64
|
+
# with proper content type
|
61
65
|
send_data @cloud_response, type: @cloud_response.headers[:content_type]
|
62
66
|
else
|
63
67
|
render json: @cloud_response, status: @cloud_response.code
|
@@ -17,9 +17,15 @@ module ForemanRhCloud
|
|
17
17
|
logger.debug("Response headers for request url #{final_params[:url]} are: #{response.headers}")
|
18
18
|
|
19
19
|
response
|
20
|
-
rescue RestClient::
|
21
|
-
logger.debug("
|
22
|
-
raise
|
20
|
+
rescue RestClient::Exceptions::Timeout => ex
|
21
|
+
logger.debug("Timeout exception raised for request url #{final_params[:url]}: #{ex}")
|
22
|
+
raise
|
23
|
+
rescue RestClient::ExceptionWithResponse => ex
|
24
|
+
logger.debug("Response headers for request url #{final_params[:url]} with status code #{ex.http_code} are: #{ex.http_headers} and body: #{ex.http_body}")
|
25
|
+
raise
|
26
|
+
rescue StandardError => ex
|
27
|
+
logger.debug("Exception raised for request url #{final_params[:url]}: #{ex}")
|
28
|
+
raise
|
23
29
|
end
|
24
30
|
end
|
25
31
|
end
|
@@ -17,8 +17,6 @@ module ForemanRhCloud
|
|
17
17
|
logger.debug("Sending request to: #{request_opts[:url]}")
|
18
18
|
|
19
19
|
execute_cloud_request(request_opts)
|
20
|
-
rescue RestClient::ExceptionWithResponse => error_response
|
21
|
-
error_response.response.presence || error_response.exception
|
22
20
|
end
|
23
21
|
|
24
22
|
def prepare_request_opts(original_request, forward_payload, forward_params, certs)
|
data/package.json
CHANGED
@@ -98,13 +98,46 @@ module InsightsCloud::Api
|
|
98
98
|
assert_equal net_http_resp[:content_type], @response.headers['Content-Type']
|
99
99
|
end
|
100
100
|
|
101
|
+
test "should handle StandardError" do
|
102
|
+
error_message = "Connection refused"
|
103
|
+
::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:execute_cloud_request).raises(Errno::ECONNREFUSED.new)
|
104
|
+
|
105
|
+
get :forward_request, params: { "path" => "platform/module-update-router/v1/channel" }
|
106
|
+
assert_equal 502, @response.status
|
107
|
+
body = JSON.parse(@response.body)
|
108
|
+
assert_equal error_message, body['error']
|
109
|
+
end
|
110
|
+
|
111
|
+
test "should handle 304 cloud" do
|
112
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 304, "Not Modified")
|
113
|
+
res = RestClient::Response.create(@body, net_http_resp, @http_req)
|
114
|
+
|
115
|
+
::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:execute_cloud_request).raises(RestClient::NotModified.new(res))
|
116
|
+
|
117
|
+
get :forward_request, params: { "path" => "platform/module-update-router/v1/channel" }
|
118
|
+
assert_equal 304, @response.status
|
119
|
+
assert_equal 'Cloud request not modified', JSON.parse(@response.body)['message']
|
120
|
+
end
|
121
|
+
|
122
|
+
test "should handle RestClient::Exceptions::Timeout" do
|
123
|
+
timeout_message = "execution expired"
|
124
|
+
::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:execute_cloud_request).raises(RestClient::Exceptions::Timeout.new(timeout_message))
|
125
|
+
|
126
|
+
get :forward_request, params: { "path" => "platform/module-update-router/v1/channel" }
|
127
|
+
assert_equal 504, @response.status
|
128
|
+
body = JSON.parse(@response.body)
|
129
|
+
assert_equal timeout_message, body['message']
|
130
|
+
assert_equal timeout_message, body['error']
|
131
|
+
end
|
132
|
+
|
101
133
|
test "should handle failed authentication to cloud" do
|
102
134
|
net_http_resp = Net::HTTPResponse.new(1.0, 401, "Unauthorized")
|
103
135
|
res = RestClient::Response.create(@body, net_http_resp, @http_req)
|
104
|
-
|
136
|
+
|
137
|
+
::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:execute_cloud_request).raises(RestClient::Unauthorized.new(res))
|
105
138
|
|
106
139
|
get :forward_request, params: { "path" => "platform/module-update-router/v1/channel" }
|
107
|
-
assert_equal
|
140
|
+
assert_equal 401, @response.status
|
108
141
|
assert_equal 'Authentication to the Insights Service failed.', JSON.parse(@response.body)['message']
|
109
142
|
end
|
110
143
|
|