当前位置: 首页>>代码示例>>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;未经允许,请勿转载。