298e4e3dfbd2477023603a23328b9df915c52615
[plcapi.git] / PLC / Methods / BlacklistKey.py
1 # $Id$
2 # $URL$
3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Keys import Key, Keys
7 from PLC.Auth import Auth
8
9 class BlacklistKey(Method):
10     """
11     Blacklists a key, disassociating it and all others identical to it
12     from all accounts and preventing it from ever being added again.
13
14     WARNING: Identical keys associated with other accounts with also
15     be blacklisted.
16
17     Returns 1 if successful, faults otherwise.
18     """
19
20     roles = ['admin']
21
22     accepts = [
23         Auth(),
24         Key.fields['key_id'],
25         ]
26
27     returns = Parameter(int, '1 if successful')
28    
29     def call(self, auth, key_id):
30         # Get associated key details
31         keys = Keys(self.api, [key_id])
32         if not keys:
33             raise PLCInvalidArgument, "No such key"
34         key = keys[0]
35
36         # N.B.: Can blacklist any key, even foreign ones
37
38         key.blacklist()
39         
40         # Logging variables
41         self.event_objects = {'Key': [key['key_id']]}
42         self.message = 'Key %d blacklisted' % key['key_id']
43
44         return 1