2022-09-13 13:56:38 +00:00
|
|
|
package middlewares
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
httperror "github.com/portainer/libhttp/error"
|
|
|
|
"github.com/portainer/portainer/api/dataservices"
|
2023-02-09 04:17:46 +00:00
|
|
|
"github.com/portainer/portainer/pkg/featureflags"
|
2022-09-13 13:56:38 +00:00
|
|
|
)
|
|
|
|
|
2023-02-09 04:17:46 +00:00
|
|
|
func FeatureFlag(settingsService dataservices.SettingsService, feature featureflags.Feature) mux.MiddlewareFunc {
|
2022-09-13 13:56:38 +00:00
|
|
|
return func(next http.Handler) http.Handler {
|
|
|
|
return http.HandlerFunc(func(rw http.ResponseWriter, request *http.Request) {
|
2023-02-09 04:17:46 +00:00
|
|
|
enabled := featureflags.IsEnabled(feature)
|
2022-09-13 13:56:38 +00:00
|
|
|
|
|
|
|
if !enabled {
|
|
|
|
httperror.WriteError(rw, http.StatusForbidden, "This feature is not enabled", nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
next.ServeHTTP(rw, request)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|