From: Marc Fiuczynski Date: Thu, 21 May 2009 01:44:44 +0000 (+0000) Subject: break out mapping to auth class into map_auth() function X-Git-Tag: PLCAPI-4.3-15~15 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=9101972fad4b6628eb666e5cf28893e4a776f419;p=plcapi.git break out mapping to auth class into map_auth() function --- diff --git a/PLC/Auth.py b/PLC/Auth.py index 3b005b6..f056552 100644 --- a/PLC/Auth.py +++ b/PLC/Auth.py @@ -21,6 +21,22 @@ from PLC.Sessions import Session, Sessions from PLC.Peers import Peer, Peers from PLC.Boot import notify_owners +def map_auth(auth): + if auth['AuthMethod'] == "session": + expected = SessionAuth() + elif auth['AuthMethod'] == "password" or \ + auth['AuthMethod'] == "capability": + expected = PasswordAuth() + elif auth['AuthMethod'] == "gpg": + expected = GPGAuth() + elif auth['AuthMethod'] == "hmac" or \ + auth['AuthMethod'] == "hmac_dummybox": + expected = BootAuth() + elif auth['AuthMethod'] == "anonymous": + expected = AnonymousAuth() + else: + raise PLCInvalidArgument("must be 'session', 'password', 'gpg', 'hmac', 'hmac_dummybox', or 'anonymous'", "AuthMethod") + class Auth(Parameter): """ Base class for all API authentication methods, as well as a class @@ -38,20 +54,7 @@ class Auth(Parameter): # mandatory fields were present. assert 'AuthMethod' in auth - if auth['AuthMethod'] == "session": - expected = SessionAuth() - elif auth['AuthMethod'] == "password" or \ - auth['AuthMethod'] == "capability": - expected = PasswordAuth() - elif auth['AuthMethod'] == "gpg": - expected = GPGAuth() - elif auth['AuthMethod'] == "hmac" or \ - auth['AuthMethod'] == "hmac_dummybox": - expected = BootAuth() - elif auth['AuthMethod'] == "anonymous": - expected = AnonymousAuth() - else: - raise PLCInvalidArgument("must be 'session', 'password', 'gpg', 'hmac', 'hmac_dummybox', or 'anonymous'", "AuthMethod") + expected = map_auth(auth) # Re-check using the specified authentication method method.type_check("auth", auth, expected, (auth,) + args)