2019-10-05 21:53:22 +05:00
|
|
|
package serverv1
|
|
|
|
|
|
|
|
import (
|
|
|
|
// stdlib
|
|
|
|
"net/http"
|
|
|
|
|
2019-10-07 18:21:26 +05:00
|
|
|
// local
|
|
|
|
"sources.dev.pztrn.name/pztrn/giredore/internal/configuration"
|
|
|
|
"sources.dev.pztrn.name/pztrn/giredore/internal/structs"
|
|
|
|
|
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 {
|
|
|
|
return ec.JSON(http.StatusOK, map[string]string{"result": "success"})
|
|
|
|
}
|
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})
|
|
|
|
}
|