1
# Software License Agreement (BSD License)
3
# Copyright (c) 2009-2011, Eucalyptus Systems, Inc.
6
# Redistribution and use of this software in source and binary forms, with or
7
# without modification, are permitted provided that the following conditions
10
# Redistributions of source code must retain the above
11
# copyright notice, this list of conditions and the
12
# following disclaimer.
14
# Redistributions in binary form must reproduce the above
15
# copyright notice, this list of conditions and the
16
# following disclaimer in the documentation and/or other
17
# materials provided with the distribution.
19
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
# POSSIBILITY OF SUCH DAMAGE.
31
# Author: Neil Soman neil@eucalyptus.com
32
# Mitch Garnaat mgarnaat@eucalyptus.com
34
from boto.roboto.awsqueryrequest import AWSQueryRequest
35
from boto.roboto.param import Param
36
import euca2ools.commands.euare
37
from euca2ools.commands.euare.listuserpolicies import ListUserPolicies
38
from euca2ools.commands.euare.deleteuserpolicy import DeleteUserPolicy
39
from euca2ools.commands.euare.listgroupsforuser import ListGroupsForUser
40
from euca2ools.commands.euare.removeuserfromgroup import RemoveUserFromGroup
41
from euca2ools.commands.euare.listsigningcertificates import ListSigningCertificates
42
from euca2ools.commands.euare.deletesigningcertificate import DeleteSigningCertificate
43
from euca2ools.commands.euare.listaccesskeys import ListAccessKeys
44
from euca2ools.commands.euare.deleteaccesskey import DeleteAccessKey
46
class DeleteUser(AWSQueryRequest):
48
ServiceClass = euca2ools.commands.euare.Euare
50
Description = """DeleteUser"""
52
Param(name='UserName',
54
long_name='user-name',
57
doc=""" Name of the User to delete. """),
58
Param(name='DelegateAccount',
63
doc=""" [Eucalyptus extension] Use the parameter only as the system admin to act as the account admin of the specified account without changing to account admin's role. """),
64
Param(name='recursive',
66
long_name='recursive',
70
doc=""" Deletes the Group, removes all Users from the Group and deletes all Policies associated with the Group."""),
71
Param(name='IsRecursive',
73
long_name='recursive-euca',
76
doc=""" Deletes the User from associated groups and deletes the User's credentials and policies along with the User. """),
82
doc="""Returns a list of credentials and policies that would be deleted, as well as the groups the user would be removed from, if the -r or -R option were actually performed.""")
85
Response = {u'type': u'object', u'name': u'DeleteUserResponse',
89
u'name': u'ResponseMetadata',
90
u'properties': [{u'type': u'string', u'optional': False, u'name'
95
def cli_formatter(self, data):
98
for ak in data['access_keys']:
99
print '\t%s' % ak['AccessKeyId']
101
for policy in data['policies']:
102
print '\t%s' % policy
104
for cert in data['certificates']:
105
print '\t%s' % cert['CertificateId']
107
for group in data['groups']:
108
print '\t%s' % group['Arn']
110
AWSQueryRequest.cli_formatter(self, data)
112
def main(self, **args):
113
recursive_local = self.cli_options.recursive or \
114
args.get('recursive', False)
115
recursive_server = self.cli_options.recursive_euca or \
116
args.get('recursive_euca', False)
117
self.pretend = self.cli_options.pretend or args.get('pretend', False)
118
user_name = self.cli_options.user_name or args.get('user_name', None)
119
if recursive_local or (recursive_server and self.pretend):
120
obj = ListUserPolicies()
121
d = obj.main(user_name=user_name)
122
data = {'policies' : d.PolicyNames}
123
obj = ListGroupsForUser()
124
d = obj.main(user_name=user_name)
125
data['groups'] = d.Groups
126
obj = ListSigningCertificates()
127
d = obj.main(user_name=user_name)
128
data['certificates'] = d.Certificates
129
obj = ListAccessKeys()
130
d = obj.main(user_name=user_name)
131
data['access_keys'] = d.AccessKeyMetadata
135
obj = DeleteAccessKey()
136
for ak in data['access_keys']:
137
obj.main(user_name=user_name, user_key_id=ak['AccessKeyId'])
138
obj = DeleteUserPolicy()
139
for policy in data['policies']:
140
obj.main(user_name=user_name, policy_name=policy)
141
obj = DeleteSigningCertificate()
142
for cert in data['certificates']:
143
obj.main(user_name=user_name, certificate_id=cert['CertificateId'])
144
obj = RemoveUserFromGroup()
145
for group in data['groups']:
146
obj.main(group_name=group['GroupName'], user_name=user_name)
148
return self.send(**args)