浏览代码

Move provisioning endpoint version into code

Tulir Asokan 3 年之前
父节点
当前提交
082bdcca11
共有 3 个文件被更改,包括 19 次插入14 次删除
  1. 6 1
      config/upgrade.go
  2. 1 1
      example-config.yaml
  3. 12 12
      provisioning.go

+ 6 - 1
config/upgrade.go

@@ -20,6 +20,7 @@ import (
 	"fmt"
 	"os"
 	"path"
+	"strings"
 
 	"gopkg.in/yaml.v3"
 
@@ -42,7 +43,11 @@ func (helper *UpgradeHelper) doUpgrade() {
 	helper.Copy(Int, "appservice", "database", "max_idle_conns")
 	helper.Copy(Str|Null, "appservice", "database", "max_conn_idle_time")
 	helper.Copy(Str|Null, "appservice", "database", "max_conn_lifetime")
-	helper.Copy(Str, "appservice", "provisioning", "prefix")
+	if prefix, ok := helper.Get(Str, "appservice", "provisioning", "prefix"); ok && strings.HasSuffix(prefix, "/v1") {
+		helper.Set(Str, strings.TrimSuffix(prefix, "/v1"), "appservice", "provisioning", "prefix")
+	} else {
+		helper.Copy(Str, "appservice", "provisioning", "prefix")
+	}
 	if secret, ok := helper.Get(Str, "appservice", "provisioning", "shared_secret"); !ok || secret == "generate" {
 		sharedSecret := appservice.RandomString(64)
 		helper.Set(Str, sharedSecret, "appservice", "provisioning", "shared_secret")

+ 1 - 1
example-config.yaml

@@ -44,7 +44,7 @@ appservice:
     # Settings for provisioning API
     provisioning:
         # Prefix for the provisioning API paths.
-        prefix: /_matrix/provision/v1
+        prefix: /_matrix/provision
         # Shared secret for authentication. If set to "generate", a random secret will be generated,
         # or if set to "disable", the provisioning API will be disabled.
         shared_secret: generate

+ 12 - 12
provisioning.go

@@ -50,22 +50,22 @@ func (prov *ProvisioningAPI) Init() {
 	prov.log.Debugln("Enabling provisioning API at", prov.bridge.Config.AppService.Provisioning.Prefix)
 	r := prov.bridge.AS.Router.PathPrefix(prov.bridge.Config.AppService.Provisioning.Prefix).Subrouter()
 	r.Use(prov.AuthMiddleware)
-	r.HandleFunc("/ping", prov.Ping).Methods(http.MethodGet)
-	r.HandleFunc("/login", prov.Login).Methods(http.MethodGet)
-	r.HandleFunc("/logout", prov.Logout).Methods(http.MethodPost)
-	r.HandleFunc("/delete_session", prov.DeleteSession).Methods(http.MethodPost)
-	r.HandleFunc("/disconnect", prov.Disconnect).Methods(http.MethodPost)
-	r.HandleFunc("/reconnect", prov.Reconnect).Methods(http.MethodPost)
-	r.HandleFunc("/sync/appstate/{name}", prov.SyncAppState).Methods(http.MethodPost)
-	r.HandleFunc("/contacts", prov.ListContacts).Methods(http.MethodGet)
-	r.HandleFunc("/groups", prov.ListGroups).Methods(http.MethodGet)
-	r.HandleFunc("/pm/{number}", prov.StartPM).Methods(http.MethodPost)
-	r.HandleFunc("/open/{groupID}", prov.OpenGroup).Methods(http.MethodPost)
+	r.HandleFunc("/v1/ping", prov.Ping).Methods(http.MethodGet)
+	r.HandleFunc("/v1/login", prov.Login).Methods(http.MethodGet)
+	r.HandleFunc("/v1/logout", prov.Logout).Methods(http.MethodPost)
+	r.HandleFunc("/v1/delete_session", prov.DeleteSession).Methods(http.MethodPost)
+	r.HandleFunc("/v1/disconnect", prov.Disconnect).Methods(http.MethodPost)
+	r.HandleFunc("/v1/reconnect", prov.Reconnect).Methods(http.MethodPost)
+	r.HandleFunc("/v1/sync/appstate/{name}", prov.SyncAppState).Methods(http.MethodPost)
+	r.HandleFunc("/v1/contacts", prov.ListContacts).Methods(http.MethodGet)
+	r.HandleFunc("/v1/groups", prov.ListGroups).Methods(http.MethodGet)
+	r.HandleFunc("/v1/pm/{number}", prov.StartPM).Methods(http.MethodPost)
+	r.HandleFunc("/v1/open/{groupID}", prov.OpenGroup).Methods(http.MethodPost)
 	prov.bridge.AS.Router.HandleFunc("/_matrix/app/com.beeper.asmux/ping", prov.BridgeStatePing).Methods(http.MethodPost)
 	prov.bridge.AS.Router.HandleFunc("/_matrix/app/com.beeper.bridge_state", prov.BridgeStatePing).Methods(http.MethodPost)
 
 	// Deprecated, just use /disconnect
-	r.HandleFunc("/delete_connection", prov.Disconnect).Methods(http.MethodPost)
+	r.HandleFunc("/v1/delete_connection", prov.Disconnect).Methods(http.MethodPost)
 }
 
 type responseWrap struct {