From f2bf33e8b3ff81d2e3b15ce8051fd8875ce08974 Mon Sep 17 00:00:00 2001 From: Michael Hierweck Date: Wed, 22 Sep 2021 12:31:20 +0200 Subject: [PATCH 1/4] Typo. --- BUILD.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUILD.txt b/BUILD.txt index 97d350a..53d5101 100644 --- a/BUILD.txt +++ b/BUILD.txt @@ -18,7 +18,7 @@ $ python ./setup.py --command-packages=stdeb.command bdist_deb Building with Python 3 --------------_-------- +---------------------- Building Debian Packages with Python 3 requires the following Debian Packages to be installed: From cd5bba77c15b5476d01f9bd6f86b7f3ec40a71d1 Mon Sep 17 00:00:00 2001 From: Michael Hierweck Date: Wed, 22 Sep 2021 12:31:48 +0200 Subject: [PATCH 2/4] Update to recent CAS protocol version. --- CHANGES.txt | 9 ++++++++- setup.py | 3 ++- src/hs/admin/api/session.py | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index c89b95f..1b3dded 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,7 +4,7 @@ Changelog 0.1 --- -- Initial release. +- Initial release. [Michael Hierweck , Hostsharing eG] @@ -16,3 +16,10 @@ Changelog - Add build instructions. [Michael Hierweck , Hostsharing eG] + + +0.3 +--- + +- Update to recent CAS protocol version. + [Michael Hierweck , Hostsharing eG] diff --git a/setup.py b/setup.py index c040da6..0efc110 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages import os -version = '0.2' +version = '0.3' long_description = ( open('README.txt').read()) @@ -28,6 +28,7 @@ install_requires=[ 'setuptools', 'requests', + 'pyyaml', # -*- Extra requirements: -*- ], entry_points=""" diff --git a/src/hs/admin/api/session.py b/src/hs/admin/api/session.py index 4432e22..e2b8e15 100644 --- a/src/hs/admin/api/session.py +++ b/src/hs/admin/api/session.py @@ -2,6 +2,7 @@ """ from requests import delete, post +from yaml import safe_load from .exceptions import LoginError, SessionError @@ -33,7 +34,7 @@ def get_ticket(self): result = post(self.tgt, data=payload) if result.status_code != 200: raise SessionError('Acquisition of session ticket failed.') - return result.text + return safe_load(result.text) def get_user(self): From 6ccaef8815d32036d17e98f9d5b6bf1638f3360b Mon Sep 17 00:00:00 2001 From: Lukas Staab Date: Mon, 18 Apr 2022 21:06:05 +0200 Subject: [PATCH 3/4] fixed indexing bug - now correctly subscripted methodnames, not static module name --- src/hs/admin/api/module.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hs/admin/api/module.py b/src/hs/admin/api/module.py index 6f59856..4775a8d 100644 --- a/src/hs/admin/api/module.py +++ b/src/hs/admin/api/module.py @@ -15,8 +15,8 @@ def __init__(self, proxy, name, properties, methods): self.methods = dict() for method in methods: - self.methods[name] = Method(proxy, self, method) - setattr(self, method, self.methods[name]) + self.methods[method] = Method(proxy, self, method) + setattr(self, method, self.methods[method]) def list_methods(self): From 5ef9fbdbef083d3ee08f54df75ff879f97f0e7fc Mon Sep 17 00:00:00 2001 From: Lukas Staab Date: Tue, 19 Apr 2022 22:59:24 +0200 Subject: [PATCH 4/4] refactored old exceptions, minor changes to doc and spacing --- src/hs/admin/api/exceptions.py | 18 ------------------ src/hs/admin/api/proxy.py | 12 +++--------- src/hs/admin/api/session.py | 14 ++++---------- 3 files changed, 7 insertions(+), 37 deletions(-) delete mode 100644 src/hs/admin/api/exceptions.py diff --git a/src/hs/admin/api/exceptions.py b/src/hs/admin/api/exceptions.py deleted file mode 100644 index 3464a58..0000000 --- a/src/hs/admin/api/exceptions.py +++ /dev/null @@ -1,18 +0,0 @@ -""" This module provides exception classes. -""" - - - -class LoginError(Exception): - """ Raised when the login failed. - """ - - -class SessionError(Exception): - """ Raised when the session failed. - """ - - -class ProxyError(Exception): - """ Raised when an remote backend invokation failed. - """ diff --git a/src/hs/admin/api/proxy.py b/src/hs/admin/api/proxy.py index 0ee380d..2ee0f07 100644 --- a/src/hs/admin/api/proxy.py +++ b/src/hs/admin/api/proxy.py @@ -1,5 +1,6 @@ """ This module provides a directly callable class that implements a remote method invokation. """ +import xmlrpc.client try: from xmlrpclib import ServerProxy @@ -8,9 +9,6 @@ from xmlrpc.client import ServerProxy from xmlrpc.client import Fault -from .exceptions import ProxyError - - class Proxy(object): """ This directly callable class implements a remote method invokation. @@ -20,13 +18,11 @@ def __init__(self, session, dispatcher): self.session = session self.dispatcher = dispatcher - def __call__(self, module, method, where=None, set=None): backend = self.dispatcher.get_backend(module) remote = getattr(ServerProxy(backend), module + '.' + method) ticket = self.session.get_ticket() user = self.session.get_user() - try: if (where is None) and (set is None): result = remote(user, ticket) @@ -36,8 +32,6 @@ def __call__(self, module, method, where=None, set=None): result = remote(user, ticket, where) else: result = remote(user, ticket, set, where) - - except Fault as fault: - raise ProxyError(fault.faultString) - + except xmlrpc.client.Fault as e: + raise Exception('HS Error' + e.faultString) return result diff --git a/src/hs/admin/api/session.py b/src/hs/admin/api/session.py index e2b8e15..48db86a 100644 --- a/src/hs/admin/api/session.py +++ b/src/hs/admin/api/session.py @@ -4,9 +4,6 @@ from requests import delete, post from yaml import safe_load -from .exceptions import LoginError, SessionError - - class Session(object): """ This class implements a remote user session. @@ -17,27 +14,24 @@ def __init__(self, provider, service, username, password): 'password': password} result = post(provider, data=payload) if result.status_code != 201: - raise LoginError('Acquisition of ticket granting ticket failed.') + raise Exception('Session Error: Acquisition of ticket granting ticket failed.') self.service = service self.tgt = result.headers['location'] self.user = username - def __exit__(self, exc_type, exc_value, traceback): delete(self.tgt) - def get_ticket(self): - """ Returns an one-time ticket for a remote user action """ + """ Returns a one-time ticket for a remote user action """ payload = {'service': self.service} result = post(self.tgt, data=payload) if result.status_code != 200: - raise SessionError('Acquisition of session ticket failed.') + raise Exception('Session Error: Acquisition of session ticket failed.') return safe_load(result.text) - def get_user(self): - """ Returns the user name """ + """ Returns the name of the user """ return self.user