2022-05-22 05:34:09 +00:00
|
|
|
package middlewares
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/portainer/portainer/api/http/errors"
|
2023-09-01 22:27:02 +00:00
|
|
|
httperror "github.com/portainer/portainer/pkg/libhttp/error"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2022-05-22 05:34:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// restrict functionality on demo environments
|
|
|
|
func RestrictDemoEnv(isDemo func() bool) mux.MiddlewareFunc {
|
|
|
|
return func(next http.Handler) http.Handler {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if !isDemo() {
|
|
|
|
next.ServeHTTP(w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
httperror.WriteError(w, http.StatusBadRequest, errors.ErrNotAvailableInDemo.Error(), errors.ErrNotAvailableInDemo)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|