當前位置: 首頁>>代碼示例>>Python>>正文


Python requests_kerberos.HTTPKerberosAuth方法代碼示例

本文整理匯總了Python中requests_kerberos.HTTPKerberosAuth方法的典型用法代碼示例。如果您正苦於以下問題:Python requests_kerberos.HTTPKerberosAuth方法的具體用法?Python requests_kerberos.HTTPKerberosAuth怎麽用?Python requests_kerberos.HTTPKerberosAuth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在requests_kerberos的用法示例。


在下文中一共展示了requests_kerberos.HTTPKerberosAuth方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setAuthMethod

# 需要導入模塊: import requests_kerberos [as 別名]
# 或者: from requests_kerberos import HTTPKerberosAuth [as 別名]
def setAuthMethod(self, auth_method):
        "Set the authentication method to use for the requests."
        self.auth_method = auth_method
        if len(self.auth_credentials) == 2:
            username, password = self.auth_credentials
            if self.auth_method == "basic":
                from requests.auth import HTTPBasicAuth
                self.h.auth = HTTPBasicAuth(username, password)
            elif self.auth_method == "digest":
                from requests.auth import HTTPDigestAuth
                self.h.auth = HTTPDigestAuth(username, password)
            elif self.auth_method == "ntlm":
                from requests_ntlm import HttpNtlmAuth
                self.h.auth = HttpNtlmAuth(username, password)
        elif self.auth_method == "kerberos":
            from requests_kerberos import HTTPKerberosAuth
            self.h.auth = HTTPKerberosAuth() 
開發者ID:flipkart-incubator,項目名稱:watchdog,代碼行數:19,代碼來源:HTTP.py

示例2: set_http_session

# 需要導入模塊: import requests_kerberos [as 別名]
# 或者: from requests_kerberos import HTTPKerberosAuth [as 別名]
def set_http_session(self, http_session):
        try:
            import requests_kerberos
        except ImportError:
            raise RuntimeError("unable to import requests_kerberos")

        if self._config:
            os.environ["KRB5_CONFIG"] = self._config
        http_session.trust_env = False
        http_session.auth = requests_kerberos.HTTPKerberosAuth(
            mutual_authentication=self._mutual_authentication,
            force_preemptive=self._force_preemptive,
            hostname_override=self._hostname_override,
            sanitize_mutual_error_response=self._sanitize_mutual_error_response,
            principal=self._principal,
            delegate=self._delegate,
            service=self._service_name,
        )
        if self._ca_bundle:
            http_session.verify = self._ca_bundle
        return http_session 
開發者ID:prestosql,項目名稱:presto-python-client,代碼行數:23,代碼來源:auth.py

示例3: _create_kerberos_session

# 需要導入模塊: import requests_kerberos [as 別名]
# 或者: from requests_kerberos import HTTPKerberosAuth [as 別名]
def _create_kerberos_session(self, timeout, kerberos_options=None):
        verify = self._options["verify"]
        if kerberos_options is None:
            kerberos_options = {}

        from requests_kerberos import DISABLED
        from requests_kerberos import HTTPKerberosAuth
        from requests_kerberos import OPTIONAL

        if kerberos_options.get("mutual_authentication", "OPTIONAL") == "OPTIONAL":
            mutual_authentication = OPTIONAL
        elif kerberos_options.get("mutual_authentication") == "DISABLED":
            mutual_authentication = DISABLED
        else:
            raise ValueError(
                "Unknown value for mutual_authentication: %s"
                % kerberos_options["mutual_authentication"]
            )

        self._session = ResilientSession(timeout=timeout)
        self._session.verify = verify
        self._session.auth = HTTPKerberosAuth(
            mutual_authentication=mutual_authentication
        ) 
開發者ID:pycontribs,項目名稱:jira,代碼行數:26,代碼來源:client.py

示例4: auth_method

# 需要導入模塊: import requests_kerberos [as 別名]
# 或者: from requests_kerberos import HTTPKerberosAuth [as 別名]
def auth_method(self, value):
        """Set the authentication method to use for the requests."""
        self._auth_method = value
        if len(self._auth_credentials) == 2:
            username, password = self._auth_credentials
            if self._auth_method == "basic":
                from requests.auth import HTTPBasicAuth
                self._session.auth = HTTPBasicAuth(username, password)
            elif self._auth_method == "digest":
                from requests.auth import HTTPDigestAuth
                self._session.auth = HTTPDigestAuth(username, password)
            elif self._auth_method == "ntlm":
                from requests_ntlm import HttpNtlmAuth
                self._session.auth = HttpNtlmAuth(username, password)
        elif self._auth_method == "kerberos":
            # On openSUSE, "zypper in krb5-devel" before installing the pip package
            from requests_kerberos import HTTPKerberosAuth
            self._session.auth = HTTPKerberosAuth() 
開發者ID:penetrate2hack,項目名稱:ITWSV,代碼行數:20,代碼來源:crawler.py

示例5: signed_session

# 需要導入模塊: import requests_kerberos [as 別名]
# 或者: from requests_kerberos import HTTPKerberosAuth [as 別名]
def signed_session(self, session=None):
        """Create requests session with Negotiate (SPNEGO) headers applied.

        If a session object is provided, configure it directly. Otherwise,
        create a new session and return it.

        :param session: The session to configure for authentication
        :type session: requests.Session
        :rtype: requests.Session
        """
        session = super(KerberosAuthentication, self).signed_session(session)
        try:
            from requests_kerberos import HTTPKerberosAuth
        except ImportError:
            raise ImportError("In order to use KerberosAuthentication please do 'pip install requests_kerberos' first")
        if self.mutual_authentication:
            session.auth = HTTPKerberosAuth(mutual_authentication=self.mutual_authentication)
        else:
            session.auth = HTTPKerberosAuth()
        return session 
開發者ID:Azure,項目名稱:msrest-for-python,代碼行數:22,代碼來源:authentication.py

示例6: _download

# 需要導入模塊: import requests_kerberos [as 別名]
# 或者: from requests_kerberos import HTTPKerberosAuth [as 別名]
def _download(url, temp):
    """Downloads the image."""
    _LOGGER.debug('Downloading tar file from %r to %r.', url, temp)

    krb_auth = requests_kerberos.HTTPKerberosAuth(
        mutual_authentication=requests_kerberos.DISABLED,
        # kerberos 1.2.5 doesn't accept None principal. Remove this once fixed.
        principal=''
    )

    request = requests.get(url, stream=True, auth=krb_auth)
    shutil.copyfileobj(request.raw, temp) 
開發者ID:Morgan-Stanley,項目名稱:treadmill,代碼行數:14,代碼來源:tar.py

示例7: get_job

# 需要導入模塊: import requests_kerberos [as 別名]
# 或者: from requests_kerberos import HTTPKerberosAuth [as 別名]
def get_job(self, id_val):
        """Retrieve job with provided id
        :param id_val:String
        :return workflow_job:Workflow"""
        workflow_job = None
        query = 'job/' + id_val
        req_get = requests.get(self.oozie_url + query, auth=HTTPKerberosAuth())
        if req_get.status_code == 200:
            my_json = json.dumps(req_get.json())
            print 'JSON: ', my_json
            workflow_job = Workflow(my_json)
        else:
            err_msg = "Error retrieving job, {id_val}. Error code: {status}"
            err_msg = err_msg.format(id_val=id_val, status=req_get.status_code)
            print err_msg
        return req_get.status_code, workflow_job 
開發者ID:Cigna,項目名稱:ibis,代碼行數:18,代碼來源:oozie_ws_helper.py

示例8: put_request

# 需要導入模塊: import requests_kerberos [as 別名]
# 或者: from requests_kerberos import HTTPKerberosAuth [as 別名]
def put_request(self, suffix_url, xml_file):
        """Make a oozie put request"""
        status = False
        file_h = open(os.path.join(self.cfg_mgr.saves, xml_file))
        data = file_h.read()
        http_headers = {'Content-Type': 'application/xml'}
        url = self.oozie_url + suffix_url
        self.logger.info(url)
        response = requests.post(url, data=data, headers=http_headers,
                                 auth=HTTPKerberosAuth())
        if 200 <= response.status_code and response.status_code < 300:
            my_json = json.dumps(response.json())
            res_val = response.json()
            # self.logger.info(json.dumps(response.json(),
            # indent=4, sort_keys=True))
            msg = "\n\n\t\tGo here: https://{0}:8888/oozie/" \
                  "list_oozie_workflow/{1}/\n".\
                format(self.cfg_mgr.workflow_host, res_val['id'])
            self.logger.info(msg)
            status = True
        else:
            self.logger.error("Error submitting job. Error code: "
                              "{status}".format(status=response.status_code))
            self.logger.error(response.text)
        return status 
開發者ID:Cigna,項目名稱:ibis,代碼行數:27,代碼來源:oozie_helper.py

示例9: test_config_kerberos_legacy

# 需要導入模塊: import requests_kerberos [as 別名]
# 或者: from requests_kerberos import HTTPKerberosAuth [as 別名]
def test_config_kerberos_legacy(self):
        instance = {'kerberos_auth': 'required'}
        init_config = {}

        # Trigger lazy import
        http = RequestsWrapper(instance, init_config)
        assert isinstance(http.options['auth'], requests_kerberos.HTTPKerberosAuth)

        with mock.patch('datadog_checks.base.utils.http.requests_kerberos.HTTPKerberosAuth') as m:
            RequestsWrapper(instance, init_config)

            m.assert_called_once_with(
                mutual_authentication=requests_kerberos.REQUIRED,
                delegate=False,
                force_preemptive=False,
                hostname_override=None,
                principal=None,
            ) 
開發者ID:DataDog,項目名稱:integrations-core,代碼行數:20,代碼來源:test_http.py

示例10: test_config_kerberos_shortcut

# 需要導入模塊: import requests_kerberos [as 別名]
# 或者: from requests_kerberos import HTTPKerberosAuth [as 別名]
def test_config_kerberos_shortcut(self):
        instance = {'auth_type': 'kerberos', 'kerberos_auth': True}
        init_config = {}

        # Trigger lazy import
        http = RequestsWrapper(instance, init_config)
        assert isinstance(http.options['auth'], requests_kerberos.HTTPKerberosAuth)

        with mock.patch('datadog_checks.base.utils.http.requests_kerberos.HTTPKerberosAuth') as m:
            RequestsWrapper(instance, init_config)

            m.assert_called_once_with(
                mutual_authentication=requests_kerberos.REQUIRED,
                delegate=False,
                force_preemptive=False,
                hostname_override=None,
                principal=None,
            ) 
開發者ID:DataDog,項目名稱:integrations-core,代碼行數:20,代碼來源:test_http.py

示例11: test_config_kerberos_legacy_remap

# 需要導入模塊: import requests_kerberos [as 別名]
# 或者: from requests_kerberos import HTTPKerberosAuth [as 別名]
def test_config_kerberos_legacy_remap(self):
        instance = {'auth_type': 'kerberos', 'kerberos': True}
        init_config = {}

        # Trigger lazy import
        http = RequestsWrapper(instance, init_config)
        assert isinstance(http.options['auth'], requests_kerberos.HTTPKerberosAuth)

        with mock.patch('datadog_checks.base.utils.http.requests_kerberos.HTTPKerberosAuth') as m:
            RequestsWrapper(instance, init_config)

            m.assert_called_once_with(
                mutual_authentication=requests_kerberos.REQUIRED,
                delegate=False,
                force_preemptive=False,
                hostname_override=None,
                principal=None,
            ) 
開發者ID:DataDog,項目名稱:integrations-core,代碼行數:20,代碼來源:test_http.py

示例12: _connect

# 需要導入模塊: import requests_kerberos [as 別名]
# 或者: from requests_kerberos import HTTPKerberosAuth [as 別名]
def _connect(self):
        self.session = requests.Session()
        if self.kerb:
            from requests_kerberos import HTTPKerberosAuth

            self.session.auth = HTTPKerberosAuth(**self.kerb_kwargs) 
開發者ID:intake,項目名稱:filesystem_spec,代碼行數:8,代碼來源:webhdfs.py

示例13: test_connection_with_kerberos

# 需要導入模塊: import requests_kerberos [as 別名]
# 或者: from requests_kerberos import HTTPKerberosAuth [as 別名]
def test_connection_with_kerberos(post):
    connection = KerberosConnection('https://host')

    post().json.return_value = {'hello': 'world'}

    assert connection.make_request('/uri', {'it\'s': 'alive'}) == {'hello': 'world'}

    capture = Capture()
    post.assert_called_with('https://host/uri', auth=capture, json={"it's": 'alive'}, verify=False)
    assert isinstance(capture.value, HTTPKerberosAuth) 
開發者ID:jakubplichta,項目名稱:grafana-dashboard-builder,代碼行數:12,代碼來源:test_connection.py

示例14: make_request

# 需要導入模塊: import requests_kerberos [as 別名]
# 或者: from requests_kerberos import HTTPKerberosAuth [as 別名]
def make_request(self, uri, body=None):
        response = requests.post('{0}{1}'.format(self._host, uri), json=body, auth=HTTPKerberosAuth(), verify=False)
        return response.json() 
開發者ID:jakubplichta,項目名稱:grafana-dashboard-builder,代碼行數:5,代碼來源:connection.py

示例15: _create_requests_session

# 需要導入模塊: import requests_kerberos [as 別名]
# 或者: from requests_kerberos import HTTPKerberosAuth [as 別名]
def _create_requests_session(self):
        """
        Creates a Requests Session and authenticates to base API URL with HTTP Basic Auth or Kerberos Auth.
        We're using a Session to persist cookies across all requests made from the Session instance.
        :return s: Requests Session.
        """
        s = requests.Session()
        # Kerberos Auth
        if self.auth == 'kerberos':
            self.principal = ticket._get_kerberos_principal()
            s.auth = HTTPKerberosAuth(mutual_authentication=DISABLED)
            s.verify = False
        # HTTP Basic Auth
        if isinstance(self.auth, tuple):
            username, password = self.auth
            self.principal = username
            s.params.update({'user': username, 'pass': password})

        # Try to authenticate to auth_url.
        try:
            r = s.get(self.auth_url)
            logger.debug("Create requests session: status code: {0}".format(r.status_code))
            r.raise_for_status()
            # Special case for RT. A 200 status code is still returned if authentication failed. Have to check r.text.
            if '200' not in r.text:
                raise requests.RequestException
            logger.info("Successfully authenticated to {0}".format(self.ticketing_tool))
            return s
        except requests.RequestException as e:
            logger.error("Error authenticating to {0}".format(self.auth_url))
            s.close() 
開發者ID:dmranck,項目名稱:ticketutil,代碼行數:33,代碼來源:rt.py


注:本文中的requests_kerberos.HTTPKerberosAuth方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。