16778: Simplify logic
authorPeter Amstutz <peter.amstutz@curii.com>
Fri, 4 Sep 2020 14:52:38 +0000 (10:52 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Fri, 4 Sep 2020 14:52:38 +0000 (10:52 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

lib/controller/federation/conn.go
lib/controller/integration_test.go

index b2d158b9a5fa447da7d9daabde7f7058d757ed44..a84f1b0171307744a36f2b3fce4b53307bae8755 100644 (file)
@@ -474,40 +474,35 @@ func (conn *Conn) UserActivate(ctx context.Context, options arvados.UserActivate
 }
 
 func (conn *Conn) UserSetup(ctx context.Context, options arvados.UserSetupOptions) (map[string]interface{}, error) {
-       var setupVM string
-       var setupRepo string
-       if conn.cluster.Login.LoginCluster != "" {
-               if options.VMUUID != "" && options.VMUUID[0:5] != options.UUID[0:5] {
-                       // When LoginCluster is in effect, and we're
-                       // setting up a remote user, and we want to
-                       // give that user access to a local VM, then
-                       // we need to set up the user on the remote
-                       // LoginCluster first, followed by calling
-                       // setup on the local instance to give access
-                       // to the VM.
-                       setupVM = options.VMUUID
-                       options.VMUUID = ""
-               }
-               if options.RepoName != "" {
-                       // Similarly, if we want to create a git repo,
-                       // it should be created on the local cluster,
-                       // not the remote one.
-                       setupRepo = options.RepoName
-                       options.RepoName = ""
+       upstream := conn.localOrLoginCluster()
+       if upstream != conn.local {
+               // When LoginCluster is in effect, and we're setting
+               // up a remote user, and we want to give that user
+               // access to a local VM, we can't include the VM in
+               // the setup call, because the remote cluster won't
+               // recognize it.
+
+               // Similarly, if we want to create a git repo,
+               // it should be created on the local cluster,
+               // not the remote one.
+
+               setupVM := options.VMUUID
+               setupRepo := options.RepoName
+               options.VMUUID = ""
+               options.RepoName = ""
+
+               ret, err := upstream.UserSetup(ctx, options)
+               if err != nil {
+                       return ret, err
                }
-       }
 
-       ret, err := conn.localOrLoginCluster().UserSetup(ctx, options)
-       if err != nil {
-               return ret, err
-       }
-
-       if setupVM != "" || setupRepo != "" {
+               // Restore VMUUID and RepoName for the call to local
+               // UserSetup below.
                options.VMUUID = setupVM
                options.RepoName = setupRepo
-               ret, err = conn.local.UserSetup(ctx, options)
        }
-       return ret, err
+
+       return conn.local.UserSetup(ctx, options)
 }
 
 func (conn *Conn) UserUnsetup(ctx context.Context, options arvados.GetOptions) (arvados.User, error) {
index 90d1c3f1705883eb246ac05cad108c55f4d39efa..077493ffc836f58260f1abb19448323ea25f45e9 100644 (file)
@@ -8,7 +8,6 @@ import (
        "bytes"
        "context"
        "encoding/json"
-       "fmt"
        "io"
        "math"
        "net"
@@ -305,7 +304,7 @@ func (s *IntegrationSuite) TestGetCollectionAsAnonymous(c *check.C) {
        c.Check(err, check.IsNil)
 
        // Make a v2 token of the z3 anonymous user, and use it on z1
-       _, anonac1, _ := s.clientsWithToken("z1111", fmt.Sprintf("v2/%v/%v", outAuth.UUID, outAuth.APIToken))
+       _, anonac1, _ := s.clientsWithToken("z1111", outAuth.TokenV2())
        outUser2, err := anonac1.CurrentUser()
        c.Check(err, check.IsNil)
        // z3 anonymous user will be mapped to the z1 anonymous user
@@ -472,7 +471,7 @@ func (s *IntegrationSuite) TestSetupUserWithVM(c *check.C) {
        c.Check(err, check.IsNil)
 
        // Make a v2 root token to communicate with z3333
-       rootctx3, rootac3, _ := s.clientsWithToken("z3333", fmt.Sprintf("v2/%v/%v", outAuth.UUID, outAuth.APIToken))
+       rootctx3, rootac3, _ := s.clientsWithToken("z3333", outAuth.TokenV2())
 
        // Create VM on z3333
        var outVM arvados.VirtualMachine