diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2020-01-07 13:20:49 -0500 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2020-02-14 19:27:53 +0000 |
commit | 91e706af8346db8247679ea07df78b05b56226f2 (patch) | |
tree | ef20040e6d9de2035f1bd519ef9b556e1239c759 | |
parent | 1e6a6ef1457a74dfe01b57f637921ae52c0ab6d3 (diff) | |
download | sos-91e706af8346db8247679ea07df78b05b56226f2.tar.gz |
[redhat] Add ability to upload to customer cases
Adds the ability to the Red Hat policy for users to upload archives
directly to existing technical support cases on the Red Hat Customer
Portal.
If a case number is provided, uploading to the case is the
preferred/default option the policy will take. If `--upload-user` is not
provided, users will be prompted for one as well as the password for the
Customer Portal account. Note that Red Hat's case management API
requires that the user credentials provided here have access to the case
number referenced on the Customer Portal.
If a case number is not provided, or if one is provided but Customer
Portal credentials are not provided, the policy will fallback to using
the public dropbox location for upload.
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r-- | sos/policies/__init__.py | 5 | ||||
-rw-r--r-- | sos/policies/redhat.py | 57 |
2 files changed, 60 insertions, 2 deletions
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py index e6cf5845..abde0093 100644 --- a/sos/policies/__init__.py +++ b/sos/policies/__init__.py @@ -9,8 +9,9 @@ import fnmatch import tempfile import random import string -from pwd import getpwuid +from getpass import getpass +from pwd import getpwuid from sos.utilities import (ImporterHelper, import_module, shell_out, @@ -1192,7 +1193,7 @@ class LinuxPolicy(Policy): except socket.gaierror: raise Exception("unable to connect to %s" % url) except ftplib.error_perm as err: - errno = err.split()[0] + errno = str(err).split()[0] if errno == 503: raise Exception("could not login as '%s'" % user) if errno == 550: diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py index eab3abb4..9fbe7431 100644 --- a/sos/policies/redhat.py +++ b/sos/policies/redhat.py @@ -21,6 +21,14 @@ from sos import SoSOptions OS_RELEASE = "/etc/os-release" +# In python2.7, input() will not properly return strings, and on python3.x +# raw_input() was renamed to input(). So, if we're running on python2.7, map +# input() to raw_input() to match the behavior +try: + input = raw_input +except NameError: + pass + class RedHatPolicy(LinuxPolicy): distro = "Red Hat" @@ -243,6 +251,9 @@ organization before being passed to any third party. No changes will be made to system configuration. """ +RH_API_HOST = "https://access.redhat.com" +RH_FTP_HOST = "ftp://dropbox.redhat.com" + class RHELPolicy(RedHatPolicy): distro = RHEL_RELEASE_STR @@ -257,6 +268,9 @@ An archive containing the collected information will be \ generated in %(tmpdir)s and may be provided to a %(vendor)s \ support representative. """ + disclaimer_text + "%(vendor_text)s\n") + _upload_url = RH_FTP_HOST + _upload_user = 'anonymous' + _upload_directory = '/incoming' def __init__(self, sysroot=None): super(RHELPolicy, self).__init__(sysroot=sysroot) @@ -286,6 +300,49 @@ support representative. return True return False + def prompt_for_upload_user(self): + if self.commons['cmdlineopts'].upload_user: + return + # Not using the default, so don't call this prompt for RHCP + if self.commons['cmdlineopts'].upload_url: + super(RHELPolicy, self).prompt_for_upload_user() + return + if self.case_id: + self.upload_user = input(_( + "Enter your Red Hat Customer Portal username (empty to use " + "public dropbox): ") + ) + + def get_upload_url(self): + if self.commons['cmdlineopts'].upload_url: + return self.commons['cmdlineopts'].upload_url + if (not self.case_id or not self.upload_user or not + self.upload_password): + # Cannot use the RHCP. Use anonymous dropbox + self.upload_user = self._upload_user + self.upload_directory = self._upload_directory + self.upload_password = None + return RH_FTP_HOST + else: + rh_case_api = "/hydra/rest/cases/%s/attachments" + return RH_API_HOST + rh_case_api % self.case_id + + def _get_upload_headers(self): + if self.get_upload_url().startswith(RH_API_HOST): + return {'isPrivate': 'false', 'cache-control': 'no-cache'} + return {} + + def get_upload_url_string(self): + if self.get_upload_url().startswith(RH_API_HOST): + return "Red Hat Customer Portal" + return self.upload_url or RH_FTP_HOST + + def get_upload_user(self): + # if this is anything other than dropbox, annonymous won't work + if self.upload_url != RH_FTP_HOST: + return self.upload_user + return self._upload_user + def dist_version(self): try: rr = self.package_manager.all_pkgs_by_name_regex("redhat-release*") |