From 9101972fad4b6628eb666e5cf28893e4a776f419 Mon Sep 17 00:00:00 2001 From: Marc Fiuczynski Date: Thu, 21 May 2009 01:44:44 +0000 Subject: [PATCH] break out mapping to auth class into map_auth() function --- PLC/Auth.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) 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) -- 2.43.0