foreman_rh_cloud 11.4.1 → 11.4.3

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: 9f8fc6102624f1f64c8417c8417d1ba48e5db528a0551027ba3fd2fac84cb11e
4
- data.tar.gz: 9a8a361d435e8ad403937c50b46c6ed3f56f127342320d00258480bd9dfad194
3
+ metadata.gz: 541ff74a97d4bb59af8e835360a62fa7a3b346d6bed9c9d656c40349d4868bb9
4
+ data.tar.gz: ed004b4c72d0da64e92b6a4cf983fd4b77d9fb054fdbd8f192dc1555618c989d
5
5
  SHA512:
6
- metadata.gz: b3d88a21a8bdb3990d0b5f76b20b9b43e1cac02d1c5f8c1adcbc565fa2291d67ede4c4fd5cc794b83db7569048853bf13dc1fa0eeb7fa0556c1e77c390ebf10e
7
- data.tar.gz: 7309c277c4478897a0cf00d5fb2a18cf9007e2231bf6c63e16ee880feed2bc664ab340e9af84d092ae4b31bd8fe1e6e3c4f282a4628a56cd463eea2b3f234b2d
6
+ metadata.gz: e7fe51a950deae4b0093048db11ee7eef4695c4d713c3d0861ea46da5ba83ba2a21dbfde9ab7f1bc9727e4e26e366a1ebdcb2d9abc66a3e893373884a3646db6
7
+ data.tar.gz: 5f94192b51c29e2a11ee8c04913e937a8cfb731363dc783ebeb78c9dcf813aba3ccb72efc9e699475604901ec2ee8381e24ddbaacbe24e1f8558de5843b745c3
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '11.4.1'.freeze
2
+ VERSION = '11.4.3'.freeze
3
3
  end
@@ -47,6 +47,8 @@ module ForemanRhCloud
47
47
  end
48
48
 
49
49
  def self.proxy_string
50
+ return '' if ForemanRhCloud.with_local_advisor_engine?
51
+
50
52
  HttpProxy.default_global_content_proxy&.full_url ||
51
53
  ForemanRhCloud.global_foreman_proxy ||
52
54
  ''
@@ -1,64 +1,122 @@
1
1
  require 'io/console'
2
+ require 'uri'
2
3
 
3
- namespace :rh_cloud do |args|
4
- desc 'Register Satellite Organization with Hybrid Cloud API. \
5
- Specify org_id=x replace your organization ID with x. \
6
- Specify SATELLITE_RH_CLOUD_URL=https://x with the Hybrid Cloud endpoint you are connecting to.'
4
+ def logger
5
+ @logger ||= Logger.new(STDOUT)
6
+ end
7
+
8
+ namespace :rh_cloud do
9
+ desc 'Register Satellite Organization with Hybrid Cloud API.'
10
+ # This task registers the Satellite Organization with the Hybrid Cloud API.
11
+ # It requires the user to input their organization ID, Insights URL, and token.
12
+ # The task will then send a POST request to the Hybrid Cloud API to register the organization.
13
+ # The response will be logged, and any errors will be caught and logged as well.
14
+ # The task will exit with an error message if the organization does not have a manifest imported or if the token is not entered.
15
+ # The task will also log a warning if the custom URL is not set and the default one is used.
7
16
  task hybridcloud_register: [:environment] do
8
17
  include ::ForemanRhCloud::CertAuth
9
18
  include ::InsightsCloud::CandlepinCache
10
19
 
11
- def logger
12
- @logger ||= Logger.new(STDOUT)
20
+ # Helper method to get the registrations URL, with a warning for default usage
21
+ def registrations_url(custom_url)
22
+ if custom_url.empty?
23
+ logger.warn("Custom url is not set, using the default one: #{ForemanRhCloud.base_url}")
24
+ URI.join(ForemanRhCloud.base_url, '/api/identity/certificate/registrations').to_s
25
+ else
26
+ URI.join(custom_url, '/api/identity/certificate/registrations').to_s
27
+ end
13
28
  end
14
29
 
15
- def registrations_url
16
- logger.warn("Custom url is not set, using the default one: #{ForemanRhCloud.base_url}") if ENV['SATELLITE_RH_CLOUD_URL'].empty?
17
- ForemanRhCloud.base_url + '/api/identity/certificate/registrations'
30
+ # --- Input Collection ---
31
+ puts "Paste in your organization ID, this can be retrieved with the command: hammer organization list"
32
+ loop do
33
+ input = STDIN.gets.chomp
34
+ if input.match?(/^\d+$/) # Checks if input consists only of digits
35
+ @user_org_id = input.to_i
36
+ break
37
+ else
38
+ puts "Invalid input. Please enter a numeric organization ID."
39
+ end
18
40
  end
19
41
 
20
- if ENV['org_id'].nil?
21
- logger.error('ERROR: org_id needs to be specified.')
22
- exit(1)
23
- end
42
+ puts "\n" + "-" * 50 + "\n\n"
43
+ puts 'Paste in your Custom Insights URL. If nothing is entered, the default will be used.'
44
+ insights_user_input = STDIN.gets.chomp
24
45
 
25
- @organization = Organization.find_by(id: ENV['org_id'].to_i) # saw this coming in as a string, so making sure it gets passed as an integer.
26
- @uid = cp_owner_id(@organization)
27
- @hostname = ForemanRhCloud.foreman_host_name
28
- logger.error('Organization provided does not have a manifest imported.') + exit(1) if @uid.nil?
46
+ # --- Data Preparation ---
29
47
 
30
- puts 'Paste your token, output will be hidden.'
31
- @token = STDIN.noecho(&:gets).chomp
32
- logger.error('Token was not entered.') + exit(1) if @token.empty?
48
+ organization = Organization.find_by(id: @user_org_id)
33
49
 
34
- def headers
35
- {
36
- Authorization: "Bearer #{@token}",
37
- }
50
+ if organization.nil?
51
+ logger.error("Organization with ID '#{@user_org_id}' not found.")
52
+ exit(1)
38
53
  end
39
54
 
40
- def payload
41
- {
42
- "uid": @uid,
43
- "display_name": "#{@hostname}+#{@organization.label}",
44
- }
55
+ uid = cp_owner_id(organization)
56
+ if uid.nil?
57
+ logger.error('Organization provided does not have a manifest imported.')
58
+ exit(1)
45
59
  end
46
60
 
47
- def method
48
- :post
61
+ hostname = ForemanRhCloud.foreman_host_name
62
+ insights_url = registrations_url(insights_user_input)
63
+
64
+ puts "\n" + "-" * 50 + "\n\n"
65
+ puts 'Paste in your Hybrid Cloud API token, output will be hidden.'
66
+ puts 'This token can be retrieved from the Hybrid Cloud console.'
67
+ token = STDIN.noecho(&:gets).chomp
68
+
69
+ if token.empty?
70
+ logger.error('Token was not entered.')
71
+ exit(1)
49
72
  end
50
73
 
74
+ # --- API Request Configuration ---
75
+
76
+ headers = {
77
+ Authorization: "Bearer #{token}",
78
+ }
79
+
80
+ payload = {
81
+ 'uid': uid,
82
+ "display_name": "#{hostname}+#{organization.label}",
83
+ }
84
+
85
+ # --- Execute Request ---
86
+
51
87
  begin
52
88
  response = execute_cloud_request(
53
- organization: @organization,
54
- method: method,
55
- url: registrations_url,
89
+ organization: organization,
90
+ method: :post,
91
+ url: insights_url,
56
92
  headers: headers,
57
93
  payload: payload.to_json
58
94
  )
59
- logger.debug(response)
95
+ logger.debug("Cloud request completed: status=#{response.code}, body_preview=#{response.body&.slice(0, 200)}")
96
+ # Add a more specific rescue for 401 Unauthorized errors
97
+ rescue RestClient::Unauthorized => _ex
98
+ logger.error('Registration failed: Your token is invalid or unauthorized. Please check your token and try again.')
99
+ # Optionally, you can still log the full debug info if helpful for advanced troubleshooting
100
+ # logger.debug(ex.backtrace.join("\n"))
101
+ exit(1)
102
+ rescue RestClient::ExceptionWithResponse => ex
103
+ # This catches any RestClient exception that has a response (like 400, 403, 404, 500, etc.)
104
+ status_code = begin
105
+ ex.response.code
106
+ rescue StandardError
107
+ "unknown"
108
+ end
109
+ logger.error("Registration failed with HTTP status #{status_code}: #{ex.message}")
110
+ logger.debug("Response body (if available): #{ex.response.body}")
111
+ # logger.debug(ex.backtrace.join("\n"))
112
+ exit(1)
60
113
  rescue StandardError => ex
61
- logger.error(ex)
114
+ # This is the catch-all for any other unexpected errors
115
+ logger.error("An unexpected error occurred during registration: #{ex.message}")
116
+ # logger.debug(ex.backtrace.join("\n")) # Log backtrace for more info
117
+ exit(1)
62
118
  end
119
+
120
+ logger.info("Satellite Organization '#{organization.label}' (ID: #{@user_org_id}) successfully registered.")
63
121
  end
64
122
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_rh_cloud",
3
- "version": "11.4.1",
3
+ "version": "11.4.3",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
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: 11.4.1
4
+ version: 11.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman Red Hat Cloud team
@@ -697,7 +697,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
697
697
  - !ruby/object:Gem::Version
698
698
  version: '0'
699
699
  requirements: []
700
- rubygems_version: 3.6.7
700
+ rubygems_version: 3.6.9
701
701
  specification_version: 4
702
702
  summary: Summary of ForemanRhCloud.
703
703
  test_files: