github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/teams/rpc_exim.go (about)

     1  // Copyright 2015 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  // Export-Import for RPC for Teams
     5  
     6  package teams
     7  
     8  import (
     9  	"golang.org/x/net/context"
    10  
    11  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
    12  )
    13  
    14  func (t *Team) ExportToTeamPlusApplicationKeys(ctx context.Context, idTime keybase1.Time,
    15  	application keybase1.TeamApplication, includeKBFSKeys bool) (ret keybase1.TeamPlusApplicationKeys, err error) {
    16  	loadKeys := true
    17  	if t.IsPublic() {
    18  		// If it's a public team, only try to load application keys if
    19  		// we are a member. If we are not, we should still be able to
    20  		// get team details using this func (and get an empty key list).
    21  		role, err := t.myRole(ctx)
    22  		loadKeys = err == nil && role != keybase1.TeamRole_NONE
    23  	}
    24  
    25  	var applicationKeys []keybase1.TeamApplicationKey
    26  	if loadKeys {
    27  		keyFunc := t.AllApplicationKeys
    28  		if includeKBFSKeys {
    29  			keyFunc = t.AllApplicationKeysWithKBFS
    30  		}
    31  		applicationKeys, err = keyFunc(ctx, application)
    32  		if err != nil {
    33  			return ret, err
    34  		}
    35  	}
    36  
    37  	members, err := t.Members()
    38  	if err != nil {
    39  		return ret, err
    40  	}
    41  
    42  	var writers, onlyReaders, onlyRestrictedBots []keybase1.UserVersion
    43  
    44  	writers = append(writers, members.Writers...)
    45  	writers = append(writers, members.Admins...)
    46  	writers = append(writers, members.Owners...)
    47  	onlyReaders = append(onlyReaders, members.Readers...)
    48  	onlyReaders = append(onlyReaders, members.Bots...)
    49  	onlyRestrictedBots = append(onlyRestrictedBots, members.RestrictedBots...)
    50  
    51  	ret = keybase1.TeamPlusApplicationKeys{
    52  		Id:                 t.chain().GetID(),
    53  		Name:               t.Name().String(),
    54  		Implicit:           t.IsImplicit(),
    55  		Public:             t.IsPublic(),
    56  		Application:        application,
    57  		Writers:            writers,
    58  		OnlyReaders:        onlyReaders,
    59  		OnlyRestrictedBots: onlyRestrictedBots,
    60  		ApplicationKeys:    applicationKeys,
    61  	}
    62  
    63  	return ret, nil
    64  }