[ARVADOS] created: a5e86befc352e31600399e9c4a476479d2155413

git at public.curoverse.com git at public.curoverse.com
Thu Oct 29 10:31:14 EDT 2015


        at  a5e86befc352e31600399e9c4a476479d2155413 (commit)


commit a5e86befc352e31600399e9c4a476479d2155413
Author: radhika <radhika at curoverse.com>
Date:   Thu Oct 29 10:30:14 2015 -0400

    7534: refactor the code from create_superuser_token.rb script into lib and verify manually that existing behavior is preserved.

diff --git a/services/api/lib/create_superuser_token.rb b/services/api/lib/create_superuser_token.rb
new file mode 100755
index 0000000..7ee951e
--- /dev/null
+++ b/services/api/lib/create_superuser_token.rb
@@ -0,0 +1,33 @@
+module CreateSuperUserToken
+  # Install the supplied string (or a randomly generated token, if none
+  # is given) as an API token that authenticates to the system user
+  # account.
+
+  require File.dirname(__FILE__) + '/../config/boot'
+  require File.dirname(__FILE__) + '/../config/environment'
+
+  include ApplicationHelper
+  act_as_system_user
+
+  def create_superuser_token supplied_token
+    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
+
+    puts api_client_auth.api_token
+  end
+end
diff --git a/services/api/script/create_superuser_token.rb b/services/api/script/create_superuser_token.rb
index d119f8a..dad9501 100755
--- a/services/api/script/create_superuser_token.rb
+++ b/services/api/script/create_superuser_token.rb
@@ -6,30 +6,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
+supplied_token = ARGV[0]
 
-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
+CreateSuperUserToken.create_superuser_token supplied_token
 
-puts api_client_auth.api_token

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list