X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/4ad105bd22c9141e5f88139ad3bf334a52f7a5d1..cac035d7a171b90f0dc714d17b500b4062c0c58b:/services/api/script/setup-new-user.rb diff --git a/services/api/script/setup-new-user.rb b/services/api/script/setup-new-user.rb index ced32bc19f..af0de13b2c 100755 --- a/services/api/script/setup-new-user.rb +++ b/services/api/script/setup-new-user.rb @@ -15,20 +15,19 @@ opts = Trollop::options do banner '' opt :debug, <<-eos Show debug messages. - eos - opt :create, <<-eos -Create a new user with the given email address if an existing user \ -is not found. eos opt :openid_prefix, <<-eos, default: 'https://www.google.com/accounts/o8/id' If creating a new user record, require authentication from an OpenID \ with this OpenID prefix *and* a matching email address in order to \ claim the account. eos + opt :send_notification_email, <<-eos, default: 'true' +Send notification email after successfully setting up the user. + eos end log.level = (ENV['DEBUG'] || opts.debug) ? Logger::DEBUG : Logger::WARN - + if ARGV.count != 3 Trollop::die "required arguments are missing" end @@ -40,27 +39,33 @@ arv = Arvados.new(api_version: 'v1') # Look up the given user by uuid or, failing that, email address. begin - user = arv.user.get(uuid: user_arg) + found_user = arv.user.get(uuid: user_arg) rescue Arvados::TransactionFailedError - found = arv.user.list(where: {email: ARGV[0]})[:items] - - if found.count == 0 + found = arv.user.list(where: {email: user_arg})[:items] + + if found.count == 0 if !user_arg.match(/\w\@\w+\.\w+/) abort "About to create new user, but #{user_arg.inspect} " + "does not look like an email address. Stop." end - - user = arv.user.setup(repo_name: user_repo_name, vm_uuid: vm_uuid, user: {email: user_arg}) - log.info { "created user: " + user[:uuid] } elsif found.count != 1 - abort "Found #{found.count} users " + - "with uuid or email #{user_arg.inspect}. Stop." - else - user = found.first - # Found user. Update ther user links - user = arv.user.setup(repo_name: user_repo_name, vm_uuid: vm_uuid, user: {email: user[:uuid]}) + abort "Found #{found.count} users with email. Stop." + else + found_user = found.first end - - puts "USER = #{user.inspect}" - log.info { "user uuid: " + user[:uuid] } end + +# Invoke user setup method +if (found_user) + user = arv.user.setup uuid: found_user[:uuid], repo_name: user_repo_name, + vm_uuid: vm_uuid, openid_prefix: opts.openid_prefix, + send_notification_email: opts.send_notification_email +else + user = arv.user.setup user: {email: user_arg}, repo_name: user_repo_name, + vm_uuid: vm_uuid, openid_prefix: opts.openid_prefix, + send_notification_email: opts.send_notification_email +end + +log.info {"user uuid: " + user[:uuid]} + +puts user.inspect