3 abort 'Error: Ruby >= 1.9.3 required.' if RUBY_VERSION < '1.9.3'
8 log = Logger.new STDERR
9 log.progname = $0.split('/').last
11 opts = Trollop::options do
13 banner "Usage: #{log.progname} " +
14 "{user_uuid_or_email} {user_and_repo_name} {vm_uuid}"
19 opt :openid_prefix, <<-eos, default: 'https://www.google.com/accounts/o8/id'
20 If creating a new user record, require authentication from an OpenID \
21 with this OpenID prefix *and* a matching email address in order to \
24 opt :send_notification_email, <<-eos, default: 'true'
25 Send notification email after successfully setting up the user.
29 log.level = (ENV['DEBUG'] || opts.debug) ? Logger::DEBUG : Logger::WARN
32 Trollop::die "required arguments are missing"
35 user_arg, user_repo_name, vm_uuid = ARGV
38 arv = Arvados.new(api_version: 'v1')
40 # Look up the given user by uuid or, failing that, email address.
42 found_user = arv.user.get(uuid: user_arg)
43 rescue Arvados::TransactionFailedError
44 found = arv.user.list(where: {email: user_arg})[:items]
47 if !user_arg.match(/\w\@\w+\.\w+/)
48 abort "About to create new user, but #{user_arg.inspect} " +
49 "does not look like an email address. Stop."
51 elsif found.count != 1
52 abort "Found #{found.count} users with email. Stop."
54 found_user = found.first
58 # Invoke user setup method
60 user = arv.user.setup uuid: found_user[:uuid], repo_name: user_repo_name,
61 vm_uuid: vm_uuid, openid_prefix: opts.openid_prefix,
62 send_notification_email: opts.send_notification_email
64 user = arv.user.setup user: {email: user_arg}, repo_name: user_repo_name,
65 vm_uuid: vm_uuid, openid_prefix: opts.openid_prefix,
66 send_notification_email: opts.send_notification_email
69 log.info {"user uuid: " + user[:uuid]}