コード例 #1
0
    def _check_owner(self):
        # Firstly, determine for whom listcases is being run and if they're a
        #    Red Hat employee (isInternal == True) or not
        # If they're internal, then display the open cases they *own* in SFDC
        # ...except however if the -o all, -g or -u options are specified, then
        #    it displays cases in the Red Hat employee's account.
        # If they're not internal, then display the open cases in their account

        try:
            api = apihelper.get_api()
            username = api.config.username

            userobj = contextmanager.get('user')
            if not userobj:
                userobj = api.users.get(username)
                contextmanager.add('user', userobj)

            if self._options['owner']:
                if not userobj.isInternal:
                    raise Exception("The -o switch is only available to Red Hat"
                                    " employees")
                elif self._options['owner'].lower() != 'all':
                    username = self._options['owner']
                    userobj = api.users.get(username)
                    if not userobj.isInternal:
                        # for some reason RH users can't display non-RH users
                        raise Exception("Red Hat employees are unable to list"
                                        "cases for non-Red Hat portal users.")

            if userobj.isInternal:
                if not (str(self._options['owner']).lower() == 'all' or
                        self._caseGroupNumbers or
                        self._options['ungrouped']):
                    # this will trigger the display of cases owned as per SFDC
                    self._associateSSOName = username
                    self._view = 'internal'

        except RequestError, re:
            if re.status == 404:
                msg = _("Unable to find user %s" % username)
            else:
                msg = _('Problem querying the support services API.  Reason: '
                        '%s' % re.reason)
            print msg
            logger.log(logging.WARNING, msg)
            raise
コード例 #2
0
    def _check_owner(self):
        # Firstly, determine for whom listcases is being run and if they're a
        #    Red Hat employee (isInternal == True) or not
        # If they're internal, then display the open cases they *own* in SFDC
        # ...except however if the -o all, -g or -u options are specified, then
        #    it displays cases in the Red Hat employee's account.
        # If they're not internal, then display the open cases in their account

        try:
            api = apihelper.get_api()
            username = api.config.username

            userobj = contextmanager.get('user')
            if not userobj:
                userobj = api.users.get(username)
                contextmanager.add('user', userobj)

            if self._options['owner']:
                if not userobj.isInternal:
                    raise Exception(
                        "The -o switch is only available to Red Hat"
                        " employees")
                elif self._options['owner'].lower() != 'all':
                    username = self._options['owner']
                    userobj = api.users.get(username)
                    if not userobj.isInternal:
                        # for some reason RH users can't display non-RH users
                        raise Exception("Red Hat employees are unable to list"
                                        "cases for non-Red Hat portal users.")

            if userobj.isInternal:
                if not (str(self._options['owner']).lower() == 'all' or
                        self._caseGroupNumbers or self._options['ungrouped']):
                    # this will trigger the display of cases owned as per SFDC
                    self._associateSSOName = username
                    self._view = 'internal'

        except RequestError, re:
            if re.status == 404:
                msg = _("Unable to find user %s" % username)
            else:
                msg = _('Problem querying the support services API.  Reason: '
                        '%s' % re.reason)
            print msg
            logger.log(logging.WARNING, msg)
            raise
コード例 #3
0
    def __init__(self,
                 username,
                 password,
                 url='https://api.access.redhat.com',
                 key_file=None,
                 cert_file=None,
                 proxy_url=None,
                 proxy_user=None,
                 proxy_pass=None,
                 ftp_host='dropbox.redhat.com',
                 ftp_port=21,
                 ftp_user=None,
                 ftp_pass=None,
                 ftp_dir="/incoming",
                 timeout=None,
                 userAgent=None,
                 no_verify_ssl=False,
                 ssl_ca=None):

        """
        Initialize an instance of the Red Hat Support Library

        :param username: User name for Red Hat Customer Portal
        :type username: string
        :param password: Password for Red Hat Customer Portal
        :type password: string
        :param url:
            Strata REST URL (by default this is https://api.access.redhat.com)

        :type url: string
        :param key_file:
            SSL key location for SSL authentication (not implemented)

        :type key_file: string
        :param cert_file:
            SSL certificate location for SSL authentication (not implemented)

        :type cert_file: string
        :param proxy_url: URL for HTTP/HTTPS proxy server (optional)
        :type proxy_url: string
        :param proxy_user: User name for HTTP/HTTPS proxy server (optional)
        :type proxy_user: string
        :param proxy_pass: Password for HTTP/HTTPS proxy server (optional)
        :type proxy_pass: string
        :param timeout: Request timeout (optional)
        :type timeout: string
        :param userAgent: User agent to set for API communications (optional)
        :type userAgent: string
        :param no_verify_ssl: If True, don't verify server identity (optional)
        :type no_verify_ssl: boolean
        :param ssl_ca: Path to an alternative certificate authority to trust
        :type ssl_ca: string/filepath
        :returns: Strata API object
        """

        # Make sure logger is initialized
        if len(logging.getLogger().handlers) == 0:
            logging.basicConfig(level=logging.CRITICAL)
        httpdebug = False
        if logging.getLogger().getEffectiveLevel() == logging.DEBUG:
            httpdebug = True

        self._ua = None
        if userAgent:
            ua = {'User-Agent': userAgent}
        else:
            ua = {'User-Agent': USER_AGENT}
        config = confighelper.get_config_helper()
        config.username = username
        config.password = password
        config.url = url
        config.key_file = key_file
        config.cert_file = cert_file
        config.proxy_url = proxy_url
        config.proxy_user = proxy_user
        config.proxy_pass = proxy_pass
        config.ftp_host = ftp_host
        config.ftp_port = ftp_port
        config.ftp_user = ftp_user
        config.ftp_pass = ftp_pass
        config.ftp_dir = ftp_dir
        config.timeout = timeout
        config.userAgent = ua
        config.http_debug = httpdebug
        config.no_verify_ssl = no_verify_ssl
        config.ssl_ca = ssl_ca
        self.config = config

        contextmanager.add('proxy',
                           Proxy(ConnectionsPool(url=config.url,
                                                 key_file=config.key_file,
                                                 cert_file=config.cert_file,
                                                 timeout=config.timeout,
                                                 username=config.username,
                                                 password=config.password,
                                                 proxy_url=config.proxy_url,
                                                 proxy_user=config.proxy_user,
                                                 proxy_pass=config.proxy_pass,
                                                 debug=config.http_debug,
                                                 noverify=config.no_verify_ssl,
                                                 ssl_ca=config.ssl_ca),
                                 config.userAgent),
                           Mode.R)

        # Initialize the container classes.
        self.solutions = solutions()
        self.articles = articles()
        self.cases = cases()
        self.groups = groups()
        self.users = users()
        self.comments = comments()
        self.attachments = attachments()
        self.problems = problems()
        self.entitlements = entitlements()
        self.products = products()
        self.symptoms = symptoms()
        self.values = values()
        self.search = search()
        self.im = InstanceMaker()