foreman_rh_cloud 10.0.6 → 10.0.7
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/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/tasks/hybrid_cloud.rake +105 -37
- data/package.json +1 -1
- 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: 65251fdae0087f5b4a2b1601fa9fb40ac63874fb48280614de3efb7fb2807e11
|
4
|
+
data.tar.gz: 654748bf9d1270e27118968d2b7ab8dfa99b133087312006f8cea4a745e94543
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da7ed0469f82a183a824b52a72fc6c85885fea0491bef66b4a473eeb113a6b80aba0b719e91d928ab9dc2b658ebf632f2cb80babaf918002a5f44dd54565ab46
|
7
|
+
data.tar.gz: e8c36cf6761e02085bc28c925095b9581eb5f94718bab25ed7bf083bb8d1cb79c33f3a95249a051379aef29ab38ea623b38e8df194bccdb659ad2a183ef7b5b7
|
data/lib/tasks/hybrid_cloud.rake
CHANGED
@@ -1,64 +1,132 @@
|
|
1
1
|
require 'io/console'
|
2
|
+
require 'uri'
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
12
|
-
|
20
|
+
def default_registrations_url
|
21
|
+
URI.join(ForemanRhCloud.base_url, '/api/identity/certificate/registrations').to_s
|
13
22
|
end
|
14
23
|
|
15
|
-
|
16
|
-
|
17
|
-
|
24
|
+
# Helper method to get the registrations URL, with a warning for default usage
|
25
|
+
def registrations_url(custom_url)
|
26
|
+
if custom_url.empty?
|
27
|
+
logger.warn("Custom url is not set, using the default one: #{default_registrations_url}")
|
28
|
+
default_registrations_url
|
29
|
+
else
|
30
|
+
if URI(custom_url).scheme.nil?
|
31
|
+
logger.warn("Custom URL lacks a scheme; prepending https:// prefix.")
|
32
|
+
custom_url = "https://" + custom_url
|
33
|
+
end
|
34
|
+
custom_url
|
35
|
+
end
|
18
36
|
end
|
19
37
|
|
20
|
-
|
21
|
-
|
22
|
-
|
38
|
+
def get_organization(user_org_id)
|
39
|
+
maybe_organization = Organization.find_by(id: user_org_id)
|
40
|
+
if maybe_organization.nil?
|
41
|
+
logger.error("Organization with ID '#{user_org_id}' not found.")
|
42
|
+
exit(1)
|
43
|
+
end
|
44
|
+
maybe_organization
|
23
45
|
end
|
24
46
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
logger.error('Token was not entered.') + exit(1) if @token.empty?
|
33
|
-
|
34
|
-
def headers
|
35
|
-
{
|
36
|
-
Authorization: "Bearer #{@token}",
|
37
|
-
}
|
47
|
+
def get_uid(organization)
|
48
|
+
maybe_uid = cp_owner_id(organization)
|
49
|
+
if maybe_uid.nil?
|
50
|
+
logger.error("Organization '#{organization}' does not have a manifest imported.")
|
51
|
+
exit(1)
|
52
|
+
end
|
53
|
+
maybe_uid
|
38
54
|
end
|
39
55
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
56
|
+
# --- Input Collection ---
|
57
|
+
puts "Paste in your organization ID, this can be retrieved with the command: hammer organization list"
|
58
|
+
loop do
|
59
|
+
input = STDIN.gets.chomp
|
60
|
+
if input.match?(/^\d+$/) # Checks if input consists only of digits
|
61
|
+
@user_org_id = input.to_i
|
62
|
+
break
|
63
|
+
else
|
64
|
+
puts "Invalid input. Please enter a numeric organization ID."
|
65
|
+
end
|
45
66
|
end
|
46
67
|
|
47
|
-
|
48
|
-
|
68
|
+
puts "\n" + "-" * 50 + "\n\n"
|
69
|
+
puts "Paste in your custom Insights URL. If nothing is entered, the default will be used (#{default_registrations_url})."
|
70
|
+
insights_user_input = STDIN.gets.chomp
|
71
|
+
|
72
|
+
puts "\n" + "-" * 50 + "\n\n"
|
73
|
+
puts 'Paste in your Hybrid Cloud API token, output will be hidden.'
|
74
|
+
puts 'This token can be retrieved from the Hybrid Cloud console.'
|
75
|
+
token = STDIN.noecho(&:gets).chomp
|
76
|
+
if token.empty?
|
77
|
+
logger.error('Token was not entered.')
|
78
|
+
exit(1)
|
49
79
|
end
|
50
80
|
|
81
|
+
# --- Data Preparation ---
|
82
|
+
|
83
|
+
organization = get_organization(@user_org_id)
|
84
|
+
uid = get_uid(organization)
|
85
|
+
hostname = ForemanRhCloud.foreman_host_name
|
86
|
+
insights_url = registrations_url(insights_user_input)
|
87
|
+
|
88
|
+
# --- API Request ---
|
89
|
+
|
90
|
+
headers = {
|
91
|
+
Authorization: "Bearer #{token}",
|
92
|
+
}
|
93
|
+
|
94
|
+
payload = {
|
95
|
+
'uid': uid,
|
96
|
+
"display_name": "#{hostname}+#{organization.label}",
|
97
|
+
}
|
98
|
+
|
51
99
|
begin
|
52
100
|
response = execute_cloud_request(
|
53
|
-
organization:
|
54
|
-
method:
|
55
|
-
url:
|
101
|
+
organization: organization,
|
102
|
+
method: :post,
|
103
|
+
url: insights_url,
|
56
104
|
headers: headers,
|
57
105
|
payload: payload.to_json
|
58
106
|
)
|
59
|
-
logger.debug(response)
|
107
|
+
logger.debug("Cloud request completed: status=#{response.code}, body_preview=#{response.body&.slice(0, 200)}")
|
108
|
+
rescue RestClient::Unauthorized => _ex
|
109
|
+
# Add a more specific rescue for 401 Unauthorized errors
|
110
|
+
logger.error('Registration failed: Your token is invalid or unauthorized. Please check your token and try again.')
|
111
|
+
# Optionally, you can still log the full debug info if helpful for advanced troubleshooting
|
112
|
+
# logger.debug(ex.backtrace.join("\n"))
|
113
|
+
exit(1)
|
114
|
+
rescue RestClient::ExceptionWithResponse => ex
|
115
|
+
# This catches any RestClient exception that has a response (like 400, 403, 404, 500, etc.)
|
116
|
+
status_code = begin
|
117
|
+
ex.response.code
|
118
|
+
rescue StandardError
|
119
|
+
"unknown"
|
120
|
+
end
|
121
|
+
logger.error("Registration failed with HTTP status #{status_code}: #{ex.message}")
|
122
|
+
logger.debug("Response body (if available): #{ex.response.body}")
|
123
|
+
exit(1)
|
60
124
|
rescue StandardError => ex
|
61
|
-
|
125
|
+
# This is the catch-all for any other unexpected errors
|
126
|
+
logger.error("An unexpected error occurred during registration: #{ex.message}")
|
127
|
+
exit(1)
|
62
128
|
end
|
129
|
+
|
130
|
+
logger.info("Satellite Organization '#{organization.label}' (ID: #{@user_org_id}) successfully registered.")
|
63
131
|
end
|
64
132
|
end
|
data/package.json
CHANGED
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.7
|
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: 2025-
|
11
|
+
date: 2025-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: foreman_ansible
|