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
|
@ -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 (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
// REST query and parameter values
|
// REST query and parameter values
|
||||||
|
@ -12,7 +13,8 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// RegisterRoutes registers the auth module REST routes.
|
// 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(
|
r.HandleFunc(
|
||||||
"/auth/accounts/{address}", QueryAccountRequestHandlerFn(storeName, clientCtx),
|
"/auth/accounts/{address}", QueryAccountRequestHandlerFn(storeName, clientCtx),
|
||||||
).Methods(MethodGet)
|
).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.
|
// 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/{hash}", QueryTxRequestHandlerFn(clientCtx)).Methods("GET")
|
||||||
r.HandleFunc("/txs", QueryTxsRequestHandlerFn(clientCtx)).Methods("GET")
|
r.HandleFunc("/txs", QueryTxsRequestHandlerFn(clientCtx)).Methods("GET")
|
||||||
r.HandleFunc("/txs", BroadcastTxRequest(clientCtx)).Methods("POST")
|
r.HandleFunc("/txs", BroadcastTxRequest(clientCtx)).Methods("POST")
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package rest
|
package rest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/rest"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
|
@ -8,7 +9,8 @@ import (
|
||||||
|
|
||||||
// RegisterHandlers registers all x/bank transaction and query HTTP REST handlers
|
// RegisterHandlers registers all x/bank transaction and query HTTP REST handlers
|
||||||
// on the provided mux router.
|
// 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/accounts/{address}/transfers", NewSendRequestHandlerFn(clientCtx)).Methods("POST")
|
||||||
r.HandleFunc("/bank/balances/{address}", QueryBalancesRequestHandlerFn(clientCtx)).Methods("GET")
|
r.HandleFunc("/bank/balances/{address}", QueryBalancesRequestHandlerFn(clientCtx)).Methods("GET")
|
||||||
r.HandleFunc("/bank/total", totalSupplyHandlerFn(clientCtx)).Methods("GET")
|
r.HandleFunc("/bank/total", totalSupplyHandlerFn(clientCtx)).Methods("GET")
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"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/client/tx"
|
||||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||||
|
@ -13,7 +14,9 @@ import (
|
||||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
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)
|
registerQueryRoutes(clientCtx, r)
|
||||||
registerTxHandlers(clientCtx, r)
|
registerTxHandlers(clientCtx, r)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/rest"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
@ -24,7 +25,9 @@ type EvidenceRESTHandler struct {
|
||||||
|
|
||||||
// RegisterRoutes registers all Evidence submission handlers for the evidence module's
|
// RegisterRoutes registers all Evidence submission handlers for the evidence module's
|
||||||
// REST service handler.
|
// 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)
|
registerQueryRoutes(clientCtx, r)
|
||||||
registerTxRoutes(clientCtx, r, handlers)
|
registerTxRoutes(clientCtx, r, handlers)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
|
clientrest "github.com/cosmos/cosmos-sdk/client/rest"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||||
)
|
)
|
||||||
|
@ -28,7 +29,8 @@ type ProposalRESTHandler struct {
|
||||||
Handler func(http.ResponseWriter, *http.Request)
|
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)
|
registerQueryRoutes(clientCtx, r)
|
||||||
registerTxHandlers(clientCtx, r, phs)
|
registerTxHandlers(clientCtx, r, phs)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,11 @@ import (
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RegisterRoutes registers minting module REST handlers on the provided router.
|
// 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)
|
registerQueryRoutes(clientCtx, r)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
package rest
|
package rest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/rest"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"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)
|
registerQueryRoutes(clientCtx, r)
|
||||||
registerTxHandlers(clientCtx, r)
|
registerTxHandlers(clientCtx, r)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
package rest
|
package rest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/rest"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"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)
|
registerQueryRoutes(clientCtx, r)
|
||||||
registerTxHandlers(clientCtx, r)
|
registerTxHandlers(clientCtx, r)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
package rest
|
package rest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/rest"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RegisterRoutes registers REST routes for the upgrade module under the path specified by routeName.
|
// 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)
|
registerQueryRoutes(clientCtx, r)
|
||||||
registerTxHandlers(clientCtx, r)
|
registerTxHandlers(clientCtx, r)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue