mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-04-11 22:33:40 +00:00
Generate sender_localpart user for each AS on startup
Signed-off-by: Andrew Morgan <andrewm@matrix.org>
This commit is contained in:
parent
4624dbbae7
commit
8f0b773fca
4 changed files with 72 additions and 2 deletions
|
@ -141,3 +141,27 @@ func generateAppServiceAccount(
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// generateAppServiceAccounts creates a dummy account based off the
|
||||||
|
// `sender_localpart` field of each application service if it doesn't
|
||||||
|
// exist already
|
||||||
|
func generateAppServiceAccount(
|
||||||
|
accountsDB *accounts.Database,
|
||||||
|
deviceDB *devices.Database,
|
||||||
|
as config.ApplicationService,
|
||||||
|
) error {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
// Create an account for the application service
|
||||||
|
acc, err := accountsDB.CreateAccount(ctx, as.SenderLocalpart, "", as.ID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if acc == nil {
|
||||||
|
// This account already exists
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a dummy device with a dummy token for the application service
|
||||||
|
_, err = deviceDB.CreateDevice(ctx, as.SenderLocalpart, nil, as.ASToken, &as.SenderLocalpart)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
|
@ -83,9 +83,12 @@ func VerifyUserFromRequest(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
userID := req.URL.Query().Get("user_id")
|
if appService != nil {
|
||||||
if appService != nil && userID != "" {
|
userID := req.URL.Query().Get("user_id")
|
||||||
localpart, err := userutil.ParseUsernameParam(userID, nil)
|
localpart, err := userutil.ParseUsernameParam(userID, nil)
|
||||||
|
if userID == "" {
|
||||||
|
localpart = appService.SenderLocalpart
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &util.JSONResponse{
|
return nil, &util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
// Copyright 2018 Vector Creations Ltd
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/matrix-org/dendrite/appservice"
|
||||||
|
"github.com/matrix-org/dendrite/common/basecomponent"
|
||||||
|
"github.com/matrix-org/dendrite/common/transactions"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
cfg := basecomponent.ParseFlags()
|
||||||
|
base := basecomponent.NewBaseDendrite(cfg, "AppServiceAPI")
|
||||||
|
|
||||||
|
defer base.Close() // nolint: errcheck
|
||||||
|
accountDB := base.CreateAccountsDB()
|
||||||
|
deviceDB := base.CreateDeviceDB()
|
||||||
|
federation := base.CreateFederationClient()
|
||||||
|
alias, _, query := base.CreateHTTPRoomserverAPIs()
|
||||||
|
cache := transactions.New()
|
||||||
|
|
||||||
|
appservice.SetupAppServiceAPIComponent(
|
||||||
|
base, accountDB, deviceDB, federation, alias, query, cache,
|
||||||
|
)
|
||||||
|
|
||||||
|
base.SetupAndServeHTTP(string(base.Cfg.Listen.FederationSender))
|
||||||
|
}
|
|
@ -65,6 +65,10 @@ func main() {
|
||||||
mediaapi.SetupMediaAPIComponent(base, deviceDB)
|
mediaapi.SetupMediaAPIComponent(base, deviceDB)
|
||||||
publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB)
|
publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB)
|
||||||
syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, query)
|
syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, query)
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
appservice.SetupAppServiceAPIComponent(base, accountDB, deviceDB, federation, alias, query, transactions.New())
|
||||||
|
>>>>>>> c65838c9... Generate sender_localpart user for each AS on startup
|
||||||
|
|
||||||
httpHandler := common.WrapHandlerInCORS(base.APIMux)
|
httpHandler := common.WrapHandlerInCORS(base.APIMux)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue