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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc6fa218e9a87166dd1b6ea44dc00f52dc4a0ee28edaa6363bfd74fd0e93c17c
4
- data.tar.gz: 80d9b1dcfa4a2e1589d2273b895360d237e84101d0e2a216a18ffc0d9259e14d
3
+ metadata.gz: a42f6e6437d9d99d173939b6ce360e573d40d4dbd2c99ba6aa71bd7c54ad868a
4
+ data.tar.gz: 811a4d82f96597e833067ce20b0654b90a99a35dd6c8da289272e479c6e83917
5
5
  SHA512:
6
- metadata.gz: 4e76e623f5509cd2bedab0fcd8abf926d7380eee120d1c73fc7f3be32ec9fe97cfc3948f56e93436ac21431ec8a5f85b4f8f349d1fe5df05bcad9d4e043eb332
7
- data.tar.gz: d6f0d6140787ba18bc69bcf4de2161795a4404530fd24bd4502c352d1e87e1d13bd447049b220901edc48f0fbb9fde78ce73b737dea5435fc841d70f6c1a38bf
6
+ metadata.gz: c9d780419f9357ba8a73c40bccb6de50aa892e21ace6d0c5a9ab0c5f49e871e33406ca7b1b2560dd973875b08f229f8d32778699dd2b68aea69e186ce9eba1d8
7
+ data.tar.gz: 6726d03325a8cf3c5bd1aab3562120252025e4a18d0910d7c3bb08708bd509d8246fe53df87121c3532cb5f1ae2b6debde64b621171af0400b04380ffead6b85
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
+ [![Ruby tests](https://github.com/theforeman/foreman_rh_cloud/actions/workflows/ruby_tests.yml/badge.svg)](https://github.com/theforeman/foreman_rh_cloud/actions/workflows/ruby_tests.yml)
2
+ [![JS](https://github.com/theforeman/foreman_rh_cloud/actions/workflows/js_tests.yml/badge.svg)](https://github.com/theforeman/foreman_rh_cloud/actions/workflows/js_tests.yml)
3
+
1
4
  # ForemanRhCloud
2
5
 
3
- *Introdction here*
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: Configure -> Inventory Upload -> Generate and upload report
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: Configure -> Insights -> Sync now
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: Configure -> Inventory Upload -> Sync all inventory status
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::Exception => e
22
- logger.info("Forwarding request failed with exception: #{e}")
23
- return render json: { error: e }, status: :bad_gateway
24
- rescue RestClient::Timeout => e
25
- logger.info("Forwarding request failed with timeout: #{e}")
26
- return render json: { error: e }, status: :gateway_timeout
27
- end
28
-
29
- return render json: { message: @cloud_response.to_s }, status: :gateway_timeout if @cloud_response.is_a?(RestClient::Exceptions::OpenTimeout)
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 => 'Authentication to the Insights Service failed.',
38
+ :message => message,
39
+ :error => response_obj.to_s,
34
40
  :headers => {},
35
- }, status: :bad_gateway
36
- end
37
-
38
- if @cloud_response.code >= 300
39
- return render json: {
40
- :message => 'Cloud request failed',
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
- # if there is no Content-Disposition, but the content type is binary according the content type,
60
- # forward the request as binry too
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::Exception => ex
21
- logger.debug("Failed response with code #{ex.http_code} headers for request url #{final_params[:url]} are: #{ex.http_headers} and body: #{ex.http_body}")
22
- raise ex
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)
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '12.1.0'.freeze
2
+ VERSION = '12.1.1'.freeze
3
3
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_rh_cloud",
3
- "version": "12.1.0",
3
+ "version": "12.1.1",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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
- ::ForemanRhCloud::CloudRequestForwarder.any_instance.stubs(:forward_request).returns(res)
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 502, @response.status
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_rh_cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.1.0
4
+ version: 12.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman Red Hat Cloud team