forked from redhat-consulting/ose-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oo-delete-user
executable file
·57 lines (49 loc) · 1.33 KB
/
oo-delete-user
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
#!/usr/bin/env oo-ruby
#usage /usr/local/bin/oo-delete-user <username> <token> <brokerHost>
#American Express Specific delete user(Not for other Openshift engagements)
require 'rubygems'
require 'json'
require "#{ENV['OPENSHIFT_BROKER_DIR'] || '/var/www/openshift/broker'}/config/environment"
username=ARGV[0]
token=ARGV[1]
brokerHost=ARGV[2]
logfile="/var/log/openshift/broker/ose-utils.log"
def usage()
puts "Usage: oo-delete-user {username} {token}"
end
def json(code,message)
puts "{
\"returnCode\" : \"#{code}\",
\"returnDesc\" : \"#{message}\"
}"
end
def error_code(json)
result=JSON.parse(json)
code=result["messages"][0]["exit_code"]
puts "code=#{code}"
return code
end
puts "ARGV.length=====#{ARGV.length}"
if ARGV.length < 1
puts "Invalid usage"
# puts "token=====#{token}"
# puts "username=====#{username}"
usage()
exit 255
end
begin
user_obj=CloudUser::find_by_identity(username)
response=`curl -k -H "Authorization: Bearer #{token}" -X DELETE https://#{brokerHost}/broker/rest/domains/#{username} --data-urlencode force=true 2>> #{logfile} | tee -a #{logfile}`
rescue Exception =>e
puts "Delete Failed with #{e}"
exit 255
end
code = error_code(response)
if code != 127 && code != 0
puts "Delete Failed! Openshift Exit code #{code}"
exit code
else
user_obj.force_delete
end
puts "Success!"
exit 0