feat_: expose deprecated endpoints, with special header field
This commit is contained in:
parent
3bc34e5464
commit
703e8a9a0f
|
@ -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": {},
|
||||
}
|
|
@ -22,3 +22,9 @@ var EndpointsUnsupported = []string{
|
|||
"/{{ $.PackageName }}/{{ . }}",
|
||||
{{- end }}
|
||||
}
|
||||
|
||||
var EndpointsDeprecated = map[string]struct{}{
|
||||
{{- range .DeprecatedEndpoints }}
|
||||
"/{{ $.PackageName }}/{{ . }}": {},
|
||||
{{- end }}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue