Moved github PAT and storage path to env vars
This commit is contained in:
@@ -12,7 +12,7 @@ func NewStaticHandler(storagePath string, siteMap map[string]config.SiteConfig)
|
||||
return func(c fiber.Ctx) error {
|
||||
site, ok := siteMap[c.Hostname()]
|
||||
if !ok {
|
||||
return c.SendStatus(fiber.StatusNotFound)
|
||||
return c.Status(fiber.StatusNotFound).SendString("Site not found")
|
||||
}
|
||||
|
||||
urlPath := filepath.Clean(c.Path())
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"quay/app/github"
|
||||
"quay/app/models"
|
||||
"quay/internal/config"
|
||||
"quay/internal/envconfig"
|
||||
"strings"
|
||||
|
||||
"crypto/subtle"
|
||||
@@ -12,7 +13,7 @@ import (
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
func NewUpdateSiteHandler(cfg *config.Config) fiber.Handler {
|
||||
func NewUpdateSiteHandler(cfg *config.Config, envCfg *envconfig.EnvConfig) fiber.Handler {
|
||||
return func(c fiber.Ctx) error {
|
||||
sitename := c.Query("site")
|
||||
if sitename == "" {
|
||||
@@ -58,7 +59,7 @@ func NewUpdateSiteHandler(cfg *config.Config) fiber.Handler {
|
||||
})
|
||||
}
|
||||
|
||||
sitePath := filepath.Join(cfg.Global.StoragePath, siteConfig.Name)
|
||||
sitePath := filepath.Join(envCfg.StoragePath, siteConfig.Name)
|
||||
if _, err := filepath.Abs(sitePath); err != nil {
|
||||
return c.Status(500).JSON(models.APIError{
|
||||
Error: "Failed to resolve site path",
|
||||
@@ -69,7 +70,7 @@ func NewUpdateSiteHandler(cfg *config.Config) fiber.Handler {
|
||||
siteConfig.Owner,
|
||||
siteConfig.Repo,
|
||||
siteConfig.Branch,
|
||||
cfg.Global.GithubPat,
|
||||
envCfg.GithubPat,
|
||||
sitePath,
|
||||
)
|
||||
|
||||
|
||||
@@ -5,17 +5,18 @@ import (
|
||||
"path/filepath"
|
||||
"quay/app/handlers"
|
||||
"quay/internal/config"
|
||||
"quay/internal/envconfig"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
func Register(app *fiber.App, cfg *config.Config) {
|
||||
func Register(app *fiber.App, cfg *config.Config, envCfg *envconfig.EnvConfig) {
|
||||
api := app.Group("/api")
|
||||
api.Get("/health", handlers.HealthCheck)
|
||||
|
||||
api.Post("/update", handlers.NewUpdateSiteHandler(cfg))
|
||||
api.Post("/update", handlers.NewUpdateSiteHandler(cfg, envCfg))
|
||||
|
||||
storagePath, err := filepath.Abs(cfg.Global.StoragePath)
|
||||
storagePath, err := filepath.Abs(envCfg.StoragePath)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to resolve storage path: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user