-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Catch scc request timeout exception #63
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
------------------------------------------------------------------- | ||
Thu Feb 8 16:10:29 UTC 2024 - Luis Caparroz <[email protected]> | ||
|
||
- Adds UI dialog to allow the user to retry the SCC credential validation when | ||
the request times out (bsc#1218084). | ||
- Adds HTTP User-Agent to requests to the SCC API and changes the enpoint for | ||
credential validation. | ||
- Version 1.3.5 | ||
|
||
------------------------------------------------------------------- | ||
Thu Jun 9 10:47:13 UTC 2022 - Dominique Leuenberger <[email protected]> | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Copyright (c) 2024 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 'rmt' | ||
|
||
describe RMT do | ||
describe '.VERSION' do | ||
subject(:version) { RMT::VERSION } | ||
|
||
let(:package_version) do | ||
filename = './package/yast2-rmt.spec' | ||
version = nil | ||
|
||
File.foreach(filename) do |line| | ||
line.match(/^Version:\s+(?<version>(\d+\.?){3})$/) do |match| | ||
version ||= match.named_captures['version'] | ||
end | ||
end | ||
|
||
raise "'#{filename}' does not include any line matching the expected package version format." if version.nil? | ||
|
||
version | ||
end | ||
|
||
it 'returns the same version as specified in the package spec file' do | ||
expect(version).to eq package_version | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright (c) 2024 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 | ||
|
||
module RMT | ||
VERSION = '1.3.5'.freeze | ||
end |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -18,6 +18,7 @@ | |||||
|
||||||
require 'uri' | ||||||
require 'net/http' | ||||||
require 'rmt' | ||||||
require 'rmt/utils' | ||||||
require 'ui/event_dispatcher' | ||||||
|
||||||
|
@@ -26,6 +27,8 @@ 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 | ||||||
|
@@ -126,14 +129,27 @@ def scc_credentials_valid? | |||||
) | ||||||
) | ||||||
|
||||||
uri = URI('https://scc.suse.com/connect/organizations/systems') | ||||||
uri = URI('https://scc.suse.com/connect/organizations/orders') | ||||||
req = Net::HTTP::Get.new(uri) | ||||||
req.basic_auth(@config['scc']['username'], @config['scc']['password']) | ||||||
|
||||||
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) } | ||||||
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) } | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a minor suggestion:
Suggested change
This is more robust as it will still work after you change the URL above to plain HTTP. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a nice enhancement, but since the URL is hard-coded, it will not be very helpful. I wonder if it would be valuable for test and development purposes to have a way to configure the SCC URL (e.g.: env var), then this change would be very welcome. I had to manually change both the URL and the |
||||||
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 | ||||||
|
||||||
res.code.to_i == 200 | ||||||
valid_credentials | ||||||
end | ||||||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much Luis! This is awesome!