2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
6 # Get or Create an anonymous user token.
7 # If get option is used, an existing anonymous user token is returned. If none exist, one is created.
8 # If the get option is omitted, a new token is created and returned.
12 opts = Trollop::options do
14 banner "Usage: get_anonymous_user_token "
17 Get an existing anonymous user token. If no such token exists \
18 or if this option is omitted, a new token is created and returned.
22 get_existing = opts[:get]
24 require File.dirname(__FILE__) + '/../config/environment'
26 include ApplicationHelper
29 def create_api_client_auth
30 api_client_auth = ApiClientAuthorization.
31 new(user: anonymous_user,
33 expires_at: Time.now + 100.years,
36 api_client_auth.reload
40 api_client_auth = ApiClientAuthorization.
41 where('user_id=?', anonymous_user.id.to_i).
42 where('expires_at>?', Time.now).
43 select { |auth| auth.scopes == ['GET /'] }.
47 # either not a get or no api_client_auth was found
49 api_client_auth = create_api_client_auth
52 # print it to the console
53 puts api_client_auth.api_token