mirror of
https://github.com/jsiebens/ionscale.git
synced 2026-03-31 15:07:49 +01:00
chore: refactor domain repository interfaces
This commit is contained in:
@@ -8,6 +8,12 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type AccountRepository interface {
|
||||
GetAccount(ctx context.Context, accountID uint64) (*Account, error)
|
||||
GetOrCreateAccount(ctx context.Context, externalID, loginName string) (*Account, bool, error)
|
||||
SetAccountLastAuthenticated(ctx context.Context, accountID uint64) error
|
||||
}
|
||||
|
||||
type Account struct {
|
||||
ID uint64 `gorm:"primary_key"`
|
||||
ExternalID string
|
||||
|
||||
@@ -33,6 +33,13 @@ func CreateApiKey(tailnet *Tailnet, user *User, expiresAt *time.Time) (string, *
|
||||
}
|
||||
}
|
||||
|
||||
type ApiKeyRepository interface {
|
||||
SaveApiKey(ctx context.Context, key *ApiKey) error
|
||||
LoadApiKey(ctx context.Context, key string) (*ApiKey, error)
|
||||
DeleteApiKeysByTailnet(ctx context.Context, tailnetID uint64) error
|
||||
DeleteApiKeysByUser(ctx context.Context, userID uint64) error
|
||||
}
|
||||
|
||||
type ApiKey struct {
|
||||
ID uint64 `gorm:"primary_key"`
|
||||
Key string
|
||||
|
||||
@@ -36,6 +36,17 @@ func CreateAuthKey(tailnet *Tailnet, user *User, ephemeral bool, preAuthorized b
|
||||
}
|
||||
}
|
||||
|
||||
type AuthKeyRepository interface {
|
||||
GetAuthKey(ctx context.Context, id uint64) (*AuthKey, error)
|
||||
SaveAuthKey(ctx context.Context, key *AuthKey) error
|
||||
DeleteAuthKey(ctx context.Context, id uint64) (bool, error)
|
||||
DeleteAuthKeysByTailnet(ctx context.Context, tailnetID uint64) error
|
||||
DeleteAuthKeysByUser(ctx context.Context, userID uint64) error
|
||||
ListAuthKeys(ctx context.Context, tailnetID uint64) ([]AuthKey, error)
|
||||
ListAuthKeysByTailnetAndUser(ctx context.Context, tailnetID, userID uint64) ([]AuthKey, error)
|
||||
LoadAuthKey(ctx context.Context, key string) (*AuthKey, error)
|
||||
}
|
||||
|
||||
type AuthKey struct {
|
||||
ID uint64 `gorm:"primary_key"`
|
||||
Key string
|
||||
|
||||
@@ -7,6 +7,12 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type AuthenticationRequestRepository interface {
|
||||
SaveAuthenticationRequest(ctx context.Context, session *AuthenticationRequest) error
|
||||
GetAuthenticationRequest(ctx context.Context, key string) (*AuthenticationRequest, error)
|
||||
DeleteAuthenticationRequest(ctx context.Context, key string) error
|
||||
}
|
||||
|
||||
type AuthenticationRequest struct {
|
||||
Key string `gorm:"primary_key"`
|
||||
Token string
|
||||
|
||||
@@ -13,6 +13,23 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type MachineRepository interface {
|
||||
SaveMachine(ctx context.Context, m *Machine) error
|
||||
DeleteMachine(ctx context.Context, id uint64) (bool, error)
|
||||
GetMachine(ctx context.Context, id uint64) (*Machine, error)
|
||||
GetMachineByKeyAndUser(ctx context.Context, key string, userID uint64) (*Machine, error)
|
||||
GetMachineByKeys(ctx context.Context, machineKey string, nodeKey string) (*Machine, error)
|
||||
CountMachinesWithIPv4(ctx context.Context, ip string) (int64, error)
|
||||
GetNextMachineNameIndex(ctx context.Context, tailnetID uint64, name string) (uint64, error)
|
||||
ListMachineByTailnet(ctx context.Context, tailnetID uint64) (Machines, error)
|
||||
CountMachineByTailnet(ctx context.Context, tailnetID uint64) (int64, error)
|
||||
DeleteMachineByTailnet(ctx context.Context, tailnetID uint64) error
|
||||
DeleteMachineByUser(ctx context.Context, userID uint64) error
|
||||
ListMachinePeers(ctx context.Context, tailnetID uint64, machineID uint64) (Machines, error)
|
||||
ListInactiveEphemeralMachines(ctx context.Context, checkpoint time.Time) (Machines, error)
|
||||
SetMachineLastSeen(ctx context.Context, machineID uint64) error
|
||||
}
|
||||
|
||||
type Machine struct {
|
||||
ID uint64 `gorm:"primary_key"`
|
||||
Name string
|
||||
|
||||
@@ -12,6 +12,12 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type RegistrationRequestRepository interface {
|
||||
SaveRegistrationRequest(ctx context.Context, request *RegistrationRequest) error
|
||||
GetRegistrationRequestByKey(ctx context.Context, key string) (*RegistrationRequest, error)
|
||||
GetRegistrationRequestByMachineKey(ctx context.Context, key string) (*RegistrationRequest, error)
|
||||
}
|
||||
|
||||
type RegistrationRequest struct {
|
||||
MachineKey string `gorm:"primary_key"`
|
||||
Key string
|
||||
|
||||
@@ -13,6 +13,17 @@ import (
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
AccountRepository
|
||||
ApiKeyRepository
|
||||
SystemApiKeyRepository
|
||||
AuthKeyRepository
|
||||
MachineRepository
|
||||
TailnetRepository
|
||||
UserRepository
|
||||
AuthenticationRequestRepository
|
||||
RegistrationRequestRepository
|
||||
SSHActionRequestRepository
|
||||
|
||||
GetControlKeys(ctx context.Context) (*ControlKeys, error)
|
||||
SetControlKeys(ctx context.Context, keys *ControlKeys) error
|
||||
|
||||
@@ -22,68 +33,6 @@ type Repository interface {
|
||||
GetDERPMap(ctx context.Context) (*DERPMap, error)
|
||||
SetDERPMap(ctx context.Context, v *DERPMap) error
|
||||
|
||||
GetAccount(ctx context.Context, accountID uint64) (*Account, error)
|
||||
GetOrCreateAccount(ctx context.Context, externalID, loginName string) (*Account, bool, error)
|
||||
SetAccountLastAuthenticated(ctx context.Context, accountID uint64) error
|
||||
|
||||
SaveTailnet(ctx context.Context, tailnet *Tailnet) error
|
||||
GetTailnet(ctx context.Context, id uint64) (*Tailnet, error)
|
||||
GetTailnetByName(ctx context.Context, name string) (*Tailnet, error)
|
||||
ListTailnets(ctx context.Context) ([]Tailnet, error)
|
||||
DeleteTailnet(ctx context.Context, id uint64) error
|
||||
|
||||
SaveSystemApiKey(ctx context.Context, key *SystemApiKey) error
|
||||
LoadSystemApiKey(ctx context.Context, key string) (*SystemApiKey, error)
|
||||
|
||||
SaveApiKey(ctx context.Context, key *ApiKey) error
|
||||
LoadApiKey(ctx context.Context, key string) (*ApiKey, error)
|
||||
DeleteApiKeysByTailnet(ctx context.Context, tailnetID uint64) error
|
||||
DeleteApiKeysByUser(ctx context.Context, userID uint64) error
|
||||
|
||||
GetAuthKey(ctx context.Context, id uint64) (*AuthKey, error)
|
||||
SaveAuthKey(ctx context.Context, key *AuthKey) error
|
||||
DeleteAuthKey(ctx context.Context, id uint64) (bool, error)
|
||||
DeleteAuthKeysByTailnet(ctx context.Context, tailnetID uint64) error
|
||||
DeleteAuthKeysByUser(ctx context.Context, userID uint64) error
|
||||
ListAuthKeys(ctx context.Context, tailnetID uint64) ([]AuthKey, error)
|
||||
ListAuthKeysByTailnetAndUser(ctx context.Context, tailnetID, userID uint64) ([]AuthKey, error)
|
||||
LoadAuthKey(ctx context.Context, key string) (*AuthKey, error)
|
||||
|
||||
GetOrCreateServiceUser(ctx context.Context, tailnet *Tailnet) (*User, bool, error)
|
||||
GetOrCreateUserWithAccount(ctx context.Context, tailnet *Tailnet, account *Account) (*User, bool, error)
|
||||
GetUser(ctx context.Context, userID uint64) (*User, error)
|
||||
DeleteUser(ctx context.Context, userID uint64) error
|
||||
ListUsers(ctx context.Context, tailnetID uint64) (Users, error)
|
||||
DeleteUsersByTailnet(ctx context.Context, tailnetID uint64) error
|
||||
SetUserLastAuthenticated(ctx context.Context, userID uint64, timestamp time.Time) error
|
||||
|
||||
SaveMachine(ctx context.Context, m *Machine) error
|
||||
DeleteMachine(ctx context.Context, id uint64) (bool, error)
|
||||
GetMachine(ctx context.Context, id uint64) (*Machine, error)
|
||||
GetMachineByKeyAndUser(ctx context.Context, key string, userID uint64) (*Machine, error)
|
||||
GetMachineByKeys(ctx context.Context, machineKey string, nodeKey string) (*Machine, error)
|
||||
CountMachinesWithIPv4(ctx context.Context, ip string) (int64, error)
|
||||
GetNextMachineNameIndex(ctx context.Context, tailnetID uint64, name string) (uint64, error)
|
||||
ListMachineByTailnet(ctx context.Context, tailnetID uint64) (Machines, error)
|
||||
CountMachineByTailnet(ctx context.Context, tailnetID uint64) (int64, error)
|
||||
DeleteMachineByTailnet(ctx context.Context, tailnetID uint64) error
|
||||
DeleteMachineByUser(ctx context.Context, userID uint64) error
|
||||
ListMachinePeers(ctx context.Context, tailnetID uint64, machineID uint64) (Machines, error)
|
||||
ListInactiveEphemeralMachines(ctx context.Context, checkpoint time.Time) (Machines, error)
|
||||
SetMachineLastSeen(ctx context.Context, machineID uint64) error
|
||||
|
||||
SaveRegistrationRequest(ctx context.Context, request *RegistrationRequest) error
|
||||
GetRegistrationRequestByKey(ctx context.Context, key string) (*RegistrationRequest, error)
|
||||
GetRegistrationRequestByMachineKey(ctx context.Context, key string) (*RegistrationRequest, error)
|
||||
|
||||
SaveAuthenticationRequest(ctx context.Context, session *AuthenticationRequest) error
|
||||
GetAuthenticationRequest(ctx context.Context, key string) (*AuthenticationRequest, error)
|
||||
DeleteAuthenticationRequest(ctx context.Context, key string) error
|
||||
|
||||
SaveSSHActionRequest(ctx context.Context, session *SSHActionRequest) error
|
||||
GetSSHActionRequest(ctx context.Context, key string) (*SSHActionRequest, error)
|
||||
DeleteSSHActionRequest(ctx context.Context, key string) error
|
||||
|
||||
Transaction(func(rp Repository) error) error
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,12 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type SSHActionRequestRepository interface {
|
||||
SaveSSHActionRequest(ctx context.Context, session *SSHActionRequest) error
|
||||
GetSSHActionRequest(ctx context.Context, key string) (*SSHActionRequest, error)
|
||||
DeleteSSHActionRequest(ctx context.Context, key string) error
|
||||
}
|
||||
|
||||
type SSHActionRequest struct {
|
||||
Key string `gorm:"primary_key"`
|
||||
Action string
|
||||
|
||||
@@ -32,6 +32,11 @@ func CreateSystemApiKey(account *Account, expiresAt *time.Time) (string, *System
|
||||
}
|
||||
}
|
||||
|
||||
type SystemApiKeyRepository interface {
|
||||
SaveSystemApiKey(ctx context.Context, key *SystemApiKey) error
|
||||
LoadSystemApiKey(ctx context.Context, key string) (*SystemApiKey, error)
|
||||
}
|
||||
|
||||
type SystemApiKey struct {
|
||||
ID uint64 `gorm:"primary_key"`
|
||||
Key string
|
||||
|
||||
@@ -22,6 +22,14 @@ type Tailnet struct {
|
||||
MachineAuthorizationEnabled bool
|
||||
}
|
||||
|
||||
type TailnetRepository interface {
|
||||
SaveTailnet(ctx context.Context, tailnet *Tailnet) error
|
||||
GetTailnet(ctx context.Context, id uint64) (*Tailnet, error)
|
||||
GetTailnetByName(ctx context.Context, name string) (*Tailnet, error)
|
||||
ListTailnets(ctx context.Context) ([]Tailnet, error)
|
||||
DeleteTailnet(ctx context.Context, id uint64) error
|
||||
}
|
||||
|
||||
func (t Tailnet) GetDERPMap(ctx context.Context, fallack DefaultDERPMap) (*DERPMap, error) {
|
||||
if t.DERPMap.Checksum == "" {
|
||||
return fallack.GetDERPMap(ctx)
|
||||
|
||||
@@ -38,6 +38,16 @@ func (s UserRole) IsAdmin() bool {
|
||||
return s == UserRoleAdmin
|
||||
}
|
||||
|
||||
type UserRepository interface {
|
||||
GetOrCreateServiceUser(ctx context.Context, tailnet *Tailnet) (*User, bool, error)
|
||||
GetOrCreateUserWithAccount(ctx context.Context, tailnet *Tailnet, account *Account) (*User, bool, error)
|
||||
GetUser(ctx context.Context, userID uint64) (*User, error)
|
||||
DeleteUser(ctx context.Context, userID uint64) error
|
||||
ListUsers(ctx context.Context, tailnetID uint64) (Users, error)
|
||||
DeleteUsersByTailnet(ctx context.Context, tailnetID uint64) error
|
||||
SetUserLastAuthenticated(ctx context.Context, userID uint64, timestamp time.Time) error
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID uint64 `gorm:"primary_key"`
|
||||
Name string
|
||||
|
||||
Reference in New Issue
Block a user