|
@ -130,12 +130,17 @@ func UploadHandler(w http.ResponseWriter, r *http.Request, pipes []pipelines.IPi |
|
|
logrus.Info("Pipeline routes registered successfully") |
|
|
logrus.Info("Pipeline routes registered successfully") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func RegisterRoutes(r *mux.Router, pipelines []pipelines.IPipeline, storageProvider storage.IStorageProvider) { |
|
|
|
|
|
r.HandleFunc("/", IndexHandler).Methods("GET") |
|
|
|
|
|
r.HandleFunc("/upload", func(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
|
|
|
|
func RegisterRoutes(r *mux.Router, appSettings settings.Settings, pipelines []pipelines.IPipeline, storageProvider storage.IStorageProvider) { |
|
|
|
|
|
index := r.Methods(http.MethodGet).Subrouter() |
|
|
|
|
|
index.HandleFunc("/", IndexHandler) |
|
|
|
|
|
|
|
|
|
|
|
upload := r.Methods(http.MethodPost).Subrouter() |
|
|
|
|
|
upload.HandleFunc("/upload", func(w http.ResponseWriter, r *http.Request) { |
|
|
UploadHandler(w, r, pipelines, storageProvider) |
|
|
UploadHandler(w, r, pipelines, storageProvider) |
|
|
}).Methods("POST") |
|
|
|
|
|
r.HandleFunc("/pipelines/{pipeline}", func(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
pipeline := r.Methods(http.MethodGet).Subrouter() |
|
|
|
|
|
pipeline.HandleFunc("/pipelines/{pipeline}", func(w http.ResponseWriter, r *http.Request) { |
|
|
for _, pipeline := range pipelines { |
|
|
for _, pipeline := range pipelines { |
|
|
if pipeline.GetSlug() == mux.Vars(r)["pipeline"] { |
|
|
if pipeline.GetSlug() == mux.Vars(r)["pipeline"] { |
|
|
PipelineHandler(pipeline, storageProvider, w, r) |
|
|
PipelineHandler(pipeline, storageProvider, w, r) |
|
@ -144,7 +149,14 @@ func RegisterRoutes(r *mux.Router, pipelines []pipelines.IPipeline, storageProvi |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
w.WriteHeader(404) |
|
|
w.WriteHeader(404) |
|
|
}).Methods("GET") |
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
if appSettings.Authentication.Enabled { |
|
|
|
|
|
authMiddleware := middlewares.CreateAuthenticationMiddleware(appSettings.Authentication.Token) |
|
|
|
|
|
|
|
|
|
|
|
upload.Use(authMiddleware.Middleware) |
|
|
|
|
|
pipeline.Use(authMiddleware.Middleware) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func main() { |
|
|
func main() { |
|
@ -177,12 +189,6 @@ func main() { |
|
|
|
|
|
|
|
|
r := mux.NewRouter() |
|
|
r := mux.NewRouter() |
|
|
|
|
|
|
|
|
if appSettings.Authentication.Enabled { |
|
|
|
|
|
authMiddleware := middlewares.CreateAuthenticationMiddleware(appSettings.Authentication.Token) |
|
|
|
|
|
|
|
|
|
|
|
r.Use(authMiddleware.Middleware) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if appSettings.RateLimiter.Enabled { |
|
|
if appSettings.RateLimiter.Enabled { |
|
|
rateLimiterMiddleware, err := middlewares.CreateRateLimiterMiddleware(appSettings.RateLimiter.RequestsPerMinute, appSettings.RateLimiter.AllowedBurst) |
|
|
rateLimiterMiddleware, err := middlewares.CreateRateLimiterMiddleware(appSettings.RateLimiter.RequestsPerMinute, appSettings.RateLimiter.AllowedBurst) |
|
|
if err != nil { |
|
|
if err != nil { |
|
@ -192,9 +198,7 @@ func main() { |
|
|
r.Use(rateLimiterMiddleware.Middleware) |
|
|
r.Use(rateLimiterMiddleware.Middleware) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
r.HandleFunc("/", IndexHandler) |
|
|
|
|
|
|
|
|
|
|
|
RegisterRoutes(r, pipes, storageProvider) |
|
|
|
|
|
|
|
|
RegisterRoutes(r, appSettings, pipes, storageProvider) |
|
|
|
|
|
|
|
|
logrus.Info("Lithium started, listening for requests...") |
|
|
logrus.Info("Lithium started, listening for requests...") |
|
|
|
|
|
|
|
|