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{
|
var EndpointsWithRequest = map[string]func(string) string{
|
||||||
"/statusgo/InitializeApplication": statusgo.InitializeApplication,
|
"/statusgo/InitializeApplication": statusgo.InitializeApplication,
|
||||||
|
"/statusgo/OpenAccounts": statusgo.OpenAccounts,
|
||||||
"/statusgo/ExtractGroupMembershipSignatures": statusgo.ExtractGroupMembershipSignatures,
|
"/statusgo/ExtractGroupMembershipSignatures": statusgo.ExtractGroupMembershipSignatures,
|
||||||
"/statusgo/SignGroupMembership": statusgo.SignGroupMembership,
|
"/statusgo/SignGroupMembership": statusgo.SignGroupMembership,
|
||||||
"/statusgo/ValidateNodeConfig": statusgo.ValidateNodeConfig,
|
"/statusgo/ValidateNodeConfig": statusgo.ValidateNodeConfig,
|
||||||
|
@ -77,8 +78,13 @@ var EndpointsUnsupported = []string{
|
||||||
"/statusgo/VerifyAccountPassword",
|
"/statusgo/VerifyAccountPassword",
|
||||||
"/statusgo/VerifyDatabasePassword",
|
"/statusgo/VerifyDatabasePassword",
|
||||||
"/statusgo/MigrateKeyStoreDir",
|
"/statusgo/MigrateKeyStoreDir",
|
||||||
|
"/statusgo/Login",
|
||||||
|
"/statusgo/LoginWithConfig",
|
||||||
|
"/statusgo/SaveAccountAndLogin",
|
||||||
"/statusgo/DeleteMultiaccount",
|
"/statusgo/DeleteMultiaccount",
|
||||||
"/statusgo/DeleteImportedKey",
|
"/statusgo/DeleteImportedKey",
|
||||||
|
"/statusgo/SaveAccountAndLoginWithKeycard",
|
||||||
|
"/statusgo/LoginWithKeycard",
|
||||||
"/statusgo/SignTypedData",
|
"/statusgo/SignTypedData",
|
||||||
"/statusgo/SignTypedDataV4",
|
"/statusgo/SignTypedDataV4",
|
||||||
"/statusgo/SendTransactionWithChainID",
|
"/statusgo/SendTransactionWithChainID",
|
||||||
|
@ -103,3 +109,12 @@ var EndpointsUnsupported = []string{
|
||||||
"/statusgo/EncodeTransfer",
|
"/statusgo/EncodeTransfer",
|
||||||
"/statusgo/EncodeFunctionCall",
|
"/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 }}/{{ . }}",
|
"/{{ $.PackageName }}/{{ . }}",
|
||||||
{{- end }}
|
{{- end }}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var EndpointsDeprecated = map[string]struct{}{
|
||||||
|
{{- range .DeprecatedEndpoints }}
|
||||||
|
"/{{ $.PackageName }}/{{ . }}": {},
|
||||||
|
{{- end }}
|
||||||
|
}
|
|
@ -39,6 +39,7 @@ type TemplateData struct {
|
||||||
FunctionsWithResp []string
|
FunctionsWithResp []string
|
||||||
FunctionsNoArgs []string
|
FunctionsNoArgs []string
|
||||||
UnsupportedEndpoints []string
|
UnsupportedEndpoints []string
|
||||||
|
DeprecatedEndpoints []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -54,6 +55,7 @@ func main() {
|
||||||
var publicFunctionsWithArgs []string
|
var publicFunctionsWithArgs []string
|
||||||
var publicFunctionsWithoutArgs []string
|
var publicFunctionsWithoutArgs []string
|
||||||
var unsupportedFunctions []string
|
var unsupportedFunctions []string
|
||||||
|
var deprecatedFucntions []string
|
||||||
var isDeprecated bool
|
var isDeprecated bool
|
||||||
var packageName string
|
var packageName string
|
||||||
|
|
||||||
|
@ -75,13 +77,13 @@ func main() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
functionName := extractFunctionName(line)
|
||||||
|
|
||||||
if isDeprecated {
|
if isDeprecated {
|
||||||
isDeprecated = false
|
isDeprecated = false
|
||||||
continue
|
deprecatedFucntions = append(deprecatedFucntions, functionName)
|
||||||
}
|
}
|
||||||
|
|
||||||
functionName := extractFunctionName(line)
|
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case isPublicFunctionWithArgs(line):
|
case isPublicFunctionWithArgs(line):
|
||||||
publicFunctionsWithArgs = append(publicFunctionsWithArgs, functionName)
|
publicFunctionsWithArgs = append(publicFunctionsWithArgs, functionName)
|
||||||
|
@ -103,6 +105,7 @@ func main() {
|
||||||
FunctionsWithResp: publicFunctionsWithArgs,
|
FunctionsWithResp: publicFunctionsWithArgs,
|
||||||
FunctionsNoArgs: publicFunctionsWithoutArgs,
|
FunctionsNoArgs: publicFunctionsWithoutArgs,
|
||||||
UnsupportedEndpoints: unsupportedFunctions,
|
UnsupportedEndpoints: unsupportedFunctions,
|
||||||
|
DeprecatedEndpoints: deprecatedFucntions,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load and parse the template
|
// Load and parse the template
|
||||||
|
|
|
@ -145,7 +145,8 @@ func (s *Server) addEndpointWithResponse(name string, handler func(string) strin
|
||||||
|
|
||||||
response := handler(string(request))
|
response := handler(string(request))
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
s.setHeaders(name, w)
|
||||||
|
|
||||||
_, err = w.Write([]byte(response))
|
_, err = w.Write([]byte(response))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("failed to write response: %w", err)
|
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) {
|
s.mux.HandleFunc(name, func(w http.ResponseWriter, r *http.Request) {
|
||||||
response := handler()
|
response := handler()
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
s.setHeaders(name, w)
|
||||||
|
|
||||||
_, err := w.Write([]byte(response))
|
_, err := w.Write([]byte(response))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("failed to write response: %w", err)
|
log.Error("failed to write response: %w", err)
|
||||||
|
@ -184,3 +186,10 @@ func (s *Server) RegisterMobileAPI() {
|
||||||
s.addUnsupportedEndpoint(name)
|
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