From 703e8a9a0fa5d548938c1383e65263182ba2d374 Mon Sep 17 00:00:00 2001 From: Igor Sirotin Date: Thu, 26 Sep 2024 15:36:14 +0100 Subject: [PATCH] feat_: expose deprecated endpoints, with special header field --- cmd/statusd/server/endpoints.go | 15 +++++++++++++++ .../server/parse-api/endpoints_template.txt | 6 ++++++ cmd/statusd/server/parse-api/main.go | 9 ++++++--- cmd/statusd/server/signals_server.go | 13 +++++++++++-- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/cmd/statusd/server/endpoints.go b/cmd/statusd/server/endpoints.go index 7dd65b2a5..8a1117bc5 100644 --- a/cmd/statusd/server/endpoints.go +++ b/cmd/statusd/server/endpoints.go @@ -7,6 +7,7 @@ import statusgo "github.com/status-im/status-go/mobile" var EndpointsWithRequest = map[string]func(string) string{ "/statusgo/InitializeApplication": statusgo.InitializeApplication, + "/statusgo/OpenAccounts": statusgo.OpenAccounts, "/statusgo/ExtractGroupMembershipSignatures": statusgo.ExtractGroupMembershipSignatures, "/statusgo/SignGroupMembership": statusgo.SignGroupMembership, "/statusgo/ValidateNodeConfig": statusgo.ValidateNodeConfig, @@ -77,8 +78,13 @@ var EndpointsUnsupported = []string{ "/statusgo/VerifyAccountPassword", "/statusgo/VerifyDatabasePassword", "/statusgo/MigrateKeyStoreDir", + "/statusgo/Login", + "/statusgo/LoginWithConfig", + "/statusgo/SaveAccountAndLogin", "/statusgo/DeleteMultiaccount", "/statusgo/DeleteImportedKey", + "/statusgo/SaveAccountAndLoginWithKeycard", + "/statusgo/LoginWithKeycard", "/statusgo/SignTypedData", "/statusgo/SignTypedDataV4", "/statusgo/SendTransactionWithChainID", @@ -103,3 +109,12 @@ var EndpointsUnsupported = []string{ "/statusgo/EncodeTransfer", "/statusgo/EncodeFunctionCall", } + +var EndpointsDeprecated = map[string]struct{}{ + "/statusgo/OpenAccounts": {}, + "/statusgo/Login": {}, + "/statusgo/LoginWithConfig": {}, + "/statusgo/SaveAccountAndLogin": {}, + "/statusgo/SaveAccountAndLoginWithKeycard": {}, + "/statusgo/LoginWithKeycard": {}, +} \ No newline at end of file diff --git a/cmd/statusd/server/parse-api/endpoints_template.txt b/cmd/statusd/server/parse-api/endpoints_template.txt index e6a1b7719..0cbafd32f 100644 --- a/cmd/statusd/server/parse-api/endpoints_template.txt +++ b/cmd/statusd/server/parse-api/endpoints_template.txt @@ -22,3 +22,9 @@ var EndpointsUnsupported = []string{ "/{{ $.PackageName }}/{{ . }}", {{- end }} } + +var EndpointsDeprecated = map[string]struct{}{ + {{- range .DeprecatedEndpoints }} + "/{{ $.PackageName }}/{{ . }}": {}, +{{- end }} +} \ No newline at end of file diff --git a/cmd/statusd/server/parse-api/main.go b/cmd/statusd/server/parse-api/main.go index 9990c9a03..3d450ae35 100644 --- a/cmd/statusd/server/parse-api/main.go +++ b/cmd/statusd/server/parse-api/main.go @@ -39,6 +39,7 @@ type TemplateData struct { FunctionsWithResp []string FunctionsNoArgs []string UnsupportedEndpoints []string + DeprecatedEndpoints []string } func main() { @@ -54,6 +55,7 @@ func main() { var publicFunctionsWithArgs []string var publicFunctionsWithoutArgs []string var unsupportedFunctions []string + var deprecatedFucntions []string var isDeprecated bool var packageName string @@ -75,13 +77,13 @@ func main() { continue } + functionName := extractFunctionName(line) + if isDeprecated { isDeprecated = false - continue + deprecatedFucntions = append(deprecatedFucntions, functionName) } - functionName := extractFunctionName(line) - switch { case isPublicFunctionWithArgs(line): publicFunctionsWithArgs = append(publicFunctionsWithArgs, functionName) @@ -103,6 +105,7 @@ func main() { FunctionsWithResp: publicFunctionsWithArgs, FunctionsNoArgs: publicFunctionsWithoutArgs, UnsupportedEndpoints: unsupportedFunctions, + DeprecatedEndpoints: deprecatedFucntions, } // Load and parse the template diff --git a/cmd/statusd/server/signals_server.go b/cmd/statusd/server/signals_server.go index 84c3e1903..e2608659a 100644 --- a/cmd/statusd/server/signals_server.go +++ b/cmd/statusd/server/signals_server.go @@ -145,7 +145,8 @@ func (s *Server) addEndpointWithResponse(name string, handler func(string) strin response := handler(string(request)) - w.Header().Set("Content-Type", "application/json") + s.setHeaders(name, w) + _, err = w.Write([]byte(response)) if err != nil { log.Error("failed to write response: %w", err) @@ -158,7 +159,8 @@ func (s *Server) addEndpointNoRequest(name string, handler func() string) { s.mux.HandleFunc(name, func(w http.ResponseWriter, r *http.Request) { response := handler() - w.Header().Set("Content-Type", "application/json") + s.setHeaders(name, w) + _, err := w.Write([]byte(response)) if err != nil { log.Error("failed to write response: %w", err) @@ -184,3 +186,10 @@ func (s *Server) RegisterMobileAPI() { s.addUnsupportedEndpoint(name) } } + +func (s *Server) setHeaders(name string, w http.ResponseWriter) { + if _, ok := EndpointsDeprecated[name]; ok { + w.Header().Set("Deprecation", "true") + } + w.Header().Set("Content-Type", "application/json") +}