Skip to content

Commit

Permalink
Merge c3b1dfd into b929036
Browse files Browse the repository at this point in the history
  • Loading branch information
atodorov committed Mar 22, 2020
2 parents b929036 + c3b1dfd commit d0fd956
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 29 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/integration.yml
Expand Up @@ -40,7 +40,7 @@ jobs:
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get install libkrb5-dev
pip install kerberos requests
pip install -r devel.txt
- name: Build & start services
run: |
Expand Down Expand Up @@ -72,10 +72,6 @@ jobs:
make verify-web-login
klist
- name: Install coverage tools
run: |
pip install coverage codecov
- name: Verify tcms-api can communicate via username/password
run: |
cat > ~/.tcms.conf << _EOF_
Expand Down
7 changes: 3 additions & 4 deletions .travis.yml
Expand Up @@ -11,15 +11,14 @@ env:
- MAKE=build

install:
- pip install coverage pylint flake8 twine kerberos requests
- pip install -r devel.txt

script:
- make $MAKE

after_success:
- |
pip install coveralls
coveralls
- coveralls

notifications:
email:
on_failure: change
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
@@ -1 +1 @@
include README.rst LICENSE
include README.rst LICENSE requirements.txt
2 changes: 1 addition & 1 deletion appveyor.yml
Expand Up @@ -16,7 +16,7 @@ install:

- "python --version"
- "python -m pip install --disable-pip-version-check --user --upgrade pip wheel"
- "python -m pip install coverage pylint flake8 twine winkerberos requests"
- "python -m pip install -r devel.txt"

build: off

Expand Down
6 changes: 6 additions & 0 deletions devel.txt
@@ -0,0 +1,6 @@
-r requirements.txt

coveralls
flake8
pylint
twine
2 changes: 1 addition & 1 deletion docs/source/conf.py
Expand Up @@ -20,7 +20,7 @@
# generate documentation from Python sources
subprocess.run(['make', '-C', '../', 'apidoc'], check=True)

autodoc_mock_imports = ['kerberos']
autodoc_mock_imports = ['gssapi']

# -- General configuration ------------------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
@@ -0,0 +1,2 @@
gssapi
requests
18 changes: 12 additions & 6 deletions setup.py
@@ -1,6 +1,5 @@
#!/usr/bin/env python
import os
import sys
from setuptools import setup


Expand All @@ -11,12 +10,22 @@ def get_version():
).replace('__version__=', '').strip().strip("'").strip('"')


def get_install_requires(path):
requires = []

with open(path, 'r') as file:
for line in file:
if line.startswith('-r '):
continue
requires.append(line.strip())
return requires


with open("README.rst") as readme:
LONG_DESCRIPTION = readme.read()


setup(name='tcms-api',
# always update version/release in docs/conf.py
version=get_version(),
packages=['tcms_api'],
description='Python API for Kiwi',
Expand All @@ -27,10 +36,7 @@ def get_version():
license='LGPLv2+',
url='https://github.com/kiwitcms/tcms-api',
python_requires='>=3.6',
install_requires=[
'requests',
'winkerberos' if sys.platform.startswith("win") else 'kerberos',
],
install_requires=get_install_requires('requirements.txt'),
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
Expand Down
18 changes: 7 additions & 11 deletions tcms_api/xmlrpc.py
@@ -1,20 +1,17 @@
# pylint: disable=too-few-public-methods

import sys
import urllib.parse

from base64 import b64encode
from http import HTTPStatus
from http.client import HTTPSConnection
from xmlrpc.client import SafeTransport, Transport, ServerProxy

import gssapi
import requests

from tcms_api.version import __version__

if sys.platform.startswith("win"):
import winkerberos as kerberos # pylint: disable=import-error
else:
import kerberos # pylint: disable=import-error

VERBOSE = 0

Expand Down Expand Up @@ -45,9 +42,8 @@ class SafeCookieTransport(SafeTransport, CookieTransport):
scheme = 'https'


# Taken from FreeIPA source freeipa-1.2.1/ipa-python/krbtransport.py
class KerbTransport(SafeCookieTransport):
"""Handles Kerberos Negotiation authentication to an XML-RPC server."""
"""Handles GSSAPI Negotiation (SPNEGO) authentication."""

def get_host_info(self, host):
host, extra_headers, x509 = Transport.get_host_info(self, host)
Expand All @@ -56,12 +52,12 @@ def get_host_info(self, host):
hostinfo = host.split(':')
service = "HTTP@" + hostinfo[0]

_result, context = kerberos.authGSSClientInit(service)
kerberos.authGSSClientStep(context, "")
service_name = gssapi.Name(service, gssapi.NameType.hostbased_service)
context = gssapi.SecurityContext(usage="initiate", name=service_name)
token = context.step()

extra_headers = [
("Authorization", "Negotiate %s" %
kerberos.authGSSClientResponse(context))
("Authorization", "Negotiate %s" % b64encode(token).decode())
]

return host, extra_headers, x509
Expand Down

0 comments on commit d0fd956

Please sign in to comment.