aboutsummaryrefslogtreecommitdiff
path: root/userapi/internal
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-06-16 17:39:56 +0100
committerGitHub <noreply@github.com>2020-06-16 17:39:56 +0100
commite15a8042a19b270060beef1358f90cda075ddd38 (patch)
treefaa2334c37ec7b0753541bbe000a16b4ac13548d /userapi/internal
parent83391da0e04dda7a52589ee7ec6df2b615571894 (diff)
BREAKING: Make eduserver/appservice use userapi (#1138)
* BREAKING: Make eduserver/appservice use userapi This is a breaking change because this PR restructures how the AS API tracks its position in Kafka streams. Previously, it used the account DB to store partition offsets. However, this is also being used by `clientapi` for the same purpose, which is bad (each component needs to store offsets independently or else you might lose messages across restarts). This PR changes this behaviour to now store partition offsets in the `appservice` database. This means that: - Upon restart, the `appservice` component will attempt to replay all room events from the beginning of time. - An additional table will be created in the appservice database, which in and of itself is backwards compatible. * Return ErrorConflict
Diffstat (limited to 'userapi/internal')
-rw-r--r--userapi/internal/api.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/userapi/internal/api.go b/userapi/internal/api.go
index 6e737b81..1b34dc7b 100644
--- a/userapi/internal/api.go
+++ b/userapi/internal/api.go
@@ -17,6 +17,7 @@ package internal
import (
"context"
"database/sql"
+ "errors"
"fmt"
"github.com/matrix-org/dendrite/appservice/types"
@@ -24,6 +25,7 @@ import (
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
"github.com/matrix-org/dendrite/clientapi/userutil"
"github.com/matrix-org/dendrite/internal/config"
+ "github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
)
@@ -36,6 +38,38 @@ type UserInternalAPI struct {
AppServices []config.ApplicationService
}
+func (a *UserInternalAPI) PerformAccountCreation(ctx context.Context, req *api.PerformAccountCreationRequest, res *api.PerformAccountCreationResponse) error {
+ acc, err := a.AccountDB.CreateAccount(ctx, req.Localpart, req.Password, req.AppServiceID)
+ if err != nil {
+ if errors.Is(err, sqlutil.ErrUserExists) { // This account already exists
+ switch req.OnConflict {
+ case api.ConflictUpdate:
+ break
+ case api.ConflictAbort:
+ return &api.ErrorConflict{
+ Message: err.Error(),
+ }
+ }
+ }
+ res.AccountCreated = false
+ res.UserID = fmt.Sprintf("@%s:%s", req.Localpart, a.ServerName)
+ return nil
+ }
+ res.AccountCreated = true
+ res.UserID = acc.UserID
+ return nil
+}
+func (a *UserInternalAPI) PerformDeviceCreation(ctx context.Context, req *api.PerformDeviceCreationRequest, res *api.PerformDeviceCreationResponse) error {
+ dev, err := a.DeviceDB.CreateDevice(ctx, req.Localpart, req.DeviceID, req.AccessToken, req.DeviceDisplayName)
+ if err != nil {
+ return err
+ }
+ res.DeviceCreated = true
+ res.AccessToken = dev.AccessToken
+ res.DeviceID = dev.ID
+ return nil
+}
+
func (a *UserInternalAPI) QueryProfile(ctx context.Context, req *api.QueryProfileRequest, res *api.QueryProfileResponse) error {
local, domain, err := gomatrixserverlib.SplitID('@', req.UserID)
if err != nil {