Blame SOURCES/sos-bz2025610-RHTS-api-change.patch

9a3f62
From 2e8b5e2d4f30854cce93d149fc7d24b9d9cfd02c Mon Sep 17 00:00:00 2001
9a3f62
From: Pavel Moravec <pmoravec@redhat.com>
9a3f62
Date: Fri, 19 Nov 2021 16:16:07 +0100
9a3f62
Subject: [PATCH 1/3] [policies] strip path from SFTP upload filename
9a3f62
9a3f62
When case_id is not supplied, we ask SFTP server to store the uploaded
9a3f62
file under name /var/tmp/<tarball>, which is confusing.
9a3f62
9a3f62
Let remove the path from it also in case_id not supplied.
9a3f62
9a3f62
Related to: #2764
9a3f62
9a3f62
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
9a3f62
---
9a3f62
 sos/policies/distros/redhat.py | 6 +++---
9a3f62
 1 file changed, 3 insertions(+), 3 deletions(-)
9a3f62
9a3f62
diff --git a/sos/policies/distros/redhat.py b/sos/policies/distros/redhat.py
9a3f62
index 3476e21fb..8817fc785 100644
9a3f62
--- a/sos/policies/distros/redhat.py
9a3f62
+++ b/sos/policies/distros/redhat.py
9a3f62
@@ -269,10 +269,10 @@ def _get_sftp_upload_name(self):
9a3f62
         """The RH SFTP server will only automatically connect file uploads to
9a3f62
         cases if the filename _starts_ with the case number
9a3f62
         """
9a3f62
+        fname = self.upload_archive_name.split('/')[-1]
9a3f62
         if self.case_id:
9a3f62
-            return "%s_%s" % (self.case_id,
9a3f62
-                              self.upload_archive_name.split('/')[-1])
9a3f62
-        return self.upload_archive_name
9a3f62
+            return "%s_%s" % (self.case_id, fname)
9a3f62
+        return fname
9a3f62
 
9a3f62
     def upload_sftp(self):
9a3f62
         """Override the base upload_sftp to allow for setting an on-demand
9a3f62
9a3f62
From 61023b29a656dd7afaa4a0643368b0a53f1a3779 Mon Sep 17 00:00:00 2001
9a3f62
From: Pavel Moravec <pmoravec@redhat.com>
9a3f62
Date: Fri, 19 Nov 2021 17:31:31 +0100
9a3f62
Subject: [PATCH 2/3] [redhat] update SFTP API version to v2
9a3f62
9a3f62
Change API version from v1 to v2, which includes:
9a3f62
- change of URL
9a3f62
- different URI
9a3f62
- POST method for token generation instead of GET
9a3f62
9a3f62
Resolves: #2764
9a3f62
9a3f62
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
9a3f62
---
9a3f62
 sos/policies/distros/redhat.py | 10 +++++-----
9a3f62
 1 file changed, 5 insertions(+), 5 deletions(-)
9a3f62
9a3f62
diff --git a/sos/policies/distros/redhat.py b/sos/policies/distros/redhat.py
9a3f62
index 8817fc785..e4e2b8835 100644
9a3f62
--- a/sos/policies/distros/redhat.py
9a3f62
+++ b/sos/policies/distros/redhat.py
9a3f62
@@ -175,7 +175,7 @@ def get_tmp_dir(self, opt_tmp_dir):
9a3f62
 No changes will be made to system configuration.
9a3f62
 """
9a3f62
 
9a3f62
-RH_API_HOST = "https://access.redhat.com"
9a3f62
+RH_API_HOST = "https://api.access.redhat.com"
9a3f62
 RH_SFTP_HOST = "sftp://sftp.access.redhat.com"
9a3f62
 
9a3f62
 
9a3f62
@@ -287,12 +287,12 @@ def upload_sftp(self):
9a3f62
                             " for obtaining SFTP auth token.")
9a3f62
         _token = None
9a3f62
         _user = None
9a3f62
+        url = RH_API_HOST + '/support/v2/sftp/token'
9a3f62
         # we have a username and password, but we need to reset the password
9a3f62
         # to be the token returned from the auth endpoint
9a3f62
         if self.get_upload_user() and self.get_upload_password():
9a3f62
-            url = RH_API_HOST + '/hydra/rest/v1/sftp/token'
9a3f62
             auth = self.get_upload_https_auth()
9a3f62
-            ret = requests.get(url, auth=auth, timeout=10)
9a3f62
+            ret = requests.post(url, auth=auth, timeout=10)
9a3f62
             if ret.status_code == 200:
9a3f62
                 # credentials are valid
9a3f62
                 _user = self.get_upload_user()
9a3f62
@@ -302,8 +302,8 @@ def upload_sftp(self):
9a3f62
                       "credentials. Will try anonymous.")
9a3f62
         # we either do not have a username or password/token, or both
9a3f62
         if not _token:
9a3f62
-            aurl = RH_API_HOST + '/hydra/rest/v1/sftp/token?isAnonymous=true'
9a3f62
-            anon = requests.get(aurl, timeout=10)
9a3f62
+            adata = {"isAnonymous": True}
9a3f62
+            anon = requests.post(url, data=json.dumps(adata), timeout=10)
9a3f62
             if anon.status_code == 200:
9a3f62
                 resp = json.loads(anon.text)
9a3f62
                 _user = resp['username']
9a3f62
9a3f62
From 267da2156ec61f526dd28e760ff6528408a76c3f Mon Sep 17 00:00:00 2001
9a3f62
From: Pavel Moravec <pmoravec@redhat.com>
9a3f62
Date: Mon, 22 Nov 2021 15:22:32 +0100
9a3f62
Subject: [PATCH 3/3] [policies] Deal 200 return code as success
9a3f62
9a3f62
Return code 200 of POST method request must be dealt as success.
9a3f62
9a3f62
Newly required due to the SFTP API change using POST.
9a3f62
9a3f62
Related to: #2764
9a3f62
9a3f62
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
9a3f62
---
9a3f62
 sos/policies/distros/__init__.py | 2 +-
9a3f62
 1 file changed, 1 insertion(+), 1 deletion(-)
9a3f62
9a3f62
diff --git a/sos/policies/distros/__init__.py b/sos/policies/distros/__init__.py
9a3f62
index 0906fa779..6f257fdce 100644
9a3f62
--- a/sos/policies/distros/__init__.py
9a3f62
+++ b/sos/policies/distros/__init__.py
9a3f62
@@ -551,7 +551,7 @@ def upload_https(self):
9a3f62
                 r = self._upload_https_put(arc, verify)
9a3f62
             else:
9a3f62
                 r = self._upload_https_post(arc, verify)
9a3f62
-            if r.status_code != 201:
9a3f62
+            if r.status_code != 200 and r.status_code != 201:
9a3f62
                 if r.status_code == 401:
9a3f62
                     raise Exception(
9a3f62
                         "Authentication failed: invalid user credentials"
9a3f62
From 8da1b14246226792c160dd04e5c7c75dd4e8d44b Mon Sep 17 00:00:00 2001
9a3f62
From: Pavel Moravec <pmoravec@redhat.com>
9a3f62
Date: Mon, 22 Nov 2021 10:44:09 +0100
9a3f62
Subject: [PATCH] [collect] fix moved get_upload_url under Policy class
9a3f62
9a3f62
SoSCollector does not further declare get_upload_url method
9a3f62
as that was moved under Policy class(es).
9a3f62
9a3f62
Resolves: #2766
9a3f62
9a3f62
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
9a3f62
---
9a3f62
 sos/collector/__init__.py | 2 +-
9a3f62
 1 file changed, 1 insertion(+), 1 deletion(-)
9a3f62
9a3f62
diff --git a/sos/collector/__init__.py b/sos/collector/__init__.py
9a3f62
index 50183e873..42a7731d6 100644
9a3f62
--- a/sos/collector/__init__.py
9a3f62
+++ b/sos/collector/__init__.py
9a3f62
@@ -1219,7 +1219,7 @@ this utility or remote systems that it c
9a3f62
             msg = 'No sosreports were collected, nothing to archive...'
9a3f62
             self.exit(msg, 1)
9a3f62
 
9a3f62
-        if self.opts.upload and self.get_upload_url():
9a3f62
+        if self.opts.upload and self.policy.get_upload_url():
9a3f62
             try:
9a3f62
                 self.policy.upload_archive(arc_name)
9a3f62
                 self.ui_log.info("Uploaded archive successfully")
9a3f62
From abb2fc65bd14760021c61699ad3113cab3bd4c64 Mon Sep 17 00:00:00 2001
9a3f62
From: Pavel Moravec <pmoravec@redhat.com>
9a3f62
Date: Tue, 30 Nov 2021 11:37:02 +0100
9a3f62
Subject: [PATCH 1/2] [redhat] Fix broken URI to upload to customer portal
9a3f62
9a3f62
Revert back the unwanted change in URI of uploading tarball to the
9a3f62
Red Hat Customer portal.
9a3f62
9a3f62
Related: #2772
9a3f62
9a3f62
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
9a3f62
---
9a3f62
 sos/policies/distros/redhat.py | 2 +-
9a3f62
 1 file changed, 1 insertion(+), 1 deletion(-)
9a3f62
9a3f62
diff --git a/sos/policies/distros/redhat.py b/sos/policies/distros/redhat.py
9a3f62
index e4e2b883..eb442407 100644
9a3f62
--- a/sos/policies/distros/redhat.py
9a3f62
+++ b/sos/policies/distros/redhat.py
9a3f62
@@ -250,7 +250,7 @@ support representative.
9a3f62
         elif self.commons['cmdlineopts'].upload_protocol == 'sftp':
9a3f62
             return RH_SFTP_HOST
9a3f62
         else:
9a3f62
-            rh_case_api = "/hydra/rest/cases/%s/attachments"
9a3f62
+            rh_case_api = "/support/v1/cases/%s/attachments"
9a3f62
             return RH_API_HOST + rh_case_api % self.case_id
9a3f62
 
9a3f62
     def _get_upload_headers(self):
9a3f62
-- 
9a3f62
2.31.1
9a3f62
9a3f62
9a3f62
From ea4f9e88a412c80a4791396e1bb78ac1e24ece14 Mon Sep 17 00:00:00 2001
9a3f62
From: Pavel Moravec <pmoravec@redhat.com>
9a3f62
Date: Tue, 30 Nov 2021 13:00:26 +0100
9a3f62
Subject: [PATCH 2/2] [policy] Add error message when FTP upload write failure
9a3f62
9a3f62
When (S)FTP upload fails to write the destination file,
9a3f62
our "expect" code should detect it sooner than after timeout happens
9a3f62
and write appropriate error message.
9a3f62
9a3f62
Resolves: #2772
9a3f62
9a3f62
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
9a3f62
---
9a3f62
 sos/policies/distros/__init__.py | 5 ++++-
9a3f62
 1 file changed, 4 insertions(+), 1 deletion(-)
9a3f62
9a3f62
diff --git a/sos/policies/distros/__init__.py b/sos/policies/distros/__init__.py
9a3f62
index 6f257fdc..7bdc81b8 100644
9a3f62
--- a/sos/policies/distros/__init__.py
9a3f62
+++ b/sos/policies/distros/__init__.py
9a3f62
@@ -473,7 +473,8 @@ class LinuxPolicy(Policy):
9a3f62
         put_expects = [
9a3f62
             u'100%',
9a3f62
             pexpect.TIMEOUT,
9a3f62
-            pexpect.EOF
9a3f62
+            pexpect.EOF,
9a3f62
+            u'No such file or directory'
9a3f62
         ]
9a3f62
 
9a3f62
         put_success = ret.expect(put_expects, timeout=180)
9a3f62
@@ -485,6 +486,8 @@ class LinuxPolicy(Policy):
9a3f62
             raise Exception("Timeout expired while uploading")
9a3f62
         elif put_success == 2:
9a3f62
             raise Exception("Unknown error during upload: %s" % ret.before)
9a3f62
+        elif put_success == 3:
9a3f62
+            raise Exception("Unable to write archive to destination")
9a3f62
         else:
9a3f62
             raise Exception("Unexpected response from server: %s" % ret.before)
9a3f62
 
9a3f62
-- 
9a3f62
2.31.1
9a3f62