Tweaked project structure (#88)

This commit is contained in:
Thomas Miceli
2023-09-03 00:30:57 +02:00
committed by GitHub
parent 25316d7bf2
commit a7b346d8df
25 changed files with 122 additions and 116 deletions

View File

@ -3,8 +3,8 @@ package ssh
import (
"errors"
"github.com/rs/zerolog/log"
"github.com/thomiceli/opengist/internal/db"
"github.com/thomiceli/opengist/internal/git"
"github.com/thomiceli/opengist/internal/models"
"golang.org/x/crypto/ssh"
"gorm.io/gorm"
"io"
@ -32,12 +32,12 @@ func runGitCommand(ch ssh.Channel, gitCmd string, key string, ip string) error {
userName := strings.ToLower(repoFields[0])
gistName := strings.TrimSuffix(strings.ToLower(repoFields[1]), ".git")
gist, err := models.GetGist(userName, gistName)
gist, err := db.GetGist(userName, gistName)
if err != nil {
return errors.New("gist not found")
}
requireLogin, err := models.GetSetting(models.SettingRequireLogin)
requireLogin, err := db.GetSetting(db.SettingRequireLogin)
if err != nil {
return errors.New("internal server error")
}
@ -52,7 +52,7 @@ func runGitCommand(ch ssh.Channel, gitCmd string, key string, ip string) error {
gist.ID == 0 ||
requireLogin == "1" {
pubKey, err := models.SSHKeyExistsForUser(key, gist.UserID)
pubKey, err := db.SSHKeyExistsForUser(key, gist.UserID)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
log.Warn().Msg("Invalid SSH authentication attempt from " + ip)
@ -61,7 +61,7 @@ func runGitCommand(ch ssh.Channel, gitCmd string, key string, ip string) error {
errorSsh("Failed to get user by SSH key id", err)
return errors.New("internal server error")
}
_ = models.SSHKeyLastUsedNow(pubKey.Content)
_ = db.SSHKeyLastUsedNow(pubKey.Content)
}
repositoryPath := git.RepositoryPath(gist.User.Username, gist.Uuid)