You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/api/http/middlewares/featureflag.go

26 lines
680 B

package middlewares
import (
"net/http"
"github.com/gorilla/mux"
httperror "github.com/portainer/libhttp/error"
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/dataservices"
)
func FeatureFlag(settingsService dataservices.SettingsService, feature portainer.Feature) mux.MiddlewareFunc {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, request *http.Request) {
enabled := settingsService.IsFeatureFlagEnabled(feature)
if !enabled {
httperror.WriteError(rw, http.StatusForbidden, "This feature is not enabled", nil)
return
}
next.ServeHTTP(rw, request)
})
}
}