Add Deprecation headers for legacy rest endpoints (#7686)
* add deprecation headers for legacy rest endpoints * add deprecation headers for missing tx routes * rm handler-level deprecation headers * switch to middleware Route.Use method for setting deprecation Headers * set deprecation headers using subrouter * cleanup gofmt * goimports * Update client/rest/rest.go * update deprecation headers to be set on each module individually Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
82f15f306e
commit
536eb689dc
|
@ -41773,4 +41773,4 @@
|
|||
}, o.resolve = i, e.exports = o, o.id = 1058
|
||||
}])
|
||||
});
|
||||
//# sourceMappingURL=swagger-ui-bundle.js.map
|
||||
//# sourceMappingURL=swagger-ui-bundle.js.map
|
||||
|
|
|
@ -2595,4 +2595,4 @@ definitions:
|
|||
total:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/definitions/Coin"
|
||||
$ref: "#/definitions/Coin"
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package rest
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// addHTTPDeprecationHeaders is a mux middleware function for adding HTTP
|
||||
// Deprecation headers to a http handler
|
||||
func addHTTPDeprecationHeaders(h http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Deprecation", "true")
|
||||
w.Header().Set("Link", "<https://docs.cosmos.network/v0.40/interfaces/rest.html>; rel=\"deprecation\"")
|
||||
w.Header().Set("Warning", "199 - \"this endpoint is deprecated and may not work as before, see deprecation link for more info\"")
|
||||
h.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
// WithHTTPDeprecationHeaders returns a new *mux.Router, identical to its input
|
||||
// but with the addition of HTTP Deprecation headers. This is used to mark legacy
|
||||
// amino REST endpoints as deprecated in the REST API.
|
||||
func WithHTTPDeprecationHeaders(r *mux.Router) *mux.Router {
|
||||
subRouter := r.NewRoute().Subrouter()
|
||||
subRouter.Use(addHTTPDeprecationHeaders)
|
||||
return subRouter
|
||||
}
|
|
@ -31,9 +31,8 @@ package module
|
|||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/spf13/cobra"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/rest"
|
||||
)
|
||||
|
||||
// REST query and parameter values
|
||||
|
@ -12,7 +13,8 @@ const (
|
|||
)
|
||||
|
||||
// RegisterRoutes registers the auth module REST routes.
|
||||
func RegisterRoutes(clientCtx client.Context, r *mux.Router, storeName string) {
|
||||
func RegisterRoutes(clientCtx client.Context, rtr *mux.Router, storeName string) {
|
||||
r := rest.WithHTTPDeprecationHeaders(rtr)
|
||||
r.HandleFunc(
|
||||
"/auth/accounts/{address}", QueryAccountRequestHandlerFn(storeName, clientCtx),
|
||||
).Methods(MethodGet)
|
||||
|
@ -24,7 +26,8 @@ func RegisterRoutes(clientCtx client.Context, r *mux.Router, storeName string) {
|
|||
}
|
||||
|
||||
// RegisterTxRoutes registers all transaction routes on the provided router.
|
||||
func RegisterTxRoutes(clientCtx client.Context, r *mux.Router) {
|
||||
func RegisterTxRoutes(clientCtx client.Context, rtr *mux.Router) {
|
||||
r := rest.WithHTTPDeprecationHeaders(rtr)
|
||||
r.HandleFunc("/txs/{hash}", QueryTxRequestHandlerFn(clientCtx)).Methods("GET")
|
||||
r.HandleFunc("/txs", QueryTxsRequestHandlerFn(clientCtx)).Methods("GET")
|
||||
r.HandleFunc("/txs", BroadcastTxRequest(clientCtx)).Methods("POST")
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package rest
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client/rest"
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
|
@ -8,7 +9,8 @@ import (
|
|||
|
||||
// RegisterHandlers registers all x/bank transaction and query HTTP REST handlers
|
||||
// on the provided mux router.
|
||||
func RegisterHandlers(clientCtx client.Context, r *mux.Router) {
|
||||
func RegisterHandlers(clientCtx client.Context, rtr *mux.Router) {
|
||||
r := rest.WithHTTPDeprecationHeaders(rtr)
|
||||
r.HandleFunc("/bank/accounts/{address}/transfers", NewSendRequestHandlerFn(clientCtx)).Methods("POST")
|
||||
r.HandleFunc("/bank/balances/{address}", QueryBalancesRequestHandlerFn(clientCtx)).Methods("GET")
|
||||
r.HandleFunc("/bank/total", totalSupplyHandlerFn(clientCtx)).Methods("GET")
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
clientrest "github.com/cosmos/cosmos-sdk/client/rest"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
|
@ -13,7 +14,9 @@ import (
|
|||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
)
|
||||
|
||||
func RegisterHandlers(clientCtx client.Context, r *mux.Router) {
|
||||
func RegisterHandlers(clientCtx client.Context, rtr *mux.Router) {
|
||||
r := clientrest.WithHTTPDeprecationHeaders(rtr)
|
||||
|
||||
registerQueryRoutes(clientCtx, r)
|
||||
registerTxHandlers(clientCtx, r)
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/rest"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
@ -24,7 +25,9 @@ type EvidenceRESTHandler struct {
|
|||
|
||||
// RegisterRoutes registers all Evidence submission handlers for the evidence module's
|
||||
// REST service handler.
|
||||
func RegisterRoutes(clientCtx client.Context, r *mux.Router, handlers []EvidenceRESTHandler) {
|
||||
func RegisterRoutes(clientCtx client.Context, rtr *mux.Router, handlers []EvidenceRESTHandler) {
|
||||
r := rest.WithHTTPDeprecationHeaders(rtr)
|
||||
|
||||
registerQueryRoutes(clientCtx, r)
|
||||
registerTxRoutes(clientCtx, r, handlers)
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
clientrest "github.com/cosmos/cosmos-sdk/client/rest"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||
)
|
||||
|
@ -28,7 +29,8 @@ type ProposalRESTHandler struct {
|
|||
Handler func(http.ResponseWriter, *http.Request)
|
||||
}
|
||||
|
||||
func RegisterHandlers(clientCtx client.Context, r *mux.Router, phs []ProposalRESTHandler) {
|
||||
func RegisterHandlers(clientCtx client.Context, rtr *mux.Router, phs []ProposalRESTHandler) {
|
||||
r := clientrest.WithHTTPDeprecationHeaders(rtr)
|
||||
registerQueryRoutes(clientCtx, r)
|
||||
registerTxHandlers(clientCtx, r, phs)
|
||||
}
|
||||
|
|
|
@ -4,9 +4,11 @@ import (
|
|||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/rest"
|
||||
)
|
||||
|
||||
// RegisterRoutes registers minting module REST handlers on the provided router.
|
||||
func RegisterRoutes(clientCtx client.Context, r *mux.Router) {
|
||||
func RegisterRoutes(clientCtx client.Context, rtr *mux.Router) {
|
||||
r := rest.WithHTTPDeprecationHeaders(rtr)
|
||||
registerQueryRoutes(clientCtx, r)
|
||||
}
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
package rest
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client/rest"
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
)
|
||||
|
||||
func RegisterHandlers(clientCtx client.Context, r *mux.Router) {
|
||||
func RegisterHandlers(clientCtx client.Context, rtr *mux.Router) {
|
||||
r := rest.WithHTTPDeprecationHeaders(rtr)
|
||||
|
||||
registerQueryRoutes(clientCtx, r)
|
||||
registerTxHandlers(clientCtx, r)
|
||||
}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
package rest
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client/rest"
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
)
|
||||
|
||||
func RegisterHandlers(clientCtx client.Context, r *mux.Router) {
|
||||
func RegisterHandlers(clientCtx client.Context, rtr *mux.Router) {
|
||||
r := rest.WithHTTPDeprecationHeaders(rtr)
|
||||
registerQueryRoutes(clientCtx, r)
|
||||
registerTxHandlers(clientCtx, r)
|
||||
}
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
package rest
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client/rest"
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
)
|
||||
|
||||
// RegisterRoutes registers REST routes for the upgrade module under the path specified by routeName.
|
||||
func RegisterRoutes(clientCtx client.Context, r *mux.Router) {
|
||||
func RegisterRoutes(clientCtx client.Context, rtr *mux.Router) {
|
||||
r := rest.WithHTTPDeprecationHeaders(rtr)
|
||||
registerQueryRoutes(clientCtx, r)
|
||||
registerTxHandlers(clientCtx, r)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue