diff options
Diffstat (limited to 'clientapi')
-rw-r--r-- | clientapi/auth/password.go | 2 | ||||
-rw-r--r-- | clientapi/auth/user_interactive.go | 2 | ||||
-rw-r--r-- | clientapi/auth/user_interactive_test.go | 7 | ||||
-rw-r--r-- | clientapi/clientapi.go | 4 | ||||
-rw-r--r-- | clientapi/routing/auth_fallback.go | 8 | ||||
-rw-r--r-- | clientapi/routing/createroom.go | 6 | ||||
-rw-r--r-- | clientapi/routing/directory.go | 5 | ||||
-rw-r--r-- | clientapi/routing/getevent.go | 4 | ||||
-rw-r--r-- | clientapi/routing/login.go | 2 | ||||
-rw-r--r-- | clientapi/routing/membership.go | 18 | ||||
-rw-r--r-- | clientapi/routing/memberships.go | 2 | ||||
-rw-r--r-- | clientapi/routing/profile.go | 16 | ||||
-rw-r--r-- | clientapi/routing/redaction.go | 4 | ||||
-rw-r--r-- | clientapi/routing/register.go | 42 | ||||
-rw-r--r-- | clientapi/routing/register_test.go | 15 | ||||
-rw-r--r-- | clientapi/routing/routing.go | 2 | ||||
-rw-r--r-- | clientapi/routing/sendevent.go | 6 | ||||
-rw-r--r-- | clientapi/routing/threepid.go | 4 | ||||
-rw-r--r-- | clientapi/routing/voip.go | 2 | ||||
-rw-r--r-- | clientapi/threepid/invites.go | 10 | ||||
-rw-r--r-- | clientapi/threepid/threepid.go | 8 |
21 files changed, 87 insertions, 82 deletions
diff --git a/clientapi/auth/password.go b/clientapi/auth/password.go index f4814925..d9801955 100644 --- a/clientapi/auth/password.go +++ b/clientapi/auth/password.go @@ -35,7 +35,7 @@ type PasswordRequest struct { // LoginTypePassword implements https://matrix.org/docs/spec/client_server/r0.6.1#password-based type LoginTypePassword struct { GetAccountByPassword GetAccountByPassword - Config *config.Dendrite + Config *config.ClientAPI } func (t *LoginTypePassword) Name() string { diff --git a/clientapi/auth/user_interactive.go b/clientapi/auth/user_interactive.go index 581a85f0..c67eba15 100644 --- a/clientapi/auth/user_interactive.go +++ b/clientapi/auth/user_interactive.go @@ -110,7 +110,7 @@ type UserInteractive struct { Sessions map[string][]string } -func NewUserInteractive(getAccByPass GetAccountByPassword, cfg *config.Dendrite) *UserInteractive { +func NewUserInteractive(getAccByPass GetAccountByPassword, cfg *config.ClientAPI) *UserInteractive { typePassword := &LoginTypePassword{ GetAccountByPassword: getAccByPass, Config: cfg, diff --git a/clientapi/auth/user_interactive_test.go b/clientapi/auth/user_interactive_test.go index d12652c0..47d1cad3 100644 --- a/clientapi/auth/user_interactive_test.go +++ b/clientapi/auth/user_interactive_test.go @@ -33,8 +33,11 @@ func getAccountByPassword(ctx context.Context, localpart, plaintextPassword stri } func setup() *UserInteractive { - cfg := &config.Dendrite{} - cfg.Matrix.ServerName = serverName + cfg := &config.ClientAPI{ + Matrix: &config.Global{ + ServerName: serverName, + }, + } return NewUserInteractive(getAccountByPassword, cfg) } diff --git a/clientapi/clientapi.go b/clientapi/clientapi.go index 9ed285a8..f3789521 100644 --- a/clientapi/clientapi.go +++ b/clientapi/clientapi.go @@ -37,7 +37,7 @@ import ( // AddPublicRoutes sets up and registers HTTP handlers for the ClientAPI component. func AddPublicRoutes( router *mux.Router, - cfg *config.Dendrite, + cfg *config.ClientAPI, producer sarama.SyncProducer, deviceDB devices.Database, accountsDB accounts.Database, @@ -54,7 +54,7 @@ func AddPublicRoutes( ) { syncProducer := &producers.SyncAPIProducer{ Producer: producer, - Topic: string(cfg.Kafka.Topics.OutputClientData), + Topic: string(cfg.Matrix.Kafka.Topics.OutputClientData), } routing.Setup( diff --git a/clientapi/routing/auth_fallback.go b/clientapi/routing/auth_fallback.go index b7f2cd6d..e639b101 100644 --- a/clientapi/routing/auth_fallback.go +++ b/clientapi/routing/auth_fallback.go @@ -101,7 +101,7 @@ func serveTemplate(w http.ResponseWriter, templateHTML string, data map[string]s // AuthFallback implements GET and POST /auth/{authType}/fallback/web?session={sessionID} func AuthFallback( w http.ResponseWriter, req *http.Request, authType string, - cfg *config.Dendrite, + cfg *config.ClientAPI, ) *util.JSONResponse { sessionID := req.URL.Query().Get("session") @@ -116,7 +116,7 @@ func AuthFallback( data := map[string]string{ "myUrl": req.URL.String(), "session": sessionID, - "siteKey": cfg.Matrix.RecaptchaPublicKey, + "siteKey": cfg.RecaptchaPublicKey, } serveTemplate(w, recaptchaTemplate, data) } @@ -181,11 +181,11 @@ func AuthFallback( // checkRecaptchaEnabled creates an error response if recaptcha is not usable on homeserver. func checkRecaptchaEnabled( - cfg *config.Dendrite, + cfg *config.ClientAPI, w http.ResponseWriter, req *http.Request, ) *util.JSONResponse { - if !cfg.Matrix.RecaptchaEnabled { + if !cfg.RecaptchaEnabled { return writeHTTPMessage(w, req, "Recaptcha login is disabled on this Homeserver", http.StatusBadRequest, diff --git a/clientapi/routing/createroom.go b/clientapi/routing/createroom.go index 027a21e7..5412c222 100644 --- a/clientapi/routing/createroom.go +++ b/clientapi/routing/createroom.go @@ -135,7 +135,7 @@ type fledglingEvent struct { // CreateRoom implements /createRoom func CreateRoom( req *http.Request, device *api.Device, - cfg *config.Dendrite, + cfg *config.ClientAPI, accountDB accounts.Database, rsAPI roomserverAPI.RoomserverInternalAPI, asAPI appserviceAPI.AppServiceQueryAPI, ) util.JSONResponse { @@ -149,7 +149,7 @@ func CreateRoom( // nolint: gocyclo func createRoom( req *http.Request, device *api.Device, - cfg *config.Dendrite, roomID string, + cfg *config.ClientAPI, roomID string, accountDB accounts.Database, rsAPI roomserverAPI.RoomserverInternalAPI, asAPI appserviceAPI.AppServiceQueryAPI, ) util.JSONResponse { @@ -438,7 +438,7 @@ func createRoom( func buildEvent( builder *gomatrixserverlib.EventBuilder, provider gomatrixserverlib.AuthEventProvider, - cfg *config.Dendrite, + cfg *config.ClientAPI, evTime time.Time, roomVersion gomatrixserverlib.RoomVersion, ) (*gomatrixserverlib.Event, error) { diff --git a/clientapi/routing/directory.go b/clientapi/routing/directory.go index 0f78f4a2..62f295fe 100644 --- a/clientapi/routing/directory.go +++ b/clientapi/routing/directory.go @@ -47,7 +47,7 @@ func DirectoryRoom( req *http.Request, roomAlias string, federation *gomatrixserverlib.FederationClient, - cfg *config.Dendrite, + cfg *config.ClientAPI, rsAPI roomserverAPI.RoomserverInternalAPI, fedSenderAPI federationSenderAPI.FederationSenderInternalAPI, ) util.JSONResponse { @@ -116,7 +116,7 @@ func SetLocalAlias( req *http.Request, device *api.Device, alias string, - cfg *config.Dendrite, + cfg *config.ClientAPI, aliasAPI roomserverAPI.RoomserverInternalAPI, ) util.JSONResponse { _, domain, err := gomatrixserverlib.SplitID('#', alias) @@ -139,6 +139,7 @@ func SetLocalAlias( // TODO: This code should eventually be refactored with: // 1. The new method for checking for things matching an AS's namespace // 2. Using an overall Regex object for all AS's just like we did for usernames + for _, appservice := range cfg.Derived.ApplicationServices { // Don't prevent AS from creating aliases in its own namespace // Note that Dendrite uses SenderLocalpart as UserID for AS users diff --git a/clientapi/routing/getevent.go b/clientapi/routing/getevent.go index 2a51db73..c74509f0 100644 --- a/clientapi/routing/getevent.go +++ b/clientapi/routing/getevent.go @@ -30,7 +30,7 @@ type getEventRequest struct { device *userapi.Device roomID string eventID string - cfg *config.Dendrite + cfg *config.ClientAPI federation *gomatrixserverlib.FederationClient requestedEvent gomatrixserverlib.Event } @@ -42,7 +42,7 @@ func GetEvent( device *userapi.Device, roomID string, eventID string, - cfg *config.Dendrite, + cfg *config.ClientAPI, rsAPI api.RoomserverInternalAPI, federation *gomatrixserverlib.FederationClient, ) util.JSONResponse { diff --git a/clientapi/routing/login.go b/clientapi/routing/login.go index 42f828f6..d2bc9337 100644 --- a/clientapi/routing/login.go +++ b/clientapi/routing/login.go @@ -58,7 +58,7 @@ func passwordLogin() flows { // Login implements GET and POST /login func Login( req *http.Request, accountDB accounts.Database, userAPI userapi.UserInternalAPI, - cfg *config.Dendrite, + cfg *config.ClientAPI, ) util.JSONResponse { if req.Method == http.MethodGet { // TODO: support other forms of login other than password, depending on config options diff --git a/clientapi/routing/membership.go b/clientapi/routing/membership.go index 90ddb699..8303a68e 100644 --- a/clientapi/routing/membership.go +++ b/clientapi/routing/membership.go @@ -41,7 +41,7 @@ var errMissingUserID = errors.New("'user_id' must be supplied") func SendBan( req *http.Request, accountDB accounts.Database, device *userapi.Device, - roomID string, cfg *config.Dendrite, + roomID string, cfg *config.ClientAPI, rsAPI roomserverAPI.RoomserverInternalAPI, asAPI appserviceAPI.AppServiceQueryAPI, ) util.JSONResponse { body, evTime, roomVer, reqErr := extractRequestData(req, roomID, rsAPI) @@ -52,7 +52,7 @@ func SendBan( } func sendMembership(ctx context.Context, accountDB accounts.Database, device *userapi.Device, - roomID, membership, reason string, cfg *config.Dendrite, targetUserID string, evTime time.Time, + roomID, membership, reason string, cfg *config.ClientAPI, targetUserID string, evTime time.Time, roomVer gomatrixserverlib.RoomVersion, rsAPI roomserverAPI.RoomserverInternalAPI, asAPI appserviceAPI.AppServiceQueryAPI) util.JSONResponse { @@ -94,7 +94,7 @@ func sendMembership(ctx context.Context, accountDB accounts.Database, device *us func SendKick( req *http.Request, accountDB accounts.Database, device *userapi.Device, - roomID string, cfg *config.Dendrite, + roomID string, cfg *config.ClientAPI, rsAPI roomserverAPI.RoomserverInternalAPI, asAPI appserviceAPI.AppServiceQueryAPI, stateAPI currentstateAPI.CurrentStateInternalAPI, ) util.JSONResponse { @@ -135,7 +135,7 @@ func SendKick( func SendUnban( req *http.Request, accountDB accounts.Database, device *userapi.Device, - roomID string, cfg *config.Dendrite, + roomID string, cfg *config.ClientAPI, rsAPI roomserverAPI.RoomserverInternalAPI, asAPI appserviceAPI.AppServiceQueryAPI, ) util.JSONResponse { body, evTime, roomVer, reqErr := extractRequestData(req, roomID, rsAPI) @@ -170,7 +170,7 @@ func SendUnban( func SendInvite( req *http.Request, accountDB accounts.Database, device *userapi.Device, - roomID string, cfg *config.Dendrite, + roomID string, cfg *config.ClientAPI, rsAPI roomserverAPI.RoomserverInternalAPI, asAPI appserviceAPI.AppServiceQueryAPI, ) util.JSONResponse { body, evTime, roomVer, reqErr := extractRequestData(req, roomID, rsAPI) @@ -236,7 +236,7 @@ func buildMembershipEvent( targetUserID, reason string, accountDB accounts.Database, device *userapi.Device, membership, roomID string, isDirect bool, - cfg *config.Dendrite, evTime time.Time, + cfg *config.ClientAPI, evTime time.Time, rsAPI roomserverAPI.RoomserverInternalAPI, asAPI appserviceAPI.AppServiceQueryAPI, ) (*gomatrixserverlib.HeaderedEvent, error) { profile, err := loadProfile(ctx, targetUserID, cfg, accountDB, asAPI) @@ -263,7 +263,7 @@ func buildMembershipEvent( return nil, err } - return eventutil.BuildEvent(ctx, &builder, cfg, evTime, rsAPI, nil) + return eventutil.BuildEvent(ctx, &builder, cfg.Matrix, evTime, rsAPI, nil) } // loadProfile lookups the profile of a given user from the database and returns @@ -273,7 +273,7 @@ func buildMembershipEvent( func loadProfile( ctx context.Context, userID string, - cfg *config.Dendrite, + cfg *config.ClientAPI, accountDB accounts.Database, asAPI appserviceAPI.AppServiceQueryAPI, ) (*authtypes.Profile, error) { @@ -326,7 +326,7 @@ func checkAndProcessThreepid( req *http.Request, device *userapi.Device, body *threepid.MembershipRequest, - cfg *config.Dendrite, + cfg *config.ClientAPI, rsAPI roomserverAPI.RoomserverInternalAPI, accountDB accounts.Database, roomID string, diff --git a/clientapi/routing/memberships.go b/clientapi/routing/memberships.go index 9c4cf749..56059350 100644 --- a/clientapi/routing/memberships.go +++ b/clientapi/routing/memberships.go @@ -48,7 +48,7 @@ type joinedMember struct { // GetMemberships implements GET /rooms/{roomId}/members func GetMemberships( req *http.Request, device *userapi.Device, roomID string, joinedOnly bool, - _ *config.Dendrite, + _ *config.ClientAPI, rsAPI api.RoomserverInternalAPI, ) util.JSONResponse { queryReq := api.QueryMembershipsForRoomRequest{ diff --git a/clientapi/routing/profile.go b/clientapi/routing/profile.go index 1df4c9b3..faf92451 100644 --- a/clientapi/routing/profile.go +++ b/clientapi/routing/profile.go @@ -37,7 +37,7 @@ import ( // GetProfile implements GET /profile/{userID} func GetProfile( - req *http.Request, accountDB accounts.Database, cfg *config.Dendrite, + req *http.Request, accountDB accounts.Database, cfg *config.ClientAPI, userID string, asAPI appserviceAPI.AppServiceQueryAPI, federation *gomatrixserverlib.FederationClient, @@ -66,7 +66,7 @@ func GetProfile( // GetAvatarURL implements GET /profile/{userID}/avatar_url func GetAvatarURL( - req *http.Request, accountDB accounts.Database, cfg *config.Dendrite, + req *http.Request, accountDB accounts.Database, cfg *config.ClientAPI, userID string, asAPI appserviceAPI.AppServiceQueryAPI, federation *gomatrixserverlib.FederationClient, ) util.JSONResponse { @@ -95,7 +95,7 @@ func GetAvatarURL( // nolint:gocyclo func SetAvatarURL( req *http.Request, accountDB accounts.Database, stateAPI currentstateAPI.CurrentStateInternalAPI, - device *userapi.Device, userID string, cfg *config.Dendrite, rsAPI api.RoomserverInternalAPI, + device *userapi.Device, userID string, cfg *config.ClientAPI, rsAPI api.RoomserverInternalAPI, ) util.JSONResponse { if userID != device.UserID { return util.JSONResponse{ @@ -184,7 +184,7 @@ func SetAvatarURL( // GetDisplayName implements GET /profile/{userID}/displayname func GetDisplayName( - req *http.Request, accountDB accounts.Database, cfg *config.Dendrite, + req *http.Request, accountDB accounts.Database, cfg *config.ClientAPI, userID string, asAPI appserviceAPI.AppServiceQueryAPI, federation *gomatrixserverlib.FederationClient, ) util.JSONResponse { @@ -213,7 +213,7 @@ func GetDisplayName( // nolint:gocyclo func SetDisplayName( req *http.Request, accountDB accounts.Database, stateAPI currentstateAPI.CurrentStateInternalAPI, - device *userapi.Device, userID string, cfg *config.Dendrite, rsAPI api.RoomserverInternalAPI, + device *userapi.Device, userID string, cfg *config.ClientAPI, rsAPI api.RoomserverInternalAPI, ) util.JSONResponse { if userID != device.UserID { return util.JSONResponse{ @@ -305,7 +305,7 @@ func SetDisplayName( // Returns an error when something goes wrong or specifically // eventutil.ErrProfileNoExists when the profile doesn't exist. func getProfile( - ctx context.Context, accountDB accounts.Database, cfg *config.Dendrite, + ctx context.Context, accountDB accounts.Database, cfg *config.ClientAPI, userID string, asAPI appserviceAPI.AppServiceQueryAPI, federation *gomatrixserverlib.FederationClient, @@ -345,7 +345,7 @@ func getProfile( func buildMembershipEvents( ctx context.Context, roomIDs []string, - newProfile authtypes.Profile, userID string, cfg *config.Dendrite, + newProfile authtypes.Profile, userID string, cfg *config.ClientAPI, evTime time.Time, rsAPI api.RoomserverInternalAPI, ) ([]gomatrixserverlib.HeaderedEvent, error) { evs := []gomatrixserverlib.HeaderedEvent{} @@ -375,7 +375,7 @@ func buildMembershipEvents( return nil, err } - event, err := eventutil.BuildEvent(ctx, &builder, cfg, evTime, rsAPI, nil) + event, err := eventutil.BuildEvent(ctx, &builder, cfg.Matrix, evTime, rsAPI, nil) if err != nil { return nil, err } diff --git a/clientapi/routing/redaction.go b/clientapi/routing/redaction.go index fd80e0ab..bb526513 100644 --- a/clientapi/routing/redaction.go +++ b/clientapi/routing/redaction.go @@ -40,7 +40,7 @@ type redactionResponse struct { } func SendRedaction( - req *http.Request, device *userapi.Device, roomID, eventID string, cfg *config.Dendrite, + req *http.Request, device *userapi.Device, roomID, eventID string, cfg *config.ClientAPI, rsAPI roomserverAPI.RoomserverInternalAPI, stateAPI currentstateAPI.CurrentStateInternalAPI, ) util.JSONResponse { resErr := checkMemberInRoom(req.Context(), stateAPI, device.UserID, roomID) @@ -115,7 +115,7 @@ func SendRedaction( } var queryRes api.QueryLatestEventsAndStateResponse - e, err := eventutil.BuildEvent(req.Context(), &builder, cfg, time.Now(), rsAPI, &queryRes) + e, err := eventutil.BuildEvent(req.Context(), &builder, cfg.Matrix, time.Now(), rsAPI, &queryRes) if err == eventutil.ErrRoomNoExists { return util.JSONResponse{ Code: http.StatusNotFound, diff --git a/clientapi/routing/register.go b/clientapi/routing/register.go index 69ebdfd7..937abc83 100644 --- a/clientapi/routing/register.go +++ b/clientapi/routing/register.go @@ -255,11 +255,11 @@ func validatePassword(password string) *util.JSONResponse { // validateRecaptcha returns an error response if the captcha response is invalid func validateRecaptcha( - cfg *config.Dendrite, + cfg *config.ClientAPI, response string, clientip string, ) *util.JSONResponse { - if !cfg.Matrix.RecaptchaEnabled { + if !cfg.RecaptchaEnabled { return &util.JSONResponse{ Code: http.StatusConflict, JSON: jsonerror.Unknown("Captcha registration is disabled"), @@ -274,9 +274,9 @@ func validateRecaptcha( } // Make a POST request to Google's API to check the captcha response - resp, err := http.PostForm(cfg.Matrix.RecaptchaSiteVerifyAPI, + resp, err := http.PostForm(cfg.RecaptchaSiteVerifyAPI, url.Values{ - "secret": {cfg.Matrix.RecaptchaPrivateKey}, + "secret": {cfg.RecaptchaPrivateKey}, "response": {response}, "remoteip": {clientip}, }, @@ -324,7 +324,7 @@ func validateRecaptcha( // Application Service is given, it will check to see if it matches any // Application Service's namespace. func UserIDIsWithinApplicationServiceNamespace( - cfg *config.Dendrite, + cfg *config.ClientAPI, userID string, appservice *config.ApplicationService, ) bool { @@ -354,7 +354,7 @@ func UserIDIsWithinApplicationServiceNamespace( // UsernameMatchesMultipleExclusiveNamespaces will check if a given username matches // more than one exclusive namespace. More than one is not allowed func UsernameMatchesMultipleExclusiveNamespaces( - cfg *config.Dendrite, + cfg *config.ClientAPI, username string, ) bool { userID := userutil.MakeUserID(username, cfg.Matrix.ServerName) @@ -374,7 +374,7 @@ func UsernameMatchesMultipleExclusiveNamespaces( // UsernameMatchesExclusiveNamespaces will check if a given username matches any // application service's exclusive users namespace func UsernameMatchesExclusiveNamespaces( - cfg *config.Dendrite, + cfg *config.ClientAPI, username string, ) bool { userID := userutil.MakeUserID(username, cfg.Matrix.ServerName) @@ -386,7 +386,7 @@ func UsernameMatchesExclusiveNamespaces( // username is within that application service's namespace. As long as these // two requirements are met, no error will be returned. func validateApplicationService( - cfg *config.Dendrite, + cfg *config.ClientAPI, username string, accessToken string, ) (string, *util.JSONResponse) { @@ -442,7 +442,7 @@ func Register( req *http.Request, userAPI userapi.UserInternalAPI, accountDB accounts.Database, - cfg *config.Dendrite, + cfg *config.ClientAPI, ) util.JSONResponse { var r registerRequest resErr := httputil.UnmarshalJSONRequest(req, &r) @@ -512,7 +512,7 @@ func Register( func handleGuestRegistration( req *http.Request, r registerRequest, - cfg *config.Dendrite, + cfg *config.ClientAPI, userAPI userapi.UserInternalAPI, ) util.JSONResponse { var res userapi.PerformAccountCreationResponse @@ -568,7 +568,7 @@ func handleRegistrationFlow( req *http.Request, r registerRequest, sessionID string, - cfg *config.Dendrite, + cfg *config.ClientAPI, userAPI userapi.UserInternalAPI, ) util.JSONResponse { // TODO: Shared secret registration (create new user scripts) @@ -580,7 +580,7 @@ func handleRegistrationFlow( // TODO: email / msisdn auth types. - if cfg.Matrix.RegistrationDisabled && r.Auth.Type != authtypes.LoginTypeSharedSecret { + if cfg.RegistrationDisabled && r.Auth.Type != authtypes.LoginTypeSharedSecret { return util.MessageResponse(http.StatusForbidden, "Registration has been disabled") } @@ -666,7 +666,7 @@ func handleApplicationServiceRegistration( tokenErr error, req *http.Request, r registerRequest, - cfg *config.Dendrite, + cfg *config.ClientAPI, userAPI userapi.UserInternalAPI, ) util.JSONResponse { // Check if we previously had issues extracting the access token from the @@ -704,7 +704,7 @@ func checkAndCompleteFlow( req *http.Request, r registerRequest, sessionID string, - cfg *config.Dendrite, + cfg *config.ClientAPI, userAPI userapi.UserInternalAPI, ) util.JSONResponse { if checkFlowCompleted(flow, cfg.Derived.Registration.Flows) { @@ -728,7 +728,7 @@ func checkAndCompleteFlow( func LegacyRegister( req *http.Request, userAPI userapi.UserInternalAPI, - cfg *config.Dendrite, + cfg *config.ClientAPI, ) util.JSONResponse { var r legacyRegisterRequest resErr := parseAndValidateLegacyLogin(req, &r) @@ -742,13 +742,13 @@ func LegacyRegister( "auth.type": r.Type, }).Info("Processing registration request") - if cfg.Matrix.RegistrationDisabled && r.Type != authtypes.LoginTypeSharedSecret { + if cfg.RegistrationDisabled && r.Type != authtypes.LoginTypeSharedSecret { return util.MessageResponse(http.StatusForbidden, "Registration has been disabled") } switch r.Type { case authtypes.LoginTypeSharedSecret: - if cfg.Matrix.RegistrationSharedSecret == "" { + if cfg.RegistrationSharedSecret == "" { return util.MessageResponse(http.StatusBadRequest, "Shared secret registration is disabled") } @@ -902,15 +902,15 @@ func completeRegistration( // Used for shared secret registration. // Checks if the username, password and isAdmin flag matches the given mac. func isValidMacLogin( - cfg *config.Dendrite, + cfg *config.ClientAPI, username, password string, isAdmin bool, givenMac []byte, ) (bool, error) { - sharedSecret := cfg.Matrix.RegistrationSharedSecret + sharedSecret := cfg.RegistrationSharedSecret // Check that shared secret registration isn't disabled. - if cfg.Matrix.RegistrationSharedSecret == "" { + if cfg.RegistrationSharedSecret == "" { return false, errors.New("Shared secret registration is disabled") } @@ -1001,7 +1001,7 @@ type availableResponse struct { // RegisterAvailable checks if the username is already taken or invalid. func RegisterAvailable( req *http.Request, - cfg *config.Dendrite, + cfg *config.ClientAPI, accountDB accounts.Database, ) util.JSONResponse { username := req.URL.Query().Get("username") diff --git a/clientapi/routing/register_test.go b/clientapi/routing/register_test.go index a44389f9..0a91ae0f 100644 --- a/clientapi/routing/register_test.go +++ b/clientapi/routing/register_test.go @@ -179,30 +179,31 @@ func TestValidationOfApplicationServices(t *testing.T) { } // Set up a config - fakeConfig := config.Dendrite{} - fakeConfig.Matrix.ServerName = "localhost" - fakeConfig.Derived.ApplicationServices = []config.ApplicationService{fakeApplicationService} + fakeConfig := &config.Dendrite{} + fakeConfig.Defaults() + fakeConfig.Global.ServerName = "localhost" + fakeConfig.ClientAPI.Derived.ApplicationServices = []config.ApplicationService{fakeApplicationService} // Access token is correct, user_id omitted so we are acting as SenderLocalpart - asID, resp := validateApplicationService(&fakeConfig, fakeSenderLocalpart, "1234") + asID, resp := validateApplicationService(&fakeConfig.ClientAPI, fakeSenderLocalpart, "1234") if resp != nil || asID != fakeID { t.Errorf("appservice should have validated and returned correct ID: %s", resp.JSON) } // Access token is incorrect, user_id omitted so we are acting as SenderLocalpart - asID, resp = validateApplicationService(&fakeConfig, fakeSenderLocalpart, "xxxx") + asID, resp = validateApplicationService(&fakeConfig.ClientAPI, fakeSenderLocalpart, "xxxx") if resp == nil || asID == fakeID { t.Errorf("access_token should have been marked as invalid") } // Access token is correct, acting as valid user_id - asID, resp = validateApplicationService(&fakeConfig, "_appservice_bob", "1234") + asID, resp = validateApplicationService(&fakeConfig.ClientAPI, "_appservice_bob", "1234") if resp != nil || asID != fakeID { t.Errorf("access_token and user_id should've been valid: %s", resp.JSON) } // Access token is correct, acting as invalid user_id - asID, resp = validateApplicationService(&fakeConfig, "_something_else", "1234") + asID, resp = validateApplicationService(&fakeConfig.ClientAPI, "_something_else", "1234") if resp == nil || asID == fakeID { t.Errorf("user_id should not have been valid: @_something_else:localhost") } diff --git a/clientapi/routing/routing.go b/clientapi/routing/routing.go index 0e58129e..883b473b 100644 --- a/clientapi/routing/routing.go +++ b/clientapi/routing/routing.go @@ -51,7 +51,7 @@ const pathPrefixUnstable = "/client/unstable" // applied: // nolint: gocyclo func Setup( - publicAPIMux *mux.Router, cfg *config.Dendrite, + publicAPIMux *mux.Router, cfg *config.ClientAPI, eduAPI eduServerAPI.EDUServerInputAPI, rsAPI roomserverAPI.RoomserverInternalAPI, asAPI appserviceAPI.AppServiceQueryAPI, diff --git a/clientapi/routing/sendevent.go b/clientapi/routing/sendevent.go index bf32992f..e0cd7eb5 100644 --- a/clientapi/routing/sendevent.go +++ b/clientapi/routing/sendevent.go @@ -43,7 +43,7 @@ func SendEvent( req *http.Request, device *userapi.Device, roomID, eventType string, txnID, stateKey *string, - cfg *config.Dendrite, + cfg *config.ClientAPI, rsAPI api.RoomserverInternalAPI, txnCache *transactions.Cache, ) util.JSONResponse { @@ -112,7 +112,7 @@ func generateSendEvent( req *http.Request, device *userapi.Device, roomID, eventType string, stateKey *string, - cfg *config.Dendrite, + cfg *config.ClientAPI, rsAPI api.RoomserverInternalAPI, ) (*gomatrixserverlib.Event, *util.JSONResponse) { // parse the incoming http request @@ -146,7 +146,7 @@ func generateSendEvent( } var queryRes api.QueryLatestEventsAndStateResponse - e, err := eventutil.BuildEvent(req.Context(), &builder, cfg, evTime, rsAPI, &queryRes) + e, err := eventutil.BuildEvent(req.Context(), &builder, cfg.Matrix, evTime, rsAPI, &queryRes) if err == eventutil.ErrRoomNoExists { return nil, &util.JSONResponse{ Code: http.StatusNotFound, diff --git a/clientapi/routing/threepid.go b/clientapi/routing/threepid.go index e7aaadf5..54ffa53f 100644 --- a/clientapi/routing/threepid.go +++ b/clientapi/routing/threepid.go @@ -40,7 +40,7 @@ type threePIDsResponse struct { // RequestEmailToken implements: // POST /account/3pid/email/requestToken // POST /register/email/requestToken -func RequestEmailToken(req *http.Request, accountDB accounts.Database, cfg *config.Dendrite) util.JSONResponse { +func RequestEmailToken(req *http.Request, accountDB accounts.Database, cfg *config.ClientAPI) util.JSONResponse { var body threepid.EmailAssociationRequest if reqErr := httputil.UnmarshalJSONRequest(req, &body); reqErr != nil { return *reqErr @@ -86,7 +86,7 @@ func RequestEmailToken(req *http.Request, accountDB accounts.Database, cfg *conf // CheckAndSave3PIDAssociation implements POST /account/3pid func CheckAndSave3PIDAssociation( req *http.Request, accountDB accounts.Database, device *api.Device, - cfg *config.Dendrite, + cfg *config.ClientAPI, ) util.JSONResponse { var body threepid.EmailAssociationCheckRequest if reqErr := httputil.UnmarshalJSONRequest(req, &body); reqErr != nil { diff --git a/clientapi/routing/voip.go b/clientapi/routing/voip.go index 046e8781..536c69fb 100644 --- a/clientapi/routing/voip.go +++ b/clientapi/routing/voip.go @@ -31,7 +31,7 @@ import ( // RequestTurnServer implements: // GET /voip/turnServer -func RequestTurnServer(req *http.Request, device *api.Device, cfg *config.Dendrite) util.JSONResponse { +func RequestTurnServer(req *http.Request, device *api.Device, cfg *config.ClientAPI) util.JSONResponse { turnConfig := cfg.TURN // TODO Guest Support diff --git a/clientapi/threepid/invites.go b/clientapi/threepid/invites.go index 89bc8606..f1d54a47 100644 --- a/clientapi/threepid/invites.go +++ b/clientapi/threepid/invites.go @@ -86,7 +86,7 @@ var ( // can be emitted. func CheckAndProcessInvite( ctx context.Context, - device *userapi.Device, body *MembershipRequest, cfg *config.Dendrite, + device *userapi.Device, body *MembershipRequest, cfg *config.ClientAPI, rsAPI api.RoomserverInternalAPI, db accounts.Database, roomID string, evTime time.Time, @@ -137,7 +137,7 @@ func CheckAndProcessInvite( // Returns an error if a check or a request failed. func queryIDServer( ctx context.Context, - db accounts.Database, cfg *config.Dendrite, device *userapi.Device, + db accounts.Database, cfg *config.ClientAPI, device *userapi.Device, body *MembershipRequest, roomID string, ) (lookupRes *idServerLookupResponse, storeInviteRes *idServerStoreInviteResponse, err error) { if err = isTrusted(body.IDServer, cfg); err != nil { @@ -206,7 +206,7 @@ func queryIDServerLookup(ctx context.Context, body *MembershipRequest) (*idServe // Returns an error if the request failed to send or if the response couldn't be parsed. func queryIDServerStoreInvite( ctx context.Context, - db accounts.Database, cfg *config.Dendrite, device *userapi.Device, + db accounts.Database, cfg *config.ClientAPI, device *userapi.Device, body *MembershipRequest, roomID string, ) (*idServerStoreInviteResponse, error) { // Retrieve the sender's profile to get their display name @@ -330,7 +330,7 @@ func checkIDServerSignatures( func emit3PIDInviteEvent( ctx context.Context, body *MembershipRequest, res *idServerStoreInviteResponse, - device *userapi.Device, roomID string, cfg *config.Dendrite, + device *userapi.Device, roomID string, cfg *config.ClientAPI, rsAPI api.RoomserverInternalAPI, evTime time.Time, ) error { @@ -354,7 +354,7 @@ func emit3PIDInviteEvent( } queryRes := api.QueryLatestEventsAndStateResponse{} - event, err := eventutil.BuildEvent(ctx, builder, cfg, evTime, rsAPI, &queryRes) + event, err := eventutil.BuildEvent(ctx, builder, cfg.Matrix, evTime, rsAPI, &queryRes) if err != nil { return err } diff --git a/clientapi/threepid/threepid.go b/clientapi/threepid/threepid.go index bffe31ad..40fd161d 100644 --- a/clientapi/threepid/threepid.go +++ b/clientapi/threepid/threepid.go @@ -53,7 +53,7 @@ type Credentials struct { // Returns an error if there was a problem sending the request or decoding the // response, or if the identity server responded with a non-OK status. func CreateSession( - ctx context.Context, req EmailAssociationRequest, cfg *config.Dendrite, + ctx context.Context, req EmailAssociationRequest, cfg *config.ClientAPI, ) (string, error) { if err := isTrusted(req.IDServer, cfg); err != nil { return "", err @@ -101,7 +101,7 @@ func CreateSession( // Returns an error if there was a problem sending the request or decoding the // response, or if the identity server responded with a non-OK status. func CheckAssociation( - ctx context.Context, creds Credentials, cfg *config.Dendrite, + ctx context.Context, creds Credentials, cfg *config.ClientAPI, ) (bool, string, string, error) { if err := isTrusted(creds.IDServer, cfg); err != nil { return false, "", "", err @@ -142,7 +142,7 @@ func CheckAssociation( // identifier and a Matrix ID. // Returns an error if there was a problem sending the request or decoding the // response, or if the identity server responded with a non-OK status. -func PublishAssociation(creds Credentials, userID string, cfg *config.Dendrite) error { +func PublishAssociation(creds Credentials, userID string, cfg *config.ClientAPI) error { if err := isTrusted(creds.IDServer, cfg); err != nil { return err } @@ -177,7 +177,7 @@ func PublishAssociation(creds Credentials, userID string, cfg *config.Dendrite) // isTrusted checks if a given identity server is part of the list of trusted // identity servers in the configuration file. // Returns an error if the server isn't trusted. -func isTrusted(idServer string, cfg *config.Dendrite) error { +func isTrusted(idServer string, cfg *config.ClientAPI) error { for _, server := range cfg.Matrix.TrustedIDServers { if idServer == server { return nil |