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

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