forked from skyarch-networks/skyhopper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
39 lines (31 loc) · 1.15 KB
/
Rakefile
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
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
SkyHopper::Application.load_tasks
task :register_users, ["users", "output"] => :environment do |_, args|
output = File.open(args.output, "w")
client = Client.find_or_create_by(name: "Skyarch Networks Trial", code: "Skyarch Networks Trial")
File.readlines(args.users).each do |row|
row_arr = row.chomp.split(",")
require 'securerandom'
u = User.new(email: row_arr[0])
u.password = SecureRandom.hex(4)
u.admin = true if row_arr.index("admin")
u.master = true if row_arr.index("master")
begin
u.save!
rescue => ex
res = "[create ng] email:#{row.chomp} #{ex.message}"
else
unless row_arr.index("no_project")
unless u.create_project(client)
res = "[create ng] email:#{u.email} password:#{u.password} failed to create project."
end
end
res = "[create ok] email:#{u.email} password:#{u.password}"
end
output.puts(res)
puts(res)
end
output.close
end