-
Notifications
You must be signed in to change notification settings - Fork 0
/
exited_user_google_action.py
executable file
·84 lines (75 loc) · 2.99 KB
/
exited_user_google_action.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/python2.4
#
# Copyright 2006 Google, Inc.
# All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Default GoogleAction for users who've exited
ExitedUserGoogleAction: the class implementing the default action
** Consult <TBD> for overall documentation on this package.
"""
import google_action
import logging
import messages
from google.appsforyourdomain import provisioning
from google.appsforyourdomain import provisioning_errs
class ExitedUserGoogleAction(google_action.GoogleAction):
""" The default "GoogleAction" for users who've exited (quit,
been terminated, retired, died, etc.)
This object does a LockAccount on the user and queues results
on the GoogleResultQueue object.
"""
def __init__(self, api, result_queue, thread_stats, **moreargs):
"""
Args:
api: a google.appsforyourdomain.provisioning.API object
result_queue: a google_result_queue.GoogleResultQueue object,
for writing results back to a status handler
"""
super(ExitedUserGoogleAction, self).__init__(api=api,
result_queue=result_queue,
thread_stats=thread_stats,
**moreargs)
self._api = api
self._result_queue = result_queue
if 'vars' in moreargs:
self._sync_google = moreargs['vars']
def Handle(self, dn, attrs):
""" Override of superclass.Handle() method
Args:
dn: distinguished name of the user
attrs: dictionary of all the user's attributes
"""
self.dn = dn
self.attrs = attrs
try:
logging.debug('about to LockAccount for %s' % \
self.attrs['GoogleUsername'])
self._api.LockAccount(self.attrs['GoogleUsername'])
# report success
logging.debug('locked %s' % self.attrs['GoogleUsername'])
self._thread_stats.IncrementStat('exits', 1)
self._result_queue.PutResult(self.dn, 'exited', None, attrs)
except provisioning_errs.ProvisioningApiError, e:
if (str(e).find('InvalidEmailException') >= 0 or
str(e).find('Object does not exist') >= 0):
# trying to exit a user that does not exist is not an error
logging.warn(messages.MSG_EXIT_EXITED_USER % dn)
self._result_queue.PutResult(self.dn, 'exited', None, attrs)
return
# report failure
logging.error('error: %s' % str(e))
self._thread_stats.IncrementStat('exit_fails', 1)
self._result_queue.PutResult(self.dn, 'exited', str(e))
if __name__ == '__main__':
pass