diff --git a/api/http/error/error.go b/api/http/error/error.go deleted file mode 100644 index 244397fdf..000000000 --- a/api/http/error/error.go +++ /dev/null @@ -1,42 +0,0 @@ -package error - -import ( - "encoding/json" - "log" - "net/http" -) - -type ( - // LoggerHandler defines a HTTP handler that includes a HandlerError return pointer - LoggerHandler func(http.ResponseWriter, *http.Request) *HandlerError - // HandlerError represents an error raised inside a HTTP handler - HandlerError struct { - StatusCode int - Message string - Err error - } - errorResponse struct { - Err string `json:"err,omitempty"` - Details string `json:"details,omitempty"` - } -) - -func (handler LoggerHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) { - err := handler(rw, r) - if err != nil { - writeErrorResponse(rw, err) - } -} - -func writeErrorResponse(rw http.ResponseWriter, err *HandlerError) { - log.Printf("http error: %s (err=%s) (code=%d)\n", err.Message, err.Err, err.StatusCode) - rw.Header().Set("Content-Type", "application/json") - rw.WriteHeader(err.StatusCode) - json.NewEncoder(rw).Encode(&errorResponse{Err: err.Message, Details: err.Err.Error()}) -} - -// WriteError is a convenience function that creates a new HandlerError before calling writeErrorResponse. -// For use outside of the standard http handlers. -func WriteError(rw http.ResponseWriter, code int, message string, err error) { - writeErrorResponse(rw, &HandlerError{code, message, err}) -} diff --git a/api/http/handler/auth/authenticate.go b/api/http/handler/auth/authenticate.go index cf928357b..d5562edd3 100644 --- a/api/http/handler/auth/authenticate.go +++ b/api/http/handler/auth/authenticate.go @@ -6,10 +6,10 @@ import ( "strings" "github.com/asaskevich/govalidator" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) type authenticatePayload struct { diff --git a/api/http/handler/auth/handler.go b/api/http/handler/auth/handler.go index 87be85429..1f0769e08 100644 --- a/api/http/handler/auth/handler.go +++ b/api/http/handler/auth/handler.go @@ -4,8 +4,8 @@ import ( "net/http" "github.com/gorilla/mux" + httperror "github.com/portainer/libhttp/error" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/dockerhub/dockerhub_inspect.go b/api/http/handler/dockerhub/dockerhub_inspect.go index 25be6617c..b149a2a35 100644 --- a/api/http/handler/dockerhub/dockerhub_inspect.go +++ b/api/http/handler/dockerhub/dockerhub_inspect.go @@ -3,8 +3,8 @@ package dockerhub import ( "net/http" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/response" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/response" ) // GET request on /api/dockerhub diff --git a/api/http/handler/dockerhub/dockerhub_update.go b/api/http/handler/dockerhub/dockerhub_update.go index 7bd37bce5..69d82ee50 100644 --- a/api/http/handler/dockerhub/dockerhub_update.go +++ b/api/http/handler/dockerhub/dockerhub_update.go @@ -4,10 +4,10 @@ import ( "net/http" "github.com/asaskevich/govalidator" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) type dockerhubUpdatePayload struct { diff --git a/api/http/handler/dockerhub/handler.go b/api/http/handler/dockerhub/handler.go index cd2f5ae50..9ad93232d 100644 --- a/api/http/handler/dockerhub/handler.go +++ b/api/http/handler/dockerhub/handler.go @@ -4,8 +4,8 @@ import ( "net/http" "github.com/gorilla/mux" + httperror "github.com/portainer/libhttp/error" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/endpointgroups/endpointgroup_create.go b/api/http/handler/endpointgroups/endpointgroup_create.go index e2d7bd0c0..cc7a23054 100644 --- a/api/http/handler/endpointgroups/endpointgroup_create.go +++ b/api/http/handler/endpointgroups/endpointgroup_create.go @@ -4,10 +4,10 @@ import ( "net/http" "github.com/asaskevich/govalidator" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) type endpointGroupCreatePayload struct { diff --git a/api/http/handler/endpointgroups/endpointgroup_delete.go b/api/http/handler/endpointgroups/endpointgroup_delete.go index 01123d850..b436b4f2f 100644 --- a/api/http/handler/endpointgroups/endpointgroup_delete.go +++ b/api/http/handler/endpointgroups/endpointgroup_delete.go @@ -3,10 +3,10 @@ package endpointgroups import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) // DELETE request on /api/endpoint_groups/:id diff --git a/api/http/handler/endpointgroups/endpointgroup_inspect.go b/api/http/handler/endpointgroups/endpointgroup_inspect.go index 168d8cb8b..46a6895e8 100644 --- a/api/http/handler/endpointgroups/endpointgroup_inspect.go +++ b/api/http/handler/endpointgroups/endpointgroup_inspect.go @@ -3,10 +3,10 @@ package endpointgroups import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) // GET request on /api/endpoint_groups/:id diff --git a/api/http/handler/endpointgroups/endpointgroup_list.go b/api/http/handler/endpointgroups/endpointgroup_list.go index fa7a35ec4..7acb696a8 100644 --- a/api/http/handler/endpointgroups/endpointgroup_list.go +++ b/api/http/handler/endpointgroups/endpointgroup_list.go @@ -3,8 +3,8 @@ package endpointgroups import ( "net/http" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/response" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/endpointgroups/endpointgroup_update.go b/api/http/handler/endpointgroups/endpointgroup_update.go index ee31e3066..ec24b801f 100644 --- a/api/http/handler/endpointgroups/endpointgroup_update.go +++ b/api/http/handler/endpointgroups/endpointgroup_update.go @@ -3,10 +3,10 @@ package endpointgroups import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) type endpointGroupUpdatePayload struct { diff --git a/api/http/handler/endpointgroups/endpointgroup_update_access.go b/api/http/handler/endpointgroups/endpointgroup_update_access.go index 7a3b3038e..6e859a4df 100644 --- a/api/http/handler/endpointgroups/endpointgroup_update_access.go +++ b/api/http/handler/endpointgroups/endpointgroup_update_access.go @@ -3,10 +3,10 @@ package endpointgroups import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) type endpointGroupUpdateAccessPayload struct { diff --git a/api/http/handler/endpointgroups/handler.go b/api/http/handler/endpointgroups/handler.go index f31a40a27..3b731e911 100644 --- a/api/http/handler/endpointgroups/handler.go +++ b/api/http/handler/endpointgroups/handler.go @@ -4,8 +4,8 @@ import ( "net/http" "github.com/gorilla/mux" + httperror "github.com/portainer/libhttp/error" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/endpointproxy/handler.go b/api/http/handler/endpointproxy/handler.go index cd17e0733..eaef36b1b 100644 --- a/api/http/handler/endpointproxy/handler.go +++ b/api/http/handler/endpointproxy/handler.go @@ -2,8 +2,8 @@ package endpointproxy import ( "github.com/gorilla/mux" + httperror "github.com/portainer/libhttp/error" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/proxy" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/endpointproxy/proxy_azure.go b/api/http/handler/endpointproxy/proxy_azure.go index dc46bfb3f..dcbe96f4b 100644 --- a/api/http/handler/endpointproxy/proxy_azure.go +++ b/api/http/handler/endpointproxy/proxy_azure.go @@ -3,9 +3,9 @@ package endpointproxy import ( "strconv" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" "net/http" ) diff --git a/api/http/handler/endpointproxy/proxy_docker.go b/api/http/handler/endpointproxy/proxy_docker.go index 01a56e017..f03ca8e67 100644 --- a/api/http/handler/endpointproxy/proxy_docker.go +++ b/api/http/handler/endpointproxy/proxy_docker.go @@ -3,9 +3,9 @@ package endpointproxy import ( "strconv" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" "net/http" ) diff --git a/api/http/handler/endpointproxy/proxy_storidge.go b/api/http/handler/endpointproxy/proxy_storidge.go index a582b561d..86375f091 100644 --- a/api/http/handler/endpointproxy/proxy_storidge.go +++ b/api/http/handler/endpointproxy/proxy_storidge.go @@ -3,9 +3,9 @@ package endpointproxy import ( "strconv" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" "net/http" ) diff --git a/api/http/handler/endpoints/endpoint_create.go b/api/http/handler/endpoints/endpoint_create.go index 277f6bd0f..a3eeeb114 100644 --- a/api/http/handler/endpoints/endpoint_create.go +++ b/api/http/handler/endpoints/endpoint_create.go @@ -6,12 +6,12 @@ import ( "runtime" "strconv" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" "github.com/portainer/portainer/crypto" "github.com/portainer/portainer/http/client" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) type endpointCreatePayload struct { @@ -71,7 +71,7 @@ func (payload *endpointCreatePayload) Validate(r *http.Request) error { payload.TLSSkipClientVerify = skipTLSClientVerification if !payload.TLSSkipVerify { - caCert, err := request.RetrieveMultiPartFormFile(r, "TLSCACertFile") + caCert, _, err := request.RetrieveMultiPartFormFile(r, "TLSCACertFile") if err != nil { return portainer.Error("Invalid CA certificate file. Ensure that the file is uploaded correctly") } @@ -79,13 +79,13 @@ func (payload *endpointCreatePayload) Validate(r *http.Request) error { } if !payload.TLSSkipClientVerify { - cert, err := request.RetrieveMultiPartFormFile(r, "TLSCertFile") + cert, _, err := request.RetrieveMultiPartFormFile(r, "TLSCertFile") if err != nil { return portainer.Error("Invalid certificate file. Ensure that the file is uploaded correctly") } payload.TLSCertFile = cert - key, err := request.RetrieveMultiPartFormFile(r, "TLSKeyFile") + key, _, err := request.RetrieveMultiPartFormFile(r, "TLSKeyFile") if err != nil { return portainer.Error("Invalid key file. Ensure that the file is uploaded correctly") } diff --git a/api/http/handler/endpoints/endpoint_delete.go b/api/http/handler/endpoints/endpoint_delete.go index 40f18f348..865c2055b 100644 --- a/api/http/handler/endpoints/endpoint_delete.go +++ b/api/http/handler/endpoints/endpoint_delete.go @@ -4,10 +4,10 @@ import ( "net/http" "strconv" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) // DELETE request on /api/endpoints/:id diff --git a/api/http/handler/endpoints/endpoint_extension_add.go b/api/http/handler/endpoints/endpoint_extension_add.go index 009083190..9a9eebbda 100644 --- a/api/http/handler/endpoints/endpoint_extension_add.go +++ b/api/http/handler/endpoints/endpoint_extension_add.go @@ -4,10 +4,10 @@ import ( "net/http" "github.com/asaskevich/govalidator" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) type endpointExtensionAddPayload struct { diff --git a/api/http/handler/endpoints/endpoint_extension_remove.go b/api/http/handler/endpoints/endpoint_extension_remove.go index 2e238a89e..8b265dc6c 100644 --- a/api/http/handler/endpoints/endpoint_extension_remove.go +++ b/api/http/handler/endpoints/endpoint_extension_remove.go @@ -3,10 +3,10 @@ package endpoints import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) // DELETE request on /api/endpoints/:id/extensions/:extensionType diff --git a/api/http/handler/endpoints/endpoint_inspect.go b/api/http/handler/endpoints/endpoint_inspect.go index e382b3f16..dd0d3485b 100644 --- a/api/http/handler/endpoints/endpoint_inspect.go +++ b/api/http/handler/endpoints/endpoint_inspect.go @@ -3,10 +3,10 @@ package endpoints import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) // GET request on /api/endpoints/:id diff --git a/api/http/handler/endpoints/endpoint_list.go b/api/http/handler/endpoints/endpoint_list.go index 3348c630e..5c1436ac9 100644 --- a/api/http/handler/endpoints/endpoint_list.go +++ b/api/http/handler/endpoints/endpoint_list.go @@ -3,8 +3,8 @@ package endpoints import ( "net/http" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/response" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/endpoints/endpoint_snapshot.go b/api/http/handler/endpoints/endpoint_snapshot.go index 51a18293e..720f4c072 100644 --- a/api/http/handler/endpoints/endpoint_snapshot.go +++ b/api/http/handler/endpoints/endpoint_snapshot.go @@ -4,9 +4,9 @@ import ( "log" "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/response" ) // POST request on /api/endpoints/snapshot diff --git a/api/http/handler/endpoints/endpoint_update.go b/api/http/handler/endpoints/endpoint_update.go index 769267449..5244cdc98 100644 --- a/api/http/handler/endpoints/endpoint_update.go +++ b/api/http/handler/endpoints/endpoint_update.go @@ -4,11 +4,11 @@ import ( "net/http" "strconv" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" "github.com/portainer/portainer/http/client" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) type endpointUpdatePayload struct { diff --git a/api/http/handler/endpoints/endpoint_update_access.go b/api/http/handler/endpoints/endpoint_update_access.go index bedf559ff..47a7d414b 100644 --- a/api/http/handler/endpoints/endpoint_update_access.go +++ b/api/http/handler/endpoints/endpoint_update_access.go @@ -3,10 +3,10 @@ package endpoints import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) type endpointUpdateAccessPayload struct { diff --git a/api/http/handler/endpoints/handler.go b/api/http/handler/endpoints/handler.go index fc1bc1e6c..779cd9390 100644 --- a/api/http/handler/endpoints/handler.go +++ b/api/http/handler/endpoints/handler.go @@ -1,8 +1,8 @@ package endpoints import ( + httperror "github.com/portainer/libhttp/error" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/proxy" "github.com/portainer/portainer/http/security" diff --git a/api/http/handler/motd/motd.go b/api/http/handler/motd/motd.go index b2599be2d..fbe8b5acd 100644 --- a/api/http/handler/motd/motd.go +++ b/api/http/handler/motd/motd.go @@ -3,10 +3,10 @@ package motd import ( "net/http" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" "github.com/portainer/portainer/crypto" "github.com/portainer/portainer/http/client" - "github.com/portainer/portainer/http/response" ) type motdResponse struct { diff --git a/api/http/handler/registries/handler.go b/api/http/handler/registries/handler.go index 7a21561db..33a161932 100644 --- a/api/http/handler/registries/handler.go +++ b/api/http/handler/registries/handler.go @@ -1,8 +1,8 @@ package registries import ( + httperror "github.com/portainer/libhttp/error" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/security" "net/http" diff --git a/api/http/handler/registries/registry_create.go b/api/http/handler/registries/registry_create.go index 781f172bf..ad4acb58a 100644 --- a/api/http/handler/registries/registry_create.go +++ b/api/http/handler/registries/registry_create.go @@ -4,10 +4,10 @@ import ( "net/http" "github.com/asaskevich/govalidator" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) type registryCreatePayload struct { diff --git a/api/http/handler/registries/registry_delete.go b/api/http/handler/registries/registry_delete.go index 2e968539b..ac463af5f 100644 --- a/api/http/handler/registries/registry_delete.go +++ b/api/http/handler/registries/registry_delete.go @@ -3,10 +3,10 @@ package registries import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) // DELETE request on /api/registries/:id diff --git a/api/http/handler/registries/registry_inspect.go b/api/http/handler/registries/registry_inspect.go index a60f24288..96cdf84ac 100644 --- a/api/http/handler/registries/registry_inspect.go +++ b/api/http/handler/registries/registry_inspect.go @@ -3,10 +3,10 @@ package registries import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) // GET request on /api/registries/:id diff --git a/api/http/handler/registries/registry_list.go b/api/http/handler/registries/registry_list.go index 9986ce820..7f75427cc 100644 --- a/api/http/handler/registries/registry_list.go +++ b/api/http/handler/registries/registry_list.go @@ -3,8 +3,8 @@ package registries import ( "net/http" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/response" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/registries/registry_update.go b/api/http/handler/registries/registry_update.go index 1a3743fb5..cd3a7ae67 100644 --- a/api/http/handler/registries/registry_update.go +++ b/api/http/handler/registries/registry_update.go @@ -4,10 +4,10 @@ import ( "net/http" "github.com/asaskevich/govalidator" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) type registryUpdatePayload struct { diff --git a/api/http/handler/registries/registry_update_access.go b/api/http/handler/registries/registry_update_access.go index a43ccb2f9..77f6fe08e 100644 --- a/api/http/handler/registries/registry_update_access.go +++ b/api/http/handler/registries/registry_update_access.go @@ -3,10 +3,10 @@ package registries import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) type registryUpdateAccessPayload struct { diff --git a/api/http/handler/resourcecontrols/handler.go b/api/http/handler/resourcecontrols/handler.go index 4ad474f6b..60757ef28 100644 --- a/api/http/handler/resourcecontrols/handler.go +++ b/api/http/handler/resourcecontrols/handler.go @@ -4,8 +4,8 @@ import ( "net/http" "github.com/gorilla/mux" + httperror "github.com/portainer/libhttp/error" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/resourcecontrols/resourcecontrol_create.go b/api/http/handler/resourcecontrols/resourcecontrol_create.go index 10bde9a4f..97c3d5ef1 100644 --- a/api/http/handler/resourcecontrols/resourcecontrol_create.go +++ b/api/http/handler/resourcecontrols/resourcecontrol_create.go @@ -4,10 +4,10 @@ import ( "net/http" "github.com/asaskevich/govalidator" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/resourcecontrols/resourcecontrol_delete.go b/api/http/handler/resourcecontrols/resourcecontrol_delete.go index 48fd8a972..04ba8d5d4 100644 --- a/api/http/handler/resourcecontrols/resourcecontrol_delete.go +++ b/api/http/handler/resourcecontrols/resourcecontrol_delete.go @@ -3,10 +3,10 @@ package resourcecontrols import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/resourcecontrols/resourcecontrol_update.go b/api/http/handler/resourcecontrols/resourcecontrol_update.go index 69299fcee..c46247c5d 100644 --- a/api/http/handler/resourcecontrols/resourcecontrol_update.go +++ b/api/http/handler/resourcecontrols/resourcecontrol_update.go @@ -3,10 +3,10 @@ package resourcecontrols import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/settings/handler.go b/api/http/handler/settings/handler.go index 58c020877..9440aedd5 100644 --- a/api/http/handler/settings/handler.go +++ b/api/http/handler/settings/handler.go @@ -4,8 +4,8 @@ import ( "net/http" "github.com/gorilla/mux" + httperror "github.com/portainer/libhttp/error" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/settings/settings_inspect.go b/api/http/handler/settings/settings_inspect.go index 48da08612..c922e1f47 100644 --- a/api/http/handler/settings/settings_inspect.go +++ b/api/http/handler/settings/settings_inspect.go @@ -3,8 +3,8 @@ package settings import ( "net/http" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/response" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/response" ) // GET request on /api/settings diff --git a/api/http/handler/settings/settings_ldap_check.go b/api/http/handler/settings/settings_ldap_check.go index 80d058e33..a8466e285 100644 --- a/api/http/handler/settings/settings_ldap_check.go +++ b/api/http/handler/settings/settings_ldap_check.go @@ -3,11 +3,11 @@ package settings import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" "github.com/portainer/portainer/filesystem" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) type settingsLDAPCheckPayload struct { diff --git a/api/http/handler/settings/settings_public.go b/api/http/handler/settings/settings_public.go index 07d9c7d75..549cf999e 100644 --- a/api/http/handler/settings/settings_public.go +++ b/api/http/handler/settings/settings_public.go @@ -3,9 +3,9 @@ package settings import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/response" ) type publicSettingsResponse struct { diff --git a/api/http/handler/settings/settings_update.go b/api/http/handler/settings/settings_update.go index 6c171917b..18513931f 100644 --- a/api/http/handler/settings/settings_update.go +++ b/api/http/handler/settings/settings_update.go @@ -4,11 +4,11 @@ import ( "net/http" "github.com/asaskevich/govalidator" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" "github.com/portainer/portainer/filesystem" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) type settingsUpdatePayload struct { diff --git a/api/http/handler/stacks/create_compose_stack.go b/api/http/handler/stacks/create_compose_stack.go index a343c96fa..a6a8ddcfd 100644 --- a/api/http/handler/stacks/create_compose_stack.go +++ b/api/http/handler/stacks/create_compose_stack.go @@ -6,11 +6,11 @@ import ( "strings" "github.com/asaskevich/govalidator" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" "github.com/portainer/portainer/filesystem" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) @@ -194,7 +194,7 @@ func (payload *composeStackFromFileUploadPayload) Validate(r *http.Request) erro } payload.Name = name - composeFileContent, err := request.RetrieveMultiPartFormFile(r, "file") + composeFileContent, _, err := request.RetrieveMultiPartFormFile(r, "file") if err != nil { return portainer.Error("Invalid Compose file. Ensure that the Compose file is uploaded correctly") } diff --git a/api/http/handler/stacks/create_swarm_stack.go b/api/http/handler/stacks/create_swarm_stack.go index 87c94e6ef..017122026 100644 --- a/api/http/handler/stacks/create_swarm_stack.go +++ b/api/http/handler/stacks/create_swarm_stack.go @@ -6,11 +6,11 @@ import ( "strings" "github.com/asaskevich/govalidator" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" "github.com/portainer/portainer/filesystem" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) @@ -211,7 +211,7 @@ func (payload *swarmStackFromFileUploadPayload) Validate(r *http.Request) error } payload.SwarmID = swarmID - composeFileContent, err := request.RetrieveMultiPartFormFile(r, "file") + composeFileContent, _, err := request.RetrieveMultiPartFormFile(r, "file") if err != nil { return portainer.Error("Invalid Compose file. Ensure that the Compose file is uploaded correctly") } diff --git a/api/http/handler/stacks/handler.go b/api/http/handler/stacks/handler.go index ba231ebfe..7f2fd4bc0 100644 --- a/api/http/handler/stacks/handler.go +++ b/api/http/handler/stacks/handler.go @@ -5,8 +5,8 @@ import ( "sync" "github.com/gorilla/mux" + httperror "github.com/portainer/libhttp/error" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/stacks/stack_create.go b/api/http/handler/stacks/stack_create.go index c0b9d9ce0..0fe7e07ad 100644 --- a/api/http/handler/stacks/stack_create.go +++ b/api/http/handler/stacks/stack_create.go @@ -1,12 +1,13 @@ package stacks import ( + "errors" "log" "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" ) func (handler *Handler) cleanUp(stack *portainer.Stack, doCleanUp *bool) error { @@ -57,7 +58,7 @@ func (handler *Handler) stackCreate(w http.ResponseWriter, r *http.Request) *htt return handler.createComposeStack(w, r, method, endpoint) } - return &httperror.HandlerError{http.StatusBadRequest, "Invalid value for query parameter: type. Value must be one of: 1 (Swarm stack) or 2 (Compose stack)", request.ErrInvalidQueryParameter} + return &httperror.HandlerError{http.StatusBadRequest, "Invalid value for query parameter: type. Value must be one of: 1 (Swarm stack) or 2 (Compose stack)", errors.New(request.ErrInvalidQueryParameter)} } func (handler *Handler) createComposeStack(w http.ResponseWriter, r *http.Request, method string, endpoint *portainer.Endpoint) *httperror.HandlerError { @@ -71,7 +72,7 @@ func (handler *Handler) createComposeStack(w http.ResponseWriter, r *http.Reques return handler.createComposeStackFromFileUpload(w, r, endpoint) } - return &httperror.HandlerError{http.StatusBadRequest, "Invalid value for query parameter: method. Value must be one of: string, repository or file", request.ErrInvalidQueryParameter} + return &httperror.HandlerError{http.StatusBadRequest, "Invalid value for query parameter: method. Value must be one of: string, repository or file", errors.New(request.ErrInvalidQueryParameter)} } func (handler *Handler) createSwarmStack(w http.ResponseWriter, r *http.Request, method string, endpoint *portainer.Endpoint) *httperror.HandlerError { @@ -84,5 +85,5 @@ func (handler *Handler) createSwarmStack(w http.ResponseWriter, r *http.Request, return handler.createSwarmStackFromFileUpload(w, r, endpoint) } - return &httperror.HandlerError{http.StatusBadRequest, "Invalid value for query parameter: method. Value must be one of: string, repository or file", request.ErrInvalidQueryParameter} + return &httperror.HandlerError{http.StatusBadRequest, "Invalid value for query parameter: method. Value must be one of: string, repository or file", errors.New(request.ErrInvalidQueryParameter)} } diff --git a/api/http/handler/stacks/stack_delete.go b/api/http/handler/stacks/stack_delete.go index f481f808a..8f8fc25e8 100644 --- a/api/http/handler/stacks/stack_delete.go +++ b/api/http/handler/stacks/stack_delete.go @@ -4,11 +4,11 @@ import ( "net/http" "strconv" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/proxy" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/stacks/stack_file.go b/api/http/handler/stacks/stack_file.go index b86888a37..b0b247cef 100644 --- a/api/http/handler/stacks/stack_file.go +++ b/api/http/handler/stacks/stack_file.go @@ -4,11 +4,11 @@ import ( "net/http" "path" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/proxy" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/stacks/stack_inspect.go b/api/http/handler/stacks/stack_inspect.go index 380482149..e5377f654 100644 --- a/api/http/handler/stacks/stack_inspect.go +++ b/api/http/handler/stacks/stack_inspect.go @@ -3,11 +3,11 @@ package stacks import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/proxy" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/stacks/stack_list.go b/api/http/handler/stacks/stack_list.go index fc4732e06..337b204a7 100644 --- a/api/http/handler/stacks/stack_list.go +++ b/api/http/handler/stacks/stack_list.go @@ -3,11 +3,11 @@ package stacks import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/proxy" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/stacks/stack_migrate.go b/api/http/handler/stacks/stack_migrate.go index b6fed5a96..8a0ec0c69 100644 --- a/api/http/handler/stacks/stack_migrate.go +++ b/api/http/handler/stacks/stack_migrate.go @@ -3,11 +3,11 @@ package stacks import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/proxy" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/stacks/stack_update.go b/api/http/handler/stacks/stack_update.go index 456612249..03999a557 100644 --- a/api/http/handler/stacks/stack_update.go +++ b/api/http/handler/stacks/stack_update.go @@ -5,11 +5,11 @@ import ( "strconv" "github.com/asaskevich/govalidator" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/proxy" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/status/handler.go b/api/http/handler/status/handler.go index 692c64130..4d26fcd3a 100644 --- a/api/http/handler/status/handler.go +++ b/api/http/handler/status/handler.go @@ -4,8 +4,8 @@ import ( "net/http" "github.com/gorilla/mux" + httperror "github.com/portainer/libhttp/error" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/status/status_inspect.go b/api/http/handler/status/status_inspect.go index 93d379179..1892ddd7d 100644 --- a/api/http/handler/status/status_inspect.go +++ b/api/http/handler/status/status_inspect.go @@ -3,8 +3,8 @@ package status import ( "net/http" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/response" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/response" ) // GET request on /api/status diff --git a/api/http/handler/tags/handler.go b/api/http/handler/tags/handler.go index a700f7c3e..b38bd28f3 100644 --- a/api/http/handler/tags/handler.go +++ b/api/http/handler/tags/handler.go @@ -4,8 +4,8 @@ import ( "net/http" "github.com/gorilla/mux" + httperror "github.com/portainer/libhttp/error" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/tags/tag_create.go b/api/http/handler/tags/tag_create.go index f75c050b9..50b9261ba 100644 --- a/api/http/handler/tags/tag_create.go +++ b/api/http/handler/tags/tag_create.go @@ -4,10 +4,10 @@ import ( "net/http" "github.com/asaskevich/govalidator" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) type tagCreatePayload struct { diff --git a/api/http/handler/tags/tag_delete.go b/api/http/handler/tags/tag_delete.go index eed7f6410..e74b5ef12 100644 --- a/api/http/handler/tags/tag_delete.go +++ b/api/http/handler/tags/tag_delete.go @@ -3,10 +3,10 @@ package tags import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) // DELETE request on /api/tags/:id diff --git a/api/http/handler/tags/tag_list.go b/api/http/handler/tags/tag_list.go index b572add68..a19aa48e7 100644 --- a/api/http/handler/tags/tag_list.go +++ b/api/http/handler/tags/tag_list.go @@ -3,8 +3,8 @@ package tags import ( "net/http" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/response" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/response" ) // GET request on /api/tags diff --git a/api/http/handler/teammemberships/handler.go b/api/http/handler/teammemberships/handler.go index c50773a85..10cd63a83 100644 --- a/api/http/handler/teammemberships/handler.go +++ b/api/http/handler/teammemberships/handler.go @@ -1,8 +1,8 @@ package teammemberships import ( + httperror "github.com/portainer/libhttp/error" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/security" "net/http" diff --git a/api/http/handler/teammemberships/teammembership_create.go b/api/http/handler/teammemberships/teammembership_create.go index 49783d767..37216df6a 100644 --- a/api/http/handler/teammemberships/teammembership_create.go +++ b/api/http/handler/teammemberships/teammembership_create.go @@ -3,10 +3,10 @@ package teammemberships import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/teammemberships/teammembership_delete.go b/api/http/handler/teammemberships/teammembership_delete.go index a1263745f..846fb7892 100644 --- a/api/http/handler/teammemberships/teammembership_delete.go +++ b/api/http/handler/teammemberships/teammembership_delete.go @@ -3,10 +3,10 @@ package teammemberships import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/teammemberships/teammembership_list.go b/api/http/handler/teammemberships/teammembership_list.go index 0f9267a10..4136053d6 100644 --- a/api/http/handler/teammemberships/teammembership_list.go +++ b/api/http/handler/teammemberships/teammembership_list.go @@ -3,9 +3,9 @@ package teammemberships import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/teammemberships/teammembership_update.go b/api/http/handler/teammemberships/teammembership_update.go index 6d08bc90a..0e400e975 100644 --- a/api/http/handler/teammemberships/teammembership_update.go +++ b/api/http/handler/teammemberships/teammembership_update.go @@ -3,10 +3,10 @@ package teammemberships import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/teams/handler.go b/api/http/handler/teams/handler.go index 2b8cd7c3b..946a071d7 100644 --- a/api/http/handler/teams/handler.go +++ b/api/http/handler/teams/handler.go @@ -4,8 +4,8 @@ import ( "net/http" "github.com/gorilla/mux" + httperror "github.com/portainer/libhttp/error" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/teams/team_create.go b/api/http/handler/teams/team_create.go index d865e56c5..16b230ec4 100644 --- a/api/http/handler/teams/team_create.go +++ b/api/http/handler/teams/team_create.go @@ -4,10 +4,10 @@ import ( "net/http" "github.com/asaskevich/govalidator" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) type teamCreatePayload struct { diff --git a/api/http/handler/teams/team_delete.go b/api/http/handler/teams/team_delete.go index 623c29c4c..00146d698 100644 --- a/api/http/handler/teams/team_delete.go +++ b/api/http/handler/teams/team_delete.go @@ -3,10 +3,10 @@ package teams import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) // DELETE request on /api/teams/:id diff --git a/api/http/handler/teams/team_inspect.go b/api/http/handler/teams/team_inspect.go index 4030a391e..b8aa83da1 100644 --- a/api/http/handler/teams/team_inspect.go +++ b/api/http/handler/teams/team_inspect.go @@ -3,10 +3,10 @@ package teams import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/teams/team_list.go b/api/http/handler/teams/team_list.go index 7c4268e13..4acc5eabb 100644 --- a/api/http/handler/teams/team_list.go +++ b/api/http/handler/teams/team_list.go @@ -3,8 +3,8 @@ package teams import ( "net/http" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/response" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/teams/team_memberships.go b/api/http/handler/teams/team_memberships.go index d09abe7d5..450458e35 100644 --- a/api/http/handler/teams/team_memberships.go +++ b/api/http/handler/teams/team_memberships.go @@ -3,10 +3,10 @@ package teams import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/teams/team_update.go b/api/http/handler/teams/team_update.go index 8c0961c31..dea180b6a 100644 --- a/api/http/handler/teams/team_update.go +++ b/api/http/handler/teams/team_update.go @@ -3,10 +3,10 @@ package teams import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) type teamUpdatePayload struct { diff --git a/api/http/handler/templates/handler.go b/api/http/handler/templates/handler.go index c193b1def..660991d8d 100644 --- a/api/http/handler/templates/handler.go +++ b/api/http/handler/templates/handler.go @@ -4,8 +4,8 @@ import ( "net/http" "github.com/gorilla/mux" + httperror "github.com/portainer/libhttp/error" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/templates/template_create.go b/api/http/handler/templates/template_create.go index f27cd494a..ef9c0c58f 100644 --- a/api/http/handler/templates/template_create.go +++ b/api/http/handler/templates/template_create.go @@ -4,11 +4,11 @@ import ( "net/http" "github.com/asaskevich/govalidator" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" "github.com/portainer/portainer/filesystem" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) type templateCreatePayload struct { diff --git a/api/http/handler/templates/template_delete.go b/api/http/handler/templates/template_delete.go index c23c2d237..f5793bb8c 100644 --- a/api/http/handler/templates/template_delete.go +++ b/api/http/handler/templates/template_delete.go @@ -3,10 +3,10 @@ package templates import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) // DELETE request on /api/templates/:id diff --git a/api/http/handler/templates/template_inspect.go b/api/http/handler/templates/template_inspect.go index 6b1b4c6a1..70b6ada02 100644 --- a/api/http/handler/templates/template_inspect.go +++ b/api/http/handler/templates/template_inspect.go @@ -3,10 +3,10 @@ package templates import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) // GET request on /api/templates/:id diff --git a/api/http/handler/templates/template_list.go b/api/http/handler/templates/template_list.go index cd312685d..24ca93bbd 100644 --- a/api/http/handler/templates/template_list.go +++ b/api/http/handler/templates/template_list.go @@ -4,10 +4,10 @@ import ( "encoding/json" "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" "github.com/portainer/portainer/http/client" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/templates/template_update.go b/api/http/handler/templates/template_update.go index 2eff9701f..123ea0f6a 100644 --- a/api/http/handler/templates/template_update.go +++ b/api/http/handler/templates/template_update.go @@ -3,10 +3,10 @@ package templates import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) type templateUpdatePayload struct { diff --git a/api/http/handler/upload/handler.go b/api/http/handler/upload/handler.go index 6ce36df77..b0068979b 100644 --- a/api/http/handler/upload/handler.go +++ b/api/http/handler/upload/handler.go @@ -1,8 +1,8 @@ package upload import ( + httperror "github.com/portainer/libhttp/error" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/security" "net/http" diff --git a/api/http/handler/upload/upload_tls.go b/api/http/handler/upload/upload_tls.go index aebab6813..964a7d29b 100644 --- a/api/http/handler/upload/upload_tls.go +++ b/api/http/handler/upload/upload_tls.go @@ -3,10 +3,10 @@ package upload import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) // POST request on /api/upload/tls/{certificate:(?:ca|cert|key)}?folder= @@ -21,7 +21,7 @@ func (handler *Handler) uploadTLS(w http.ResponseWriter, r *http.Request) *httpe return &httperror.HandlerError{http.StatusBadRequest, "Invalid query parameter: folder", err} } - file, err := request.RetrieveMultiPartFormFile(r, "file") + file, _, err := request.RetrieveMultiPartFormFile(r, "file") if err != nil { return &httperror.HandlerError{http.StatusBadRequest, "Invalid certificate file. Ensure that the certificate file is uploaded correctly", err} } diff --git a/api/http/handler/users/admin_check.go b/api/http/handler/users/admin_check.go index 4d7ba233a..5fcd1d33d 100644 --- a/api/http/handler/users/admin_check.go +++ b/api/http/handler/users/admin_check.go @@ -3,9 +3,9 @@ package users import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/response" ) // GET request on /api/users/admin/check diff --git a/api/http/handler/users/admin_init.go b/api/http/handler/users/admin_init.go index f44eb43ca..fb2172686 100644 --- a/api/http/handler/users/admin_init.go +++ b/api/http/handler/users/admin_init.go @@ -4,10 +4,10 @@ import ( "net/http" "github.com/asaskevich/govalidator" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) type adminInitPayload struct { diff --git a/api/http/handler/users/handler.go b/api/http/handler/users/handler.go index 4a0dd2df2..ae43ef521 100644 --- a/api/http/handler/users/handler.go +++ b/api/http/handler/users/handler.go @@ -1,8 +1,8 @@ package users import ( + httperror "github.com/portainer/libhttp/error" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/security" "net/http" diff --git a/api/http/handler/users/user_create.go b/api/http/handler/users/user_create.go index 9fb4cddda..7948ec2b6 100644 --- a/api/http/handler/users/user_create.go +++ b/api/http/handler/users/user_create.go @@ -4,10 +4,10 @@ import ( "net/http" "github.com/asaskevich/govalidator" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/users/user_delete.go b/api/http/handler/users/user_delete.go index 90a5b52cc..1c500bfc1 100644 --- a/api/http/handler/users/user_delete.go +++ b/api/http/handler/users/user_delete.go @@ -3,10 +3,10 @@ package users import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/users/user_inspect.go b/api/http/handler/users/user_inspect.go index 9583c833c..a2e185bdf 100644 --- a/api/http/handler/users/user_inspect.go +++ b/api/http/handler/users/user_inspect.go @@ -3,10 +3,10 @@ package users import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) // GET request on /api/users/:id diff --git a/api/http/handler/users/user_list.go b/api/http/handler/users/user_list.go index 945e85f10..9b46ff5eb 100644 --- a/api/http/handler/users/user_list.go +++ b/api/http/handler/users/user_list.go @@ -3,8 +3,8 @@ package users import ( "net/http" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/response" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/users/user_memberships.go b/api/http/handler/users/user_memberships.go index dfbb355ab..2ba837aec 100644 --- a/api/http/handler/users/user_memberships.go +++ b/api/http/handler/users/user_memberships.go @@ -3,10 +3,10 @@ package users import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/users/user_update.go b/api/http/handler/users/user_update.go index a8b6c8b1a..4ae5e50ab 100644 --- a/api/http/handler/users/user_update.go +++ b/api/http/handler/users/user_update.go @@ -3,10 +3,10 @@ package users import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/users/user_update_password.go b/api/http/handler/users/user_update_password.go index f810f0888..e5a65c8e3 100644 --- a/api/http/handler/users/user_update_password.go +++ b/api/http/handler/users/user_update_password.go @@ -4,10 +4,10 @@ import ( "net/http" "github.com/asaskevich/govalidator" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/webhooks/handler.go b/api/http/handler/webhooks/handler.go index fe60f3fdb..d9b583535 100644 --- a/api/http/handler/webhooks/handler.go +++ b/api/http/handler/webhooks/handler.go @@ -4,9 +4,9 @@ import ( "net/http" "github.com/gorilla/mux" + httperror "github.com/portainer/libhttp/error" portainer "github.com/portainer/portainer" "github.com/portainer/portainer/docker" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/webhooks/webhook_create.go b/api/http/handler/webhooks/webhook_create.go index c74db0c6e..288435889 100644 --- a/api/http/handler/webhooks/webhook_create.go +++ b/api/http/handler/webhooks/webhook_create.go @@ -4,10 +4,10 @@ import ( "net/http" "github.com/asaskevich/govalidator" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" "github.com/satori/go.uuid" ) diff --git a/api/http/handler/webhooks/webhook_delete.go b/api/http/handler/webhooks/webhook_delete.go index b81a445e1..6df0e4156 100644 --- a/api/http/handler/webhooks/webhook_delete.go +++ b/api/http/handler/webhooks/webhook_delete.go @@ -3,10 +3,10 @@ package webhooks import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) // DELETE request on /api/webhook/:serviceID diff --git a/api/http/handler/webhooks/webhook_execute.go b/api/http/handler/webhooks/webhook_execute.go index 395be9999..f43045899 100644 --- a/api/http/handler/webhooks/webhook_execute.go +++ b/api/http/handler/webhooks/webhook_execute.go @@ -6,10 +6,10 @@ import ( "strings" dockertypes "github.com/docker/docker/api/types" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) // Acts on a passed in token UUID to restart the docker service diff --git a/api/http/handler/webhooks/webhook_list.go b/api/http/handler/webhooks/webhook_list.go index 288bdcd65..7ed0df213 100644 --- a/api/http/handler/webhooks/webhook_list.go +++ b/api/http/handler/webhooks/webhook_list.go @@ -3,10 +3,10 @@ package webhooks import ( "net/http" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" + "github.com/portainer/libhttp/response" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" - "github.com/portainer/portainer/http/response" ) type webhookListOperationFilters struct { diff --git a/api/http/handler/websocket/handler.go b/api/http/handler/websocket/handler.go index 20364f52b..3de1cbc60 100644 --- a/api/http/handler/websocket/handler.go +++ b/api/http/handler/websocket/handler.go @@ -3,8 +3,8 @@ package websocket import ( "github.com/gorilla/mux" "github.com/gorilla/websocket" + httperror "github.com/portainer/libhttp/error" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "github.com/portainer/portainer/http/security" ) diff --git a/api/http/handler/websocket/websocket_exec.go b/api/http/handler/websocket/websocket_exec.go index 80c62b9d9..d797e020a 100644 --- a/api/http/handler/websocket/websocket_exec.go +++ b/api/http/handler/websocket/websocket_exec.go @@ -15,10 +15,10 @@ import ( "github.com/asaskevich/govalidator" "github.com/gorilla/websocket" "github.com/koding/websocketproxy" + httperror "github.com/portainer/libhttp/error" + "github.com/portainer/libhttp/request" "github.com/portainer/portainer" "github.com/portainer/portainer/crypto" - httperror "github.com/portainer/portainer/http/error" - "github.com/portainer/portainer/http/request" ) type webSocketExecRequestParams struct { @@ -252,7 +252,7 @@ func streamFromWebsocketConnToTCPConn(websocketConn *websocket.Conn, tcpConn net func streamFromTCPConnToWebsocketConn(websocketConn *websocket.Conn, br *bufio.Reader, errorChan chan error) { for { - out := make([]byte, 1024) + out := make([]byte, 2048) _, err := br.Read(out) if err != nil { errorChan <- err diff --git a/api/http/proxy/local.go b/api/http/proxy/local.go index 8a7f5842d..7686768ad 100644 --- a/api/http/proxy/local.go +++ b/api/http/proxy/local.go @@ -5,7 +5,7 @@ import ( "log" "net/http" - httperror "github.com/portainer/portainer/http/error" + httperror "github.com/portainer/libhttp/error" ) type localProxy struct { diff --git a/api/http/request/request.go b/api/http/request/request.go deleted file mode 100644 index ee56b0d05..000000000 --- a/api/http/request/request.go +++ /dev/null @@ -1,163 +0,0 @@ -package request - -import ( - "encoding/json" - "io/ioutil" - "net/http" - "strconv" - - "github.com/gorilla/mux" - "github.com/portainer/portainer" -) - -const ( - // ErrInvalidQueryParameter defines an error raised when a mandatory query parameter has an invalid value. - ErrInvalidQueryParameter = portainer.Error("Invalid query parameter") - // errInvalidRequestURL defines an error raised when the data sent in the query or the URL is invalid - errInvalidRequestURL = portainer.Error("Invalid request URL") - // errMissingQueryParameter defines an error raised when a mandatory query parameter is missing. - errMissingQueryParameter = portainer.Error("Missing query parameter") - // errMissingFormDataValue defines an error raised when a mandatory form data value is missing. - errMissingFormDataValue = portainer.Error("Missing form data value") -) - -// PayloadValidation is an interface used to validate the payload of a request. -type PayloadValidation interface { - Validate(request *http.Request) error -} - -// DecodeAndValidateJSONPayload decodes the body of the request into an object -// implementing the PayloadValidation interface. -// It also triggers a validation of object content. -func DecodeAndValidateJSONPayload(request *http.Request, v PayloadValidation) error { - if err := json.NewDecoder(request.Body).Decode(v); err != nil { - return err - } - return v.Validate(request) -} - -// RetrieveMultiPartFormFile returns the content of an uploaded file (form data) as bytes. -func RetrieveMultiPartFormFile(request *http.Request, requestParameter string) ([]byte, error) { - file, _, err := request.FormFile(requestParameter) - if err != nil { - return nil, err - } - defer file.Close() - - fileContent, err := ioutil.ReadAll(file) - if err != nil { - return nil, err - } - return fileContent, nil -} - -// RetrieveMultiPartFormJSONValue decodes the value of some form data as a JSON object into the target parameter. -// If optional is set to true, will not return an error when the form data value is not found. -func RetrieveMultiPartFormJSONValue(request *http.Request, name string, target interface{}, optional bool) error { - value, err := RetrieveMultiPartFormValue(request, name, optional) - if err != nil { - return err - } - if value == "" { - return nil - } - return json.Unmarshal([]byte(value), target) -} - -// RetrieveMultiPartFormValue returns the value of some form data as a string. -// If optional is set to true, will not return an error when the form data value is not found. -func RetrieveMultiPartFormValue(request *http.Request, name string, optional bool) (string, error) { - value := request.FormValue(name) - if value == "" && !optional { - return "", errMissingFormDataValue - } - return value, nil -} - -// RetrieveNumericMultiPartFormValue returns the value of some form data as an integer. -// If optional is set to true, will not return an error when the form data value is not found. -func RetrieveNumericMultiPartFormValue(request *http.Request, name string, optional bool) (int, error) { - value, err := RetrieveMultiPartFormValue(request, name, optional) - if err != nil { - return 0, err - } - return strconv.Atoi(value) -} - -// RetrieveBooleanMultiPartFormValue returns the value of some form data as a boolean. -// If optional is set to true, will not return an error when the form data value is not found. -func RetrieveBooleanMultiPartFormValue(request *http.Request, name string, optional bool) (bool, error) { - value, err := RetrieveMultiPartFormValue(request, name, optional) - if err != nil { - return false, err - } - return value == "true", nil -} - -// RetrieveRouteVariableValue returns the value of a route variable as a string. -func RetrieveRouteVariableValue(request *http.Request, name string) (string, error) { - routeVariables := mux.Vars(request) - if routeVariables == nil { - return "", errInvalidRequestURL - } - routeVar := routeVariables[name] - if routeVar == "" { - return "", errInvalidRequestURL - } - return routeVar, nil -} - -// RetrieveNumericRouteVariableValue returns the value of a route variable as an integer. -func RetrieveNumericRouteVariableValue(request *http.Request, name string) (int, error) { - routeVar, err := RetrieveRouteVariableValue(request, name) - if err != nil { - return 0, err - } - return strconv.Atoi(routeVar) -} - -// RetrieveQueryParameter returns the value of a query parameter as a string. -// If optional is set to true, will not return an error when the query parameter is not found. -func RetrieveQueryParameter(request *http.Request, name string, optional bool) (string, error) { - queryParameter := request.FormValue(name) - if queryParameter == "" && !optional { - return "", errMissingQueryParameter - } - return queryParameter, nil -} - -// RetrieveNumericQueryParameter returns the value of a query parameter as an integer. -// If optional is set to true, will not return an error when the query parameter is not found. -func RetrieveNumericQueryParameter(request *http.Request, name string, optional bool) (int, error) { - queryParameter, err := RetrieveQueryParameter(request, name, optional) - if err != nil { - return 0, err - } - if queryParameter == "" && optional { - return 0, nil - } - return strconv.Atoi(queryParameter) -} - -// RetrieveBooleanQueryParameter returns the value of a query parameter as a boolean. -// If optional is set to true, will not return an error when the query parameter is not found. -func RetrieveBooleanQueryParameter(request *http.Request, name string, optional bool) (bool, error) { - queryParameter, err := RetrieveQueryParameter(request, name, optional) - if err != nil { - return false, err - } - return queryParameter == "true", nil -} - -// RetrieveJSONQueryParameter decodes the value of a query paramater as a JSON object into the target parameter. -// If optional is set to true, will not return an error when the query parameter is not found. -func RetrieveJSONQueryParameter(request *http.Request, name string, target interface{}, optional bool) error { - queryParameter, err := RetrieveQueryParameter(request, name, optional) - if err != nil { - return err - } - if queryParameter == "" { - return nil - } - return json.Unmarshal([]byte(queryParameter), target) -} diff --git a/api/http/response/response.go b/api/http/response/response.go deleted file mode 100644 index 2451abd24..000000000 --- a/api/http/response/response.go +++ /dev/null @@ -1,25 +0,0 @@ -package response - -import ( - "encoding/json" - "net/http" - - httperror "github.com/portainer/portainer/http/error" -) - -// JSON encodes data to rw in JSON format. Returns a pointer to a -// HandlerError if encoding fails. -func JSON(rw http.ResponseWriter, data interface{}) *httperror.HandlerError { - rw.Header().Set("Content-Type", "application/json") - err := json.NewEncoder(rw).Encode(data) - if err != nil { - return &httperror.HandlerError{http.StatusInternalServerError, "Unable to write JSON response", err} - } - return nil -} - -// Empty merely sets the response code to NoContent (204). -func Empty(rw http.ResponseWriter) *httperror.HandlerError { - rw.WriteHeader(http.StatusNoContent) - return nil -} diff --git a/api/http/security/bouncer.go b/api/http/security/bouncer.go index 5aad463f1..0b25bd389 100644 --- a/api/http/security/bouncer.go +++ b/api/http/security/bouncer.go @@ -1,8 +1,8 @@ package security import ( + httperror "github.com/portainer/libhttp/error" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" "net/http" "strings" diff --git a/api/http/security/rate_limiter.go b/api/http/security/rate_limiter.go index 27ab2523a..307329723 100644 --- a/api/http/security/rate_limiter.go +++ b/api/http/security/rate_limiter.go @@ -6,8 +6,8 @@ import ( "time" "github.com/g07cha/defender" + httperror "github.com/portainer/libhttp/error" "github.com/portainer/portainer" - httperror "github.com/portainer/portainer/http/error" ) // RateLimiter represents an entity that manages request rate limiting