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
Prev Previous commit
Next Next commit
cleanup gofmt
  • Loading branch information
clevinson committed Oct 28, 2020
commit abccbb246ecc9c47c492e78f897291fbd742641d
3 changes: 2 additions & 1 deletion client/rest/rest.go
Original file line number Diff line number Diff line change
@@ -1,8 1,9 @@
package rest

import (
"github.com/gorilla/mux"
"net/http"

"github.com/gorilla/mux"
)

// addHTTPDeprecationHeaders is a mux middleware function for adding HTTP
Expand Down
7 changes: 4 additions & 3 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 30,14 @@ package module

import (
"encoding/json"
"github.com/cosmos/cosmos-sdk/client/rest"
"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"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/rest"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -110,8 110,9 @@ func (bm BasicManager) ValidateGenesis(cdc codec.JSONMarshaler, txEncCfg client.

// RegisterRESTRoutes registers all module rest routes
func (bm BasicManager) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {
r := rest.WithHTTPDeprecationHeaders(rtr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually shouldn't be be doing this module by module? Putting this in BasicManager means that other projects with other modules will have their REST routes auto-deprecated. That's not really what we want right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this was what we wanted, as this entire process for generating REST routes will be deprecated at the SDK level in future releases, no?

Copy link
Member

@aaronc aaronc Oct 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're probably right... That would make SDK maintenance easier. Still this deprecation goes to clients. RegisterRESTRoutes should be deprecated for module developers. Module developers may decide not to deprecate their own REST routes for clients and instead do that wiring on their own.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry- i'm not following exactly what you mean. Is this still something you are wanting changed? Or do you now think the current implementation is correct in the context of this PR?

Copy link
Member

@aaronc aaronc Oct 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes It still should be their decision. So I would prefer we do module by module.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REST routes for clients and instead do that wiring on their own.

This should be on by default to let the developers and users to know and prepare for that.
At some point we will remove the REST API.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we need to coustomze it at the SDK level, then we can add a parameter to the RegisterRESTRoutes function:

 RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router, deprecateREST bool)

for _, b := range bm {
b.RegisterRESTRoutes(clientCtx, rest.WithHTTPDeprecationHeaders(rtr))
b.RegisterRESTRoutes(clientCtx, r)
}
}

Expand Down