Merge branch 'copilot/vcard-api-integraciones-anlisis'
# Conflicts: # rest/controllers/coolify_controller.go
This commit is contained in:
@@ -12,13 +12,9 @@ import (
|
|||||||
"github.com/sujit-baniya/fiber-boilerplate/pkg/models"
|
"github.com/sujit-baniya/fiber-boilerplate/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ─── helpers internos ────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
// coolifyDo ejecuta una petición a la API de Coolify y devuelve el body crudo.
|
|
||||||
func coolifyDo(method, endpoint string, reqBody io.Reader, contentType string, cfg *models.CoolifyConfig) ([]byte, int, error) {
|
func coolifyDo(method, endpoint string, reqBody io.Reader, contentType string, cfg *models.CoolifyConfig) ([]byte, int, error) {
|
||||||
base := strings.TrimRight(cfg.BaseURL, "/")
|
base := strings.TrimRight(cfg.BaseURL, "/")
|
||||||
url := fmt.Sprintf("%s/api/v1%s", base, endpoint)
|
url := fmt.Sprintf("%s/api/v1%s", base, endpoint)
|
||||||
|
|
||||||
client := &http.Client{Timeout: 30 * time.Second}
|
client := &http.Client{Timeout: 30 * time.Second}
|
||||||
req, err := http.NewRequest(method, url, reqBody)
|
req, err := http.NewRequest(method, url, reqBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -29,7 +25,6 @@ func coolifyDo(method, endpoint string, reqBody io.Reader, contentType string, c
|
|||||||
if contentType != "" {
|
if contentType != "" {
|
||||||
req.Header.Set("Content-Type", contentType)
|
req.Header.Set("Content-Type", contentType)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
@@ -39,7 +34,6 @@ func coolifyDo(method, endpoint string, reqBody io.Reader, contentType string, c
|
|||||||
return body, resp.StatusCode, nil
|
return body, resp.StatusCode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// coolifyProxy resuelve config, aplica qs de la request y responde al frontend.
|
|
||||||
func coolifyProxy(c *fiber.Ctx, method, endpoint string) error {
|
func coolifyProxy(c *fiber.Ctx, method, endpoint string) error {
|
||||||
cfg, err := models.GetCoolifyConfig()
|
cfg, err := models.GetCoolifyConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -48,24 +42,20 @@ func coolifyProxy(c *fiber.Ctx, method, endpoint string) error {
|
|||||||
if !cfg.Activo {
|
if !cfg.Activo {
|
||||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "La integración Coolify está inactiva"})
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "La integración Coolify está inactiva"})
|
||||||
}
|
}
|
||||||
|
|
||||||
ep := endpoint
|
ep := endpoint
|
||||||
if qs := string(c.Request().URI().QueryString()); qs != "" {
|
if qs := string(c.Request().URI().QueryString()); qs != "" {
|
||||||
ep = endpoint + "?" + qs
|
ep = endpoint + "?" + qs
|
||||||
}
|
}
|
||||||
|
|
||||||
var bodyReader io.Reader
|
var bodyReader io.Reader
|
||||||
ct := ""
|
ct := ""
|
||||||
if raw := c.Body(); len(raw) > 0 {
|
if raw := c.Body(); len(raw) > 0 {
|
||||||
bodyReader = strings.NewReader(string(raw))
|
bodyReader = strings.NewReader(string(raw))
|
||||||
ct = c.Get("Content-Type", "application/json")
|
ct = c.Get("Content-Type", "application/json")
|
||||||
}
|
}
|
||||||
|
|
||||||
body, status, err := coolifyDo(method, ep, bodyReader, ct, cfg)
|
body, status, err := coolifyDo(method, ep, bodyReader, ct, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusBadGateway).JSON(fiber.Map{"error": err.Error()})
|
return c.Status(fiber.StatusBadGateway).JSON(fiber.Map{"error": err.Error()})
|
||||||
}
|
}
|
||||||
|
|
||||||
var result json.RawMessage
|
var result json.RawMessage
|
||||||
if err := json.Unmarshal(body, &result); err != nil {
|
if err := json.Unmarshal(body, &result); err != nil {
|
||||||
result = json.RawMessage(fmt.Sprintf(`{"raw":%q}`, string(body)))
|
result = json.RawMessage(fmt.Sprintf(`{"raw":%q}`, string(body)))
|
||||||
@@ -74,8 +64,6 @@ func coolifyProxy(c *fiber.Ctx, method, endpoint string) error {
|
|||||||
return c.JSON(result)
|
return c.JSON(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Página principal ─────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
func CoolifyIndex(c *fiber.Ctx) error {
|
func CoolifyIndex(c *fiber.Ctx) error {
|
||||||
cfg, _ := models.GetCoolifyConfig()
|
cfg, _ := models.GetCoolifyConfig()
|
||||||
return c.Render("coolify", fiber.Map{
|
return c.Render("coolify", fiber.Map{
|
||||||
@@ -85,8 +73,6 @@ func CoolifyIndex(c *fiber.Ctx) error {
|
|||||||
}, "layouts/main")
|
}, "layouts/main")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Configuración ────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
func CoolifyGetConfig(c *fiber.Ctx) error {
|
func CoolifyGetConfig(c *fiber.Ctx) error {
|
||||||
cfg, err := models.GetCoolifyConfig()
|
cfg, err := models.GetCoolifyConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -127,7 +113,6 @@ func CoolifySaveConfig(c *fiber.Ctx) error {
|
|||||||
return c.JSON(fiber.Map{"ok": true, "config": cfg})
|
return c.JSON(fiber.Map{"ok": true, "config": cfg})
|
||||||
}
|
}
|
||||||
|
|
||||||
// CoolifyTestConnection verifica conectividad con /health (no requiere auth).
|
|
||||||
func CoolifyTestConnection(c *fiber.Ctx) error {
|
func CoolifyTestConnection(c *fiber.Ctx) error {
|
||||||
cfg, err := models.GetCoolifyConfig()
|
cfg, err := models.GetCoolifyConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -149,165 +134,120 @@ func CoolifyTestConnection(c *fiber.Ctx) error {
|
|||||||
return c.JSON(result)
|
return c.JSON(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Applications ─────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
func CoolifyListApplications(c *fiber.Ctx) error {
|
func CoolifyListApplications(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/applications")
|
return coolifyProxy(c, http.MethodGet, "/applications")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyGetApplication(c *fiber.Ctx) error {
|
func CoolifyGetApplication(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/applications/"+c.Params("uuid"))
|
return coolifyProxy(c, http.MethodGet, "/applications/"+c.Params("uuid"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyApplicationLogs(c *fiber.Ctx) error {
|
func CoolifyApplicationLogs(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/applications/"+c.Params("uuid")+"/logs")
|
return coolifyProxy(c, http.MethodGet, "/applications/"+c.Params("uuid")+"/logs")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyApplicationEnvs(c *fiber.Ctx) error {
|
func CoolifyApplicationEnvs(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/applications/"+c.Params("uuid")+"/envs")
|
return coolifyProxy(c, http.MethodGet, "/applications/"+c.Params("uuid")+"/envs")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyApplicationEnvCreate(c *fiber.Ctx) error {
|
func CoolifyApplicationEnvCreate(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodPost, "/applications/"+c.Params("uuid")+"/envs")
|
return coolifyProxy(c, http.MethodPost, "/applications/"+c.Params("uuid")+"/envs")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyApplicationEnvUpdateBulk(c *fiber.Ctx) error {
|
func CoolifyApplicationEnvUpdateBulk(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodPatch, "/applications/"+c.Params("uuid")+"/envs")
|
return coolifyProxy(c, http.MethodPatch, "/applications/"+c.Params("uuid")+"/envs")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyApplicationEnvDelete(c *fiber.Ctx) error {
|
func CoolifyApplicationEnvDelete(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodDelete, "/applications/"+c.Params("uuid")+"/envs/"+c.Params("env_id"))
|
return coolifyProxy(c, http.MethodDelete, "/applications/"+c.Params("uuid")+"/envs/"+c.Params("env_id"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyApplicationStart(c *fiber.Ctx) error {
|
func CoolifyApplicationStart(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/applications/"+c.Params("uuid")+"/start")
|
return coolifyProxy(c, http.MethodGet, "/applications/"+c.Params("uuid")+"/start")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyApplicationStop(c *fiber.Ctx) error {
|
func CoolifyApplicationStop(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/applications/"+c.Params("uuid")+"/stop")
|
return coolifyProxy(c, http.MethodGet, "/applications/"+c.Params("uuid")+"/stop")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyApplicationRestart(c *fiber.Ctx) error {
|
func CoolifyApplicationRestart(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/applications/"+c.Params("uuid")+"/restart")
|
return coolifyProxy(c, http.MethodGet, "/applications/"+c.Params("uuid")+"/restart")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyApplicationDeployments(c *fiber.Ctx) error {
|
func CoolifyApplicationDeployments(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/applications/"+c.Params("uuid")+"/deployments")
|
return coolifyProxy(c, http.MethodGet, "/applications/"+c.Params("uuid")+"/deployments")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyApplicationDeploy(c *fiber.Ctx) error {
|
func CoolifyApplicationDeploy(c *fiber.Ctx) error {
|
||||||
// POST /api/v1/deploy?uuid={uuid}&force=false
|
|
||||||
return coolifyProxy(c, http.MethodPost, "/deploy")
|
return coolifyProxy(c, http.MethodPost, "/deploy")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Servers ──────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
func CoolifyListServers(c *fiber.Ctx) error {
|
func CoolifyListServers(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/servers")
|
return coolifyProxy(c, http.MethodGet, "/servers")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyGetServer(c *fiber.Ctx) error {
|
func CoolifyGetServer(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/servers/"+c.Params("uuid"))
|
return coolifyProxy(c, http.MethodGet, "/servers/"+c.Params("uuid"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyServerResources(c *fiber.Ctx) error {
|
func CoolifyServerResources(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/servers/"+c.Params("uuid")+"/resources")
|
return coolifyProxy(c, http.MethodGet, "/servers/"+c.Params("uuid")+"/resources")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyServerDomains(c *fiber.Ctx) error {
|
func CoolifyServerDomains(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/servers/"+c.Params("uuid")+"/domains")
|
return coolifyProxy(c, http.MethodGet, "/servers/"+c.Params("uuid")+"/domains")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyServerValidate(c *fiber.Ctx) error {
|
func CoolifyServerValidate(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/servers/"+c.Params("uuid")+"/validate")
|
return coolifyProxy(c, http.MethodGet, "/servers/"+c.Params("uuid")+"/validate")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Services ─────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
func CoolifyListServices(c *fiber.Ctx) error {
|
func CoolifyListServices(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/services")
|
return coolifyProxy(c, http.MethodGet, "/services")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyGetService(c *fiber.Ctx) error {
|
func CoolifyGetService(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/services/"+c.Params("uuid"))
|
return coolifyProxy(c, http.MethodGet, "/services/"+c.Params("uuid"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyServiceStart(c *fiber.Ctx) error {
|
func CoolifyServiceStart(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/services/"+c.Params("uuid")+"/start")
|
return coolifyProxy(c, http.MethodGet, "/services/"+c.Params("uuid")+"/start")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyServiceStop(c *fiber.Ctx) error {
|
func CoolifyServiceStop(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/services/"+c.Params("uuid")+"/stop")
|
return coolifyProxy(c, http.MethodGet, "/services/"+c.Params("uuid")+"/stop")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyServiceRestart(c *fiber.Ctx) error {
|
func CoolifyServiceRestart(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/services/"+c.Params("uuid")+"/restart")
|
return coolifyProxy(c, http.MethodGet, "/services/"+c.Params("uuid")+"/restart")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyServiceEnvs(c *fiber.Ctx) error {
|
func CoolifyServiceEnvs(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/services/"+c.Params("uuid")+"/envs")
|
return coolifyProxy(c, http.MethodGet, "/services/"+c.Params("uuid")+"/envs")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyServiceEnvUpdateBulk(c *fiber.Ctx) error {
|
func CoolifyServiceEnvUpdateBulk(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodPatch, "/services/"+c.Params("uuid")+"/envs")
|
return coolifyProxy(c, http.MethodPatch, "/services/"+c.Params("uuid")+"/envs")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Databases ────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
func CoolifyListDatabases(c *fiber.Ctx) error {
|
func CoolifyListDatabases(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/databases")
|
return coolifyProxy(c, http.MethodGet, "/databases")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyGetDatabase(c *fiber.Ctx) error {
|
func CoolifyGetDatabase(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/databases/"+c.Params("uuid"))
|
return coolifyProxy(c, http.MethodGet, "/databases/"+c.Params("uuid"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyDatabaseStart(c *fiber.Ctx) error {
|
func CoolifyDatabaseStart(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/databases/"+c.Params("uuid")+"/start")
|
return coolifyProxy(c, http.MethodGet, "/databases/"+c.Params("uuid")+"/start")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyDatabaseStop(c *fiber.Ctx) error {
|
func CoolifyDatabaseStop(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/databases/"+c.Params("uuid")+"/stop")
|
return coolifyProxy(c, http.MethodGet, "/databases/"+c.Params("uuid")+"/stop")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyDatabaseRestart(c *fiber.Ctx) error {
|
func CoolifyDatabaseRestart(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/databases/"+c.Params("uuid")+"/restart")
|
return coolifyProxy(c, http.MethodGet, "/databases/"+c.Params("uuid")+"/restart")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Projects ─────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
func CoolifyListProjects(c *fiber.Ctx) error {
|
func CoolifyListProjects(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/projects")
|
return coolifyProxy(c, http.MethodGet, "/projects")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyGetProject(c *fiber.Ctx) error {
|
func CoolifyGetProject(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/projects/"+c.Params("uuid"))
|
return coolifyProxy(c, http.MethodGet, "/projects/"+c.Params("uuid"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyProjectEnvironments(c *fiber.Ctx) error {
|
func CoolifyProjectEnvironments(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/projects/"+c.Params("uuid")+"/environments")
|
return coolifyProxy(c, http.MethodGet, "/projects/"+c.Params("uuid")+"/environments")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Deployments ──────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
func CoolifyListDeployments(c *fiber.Ctx) error {
|
func CoolifyListDeployments(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/deployments")
|
return coolifyProxy(c, http.MethodGet, "/deployments")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyGetDeployment(c *fiber.Ctx) error {
|
func CoolifyGetDeployment(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/deployments/"+c.Params("uuid"))
|
return coolifyProxy(c, http.MethodGet, "/deployments/"+c.Params("uuid"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Teams ────────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
func CoolifyListTeams(c *fiber.Ctx) error {
|
func CoolifyListTeams(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/teams")
|
return coolifyProxy(c, http.MethodGet, "/teams")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyCurrentTeam(c *fiber.Ctx) error {
|
func CoolifyCurrentTeam(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/teams/current")
|
return coolifyProxy(c, http.MethodGet, "/teams/current")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CoolifyTeamMembers(c *fiber.Ctx) error {
|
func CoolifyTeamMembers(c *fiber.Ctx) error {
|
||||||
return coolifyProxy(c, http.MethodGet, "/teams/current/members")
|
return coolifyProxy(c, http.MethodGet, "/teams/current/members")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user