1 package authremote 2 3 import ( 4 "context" 5 "strconv" 6 7 "golang.conradwood.net/go-easyops/auth" 8 "golang.conradwood.net/go-easyops/errors" 9 ) 10 11 /* 12 returns the partitionid for the user in this context. 13 a partition is either: 14 - specific to a particular user 15 - specific to an organisation 16 17 the information in the context determines which partition will be returned 18 a context without user information will always use partition 0 19 20 Note: currently this is a bit of a stub. it only resolves the userid to a partition and does not consider the organisation 21 22 PartitionIDs start from 100 upwards. this is meant to make it easier for tools to support custom partitions, such as "any user" or "no user" or so 23 */ 24 func PartitionID(ctx context.Context) (uint64, error) { 25 u := auth.GetUser(ctx) 26 if u == nil { 27 // no user -> partition #0 28 return 0, nil 29 } 30 id, err := strconv.ParseUint(u.ID, 10, 64) 31 if err != nil { 32 return 0, errors.Wrap(err) 33 } 34 return id + 100, nil // just adding some random offset so it is guaranteed to be NOT the same as the userid 35 } 36