mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-30 04:52:46 +00:00
Configuration format v1 (#1230)
* Initial pass at refactoring config (not finished) * Don't forget current state and EDU servers * More shifting around * Update server key API tests * Fix roomserver test * Fix more tests * Further tweaks * Fix current state server test (sort of) * Maybe fix appservices * Fix client API test * Include database connection string in database options * Fix sync API build * Update config test * Fix unit tests * Fix federation sender build * Fix gobind build * Set Listen address for all services in HTTP monolith mode * Validate config, reinstate appservice derived in directory, tweaks * Tweak federation API test * Set MaxOpenConnections/MaxIdleConnections to previous values * Update generate-config
This commit is contained in:
parent
fdabba1851
commit
4b09f445c9
155 changed files with 1716 additions and 1503 deletions
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue