Compare commits
10
Commits
cda0edfde2
...
d6859d8cf9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6859d8cf9 | ||
|
|
99ffa05c61 | ||
|
|
c6d5fa02d1 | ||
|
|
b92682177c | ||
|
|
4be8faaa67 | ||
|
|
e78fd22f51 | ||
|
|
7a189d56ea | ||
|
|
441253351d | ||
|
|
ffec908ca4 | ||
|
|
26052db142 |
@@ -0,0 +1,34 @@
|
|||||||
|
// Package auth provides authentication-related API endpoints for the Triggersmith application.
|
||||||
|
// It handles login, logout, and user management operations.
|
||||||
|
package auth
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"git.oblat.lv/alex/triggerssmith/internal/config"
|
||||||
|
"github.com/go-chi/chi/v5"
|
||||||
|
)
|
||||||
|
|
||||||
|
type authHandler struct {
|
||||||
|
cfg *config.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
func Route(config *config.Config) func(chi.Router) {
|
||||||
|
h := &authHandler{
|
||||||
|
cfg: config,
|
||||||
|
}
|
||||||
|
return func(r chi.Router) {
|
||||||
|
r.Get("/login", h.handleLogin)
|
||||||
|
r.Get("/logout", h.handleLogout)
|
||||||
|
r.Get("/me", h.handleMe)
|
||||||
|
r.Get("/revoke", h.handleRevoke)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *authHandler) handleLogin(w http.ResponseWriter, r *http.Request) {}
|
||||||
|
|
||||||
|
func (h *authHandler) handleLogout(w http.ResponseWriter, r *http.Request) {}
|
||||||
|
|
||||||
|
func (h *authHandler) handleMe(w http.ResponseWriter, r *http.Request) {}
|
||||||
|
|
||||||
|
func (h *authHandler) handleRevoke(w http.ResponseWriter, r *http.Request) {}
|
||||||
+26
-6
@@ -1,3 +1,11 @@
|
|||||||
|
// Package block provides functionality to load HTML blocks with associated content, JavaScript, and CSS from the filesystem.
|
||||||
|
// API Endpoint:
|
||||||
|
//
|
||||||
|
// /api/block/{blockPath}
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// /api/block/header would load the block located at {BlockDir}/header/
|
||||||
package block
|
package block
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -8,6 +16,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"git.oblat.lv/alex/triggerssmith/internal/config"
|
"git.oblat.lv/alex/triggerssmith/internal/config"
|
||||||
|
"github.com/go-chi/chi/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Block struct {
|
type Block struct {
|
||||||
@@ -16,15 +25,27 @@ type Block struct {
|
|||||||
CSS string `json:"css"`
|
CSS string `json:"css"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadHtmlBlock(cfg *config.Config) func(w http.ResponseWriter, r *http.Request) {
|
type blockHandler struct {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
cfg *config.Config
|
||||||
if !cfg.Server.BlockConfig.Enabled {
|
}
|
||||||
http.Error(w, "Block serving is disabled", http.StatusNotImplemented)
|
|
||||||
|
func Route(config *config.Config) func(chi.Router) {
|
||||||
|
h := &blockHandler{
|
||||||
|
cfg: config,
|
||||||
|
}
|
||||||
|
return func(r chi.Router) {
|
||||||
|
r.Get("/*", h.handleBlock)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *blockHandler) handleBlock(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if !h.cfg.Server.BlockConfig.Enabled {
|
||||||
|
http.Error(w, "Block serving is disabled", http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
blockPath := r.URL.Path[len("/api/block/"):]
|
blockPath := r.URL.Path[len("/api/block/"):]
|
||||||
block, err := LoadBlock(blockPath, cfg)
|
block, err := LoadBlock(blockPath, h.cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@@ -32,7 +53,6 @@ func LoadHtmlBlock(cfg *config.Config) func(w http.ResponseWriter, r *http.Reque
|
|||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write([]byte(block.ToJSON()))
|
w.Write([]byte(block.ToJSON()))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadBlock loads a block from the filesystem given its path and configuration.
|
// LoadBlock loads a block from the filesystem given its path and configuration.
|
||||||
|
|||||||
+10
-1
@@ -1,3 +1,4 @@
|
|||||||
|
// Package api provides the main API router and route handlers for the Triggersmith application.
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -7,6 +8,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.oblat.lv/alex/triggerssmith/api/auth"
|
||||||
"git.oblat.lv/alex/triggerssmith/api/block"
|
"git.oblat.lv/alex/triggerssmith/api/block"
|
||||||
"git.oblat.lv/alex/triggerssmith/internal/config"
|
"git.oblat.lv/alex/triggerssmith/internal/config"
|
||||||
"git.oblat.lv/alex/triggerssmith/internal/vars"
|
"git.oblat.lv/alex/triggerssmith/internal/vars"
|
||||||
@@ -47,10 +49,17 @@ func (r *Router) RouteHandler() chi.Router {
|
|||||||
r.r.Handle("/static/*", http.StripPrefix("/static/", fs))
|
r.r.Handle("/static/*", http.StripPrefix("/static/", fs))
|
||||||
} else {
|
} else {
|
||||||
slog.Info("Static file serving is disabled")
|
slog.Info("Static file serving is disabled")
|
||||||
|
r.r.Get("/", func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
http.Error(w, "Static serving is disabled", http.StatusForbidden)
|
||||||
|
})
|
||||||
|
r.r.HandleFunc("/static/*", func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
http.Error(w, "Static serving is disabled", http.StatusForbidden)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
r.r.Route("/api", func(api chi.Router) {
|
r.r.Route("/api", func(api chi.Router) {
|
||||||
api.Get("/block/*", block.LoadHtmlBlock(r.cfg))
|
api.Route("/block", block.Route(r.cfg))
|
||||||
|
api.Route("/auth", auth.Route(r.cfg))
|
||||||
})
|
})
|
||||||
|
|
||||||
r.r.Get("/health", func(w http.ResponseWriter, r *http.Request) {
|
r.r.Get("/health", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user