本文整理匯總了Python中requests_kerberos.OPTIONAL屬性的典型用法代碼示例。如果您正苦於以下問題:Python requests_kerberos.OPTIONAL屬性的具體用法?Python requests_kerberos.OPTIONAL怎麽用?Python requests_kerberos.OPTIONAL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類requests_kerberos
的用法示例。
在下文中一共展示了requests_kerberos.OPTIONAL屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _create_kerberos_session
# 需要導入模塊: import requests_kerberos [as 別名]
# 或者: from requests_kerberos import OPTIONAL [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
)
示例2: create_kerberos_auth
# 需要導入模塊: import requests_kerberos [as 別名]
# 或者: from requests_kerberos import OPTIONAL [as 別名]
def create_kerberos_auth(config):
global requests_kerberos
if requests_kerberos is None:
import requests_kerberos
KERBEROS_STRATEGIES['required'] = requests_kerberos.REQUIRED
KERBEROS_STRATEGIES['optional'] = requests_kerberos.OPTIONAL
KERBEROS_STRATEGIES['disabled'] = requests_kerberos.DISABLED
# For convenience
if config['kerberos_auth'] is None or is_affirmative(config['kerberos_auth']):
config['kerberos_auth'] = 'required'
if config['kerberos_auth'] not in KERBEROS_STRATEGIES:
raise ConfigurationError(
'Invalid Kerberos strategy `{}`, must be one of: {}'.format(
config['kerberos_auth'], ' | '.join(KERBEROS_STRATEGIES)
)
)
return requests_kerberos.HTTPKerberosAuth(
mutual_authentication=KERBEROS_STRATEGIES[config['kerberos_auth']],
delegate=is_affirmative(config['kerberos_delegate']),
force_preemptive=is_affirmative(config['kerberos_force_initiate']),
hostname_override=config['kerberos_hostname'],
principal=config['kerberos_principal'],
)
示例3: test_config_kerberos
# 需要導入模塊: import requests_kerberos [as 別名]
# 或者: from requests_kerberos import OPTIONAL [as 別名]
def test_config_kerberos(self):
instance = {'auth_type': 'kerberos', '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,
)
with mock.patch('datadog_checks.base.utils.http.requests_kerberos.HTTPKerberosAuth') as m:
RequestsWrapper({'auth_type': 'kerberos', 'kerberos_auth': 'optional'}, init_config)
m.assert_called_once_with(
mutual_authentication=requests_kerberos.OPTIONAL,
delegate=False,
force_preemptive=False,
hostname_override=None,
principal=None,
)
with mock.patch('datadog_checks.base.utils.http.requests_kerberos.HTTPKerberosAuth') as m:
RequestsWrapper({'auth_type': 'kerberos', 'kerberos_auth': 'disabled'}, init_config)
m.assert_called_once_with(
mutual_authentication=requests_kerberos.DISABLED,
delegate=False,
force_preemptive=False,
hostname_override=None,
principal=None,
)