Add auth token to gitservers
This commit is contained in:
@@ -3,11 +3,12 @@ package models
|
||||
import "errors"
|
||||
|
||||
type GitServer struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Protocol string `json:"protocol"`
|
||||
BaseUrl string `json:"baseUrl"`
|
||||
Type string `json:"type"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Protocol string `json:"protocol"`
|
||||
BaseUrl string `json:"baseUrl"`
|
||||
Type string `json:"type"`
|
||||
AuthToken string `json:"auth_token"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
}
|
||||
|
||||
|
||||
@@ -21,21 +21,6 @@ func Register(app *fiber.App, cfg *config.Config, envCfg *envconfig.EnvConfig, d
|
||||
userRepository := database.NewSQLiteUserRepository(db)
|
||||
gitServerRepository := database.NewSQLiteGitServerRepository(db)
|
||||
|
||||
// Seed default git servers if none exist
|
||||
if gsList, err := gitServerRepository.ListGitServers(); err != nil {
|
||||
log.Printf("Warning checking gitservers: %v", err)
|
||||
} else if len(gsList) == 0 {
|
||||
defaults := []models.GitServer{
|
||||
{Name: "GitHub", Protocol: "https", BaseUrl: "github.com", Type: "github"},
|
||||
{Name: "GitLab", Protocol: "https", BaseUrl: "gitlab.com", Type: "gitlab"},
|
||||
}
|
||||
for _, d := range defaults {
|
||||
if err := gitServerRepository.CreateGitServer(&d); err != nil {
|
||||
log.Printf("Warning creating default gitserver %s: %v", d.Name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
siteHandler := handlers.NewSiteHandler(siteRepository)
|
||||
deploySiteHandler := handlers.NewDeploySiteHandler(envCfg, siteRepository, deploymentRepository)
|
||||
userHandler := handlers.NewUserHandler(userRepository)
|
||||
|
||||
@@ -20,7 +20,7 @@ func NewSQLiteGitServerRepository(db *sql.DB) *SQLiteGitServerRepository {
|
||||
var _ repository.GitServerRepository = (*SQLiteGitServerRepository)(nil)
|
||||
|
||||
func (r *SQLiteGitServerRepository) ListGitServers() ([]models.GitServer, error) {
|
||||
rows, err := r.db.Query(`SELECT id, name, protocol, base_url, type, created_at FROM gitservers`)
|
||||
rows, err := r.db.Query(`SELECT id, name, protocol, base_url, type, auth_token, created_at FROM gitservers`)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("list gitservers: %w", err)
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func (r *SQLiteGitServerRepository) ListGitServers() ([]models.GitServer, error)
|
||||
}
|
||||
|
||||
func (r *SQLiteGitServerRepository) GetGitServer(id string) (*models.GitServer, error) {
|
||||
row := r.db.QueryRow(`SELECT id, name, protocol, base_url, type, created_at FROM gitservers WHERE id = ?`, id)
|
||||
row := r.db.QueryRow(`SELECT id, name, protocol, base_url, type, auth_token, created_at FROM gitservers WHERE id = ?`, id)
|
||||
return scanGitServer(row)
|
||||
}
|
||||
|
||||
@@ -55,8 +55,8 @@ func (r *SQLiteGitServerRepository) CreateGitServer(gs *models.GitServer) error
|
||||
|
||||
gs.ID = uuid.NewString()
|
||||
|
||||
_, err = tx.Exec(`INSERT INTO gitservers (id, name, protocol, base_url, type) VALUES (?, ?, ?, ?, ?)`,
|
||||
gs.ID, gs.Name, gs.Protocol, gs.BaseUrl, gs.Type)
|
||||
_, err = tx.Exec(`INSERT INTO gitservers (id, name, protocol, base_url, type, auth_token) VALUES (?, ?, ?, ?, ?, ?)`,
|
||||
gs.ID, gs.Name, gs.Protocol, gs.BaseUrl, gs.Type, gs.AuthToken)
|
||||
if err != nil {
|
||||
if isSQLiteUniqueConstraintError(err) {
|
||||
return fmt.Errorf("create gitserver insert: %w", repository.ErrGitServerAlreadyExists)
|
||||
@@ -74,8 +74,8 @@ func (r *SQLiteGitServerRepository) UpdateGitServer(gs *models.GitServer) error
|
||||
}
|
||||
defer tx.Rollback()
|
||||
|
||||
_, err = tx.Exec(`UPDATE gitservers SET name = ?, protocol = ?, base_url = ?, type = ? WHERE id = ?`,
|
||||
gs.Name, gs.Protocol, gs.BaseUrl, gs.Type, gs.ID)
|
||||
_, err = tx.Exec(`UPDATE gitservers SET name = ?, protocol = ?, base_url = ?, type = ?, auth_token = ? WHERE id = ?`,
|
||||
gs.Name, gs.Protocol, gs.BaseUrl, gs.Type, gs.AuthToken, gs.ID)
|
||||
if err != nil {
|
||||
if isSQLiteUniqueConstraintError(err) {
|
||||
return fmt.Errorf("update gitserver: %w", repository.ErrGitServerAlreadyExists)
|
||||
@@ -96,7 +96,7 @@ func (r *SQLiteGitServerRepository) DeleteGitServer(id string) error {
|
||||
|
||||
func scanGitServer(s scanner) (*models.GitServer, error) {
|
||||
g := new(models.GitServer)
|
||||
err := s.Scan(&g.ID, &g.Name, &g.Protocol, &g.BaseUrl, &g.Type, &g.CreatedAt)
|
||||
err := s.Scan(&g.ID, &g.Name, &g.Protocol, &g.BaseUrl, &g.Type, &g.AuthToken, &g.CreatedAt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ CREATE TABLE IF NOT EXISTS gitservers (
|
||||
protocol TEXT NOT NULL,
|
||||
base_url TEXT NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
auth_token TEXT,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
`)
|
||||
|
||||
Reference in New Issue
Block a user