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 \
26 log.level = (ENV['DEBUG'] || opts.debug) ? Logger::DEBUG : Logger::WARN
29 Trollop::die "required arguments are missing"
32 user_arg, user_repo_name, vm_uuid = ARGV
35 arv = Arvados.new(api_version: 'v1')
37 # Look up the given user by uuid or, failing that, email address.
39 found_user = arv.user.get(uuid: user_arg)
40 rescue Arvados::TransactionFailedError
41 found = arv.user.list(where: {email: user_arg})[:items]
44 if !user_arg.match(/\w\@\w+\.\w+/)
45 abort "About to create new user, but #{user_arg.inspect} " +
46 "does not look like an email address. Stop."
48 elsif found.count != 1
49 abort "Found #{found.count} users with email. Stop."
51 found_user = found.first
55 # Invoke user setup method
57 user = arv.user.setup uuid: found_user[:uuid], repo_name: user_repo_name,
58 vm_uuid: vm_uuid, openid_prefix: opts.openid_prefix
60 user = arv.user.setup user: {email: user_arg}, repo_name: user_repo_name,
61 vm_uuid: vm_uuid, openid_prefix: opts.openid_prefix
64 log.info {"user uuid: " + user[:uuid]}