This commit is contained in:
Jabberwocky238
2026-07-29 06:51:43 -04:00
parent 68cda1972c
commit 319f5dd148
64 changed files with 4952 additions and 2186 deletions
+12 -30
View File
@@ -1,16 +1,3 @@
package state
import (
@@ -50,15 +37,19 @@ type IState interface {
KnownSSHKey(key ssh.PublicKey) (bool, error)
AccessBySSHKey(ctx context.Context, key ssh.PublicKey, repons, reponame string, perm common.Perm) (ok bool, err error)
AccessByPAT(ctx context.Context, pat, repons, reponame string, perm common.Perm) (ok bool, err error)
AccessByUserPswd(ctx context.Context, username, password, repons, reponame string, perm common.Perm) (ok bool, err error)
Signers() ([]ssh.Signer, error)
}
type IStateMut interface {
IState
Engine() *xorm.Engine
MoveNS(old, new string) error
MoveRepo(old, new string) error
CreateNS(ns string) error
DeleteNS(ns string) error
CreateRepo(ns, name string) error
UpsertRepo(ns, name string, isPrivate bool) error
ExistRepo(ns, name string) error
DeleteRepo(ns, name string) error
@@ -67,9 +58,11 @@ type IStateMut interface {
ACLUpsertSSHKeyOnRepo(reponame string, key ssh.PublicKey, perm common.Perm) (aclID int64, err error)
ACLUpsertPATOnRepo(reponame string, pat string, perm common.Perm) (aclID int64, err error)
ACLDelete(id int64) error
ACLSetPerm(id int64, perm common.Perm) error
UserPasswordUpsert(ns, password string) error
UserDelete(ns string) error
}
var (
_ IState = (*LocalState)(nil)
_ IStateMut = (*LocalState)(nil)
@@ -86,7 +79,6 @@ type LocalState struct {
func init() {
sql.Register(sqliteDriver, &sqlite.Driver{})
}
@@ -106,8 +98,6 @@ func Open(cfg *common.Config) (*LocalState, error) {
}, nil
}
func (s *LocalState) Signers() ([]ssh.Signer, error) {
s.signerMu.Lock()
defer s.signerMu.Unlock()
@@ -185,11 +175,12 @@ func fingerprint(key ssh.PublicKey) string {
return "SHA256:" + hex.EncodeToString(sum[:])
}
func (s *LocalState) findRepo(owner, name string) (*Repo, error) {
var r Repo
has, err := s.engine.Where("namespace = ? AND name = ?", owner, strings.TrimSuffix(name, ".git")).Get(&r)
has, err := s.engine.Where(
"namespace_id IN (SELECT id FROM namespace WHERE name = ?) AND name = ?",
owner, strings.TrimSuffix(name, ".git"),
).Get(&r)
if err != nil {
return nil, fmt.Errorf("lookup repo: %w", err)
}
@@ -203,9 +194,6 @@ func (s *LocalState) RepoPath(owner, name string) (string, error) {
return s.cfg.RepoPath(owner, name)
}
func (s *LocalState) Open(owner, name string) (*gitcmd.Repository, error) {
path, err := s.RepoPath(owner, name)
if err != nil {
@@ -214,10 +202,4 @@ func (s *LocalState) Open(owner, name string) (*gitcmd.Repository, error) {
return gitcmd.OpenRepository(context.Background(), path)
}
func (s *LocalState) Engine() *xorm.Engine { return s.engine }