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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/webee/commands/user.rb', line 50
def run
roles_map = {
'cloud-admin' => WeBee::UserRole.cloud_admin,
'enterprise-admin' => WeBee::UserRole.enterprise_admin,
'user' => WeBee::UserRole.user
}
actions = %w{create}
if not actions.include? ARGV.first
$stderr.puts "Invalid action.\n\nAVAILABLE ACTIONS: #{actions.join(' ')}\n\n"
return
else
if config[:name].nil?
$stderr.puts 'Invalid user name.'
$stderr.puts opt_parser.help
return
end
if config[:surname].nil?
$stderr.puts 'Invalid surname.'
$stderr.puts opt_parser.help
return
end
if config[:email].nil?
$stderr.puts 'Invalid email.'
$stderr.puts opt_parser.help
return
end
if config[:nick].nil?
$stderr.puts 'Invalid nick.'
$stderr.puts opt_parser.help
return
end
if config[:password].nil?
$stderr.puts 'Invalid password.'
$stderr.puts opt_parser.help
return
end
role = roles_map[config[:role]]
if role.nil?
$stderr.puts "Invalid role.\n\nAVAILABLE_ROLES: cloud-admin enterprise-admin user\n\n"
$stderr.puts opt_parser.help
return
end
begin
::WeBee::User.create :name => config[:name],
:surname => config[:surname],
:email => config[:email],
:description => config[:description],
:nick => config[:nick],
:password => config[:password],
:role => role,
:locale => config[:locale],
:enterprise => Enterprise.find(config[:enterprise]),
:active => config[:active]
rescue Exception => e
puts e.message
end
end
end
|