48 lines
809 B
Go
48 lines
809 B
Go
package agent
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"forge.cadoles.com/Cadoles/emissary/internal/auth"
|
|
"forge.cadoles.com/Cadoles/emissary/internal/datastore"
|
|
)
|
|
|
|
type User struct {
|
|
agent *datastore.Agent
|
|
}
|
|
|
|
// Subject implements auth.User
|
|
func (u *User) Subject() string {
|
|
return fmt.Sprintf("agent-%d", u.agent.ID)
|
|
}
|
|
|
|
// Subject implements auth.User
|
|
func (u *User) Tenant() datastore.TenantID {
|
|
if u.agent.TenantID == nil {
|
|
return ""
|
|
}
|
|
|
|
return *u.agent.TenantID
|
|
}
|
|
|
|
func (u *User) Agent() *datastore.Agent {
|
|
return u.agent
|
|
}
|
|
|
|
func (u *User) MarshalJSON() ([]byte, error) {
|
|
type user struct {
|
|
Subject string `json:"subject"`
|
|
Tenant string `json:"tenant"`
|
|
}
|
|
|
|
jsonUser := user{
|
|
Subject: u.Subject(),
|
|
Tenant: string(u.Tenant()),
|
|
}
|
|
|
|
return json.Marshal(jsonUser)
|
|
}
|
|
|
|
var _ auth.User = &User{}
|