photoprism/internal/entity/auth_client_fixtures.go
Michael Mayer 7e7ba69982 Auth: Add client_uid and client_name to auth_sessions table #808 #3943
This also adds the ability to change the client role if needed and
improves the usage information and output of the CLI commands.

Signed-off-by: Michael Mayer <michael@photoprism.app>
2024-01-18 16:53:05 +01:00

120 lines
2.8 KiB
Go

package entity
import (
"github.com/photoprism/photoprism/internal/acl"
"github.com/photoprism/photoprism/pkg/authn"
)
type ClientMap map[string]Client
func (m ClientMap) Get(name string) Client {
if result, ok := m[name]; ok {
return result
}
return Client{}
}
func (m ClientMap) Pointer(name string) *Client {
if result, ok := m[name]; ok {
return &result
}
return &Client{}
}
var ClientFixtures = ClientMap{
"alice": {
ClientUID: "cs5gfen1bgxz7s9i",
UserUID: UserFixtures.Pointer("alice").UserUID,
UserName: UserFixtures.Pointer("alice").UserName,
user: UserFixtures.Pointer("alice"),
ClientName: "Alice",
ClientRole: acl.RoleClient.String(),
ClientType: authn.ClientConfidential,
ClientURL: "",
CallbackURL: "",
AuthMethod: authn.MethodOAuth2.String(),
AuthScope: "*",
AuthExpires: UnixDay,
AuthTokens: -1,
AuthEnabled: true,
LastActive: 0,
},
"bob": {
ClientUID: "cs5gfsvbd7ejzn8m",
UserUID: UserFixtures.Pointer("bob").UserUID,
UserName: UserFixtures.Pointer("bob").UserName,
user: UserFixtures.Pointer("bob"),
ClientName: "Bob",
ClientRole: acl.RoleClient.String(),
ClientType: authn.ClientPublic,
ClientURL: "",
CallbackURL: "",
AuthMethod: authn.MethodOAuth2.String(),
AuthScope: "*",
AuthExpires: 0,
AuthTokens: -1,
AuthEnabled: false,
LastActive: 0,
},
"metrics": {
ClientUID: "cs5cpu17n6gj2qo5",
UserUID: "",
UserName: "",
user: nil,
ClientName: "Monitoring",
ClientRole: acl.RoleClient.String(),
ClientType: authn.ClientConfidential,
ClientURL: "",
CallbackURL: "",
AuthMethod: authn.MethodOAuth2.String(),
AuthScope: "metrics",
AuthExpires: UnixHour,
AuthTokens: 2,
AuthEnabled: true,
LastActive: 0,
},
"Unknown": {
ClientUID: "cs5cpu17n6gj2jh6",
UserUID: "",
UserName: "",
user: nil,
ClientName: "Unknown",
ClientRole: acl.RoleNone.String(),
ClientType: authn.ClientUnknown,
ClientURL: "",
CallbackURL: "",
AuthMethod: authn.MethodUnknown.String(),
AuthScope: "*",
AuthExpires: UnixHour,
AuthTokens: 2,
AuthEnabled: true,
LastActive: 0,
},
"deleted": {
ClientUID: "cs5cpu17n6gj2gf7",
UserUID: "",
UserName: "",
user: nil,
ClientName: "Deleted Monitoring",
ClientRole: acl.RoleClient.String(),
ClientType: authn.ClientConfidential,
ClientURL: "",
CallbackURL: "",
AuthMethod: authn.MethodOAuth2.String(),
AuthScope: "metrics",
AuthExpires: UnixHour,
AuthTokens: 2,
AuthEnabled: true,
LastActive: 0,
DeletedAt: TimePointer(),
},
}
// CreateClientFixtures inserts known entities into the database for testing.
func CreateClientFixtures() {
for _, entity := range ClientFixtures {
Db().Create(&entity)
}
}