~ubuntu-branches/ubuntu/precise/euca2ools/precise-proposed

« back to all changes in this revision

Viewing changes to .pc/debian-changes-2.0.0~bzr464-0ubuntu1/euca2ools/commands/euare/deleteuser.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott Moser
  • Date: 2011-08-15 11:16:29 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20110815111629-3u49jvtwabwozpb7
Tags: 2.0.0~bzr464-0ubuntu1
* new upstream snapshot of bzr revno 464. (LP: #826022)
* Note, previous upload was incorrectly named 'bzr451'.  It should have
  been named bzr461 as it was a snapshot of revision 461.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Software License Agreement (BSD License)
 
2
#
 
3
# Copyright (c) 2009-2011, Eucalyptus Systems, Inc.
 
4
# All rights reserved.
 
5
#
 
6
# Redistribution and use of this software in source and binary forms, with or
 
7
# without modification, are permitted provided that the following conditions
 
8
# are met:
 
9
#
 
10
#   Redistributions of source code must retain the above
 
11
#   copyright notice, this list of conditions and the
 
12
#   following disclaimer.
 
13
#
 
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.
 
18
#
 
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.
 
30
#
 
31
# Author: Neil Soman neil@eucalyptus.com
 
32
#         Mitch Garnaat mgarnaat@eucalyptus.com
 
33
 
 
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
 
45
 
 
46
class DeleteUser(AWSQueryRequest):
 
47
 
 
48
    ServiceClass = euca2ools.commands.euare.Euare
 
49
 
 
50
    Description = """DeleteUser"""
 
51
    Params = [
 
52
        Param(name='UserName',
 
53
              short_name='u',
 
54
              long_name='user-name',
 
55
              ptype='string',
 
56
              optional=False,
 
57
              doc=""" Name of the User to delete. """),
 
58
        Param(name='DelegateAccount',
 
59
              short_name=None,
 
60
              long_name='delegate',
 
61
              ptype='string',
 
62
              optional=True,
 
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',
 
65
              short_name='r',
 
66
              long_name='recursive',
 
67
              ptype='boolean',
 
68
              optional=True,
 
69
              request_param=False,
 
70
              doc=""" Deletes the Group, removes all Users from the Group and deletes all Policies associated with the Group."""),
 
71
        Param(name='IsRecursive',
 
72
              short_name='R',
 
73
              long_name='recursive-euca',
 
74
              ptype='boolean',
 
75
              optional=True,
 
76
              doc=""" Deletes the User from associated groups and deletes the User's credentials and policies along with the User. """),
 
77
        Param(name='pretend',
 
78
              short_name='p',
 
79
              long_name='pretend',
 
80
              ptype='boolean',
 
81
              optional=True,
 
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.""")
 
83
        ]
 
84
 
 
85
    Response = {u'type': u'object', u'name': u'DeleteUserResponse',
 
86
                u'properties': [{
 
87
        u'type': u'object',
 
88
        u'optional': False,
 
89
        u'name': u'ResponseMetadata',
 
90
        u'properties': [{u'type': u'string', u'optional': False, u'name'
 
91
                        : u'RequestId'}],
 
92
        }]}
 
93
 
 
94
 
 
95
    def cli_formatter(self, data):
 
96
        if self.pretend:
 
97
            print 'accesskeys'
 
98
            for ak in data['access_keys']:
 
99
                print '\t%s' % ak['AccessKeyId']
 
100
            print 'policies'
 
101
            for policy in data['policies']:
 
102
                print '\t%s' % policy
 
103
            print 'certificates'
 
104
            for cert in data['certificates']:
 
105
                print '\t%s' % cert['CertificateId']
 
106
            print 'groups'
 
107
            for group in data['groups']:
 
108
                print '\t%s' % group['Arn']
 
109
        else:
 
110
            AWSQueryRequest.cli_formatter(self, data)
 
111
            
 
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
 
132
            if self.pretend:
 
133
                return data
 
134
            else:
 
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)
 
147
        if not self.pretend:
 
148
            return self.send(**args)
 
149
        
 
150
    def main_cli(self):
 
151
        self.do_cli()