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