X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/964ab3dd90ff1508efc0c77378cde2b3a4da1029..656176226eeb75d24c17de792cc090e4862c46f5:/services/api/script/create_superuser_token.rb diff --git a/services/api/script/create_superuser_token.rb b/services/api/script/create_superuser_token.rb index d119f8a887..3d5de35fd7 100755 --- a/services/api/script/create_superuser_token.rb +++ b/services/api/script/create_superuser_token.rb @@ -1,4 +1,7 @@ #!/usr/bin/env ruby +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 # Install the supplied string (or a randomly generated token, if none # is given) as an API token that authenticates to the system user @@ -6,30 +9,10 @@ # # Print the token on stdout. -supplied_token = ARGV[0] - -require File.dirname(__FILE__) + '/../config/boot' -require File.dirname(__FILE__) + '/../config/environment' +require './lib/create_superuser_token' +include CreateSuperUserToken -include ApplicationHelper -act_as_system_user - -if supplied_token - api_client_auth = ApiClientAuthorization. - where(api_token: supplied_token). - first - if api_client_auth && !api_client_auth.user.uuid.match(/-000000000000000$/) - raise ActiveRecord::RecordNotUnique("Token already exists but is not a superuser token.") - end -end - -if !api_client_auth - api_client_auth = ApiClientAuthorization. - new(user: system_user, - api_client_id: 0, - created_by_ip_address: '::1', - api_token: supplied_token) - api_client_auth.save! -end +supplied_token = ARGV[0] -puts api_client_auth.api_token +token = CreateSuperUserToken.create_superuser_token supplied_token +puts token