2019-10-05 21:53:22 +05:00
|
|
|
package serverv1
|
|
|
|
|
|
|
|
import (
|
|
|
|
// stdlib
|
|
|
|
"net/http"
|
|
|
|
|
2019-10-07 18:21:26 +05:00
|
|
|
// local
|
2019-10-13 15:12:54 +05:00
|
|
|
"go.dev.pztrn.name/giredore/internal/configuration"
|
|
|
|
"go.dev.pztrn.name/giredore/internal/structs"
|
2019-10-07 18:21:26 +05:00
|
|
|
|
2019-10-05 21:53:22 +05:00
|
|
|
// other
|
|
|
|
"github.com/labstack/echo"
|
|
|
|
)
|
|
|
|
|
|
|
|
// This function responsible for getting runtime configuration.
|
|
|
|
func configurationGET(ec echo.Context) error {
|
2020-04-27 03:45:43 +05:00
|
|
|
return ec.JSON(http.StatusOK, configuration.Cfg.GetAllPackagesInfo())
|
2019-10-05 21:53:22 +05:00
|
|
|
}
|
2019-10-07 18:21:26 +05:00
|
|
|
|
|
|
|
func configurationAllowedIPsSET(ec echo.Context) error {
|
|
|
|
req := &structs.AllowedIPsSetRequest{}
|
|
|
|
if err := ec.Bind(req); err != nil {
|
|
|
|
log.Error().Err(err).Msg("Failed to parse allowed IPs set request")
|
|
|
|
return ec.JSON(http.StatusBadRequest, &structs.Reply{Status: structs.StatusFailure, Errors: []structs.Error{structs.ErrParsingAllowedIPsSetRequest}})
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug().Msgf("Got set allowed IPs request: %+v", req)
|
|
|
|
|
|
|
|
configuration.Cfg.SetAllowedIPs(req.AllowedIPs)
|
|
|
|
|
|
|
|
return ec.JSON(http.StatusOK, &structs.Reply{Status: structs.StatusSuccess})
|
|
|
|
}
|