Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 77 lines (63 sloc) 2.042 kb
ee1db75 @burtbeckwith new cf-add-user, cf-delete-user, and cf-change-password scripts for w…
burtbeckwith authored
1 /* Copyright 2011 SpringSource.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 import org.cloudfoundry.client.lib.CloudApplication
17 import org.cloudfoundry.client.lib.CloudFoundryException
18 import org.cloudfoundry.client.lib.CloudService
19 import org.springframework.http.HttpStatus
20
21 /**
22 * @author Burt Beckwith
23 */
24
25 includeTargets << new File("$cloudFoundryPluginDir/scripts/_CfCommon.groovy")
26
27 USAGE = '''
28 grails cf-delete-user <email>
29 '''
30
31 target(cfDeleteUser: 'Delete a user and all apps and services (requires admin privileges)') {
32 depends cfInit
33
34 doWithTryCatch {
35
36 String email = getRequiredArg()
37
38 // Check to make sure all apps and services are deleted before deleting the user
39 List<CloudApplication> applications = client.getApplications()
40 if (applications) {
41 String answer = ask("\nDeployed applications and associated services will be DELETED, continue?", 'y,n', 'n')
42 if ('n'.equalsIgnoreCase(answer)) {
43 println 'Aborted'
44 return
45 }
46 }
47
48 for (CloudApplication application in applications) {
49 deleteApplication true, application.name
50 }
51
52 List<CloudService> services = client.getServices()
53 if (services) {
54 for (CloudService service in services) {
55 client.deleteService service.name
56 }
57 }
58
59 print 'Deleting User: '
60 try {
61 client.unregister()
62 println 'OK'
63 }
64 catch (CloudFoundryException e) {
65 if (e.statusCode == HttpStatus.FORBIDDEN) {
66 println "\n\nSorry, the request was denied.\n"
67 }
68 else {
69 throw e
70 }
71 }
72 }
73 }
74
75 setDefaultTarget cfDeleteUser
76
Something went wrong with that request. Please try again.