feat: API Hermes con acceso total para consumo externo (API Key auth)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Lizandro GD
2026-07-13 02:50:31 +00:00
co-authored by Claude Sonnet 5
parent 6e281dfbda
commit 6ccdbd93c8
4 changed files with 409 additions and 1 deletions
+32
View File
@@ -0,0 +1,32 @@
package middlewares
import (
"os"
"strings"
"github.com/gofiber/fiber/v2"
)
func HermesAuth() fiber.Handler {
return func(c *fiber.Ctx) error {
apiKey := os.Getenv("HERMES_API_KEY")
if apiKey == "" {
return c.Status(503).JSON(fiber.Map{"error": "HERMES_API_KEY not configured"})
}
token := ""
auth := c.Get("Authorization")
if strings.HasPrefix(auth, "Bearer ") {
token = auth[7:]
}
if token == "" {
token = c.Get("X-API-Key")
}
if token == "" || token != apiKey {
return c.Status(401).JSON(fiber.Map{"error": "unauthorized"})
}
return c.Next()
}
}