2023-03-07 23:10:42 +01:00
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
2024-03-03 18:40:56 +01:00
|
|
|
"encoding/json"
|
2023-03-07 23:10:42 +01:00
|
|
|
"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)
|
|
|
|
}
|
|
|
|
|
2024-02-26 18:20:40 +01:00
|
|
|
// Subject implements auth.User
|
|
|
|
func (u *User) Tenant() datastore.TenantID {
|
|
|
|
if u.agent.TenantID == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
return *u.agent.TenantID
|
|
|
|
}
|
|
|
|
|
2023-03-07 23:10:42 +01:00
|
|
|
func (u *User) Agent() *datastore.Agent {
|
|
|
|
return u.agent
|
|
|
|
}
|
|
|
|
|
2024-03-03 18:40:56 +01:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2023-03-07 23:10:42 +01:00
|
|
|
var _ auth.User = &User{}
|