Skip to content

Commit f706d08

Browse files
committed
[upload] Enable sos uploads of files bigger than 1Gb
Uploads of files greater than 1Gb switch to go to sftp. The code incorrectly tried to write to the home directory in sftp, but should switch into the /{user} directory instead so proper permissions exist. Related: RHEL-52919 Signed-off-by: David Wolstromer <dwolstro@redhat.com>
1 parent ea8aa62 commit f706d08

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

sos/upload/targets/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def get_upload_password(self):
465465
self.upload_password or
466466
self._upload_password)
467467

468-
def upload_sftp(self, user=None, password=None):
468+
def upload_sftp(self, user=None, password=None, user_dir=None):
469469
"""Attempts to upload the archive to an SFTP location.
470470
471471
Due to the lack of well maintained, secure, and generally widespread
@@ -540,10 +540,13 @@ def upload_sftp(self, user=None, password=None):
540540
raise Exception("Unable to connect via SFTP to "
541541
f"{self.get_upload_url_string()}")
542542

543-
put_cmd = (f'put {self.upload_archive_name} '
544-
f'{self._get_sftp_upload_name()}')
543+
# certain implementations require file to be put in the user dir
544+
put_cmd = (
545+
f"put {self.upload_archive_name} "
546+
f"{f'{user_dir}/' if user_dir else ''}"
547+
f"{self._get_sftp_upload_name()}"
548+
)
545549
ret.sendline(put_cmd)
546-
547550
put_expects = [
548551
'100%',
549552
pexpect.TIMEOUT,

sos/upload/targets/redhat.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def _get_sftp_upload_name(self):
145145
return fname
146146

147147
# pylint: disable=too-many-branches
148-
def upload_sftp(self, user=None, password=None):
148+
def upload_sftp(self, user=None, password=None, user_dir=None):
149149
"""Override the base upload_sftp to allow for setting an on-demand
150150
generated anonymous login for the RH SFTP server if a username and
151151
password are not given
@@ -217,7 +217,8 @@ def upload_sftp(self, user=None, password=None):
217217
f"{anon.status_code}): {anon.json()}"
218218
)
219219
if _user and _token:
220-
return super().upload_sftp(user=_user, password=_token)
220+
return super().upload_sftp(user=_user, password=_token,
221+
user_dir=_user)
221222
raise Exception("Could not retrieve valid or anonymous credentials")
222223

223224
def check_file_too_big(self, archive):

0 commit comments

Comments
 (0)