Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Deprecation headers for legacy rest endpoints #7686

Merged
merged 10 commits into from
Oct 29, 2020
2 changes: 1 addition & 1 deletion client/docs/swagger-ui/swagger-ui-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion client/docs/swagger_legacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2595,4 +2595,4 @@ definitions:
total:
type: array
items:
$ref: "#/definitions/Coin"
$ref: "#/definitions/Coin"
9 changes: 9 additions & 0 deletions client/legacy_rest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package client

import "net/http"

func AddDeprecationHeaders(rw http.ResponseWriter) http.ResponseWriter {
rw.Header().Set("Deprecation", "true")
rw.Header().Set("Link", "<https://docs.cosmos.network/v0.40/interfaces/rest.html>; rel=\"deprecation\"")
return rw
}
8 changes: 8 additions & 0 deletions x/auth/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
// query accountREST Handler
func QueryAccountRequestHandlerFn(storeName string, clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

vars := mux.Vars(r)
bech32addr := vars["address"]

Expand Down Expand Up @@ -58,6 +60,8 @@ func QueryAccountRequestHandlerFn(storeName string, clientCtx client.Context) ht
// otherwise the transactions are searched for by events.
func QueryTxsRequestHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

err := r.ParseForm()
if err != nil {
rest.WriteErrorResponse(
Expand Down Expand Up @@ -110,6 +114,8 @@ func QueryTxsRequestHandlerFn(clientCtx client.Context) http.HandlerFunc {
// by hash in a committed block.
func QueryTxRequestHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

vars := mux.Vars(r)
hashHexStr := vars["hash"]

Expand Down Expand Up @@ -146,6 +152,8 @@ func QueryTxRequestHandlerFn(clientCtx client.Context) http.HandlerFunc {

func queryParamsHandler(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)
clevinson marked this conversation as resolved.
Show resolved Hide resolved

clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r)
if !ok {
return
Expand Down
3 changes: 1 addition & 2 deletions x/auth/client/rest/rest.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package rest

import (
"github.com/gorilla/mux"

"github.com/cosmos/cosmos-sdk/client"
"github.com/gorilla/mux"
)

// REST query and parameter values
Expand Down
5 changes: 5 additions & 0 deletions x/bank/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
// account balances or a specific balance by denomination.
func QueryBalancesRequestHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)
w.Header().Set("Content-Type", "application/json")

vars := mux.Vars(r)
Expand Down Expand Up @@ -63,6 +64,8 @@ func QueryBalancesRequestHandlerFn(clientCtx client.Context) http.HandlerFunc {
// HTTP request handler to query the total supply of coins
func totalSupplyHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)
clevinson marked this conversation as resolved.
Show resolved Hide resolved

_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
if rest.CheckBadRequestError(w, err) {
return
Expand Down Expand Up @@ -94,6 +97,8 @@ func totalSupplyHandlerFn(clientCtx client.Context) http.HandlerFunc {
// HTTP request handler to query the supply of a single denom
func supplyOfHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)
clevinson marked this conversation as resolved.
Show resolved Hide resolved

denom := mux.Vars(r)["denom"]
clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r)
if !ok {
Expand Down
2 changes: 2 additions & 0 deletions x/bank/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type SendReq struct {
// transaction.
func NewSendRequestHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

vars := mux.Vars(r)
bech32Addr := vars["address"]

Expand Down
6 changes: 6 additions & 0 deletions x/distribution/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func registerQueryRoutes(clientCtx client.Context, r *mux.Router) {
// HTTP request handler to query the total rewards balance from all delegations
func delegatorRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r)
if !ok {
return
Expand Down Expand Up @@ -99,6 +101,8 @@ func delegatorRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc {
// HTTP request handler to query a delegation rewards
func delegationRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r)
if !ok {
return
Expand All @@ -121,6 +125,8 @@ func delegationRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc {
// HTTP request handler to query a delegation rewards
func delegatorWithdrawalAddrHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

delegatorAddr, ok := checkDelegatorAddressVar(w, r)
if !ok {
return
Expand Down
2 changes: 2 additions & 0 deletions x/distribution/client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func ProposalRESTHandler(clientCtx client.Context) govrest.ProposalRESTHandler {

func postProposalHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

var req CommunityPoolSpendProposalReq
if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) {
return
Expand Down
10 changes: 10 additions & 0 deletions x/distribution/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ func registerTxHandlers(clientCtx client.Context, r *mux.Router) {

func newWithdrawDelegatorRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

var req withdrawRewardsReq
if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) {
return
Expand Down Expand Up @@ -90,6 +92,8 @@ func newWithdrawDelegatorRewardsHandlerFn(clientCtx client.Context) http.Handler

func newWithdrawDelegationRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

var req withdrawRewardsReq
if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) {
return
Expand Down Expand Up @@ -122,6 +126,8 @@ func newWithdrawDelegationRewardsHandlerFn(clientCtx client.Context) http.Handle

func newSetDelegatorWithdrawalAddrHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

var req setWithdrawalAddrReq
if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) {
return
Expand Down Expand Up @@ -149,6 +155,8 @@ func newSetDelegatorWithdrawalAddrHandlerFn(clientCtx client.Context) http.Handl

func newWithdrawValidatorRewardsHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

var req withdrawRewardsReq
if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) {
return
Expand Down Expand Up @@ -177,6 +185,8 @@ func newWithdrawValidatorRewardsHandlerFn(clientCtx client.Context) http.Handler

func newFundCommunityPoolHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

var req fundCommunityPoolReq
if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) {
return
Expand Down
4 changes: 4 additions & 0 deletions x/evidence/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func registerQueryRoutes(clientCtx client.Context, r *mux.Router) {

func queryEvidenceHandler(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)
clevinson marked this conversation as resolved.
Show resolved Hide resolved

vars := mux.Vars(r)
evidenceHash := vars[RestParamEvidenceHash]

Expand Down Expand Up @@ -66,6 +68,8 @@ func queryEvidenceHandler(clientCtx client.Context) http.HandlerFunc {

func queryAllEvidenceHandler(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
if rest.CheckBadRequestError(w, err) {
return
Expand Down
18 changes: 18 additions & 0 deletions x/gov/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func registerQueryRoutes(clientCtx client.Context, r *mux.Router) {

func queryParamsHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

vars := mux.Vars(r)
paramType := vars[RestParamsType]

Expand All @@ -48,6 +50,8 @@ func queryParamsHandlerFn(clientCtx client.Context) http.HandlerFunc {

func queryProposalHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

vars := mux.Vars(r)
strProposalID := vars[RestProposalID]

Expand Down Expand Up @@ -86,6 +90,8 @@ func queryProposalHandlerFn(clientCtx client.Context) http.HandlerFunc {

func queryDepositsHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

vars := mux.Vars(r)
strProposalID := vars[RestProposalID]

Expand Down Expand Up @@ -135,6 +141,8 @@ func queryDepositsHandlerFn(clientCtx client.Context) http.HandlerFunc {

func queryProposerHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

vars := mux.Vars(r)
strProposalID := vars[RestProposalID]

Expand All @@ -159,6 +167,8 @@ func queryProposerHandlerFn(clientCtx client.Context) http.HandlerFunc {

func queryDepositHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

vars := mux.Vars(r)
strProposalID := vars[RestProposalID]
bechDepositorAddr := vars[RestDepositor]
Expand Down Expand Up @@ -235,6 +245,8 @@ func queryDepositHandlerFn(clientCtx client.Context) http.HandlerFunc {

func queryVoteHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

vars := mux.Vars(r)
strProposalID := vars[RestProposalID]
bechVoterAddr := vars[RestVoter]
Expand Down Expand Up @@ -313,6 +325,8 @@ func queryVoteHandlerFn(clientCtx client.Context) http.HandlerFunc {
// todo: Split this functionality into helper functions to remove the above
func queryVotesOnProposalHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

_, page, limit, err := rest.ParseHTTPArgs(r)
if rest.CheckBadRequestError(w, err) {
return
Expand Down Expand Up @@ -379,6 +393,8 @@ func queryVotesOnProposalHandlerFn(clientCtx client.Context) http.HandlerFunc {
// HTTP request handler to query list of governance proposals
func queryProposalsWithParameterFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
if rest.CheckBadRequestError(w, err) {
return
Expand Down Expand Up @@ -436,6 +452,8 @@ func queryProposalsWithParameterFn(clientCtx client.Context) http.HandlerFunc {
// todo: Split this functionality into helper functions to remove the above
func queryTallyOnProposalHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

vars := mux.Vars(r)
strProposalID := vars[RestProposalID]

Expand Down
6 changes: 6 additions & 0 deletions x/gov/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func registerTxHandlers(clientCtx client.Context, r *mux.Router, phs []ProposalR

func newPostProposalHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

var req PostProposalReq
if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) {
return
Expand Down Expand Up @@ -53,6 +55,8 @@ func newPostProposalHandlerFn(clientCtx client.Context) http.HandlerFunc {

func newDepositHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

vars := mux.Vars(r)
strProposalID := vars[RestProposalID]

Expand Down Expand Up @@ -88,6 +92,8 @@ func newDepositHandlerFn(clientCtx client.Context) http.HandlerFunc {

func newVoteHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

vars := mux.Vars(r)
strProposalID := vars[RestProposalID]

Expand Down
6 changes: 6 additions & 0 deletions x/mint/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func registerQueryRoutes(clientCtx client.Context, r *mux.Router) {

func queryParamsHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParameters)

clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r)
Expand All @@ -49,6 +51,8 @@ func queryParamsHandlerFn(clientCtx client.Context) http.HandlerFunc {

func queryInflationHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryInflation)

clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r)
Expand All @@ -68,6 +72,8 @@ func queryInflationHandlerFn(clientCtx client.Context) http.HandlerFunc {

func queryAnnualProvisionsHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryAnnualProvisions)

clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r)
Expand Down
2 changes: 2 additions & 0 deletions x/params/client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func ProposalRESTHandler(clientCtx client.Context) govrest.ProposalRESTHandler {

func postProposalHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

var req paramscutils.ParamChangeProposalReq
if !rest.ReadRESTReq(w, r, clientCtx.LegacyAmino, &req) {
return
Expand Down
6 changes: 6 additions & 0 deletions x/slashing/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func registerQueryRoutes(clientCtx client.Context, r *mux.Router) {
// http request handler to query signing info
func signingInfoHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

vars := mux.Vars(r)
pk, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, vars["validatorPubKey"])
if rest.CheckBadRequestError(w, err) {
Expand Down Expand Up @@ -64,6 +66,8 @@ func signingInfoHandlerFn(clientCtx client.Context) http.HandlerFunc {
// http request handler to query signing info
func signingInfoHandlerListFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)
clevinson marked this conversation as resolved.
Show resolved Hide resolved

_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
if rest.CheckBadRequestError(w, err) {
return
Expand Down Expand Up @@ -93,6 +97,8 @@ func signingInfoHandlerListFn(clientCtx client.Context) http.HandlerFunc {

func queryParamsHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

clientCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, clientCtx, r)
if !ok {
return
Expand Down
2 changes: 2 additions & 0 deletions x/slashing/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type UnjailReq struct {
// transaction.
func NewUnjailRequestHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
client.AddDeprecationHeaders(w)

vars := mux.Vars(r)
bech32Validator := vars["validatorAddr"]

Expand Down
Loading