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 +4 -4
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/foreman_rh_cloud.rb +2 -0
- data/lib/tasks/hybrid_cloud.rake +94 -36
- 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: 541ff74a97d4bb59af8e835360a62fa7a3b346d6bed9c9d656c40349d4868bb9
|
4
|
+
data.tar.gz: ed004b4c72d0da64e92b6a4cf983fd4b77d9fb054fdbd8f192dc1555618c989d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7fe51a950deae4b0093048db11ee7eef4695c4d713c3d0861ea46da5ba83ba2a21dbfde9ab7f1bc9727e4e26e366a1ebdcb2d9abc66a3e893373884a3646db6
|
7
|
+
data.tar.gz: 5f94192b51c29e2a11ee8c04913e937a8cfb731363dc783ebeb78c9dcf813aba3ccb72efc9e699475604901ec2ee8381e24ddbaacbe24e1f8558de5843b745c3
|
data/lib/foreman_rh_cloud.rb
CHANGED
data/lib/tasks/hybrid_cloud.rake
CHANGED
@@ -1,64 +1,122 @@
|
|
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
|
-
|
12
|
-
|
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
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
35
|
-
{
|
36
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
48
|
-
|
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:
|
54
|
-
method:
|
55
|
-
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
|
-
|
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
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.
|
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.
|
700
|
+
rubygems_version: 3.6.9
|
701
701
|
specification_version: 4
|
702
702
|
summary: Summary of ForemanRhCloud.
|
703
703
|
test_files:
|