3 # Install the supplied string (or a randomly generated token, if none
4 # is given) as an API token that authenticates to the system user
7 # Print the token on stdout.
9 supplied_token = ARGV[0]
11 require File.dirname(__FILE__) + '/../config/boot'
12 require File.dirname(__FILE__) + '/../config/environment'
14 include ApplicationHelper
18 api_client_auth = ApiClientAuthorization.
19 where(api_token: supplied_token).
21 if api_client_auth && !api_client_auth.user.uuid.match(/-000000000000000$/)
22 raise ActiveRecord::RecordNotUnique("Token already exists but is not a superuser token.")
27 api_client_auth = ApiClientAuthorization.
28 new(user: system_user,
30 created_by_ip_address: '::1',
31 api_token: supplied_token)
35 puts api_client_auth.api_token