github.com/cozy/cozy-stack@v0.0.0-20240603063001-31110fa4cae1/web/instances/debug.go (about)

     1  package instances
     2  
     3  import (
     4  	"errors"
     5  	"net/http"
     6  	"time"
     7  
     8  	"github.com/cozy/cozy-stack/pkg/jsonapi"
     9  	"github.com/cozy/cozy-stack/pkg/logger"
    10  	"github.com/labstack/echo/v4"
    11  )
    12  
    13  func getDebug(c echo.Context) error {
    14  	domain := c.Param("domain")
    15  	until := logger.DebugExpiration(domain)
    16  	if until == nil {
    17  		return jsonapi.NotFound(errors.New("Debug is disabled on this domain"))
    18  	}
    19  	res := map[string]interface{}{domain: true, "until": until}
    20  	return c.JSON(http.StatusOK, res)
    21  }
    22  
    23  func enableDebug(c echo.Context) error {
    24  	domain := c.Param("domain")
    25  	ttl, err := time.ParseDuration(c.QueryParam("TTL"))
    26  	if err != nil {
    27  		ttl = 24 * time.Hour
    28  	}
    29  	if err := logger.AddDebugDomain(domain, ttl); err != nil {
    30  		return wrapError(err)
    31  	}
    32  	return c.NoContent(http.StatusNoContent)
    33  }
    34  
    35  func disableDebug(c echo.Context) error {
    36  	domain := c.Param("domain")
    37  	if err := logger.RemoveDebugDomain(domain); err != nil {
    38  		return wrapError(err)
    39  	}
    40  	return c.NoContent(http.StatusNoContent)
    41  }