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