16263: Add no_federation to user update
authorPeter Amstutz <peter.amstutz@curii.com>
Tue, 31 Mar 2020 18:42:46 +0000 (14:42 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Tue, 31 Mar 2020 18:42:46 +0000 (14:42 -0400)
We might agree on a different API but try this and see if it helps
pass the test.

Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

lib/controller/federation/conn.go
sdk/go/arvados/api.go
sdk/python/arvados/commands/federation_migrate.py
services/api/app/controllers/arvados/v1/users_controller.rb

index f67ea6713ec6a8bca926c939defdb141867735e9..05ea7769f14267b5e74927b6173665bcce24d281 100644 (file)
@@ -447,6 +447,9 @@ func (conn *Conn) UserCreate(ctx context.Context, options arvados.CreateOptions)
 }
 
 func (conn *Conn) UserUpdate(ctx context.Context, options arvados.UpdateOptions) (arvados.User, error) {
+       if options.NoFederation {
+               return conn.local.UserUpdate(ctx, options)
+       }
        return conn.chooseBackend(options.UUID).UserUpdate(ctx, options)
 }
 
index a30da62425883988f52f71aa9b48d5495df54f72..f3fdd254ffe99a5cd1110de920c4ca68aac41e50 100644 (file)
@@ -95,8 +95,9 @@ type CreateOptions struct {
 }
 
 type UpdateOptions struct {
-       UUID  string                 `json:"uuid"`
-       Attrs map[string]interface{} `json:"attrs"`
+       UUID         string                 `json:"uuid"`
+       Attrs        map[string]interface{} `json:"attrs"`
+       NoFederation bool                   `json:"no_federation"`
 }
 
 type UpdateUUIDOptions struct {
index e1b8ee7d8402f5834ba9391c6fddb78b5d79ef14..0eaf1c03e2bcf1148e97f43d438a5de01853d9a9 100755 (executable)
@@ -173,8 +173,13 @@ def update_username(args, email, user_uuid, username, migratecluster, migratearv
         try:
             conflicts = migratearv.users().list(filters=[["username", "=", username]], no_federation=True).execute()
             if conflicts["items"]:
-                migratearv.users().update(uuid=conflicts["items"][0]["uuid"], body={"user": {"username": username+"migrate"}}).execute()
-            migratearv.users().update(uuid=user_uuid, body={"user": {"username": username}}).execute()
+                # There's already a user with the username, move the old user out of the way
+                migratearv.users().update(uuid=conflicts["items"][0]["uuid"],
+                                          no_federation=True,
+                                          body={"user": {"username": username+"migrate"}}).execute()
+            migratearv.users().update(uuid=user_uuid,
+                                      no_federation=True,
+                                      body={"user": {"username": username}}).execute()
         except arvados.errors.ApiError as e:
             print("(%s) Error updating username of %s to '%s' on %s: %s" % (email, user_uuid, username, migratecluster, e))
 
@@ -204,10 +209,14 @@ def choose_new_user(args, by_email, email, userhome, username, old_user_uuid, cl
             user = None
             try:
                 olduser = oldhomearv.users().get(uuid=old_user_uuid).execute()
-                conflicts = homearv.users().list(filters=[["username", "=", username]], no_federation=True).execute()
+                conflicts = homearv.users().list(filters=[["username", "=", username]],
+                                                 no_federation=True).execute()
                 if conflicts["items"]:
-                    homearv.users().update(uuid=conflicts["items"][0]["uuid"], body={"user": {"username": username+"migrate"}}).execute()
-                user = homearv.users().create(body={"user": {"email": email, "username": username, "is_active": olduser["is_active"]}}).execute()
+                    homearv.users().update(uuid=conflicts["items"][0]["uuid"],
+                                           no_federation=True,
+                                           body={"user": {"username": username+"migrate"}}).execute()
+                user = homearv.users().create(body={"user": {"email": email, "username": username,
+                                                             "is_active": olduser["is_active"]}}).execute()
             except arvados.errors.ApiError as e:
                 print("(%s) Could not create user: %s" % (email, str(e)))
                 return None
@@ -259,7 +268,8 @@ def activate_remote_user(args, email, homearv, migratearv, old_user_uuid, new_us
     try:
         ru = urllib.parse.urlparse(migratearv._rootDesc["rootUrl"])
         if not args.dry_run:
-            newuser = arvados.api(host=ru.netloc, token=salted, insecure=os.environ.get("ARVADOS_API_HOST_INSECURE")).users().current().execute()
+            newuser = arvados.api(host=ru.netloc, token=salted,
+                                  insecure=os.environ.get("ARVADOS_API_HOST_INSECURE")).users().current().execute()
         else:
             newuser = {"is_active": True, "username": username}
     except arvados.errors.ApiError as e:
@@ -270,7 +280,8 @@ def activate_remote_user(args, email, homearv, migratearv, old_user_uuid, new_us
         print("(%s) Activating user %s on %s" % (email, new_user_uuid, migratecluster))
         try:
             if not args.dry_run:
-                migratearv.users().update(uuid=new_user_uuid, body={"is_active": True}).execute()
+                migratearv.users().update(uuid=new_user_uuid, no_federation=True,
+                                          body={"is_active": True}).execute()
         except arvados.errors.ApiError as e:
             print("(%s) Could not activate user %s on %s: %s" % (email, new_user_uuid, migratecluster, e))
             return None
index 289e82567a67f7eb4f1c8223153f2bc9c76f439a..475f6d54ad95fe63c64374211d063e6300235188 100644 (file)
@@ -249,6 +249,14 @@ class Arvados::V1::UsersController < ApplicationController
     }
   end
 
+  def self._update_requires_parameters
+    super.merge({
+      no_federation: {
+        type: 'boolean', required: false,
+      },
+    })
+  end
+
   def self._update_uuid_requires_parameters
     {
       new_uuid: {