updated fields
[plcapi.git] / PLC / Auth.py
1 #
2 import os
3
4 from PLC.Parameter import Parameter
5
6 class Auth(Parameter):
7     """
8     Base class for all API authentication methods, as well as a class
9     that can be used to represent all supported API authentication
10     methods.
11     """
12
13     def __init__(self, auth = None):
14         if auth is None:
15             auth = {'AuthMethod': Parameter(str, "Authentication method to use", optional = False)}
16         Parameter.__init__(self, auth, "API authentication structure")
17
18 class PasswordAuth(Auth):
19     """
20     PlanetLab version 3.x password authentication structure.
21     """
22
23     def __init__(self):
24         Auth.__init__(self, {
25             'AuthMethod': Parameter(str, "Authentication method to use, always 'password' or 'capability'", optional = False),
26             'Username': Parameter(str, "Username, typically an e-mail address", optional = False),
27             'AuthString': Parameter(str, "Authentication string, typically a password", optional = False),
28             'Tenant': Parameter(str, "User Tenant", optional = False),
29             })
30 path = os.path.dirname(__file__) + "/Auth.d"
31 try:
32     extensions = os.listdir(path)
33 except OSError, e:
34     extensions = []
35 for extension in extensions:
36     if extension.startswith("."):
37         continue
38     if not extension.endswith(".py"):
39         continue
40     execfile("%s/%s" % (path, extension))
41 del extensions