File tree Expand file tree Collapse file tree 6 files changed +31
-1
lines changed Expand file tree Collapse file tree 6 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 42
42
run : sudo mkdir -p /etc/rhsm/ca/ && sudo curl -o /etc/rhsm/ca/redhat-uep.pem https://ftp.redhat.com/redhat/convert2rhel/redhat-uep.pem
43
43
- name : Install system dependencies
44
44
# libyaml-dev for PyYAML, rpm for rpm-py-installer, python3-rpm for rpm-shim
45
- run : sudo apt-get install -y libyaml-dev rpm python3-rpm
45
+ run : sudo apt-get install -y libyaml-dev rpm python3-rpm libkrb5-dev build-essential --no-install-recommends
46
46
- name : Fix up Python RPM binding filenames so that other Pythons find it
47
47
run : |
48
48
for file in /usr/lib/python3/dist-packages/rpm/_rpm*.cpython-*.so; do
Original file line number Diff line number Diff line change 12
12
from urllib .parse import urljoin # type: ignore
13
13
import requests
14
14
15
+ try :
16
+ from requests_gssapi import HTTPKerberosAuth # type: ignore
17
+ except ImportError :
18
+ try :
19
+ from requests_kerberos import HTTPKerberosAuth # type: ignore
20
+ except ImportError :
21
+ HTTPKerberosAuth = None
22
+
15
23
from apypie .resource import Resource
16
24
from apypie .exceptions import DocLoadingError
17
25
@@ -40,6 +48,7 @@ class Api(object):
40
48
:param password: password to access the API
41
49
:param client_cert: client cert to access the API
42
50
:param client_key: client key to access the API
51
+ :param kerberos: use Kerberos/GSSAPI for authentication with the API. Requires either `requests-gssapi` or `requests-kerberos`.
43
52
:param api_version: version of the API. Defaults to `1`
44
53
:param language: prefered locale for the API description
45
54
:param apidoc_cache_base_dir: base directory for building apidoc_cache_dir. Defaults to `~/.cache/apipie_bindings`.
@@ -85,6 +94,12 @@ def __init__(self, **kwargs):
85
94
if kwargs .get ('client_cert' ) and kwargs .get ('client_key' ):
86
95
self ._session .cert = (kwargs ['client_cert' ], kwargs ['client_key' ])
87
96
97
+ if kwargs .get ('kerberos' ):
98
+ if HTTPKerberosAuth is not None :
99
+ self ._session .auth = HTTPKerberosAuth ()
100
+ else :
101
+ raise ValueError ('Kerberos authentication requested, but neither requests-gssapi nor requests-kerberos found.' )
102
+
88
103
self ._apidoc = None
89
104
90
105
@property
Original file line number Diff line number Diff line change @@ -63,6 +63,8 @@ def __init__(self, **kwargs):
63
63
self .task_poll = 4
64
64
kwargs ['api_version' ] = 2
65
65
super ().__init__ (** kwargs )
66
+ if kwargs .get ('kerberos' ):
67
+ self .call ('users' , 'extlogin' )
66
68
67
69
def _resource (self , resource : str ) -> 'Resource' :
68
70
if resource not in self .resources :
Original file line number Diff line number Diff line change @@ -8,4 +8,5 @@ pytest-xdist
8
8
pytest-pylint
9
9
pytest-mock
10
10
requests_mock
11
+ requests-gssapi
11
12
setuptools
Original file line number Diff line number Diff line change 39
39
install_requires = [
40
40
'requests>=2.4.2' ,
41
41
],
42
+ extras_require = {
43
+ 'kerberos' : ['requests-gssapi' ],
44
+ },
42
45
)
Original file line number Diff line number Diff line change @@ -36,6 +36,15 @@ def test_init(foremanapi):
36
36
assert foremanapi .apidoc
37
37
38
38
39
+ def test_kerberos (fixture_dir , requests_mock , tmpdir ):
40
+ with fixture_dir .join ('foreman.json' ).open () as read_file :
41
+ data = json .load (read_file )
42
+ requests_mock .get ('https://api.example.com/apidoc/v2.json' , json = data )
43
+ requests_mock .get ('https://api.example.com/api/users/extlogin' , status_code = 204 )
44
+ ForemanApi (uri = 'https://api.example.com' , apidoc_cache_dir = tmpdir .strpath , kerberos = True )
45
+ assert requests_mock .last_request .url == 'https://api.example.com/api/users/extlogin'
46
+
47
+
39
48
def test_resources (foremanapi ):
40
49
assert 'domains' in foremanapi .resources
41
50
You can’t perform that action at this time.
0 commit comments