mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-02 11:39:06 +02:00
Merge remote-tracking branch 'origin/main' into fix_debug_upload_url_from_mgmt
# Conflicts: # management/server/activity/codes.go # management/server/store/sql_store.go # management/server/store/sql_store_test.go # upload-server/server/server.go
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/google/uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/netbirdio/netbird/management/server/http/middleware"
|
||||
"github.com/netbirdio/netbird/upload-server/types"
|
||||
)
|
||||
|
||||
@@ -34,6 +35,7 @@ const (
|
||||
|
||||
type Server struct {
|
||||
srv *http.Server
|
||||
limiter *middleware.APIRateLimiter
|
||||
certFile string
|
||||
keyFile string
|
||||
}
|
||||
@@ -45,7 +47,7 @@ func NewServer() *Server {
|
||||
address = "0.0.0.0:8080"
|
||||
}
|
||||
mux := http.NewServeMux()
|
||||
err := configureMux(mux)
|
||||
limiter, err := configureMux(mux)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to configure server: %v", err)
|
||||
}
|
||||
@@ -73,6 +75,7 @@ func NewServer() *Server {
|
||||
ReadTimeout: readTimeout,
|
||||
IdleTimeout: 60 * time.Second,
|
||||
},
|
||||
limiter: limiter,
|
||||
certFile: certFile,
|
||||
keyFile: keyFile,
|
||||
}
|
||||
@@ -89,6 +92,9 @@ func (s *Server) Start() error {
|
||||
}
|
||||
|
||||
func (s *Server) Stop() error {
|
||||
if s.limiter != nil {
|
||||
s.limiter.Stop()
|
||||
}
|
||||
if s.srv != nil {
|
||||
log.Infof("Stopping upload server on %s", s.srv.Addr)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
@@ -98,13 +104,14 @@ func (s *Server) Stop() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func configureMux(mux *http.ServeMux) error {
|
||||
func configureMux(mux *http.ServeMux) (*middleware.APIRateLimiter, error) {
|
||||
limiter := newRateLimiter()
|
||||
|
||||
_, ok := os.LookupEnv(bucketVar)
|
||||
if ok {
|
||||
return configureS3Handlers(mux)
|
||||
} else {
|
||||
return configureLocalHandlers(mux)
|
||||
return limiter, configureS3Handlers(mux, limiter)
|
||||
}
|
||||
return limiter, configureLocalHandlers(mux, limiter)
|
||||
}
|
||||
|
||||
func getObjectKey(w http.ResponseWriter, r *http.Request) string {
|
||||
|
||||
Reference in New Issue
Block a user