make tags first class node owner (#2885)
This PR changes tags to be something that exists on nodes in addition to users, to being its own thing. It is part of moving our tags support towards the correct tailscale compatible implementation. There are probably rough edges in this PR, but the intention is to get it in, and then start fixing bugs from 0.28.0 milestone (long standing tags issue) to discover what works and what doesnt. Updates #2417 Closes #2619
This commit is contained in:
parent
705b239677
commit
eb788cd007
49 changed files with 3102 additions and 757 deletions
|
|
@ -22,6 +22,21 @@ type UserID uint64
|
|||
|
||||
type Users []User
|
||||
|
||||
const (
|
||||
// TaggedDevicesUserID is the special user ID for tagged devices.
|
||||
// This ID is used when rendering tagged nodes in the Tailscale protocol.
|
||||
TaggedDevicesUserID = 2147455555
|
||||
)
|
||||
|
||||
// TaggedDevices is a special user used in MapResponse for tagged nodes.
|
||||
// Tagged nodes don't belong to a real user - the tag is their identity.
|
||||
// This special user ID is used when rendering tagged nodes in the Tailscale protocol.
|
||||
var TaggedDevices = User{
|
||||
Model: gorm.Model{ID: TaggedDevicesUserID},
|
||||
Name: "tagged-devices",
|
||||
DisplayName: "Tagged Devices",
|
||||
}
|
||||
|
||||
func (u Users) String() string {
|
||||
var sb strings.Builder
|
||||
sb.WriteString("[ ")
|
||||
|
|
@ -77,6 +92,13 @@ func (u *User) StringID() string {
|
|||
return strconv.FormatUint(uint64(u.ID), 10)
|
||||
}
|
||||
|
||||
// TypedID returns a pointer to the user's ID as a UserID type.
|
||||
// This is a convenience method to avoid ugly casting like ptr.To(types.UserID(user.ID)).
|
||||
func (u *User) TypedID() *UserID {
|
||||
uid := UserID(u.ID)
|
||||
return &uid
|
||||
}
|
||||
|
||||
// Username is the main way to get the username of a user,
|
||||
// it will return the email if it exists, the name if it exists,
|
||||
// the OIDCIdentifier if it exists, and the ID if nothing else exists.
|
||||
|
|
@ -117,6 +139,13 @@ func (u UserView) TailscaleUser() tailcfg.User {
|
|||
return u.ж.TailscaleUser()
|
||||
}
|
||||
|
||||
// ID returns the user's ID.
|
||||
// This is a custom accessor because gorm.Model.ID is embedded
|
||||
// and the viewer generator doesn't always produce it.
|
||||
func (u UserView) ID() uint {
|
||||
return u.ж.ID
|
||||
}
|
||||
|
||||
func (u *User) TailscaleLogin() tailcfg.Login {
|
||||
return tailcfg.Login{
|
||||
ID: tailcfg.LoginID(u.ID),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue