1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """
18 Provides decorator classes & funcitons.
19 """
20
21 from gofer import NAME
22 from gofer.messaging import Options
23 from gofer.collator import Collator
27 """
28 @cvar functions: The list of decorated functions.
29 """
30 functions = []
31
32 @classmethod
35
36 @classmethod
38 purged = []
39 for fn in cls.find(mod):
40 purged.append(fn)
41 for fn in purged:
42 cls.functions.remove(fn)
43
44 @classmethod
46 for fn in cls.functions:
47 if fn.__module__ == mod:
48 yield fn
49
50 @classmethod
53
54 @classmethod
64
66 """
67 Ensure funtion has the gofer options attribute
68 and return it.
69 @param fn: A function
70 @return: The funtion options object.
71 @rtype: L{Options}
72 """
73 if not hasattr(fn, NAME):
74 opt = Options()
75 opt.security = []
76 setattr(fn, NAME, opt)
77 else:
78 opt = getattr(fn, NAME)
79 return opt
80
81
82 -def remote(*args, **kwargs):
83 """
84 Remote method decorator.
85 keywords:
86 - shared: method shared across plugins.
87 - secret: authorization secret.
88 """
89 shared = bool(kwargs.get('shared', 1))
90 secret = kwargs.get('secret',())
91 def df(fn):
92 opt = __options(fn)
93 opt.shared = shared
94 if secret:
95 required = Options()
96 required.secret = secret
97 auth = ('secret', required)
98 opt.security.append(auth)
99 Remote.add(fn)
100 return fn
101 if args:
102 return df(args[0])
103 else:
104 return df
105
106
107 -def pam(*args, **kwargs):
108 """
109 PAM authentication method decorator.
110 keywords:
111 - user: user name.
112 - service: (optional) PAM service.
113 """
114 user = kwargs.get('user')
115 service = kwargs.get('service')
116 if not user:
117 raise Exception('(user) must be specified')
118 def df(fn):
119 opt = __options(fn)
120 required = Options()
121 required.user = user
122 required.service = service
123 auth = ('pam', required)
124 opt.security.append(auth)
125 return fn
126 if args:
127 return df(args[0])
128 else:
129 return df
130
131
132 -def user(*args, **kwargs):
133 """
134 user (PAM) authentication method decorator.
135 keywords:
136 - name: user name.
137 """
138 name = kwargs.get('name')
139 def df(fn):
140 opt = __options(fn)
141 required = Options()
142 required.user = name
143 auth = ('pam', required)
144 opt.security.append(auth)
145 return fn
146 if args:
147 return df(args[0])
148 else:
149 return df
150