X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/e9a25bfe507179a20c4bb8a994ad394759b5239f..636d833ed4206ffe44e5e9b9b9100ac9d82bc603:/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 835fb544c0..af0de13b2c 100755 --- a/services/api/script/setup-new-user.rb +++ b/services/api/script/setup-new-user.rb @@ -21,12 +21,13 @@ 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 -default_openid_prefix = 'https://www.google.com/accounts/o8/id' - log.level = (ENV['DEBUG'] || opts.debug) ? Logger::DEBUG : Logger::WARN - + if ARGV.count != 3 Trollop::die "required arguments are missing" end @@ -40,37 +41,31 @@ arv = Arvados.new(api_version: 'v1') begin 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 elsif found.count != 1 - abort "Found #{found.count} users " + - "with uuid or email #{user_arg.inspect}. Stop." + abort "Found #{found.count} users with email. Stop." else found_user = found.first end end -# Invoke user setup method +# Invoke user setup method if (found_user) - user = {uuid: found_user[:uuid]} -else - user = {email: user_arg} -end - -if opts.openid_prefix - puts "used the -o option" -end - -if opts.openid_prefix == default_openid_prefix - user = arv.user.setup user: user, repo_name: user_repo_name, vm_uuid: vm_uuid + 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: user, repo_name: user_repo_name, vm_uuid: vm_uuid, - openid_prefix: opts.openid_prefix + 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