github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/tlfupgrade/kbfs.go (about) 1 package tlfupgrade 2 3 import ( 4 "context" 5 "errors" 6 "fmt" 7 8 "github.com/keybase/client/go/libkb" 9 "github.com/keybase/client/go/protocol/keybase1" 10 "github.com/keybase/client/go/teams" 11 "github.com/keybase/go-framed-msgpack-rpc/rpc" 12 ) 13 14 func UpgradeTLFForKBFS(ctx context.Context, g *libkb.GlobalContext, tlfName string, public bool) (err error) { 15 ctx = libkb.WithLogTag(ctx, "KBFSUP") 16 defer g.CTrace(ctx, fmt.Sprintf("UpgradeTLFForKBFS(%s,%v)", tlfName, public), 17 &err)() 18 19 // Set up KBFS connection 20 if g.ConnectionManager == nil { 21 return errors.New("not connection manager available") 22 } 23 xp := g.ConnectionManager.LookupByClientType(keybase1.ClientType_KBFS) 24 if xp == nil { 25 return libkb.KBFSNotRunningError{} 26 } 27 keysCli := &keybase1.TlfKeysClient{ 28 Cli: rpc.NewClient(xp, libkb.NewContextifiedErrorUnwrapper(g), libkb.LogTagsFromContext), 29 } 30 upgradeCli := &keybase1.ImplicitTeamMigrationClient{ 31 Cli: rpc.NewClient(xp, libkb.NewContextifiedErrorUnwrapper(g), libkb.LogTagsFromContext), 32 } 33 34 // Run migration 35 ft := keybase1.FolderType_PRIVATE 36 if public { 37 ft = keybase1.FolderType_PUBLIC 38 } 39 folder := keybase1.Folder{ 40 Name: tlfName, 41 Private: !public, 42 FolderType: ft, 43 } 44 g.Log.CDebugf(ctx, "UpgradeTLFForKBFS: starting migration on KBFS daemon") 45 if err := upgradeCli.StartMigration(ctx, folder); err != nil { 46 return err 47 } 48 var tlfID keybase1.TLFID 49 var cryptKeys []keybase1.CryptKey 50 query := keybase1.TLFQuery{ 51 TlfName: folder.Name, 52 IdentifyBehavior: keybase1.TLFIdentifyBehavior_CHAT_SKIP, 53 } 54 if !public { 55 g.Log.CDebugf(ctx, "UpgradeTLFForKBFS: fetching TLF crypt keys") 56 keysRes, err := keysCli.GetTLFCryptKeys(ctx, query) 57 if err != nil { 58 return err 59 } 60 cryptKeys = keysRes.CryptKeys 61 tlfID = keysRes.NameIDBreaks.TlfID 62 } else { 63 g.Log.CDebugf(ctx, "UpgradeTLFForKBFS: getting public TLFID") 64 pres, err := keysCli.GetPublicCanonicalTLFNameAndID(ctx, query) 65 if err != nil { 66 return err 67 } 68 tlfID = pres.TlfID 69 } 70 g.Log.CDebugf(ctx, "UpgradeTLFForKBFS: posting crypt keys to the team") 71 if err := teams.UpgradeTLFIDToImpteam(ctx, g, folder.Name, tlfID, 72 !folder.Private, keybase1.TeamApplication_KBFS, cryptKeys); err != nil { 73 return err 74 } 75 g.Log.CDebugf(ctx, "UpgradeTLFForKBFS: finalizing migration") 76 if err := upgradeCli.FinalizeMigration(ctx, folder); err != nil { 77 return err 78 } 79 return nil 80 }