-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathwizard_scc_page.rb
More file actions
152 lines (125 loc) · 4.29 KB
/
Copy pathwizard_scc_page.rb
File metadata and controls
152 lines (125 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Copyright (c) 2018 SUSE LLC.
# All Rights Reserved.
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 or 3 of the GNU General
# Public License as published by the Free Software Foundation.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact SUSE LLC.
# To contact SUSE about this file by physical or electronic mail,
# you may find current contact information at www.suse.com
require 'uri'
require 'net/http'
require 'rmt'
require 'rmt/utils'
require 'ui/event_dispatcher'
module RMT; end
class RMT::WizardSCCPage < Yast::Client
include ::UI::EventDispatcher
YAST_RMT_USER_AGENT = "yast2-rmt/#{RMT::VERSION}".freeze
def initialize(config)
textdomain 'rmt'
@config = config
end
def render_content
Wizard.SetAbortButton(:abort, Label.CancelButton)
Wizard.SetNextButton(:next, Label.NextButton)
Wizard.SetBackButton(:skip, Label.SkipButton)
contents = Frame(
_('Organization Credentials'),
HBox(
HSpacing(1),
VBox(
VSpacing(1),
HSquash(
MinWidth(30, InputField(Id(:scc_username), _('Organization &Username')))
),
HSquash(
MinWidth(30, Password(Id(:scc_password), _('Organization &Password')))
),
VSpacing(1)
),
HSpacing(1)
)
)
Wizard.SetContents(
_('RMT Configuration - Step 1/5'),
contents,
_('<p>Organization credentials can be found on the Organization page in the SUSE Customer Center.</p><p>https://scc.suse.com</p>'),
true,
true
)
UI.ChangeWidget(Id(:scc_username), :Value, @config['scc']['username'])
UI.ChangeWidget(Id(:scc_password), :Value, @config['scc']['password'])
end
def abort_handler
finish_dialog(:abort)
end
def skip_handler
@config['scc']['username'] = UI.QueryWidget(Id(:scc_username), :Value)
@config['scc']['password'] = UI.QueryWidget(Id(:scc_password), :Value)
@config['scc']['sync_systems'] = true
return unless Popup.AnyQuestion(
_('Skip SCC registration?'),
_("This is only recommended for air-gapped environments.\nRMT will not be able to sync and mirror data.\n\nDo you want to continue?"),
_('Ignore and continue'),
_('Go back'),
:focus_no
)
RMT::Utils.write_config_file(@config)
finish_dialog(:next)
end
def next_handler
@config['scc']['username'] = UI.QueryWidget(Id(:scc_username), :Value)
@config['scc']['password'] = UI.QueryWidget(Id(:scc_password), :Value)
@config['scc']['sync_systems'] = true
return unless scc_credentials_valid? || Popup.AnyQuestion(
_('Continue with invalid credentials?'),
_("Organization credentials are invalid.\nRMT will not be able to sync and mirror data.\n\nDo you want to continue?"),
_('Ignore and continue'),
_('Go back'),
:focus_no
)
RMT::Utils.write_config_file(@config)
finish_dialog(:next)
end
def run
render_content
event_loop
end
def scc_credentials_valid?
UI.OpenDialog(
HBox(
HSpacing(5),
VBox(
VSpacing(5),
Left(Label(_('Checking organization credentials...'))),
VSpacing(5)
),
HSpacing(5)
)
)
uri = URI('https://scc.suse.com/connect/organizations/orders')
req = Net::HTTP::Get.new(uri)
req.basic_auth(@config['scc']['username'], @config['scc']['password'])
req['User-Agent'] = YAST_RMT_USER_AGENT
valid_credentials = nil
while valid_credentials.nil?
begin
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
valid_credentials = (res.code.to_i == 200)
rescue Net::ReadTimeout
break valid_credentials = false unless Popup.ErrorAnyQuestion(
_('Request Timeout'),
_("The request to SCC timed out.\n\nWould you like to try again?"),
_('Retry'), _('Cancel'), :focus_yes
)
end
end
UI.CloseDialog
valid_credentials
end
end