mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-30 04:52:46 +00:00
- Removed double imports (#1989)
- Lower cased error messages Signed-off-by: Ryan Whittington <twentybitdev@gmail.com> Co-authored-by: kegsay <kegan@matrix.org>
This commit is contained in:
parent
7dc8fb1fe7
commit
a624eab309
38 changed files with 162 additions and 177 deletions
|
@ -32,7 +32,7 @@ func ParseTSParam(req *http.Request) (time.Time, error) {
|
|||
// The parameter exists, parse into a Time object
|
||||
ts, err := strconv.ParseInt(tsStr, 10, 64)
|
||||
if err != nil {
|
||||
return time.Time{}, fmt.Errorf("Param 'ts' is no valid int (%s)", err.Error())
|
||||
return time.Time{}, fmt.Errorf("param 'ts' is no valid int (%s)", err.Error())
|
||||
}
|
||||
|
||||
return time.Unix(ts/1000, 0), nil
|
||||
|
|
|
@ -23,7 +23,6 @@ import (
|
|||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/userapi/api"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/util"
|
||||
)
|
||||
|
@ -50,18 +49,18 @@ type devicesDeleteJSON struct {
|
|||
|
||||
// GetDeviceByID handles /devices/{deviceID}
|
||||
func GetDeviceByID(
|
||||
req *http.Request, userAPI userapi.UserInternalAPI, device *api.Device,
|
||||
req *http.Request, userAPI api.UserInternalAPI, device *api.Device,
|
||||
deviceID string,
|
||||
) util.JSONResponse {
|
||||
var queryRes userapi.QueryDevicesResponse
|
||||
err := userAPI.QueryDevices(req.Context(), &userapi.QueryDevicesRequest{
|
||||
var queryRes api.QueryDevicesResponse
|
||||
err := userAPI.QueryDevices(req.Context(), &api.QueryDevicesRequest{
|
||||
UserID: device.UserID,
|
||||
}, &queryRes)
|
||||
if err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Error("QueryDevices failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
var targetDevice *userapi.Device
|
||||
var targetDevice *api.Device
|
||||
for _, device := range queryRes.Devices {
|
||||
if device.ID == deviceID {
|
||||
targetDevice = &device
|
||||
|
@ -88,10 +87,10 @@ func GetDeviceByID(
|
|||
|
||||
// GetDevicesByLocalpart handles /devices
|
||||
func GetDevicesByLocalpart(
|
||||
req *http.Request, userAPI userapi.UserInternalAPI, device *api.Device,
|
||||
req *http.Request, userAPI api.UserInternalAPI, device *api.Device,
|
||||
) util.JSONResponse {
|
||||
var queryRes userapi.QueryDevicesResponse
|
||||
err := userAPI.QueryDevices(req.Context(), &userapi.QueryDevicesRequest{
|
||||
var queryRes api.QueryDevicesResponse
|
||||
err := userAPI.QueryDevices(req.Context(), &api.QueryDevicesRequest{
|
||||
UserID: device.UserID,
|
||||
}, &queryRes)
|
||||
if err != nil {
|
||||
|
|
|
@ -23,7 +23,6 @@ import (
|
|||
federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api"
|
||||
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
"github.com/matrix-org/dendrite/userapi/api"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/util"
|
||||
|
@ -115,7 +114,7 @@ func DirectoryRoom(
|
|||
// SetLocalAlias implements PUT /directory/room/{roomAlias}
|
||||
func SetLocalAlias(
|
||||
req *http.Request,
|
||||
device *api.Device,
|
||||
device *userapi.Device,
|
||||
alias string,
|
||||
cfg *config.ClientAPI,
|
||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
|
@ -192,7 +191,7 @@ func SetLocalAlias(
|
|||
// RemoveLocalAlias implements DELETE /directory/room/{roomAlias}
|
||||
func RemoveLocalAlias(
|
||||
req *http.Request,
|
||||
device *api.Device,
|
||||
device *userapi.Device,
|
||||
alias string,
|
||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
) util.JSONResponse {
|
||||
|
|
|
@ -19,16 +19,15 @@ import (
|
|||
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/userapi/api"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
"github.com/matrix-org/util"
|
||||
)
|
||||
|
||||
// Logout handles POST /logout
|
||||
func Logout(
|
||||
req *http.Request, userAPI userapi.UserInternalAPI, device *api.Device,
|
||||
req *http.Request, userAPI api.UserInternalAPI, device *api.Device,
|
||||
) util.JSONResponse {
|
||||
var performRes userapi.PerformDeviceDeletionResponse
|
||||
err := userAPI.PerformDeviceDeletion(req.Context(), &userapi.PerformDeviceDeletionRequest{
|
||||
var performRes api.PerformDeviceDeletionResponse
|
||||
err := userAPI.PerformDeviceDeletion(req.Context(), &api.PerformDeviceDeletionRequest{
|
||||
UserID: device.UserID,
|
||||
DeviceIDs: []string{device.ID},
|
||||
}, &performRes)
|
||||
|
@ -45,10 +44,10 @@ func Logout(
|
|||
|
||||
// LogoutAll handles POST /logout/all
|
||||
func LogoutAll(
|
||||
req *http.Request, userAPI userapi.UserInternalAPI, device *api.Device,
|
||||
req *http.Request, userAPI api.UserInternalAPI, device *api.Device,
|
||||
) util.JSONResponse {
|
||||
var performRes userapi.PerformDeviceDeletionResponse
|
||||
err := userAPI.PerformDeviceDeletion(req.Context(), &userapi.PerformDeviceDeletionRequest{
|
||||
var performRes api.PerformDeviceDeletionResponse
|
||||
err := userAPI.PerformDeviceDeletion(req.Context(), &api.PerformDeviceDeletionRequest{
|
||||
UserID: device.UserID,
|
||||
DeviceIDs: nil,
|
||||
}, &performRes)
|
||||
|
|
|
@ -26,7 +26,6 @@ import (
|
|||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/clientapi/threepid"
|
||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
|
@ -107,7 +106,7 @@ func sendMembership(ctx context.Context, accountDB accounts.Database, device *us
|
|||
|
||||
if err = roomserverAPI.SendEvents(
|
||||
ctx, rsAPI,
|
||||
api.KindNew,
|
||||
roomserverAPI.KindNew,
|
||||
[]*gomatrixserverlib.HeaderedEvent{event.Event.Headered(roomVer)},
|
||||
cfg.Matrix.ServerName,
|
||||
nil,
|
||||
|
@ -328,11 +327,11 @@ func loadProfile(
|
|||
return profile, err
|
||||
}
|
||||
|
||||
func extractRequestData(req *http.Request, roomID string, rsAPI api.RoomserverInternalAPI) (
|
||||
func extractRequestData(req *http.Request, roomID string, rsAPI roomserverAPI.RoomserverInternalAPI) (
|
||||
body *threepid.MembershipRequest, evTime time.Time, roomVer gomatrixserverlib.RoomVersion, resErr *util.JSONResponse,
|
||||
) {
|
||||
verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID}
|
||||
verRes := api.QueryRoomVersionForRoomResponse{}
|
||||
verReq := roomserverAPI.QueryRoomVersionForRoomRequest{RoomID: roomID}
|
||||
verRes := roomserverAPI.QueryRoomVersionForRoomResponse{}
|
||||
if err := rsAPI.QueryRoomVersionForRoom(req.Context(), &verReq, &verRes); err != nil {
|
||||
resErr = &util.JSONResponse{
|
||||
Code: http.StatusBadRequest,
|
||||
|
@ -402,13 +401,13 @@ func checkAndProcessThreepid(
|
|||
return
|
||||
}
|
||||
|
||||
func checkMemberInRoom(ctx context.Context, rsAPI api.RoomserverInternalAPI, userID, roomID string) *util.JSONResponse {
|
||||
func checkMemberInRoom(ctx context.Context, rsAPI roomserverAPI.RoomserverInternalAPI, userID, roomID string) *util.JSONResponse {
|
||||
tuple := gomatrixserverlib.StateKeyTuple{
|
||||
EventType: gomatrixserverlib.MRoomMember,
|
||||
StateKey: userID,
|
||||
}
|
||||
var membershipRes api.QueryCurrentStateResponse
|
||||
err := rsAPI.QueryCurrentState(ctx, &api.QueryCurrentStateRequest{
|
||||
var membershipRes roomserverAPI.QueryCurrentStateResponse
|
||||
err := rsAPI.QueryCurrentState(ctx, &roomserverAPI.QueryCurrentStateRequest{
|
||||
RoomID: roomID,
|
||||
StateTuples: []gomatrixserverlib.StateKeyTuple{tuple},
|
||||
}, &membershipRes)
|
||||
|
@ -445,8 +444,8 @@ func SendForget(
|
|||
) util.JSONResponse {
|
||||
ctx := req.Context()
|
||||
logger := util.GetLogger(ctx).WithField("roomID", roomID).WithField("userID", device.UserID)
|
||||
var membershipRes api.QueryMembershipForUserResponse
|
||||
membershipReq := api.QueryMembershipForUserRequest{
|
||||
var membershipRes roomserverAPI.QueryMembershipForUserResponse
|
||||
membershipReq := roomserverAPI.QueryMembershipForUserRequest{
|
||||
RoomID: roomID,
|
||||
UserID: device.UserID,
|
||||
}
|
||||
|
@ -468,11 +467,11 @@ func SendForget(
|
|||
}
|
||||
}
|
||||
|
||||
request := api.PerformForgetRequest{
|
||||
request := roomserverAPI.PerformForgetRequest{
|
||||
RoomID: roomID,
|
||||
UserID: device.UserID,
|
||||
}
|
||||
response := api.PerformForgetResponse{}
|
||||
response := roomserverAPI.PerformForgetResponse{}
|
||||
if err := rsAPI.PerformForget(ctx, &request, &response); err != nil {
|
||||
logger.WithError(err).Error("PerformForget: unable to forget room")
|
||||
return jsonerror.InternalServerError()
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
"github.com/matrix-org/dendrite/userapi/api"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
"github.com/matrix-org/dendrite/userapi/storage/accounts"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/util"
|
||||
|
@ -29,7 +28,7 @@ type newPasswordAuth struct {
|
|||
|
||||
func Password(
|
||||
req *http.Request,
|
||||
userAPI userapi.UserInternalAPI,
|
||||
userAPI api.UserInternalAPI,
|
||||
accountDB accounts.Database,
|
||||
device *api.Device,
|
||||
cfg *config.ClientAPI,
|
||||
|
@ -90,11 +89,11 @@ func Password(
|
|||
}
|
||||
|
||||
// Ask the user API to perform the password change.
|
||||
passwordReq := &userapi.PerformPasswordUpdateRequest{
|
||||
passwordReq := &api.PerformPasswordUpdateRequest{
|
||||
Localpart: localpart,
|
||||
Password: r.NewPassword,
|
||||
}
|
||||
passwordRes := &userapi.PerformPasswordUpdateResponse{}
|
||||
passwordRes := &api.PerformPasswordUpdateResponse{}
|
||||
if err := userAPI.PerformPasswordUpdate(req.Context(), passwordReq, passwordRes); err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Error("PerformPasswordUpdate failed")
|
||||
return jsonerror.InternalServerError()
|
||||
|
@ -107,12 +106,12 @@ func Password(
|
|||
// If the request asks us to log out all other devices then
|
||||
// ask the user API to do that.
|
||||
if r.LogoutDevices {
|
||||
logoutReq := &userapi.PerformDeviceDeletionRequest{
|
||||
logoutReq := &api.PerformDeviceDeletionRequest{
|
||||
UserID: device.UserID,
|
||||
DeviceIDs: nil,
|
||||
ExceptDeviceID: device.ID,
|
||||
}
|
||||
logoutRes := &userapi.PerformDeviceDeletionResponse{}
|
||||
logoutRes := &api.PerformDeviceDeletionResponse{}
|
||||
if err := userAPI.PerformDeviceDeletion(req.Context(), logoutReq, logoutRes); err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Error("PerformDeviceDeletion failed")
|
||||
return jsonerror.InternalServerError()
|
||||
|
|
|
@ -22,7 +22,6 @@ import (
|
|||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
|
@ -113,7 +112,7 @@ func SendRedaction(
|
|||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
var queryRes api.QueryLatestEventsAndStateResponse
|
||||
var queryRes roomserverAPI.QueryLatestEventsAndStateResponse
|
||||
e, err := eventutil.QueryAndBuildEvent(req.Context(), &builder, cfg.Matrix, time.Now(), rsAPI, &queryRes)
|
||||
if err == eventutil.ErrRoomNoExists {
|
||||
return util.JSONResponse{
|
||||
|
@ -121,7 +120,7 @@ func SendRedaction(
|
|||
JSON: jsonerror.NotFound("Room does not exist"),
|
||||
}
|
||||
}
|
||||
if err = roomserverAPI.SendEvents(context.Background(), rsAPI, api.KindNew, []*gomatrixserverlib.HeaderedEvent{e}, cfg.Matrix.ServerName, nil); err != nil {
|
||||
if err = roomserverAPI.SendEvents(context.Background(), rsAPI, roomserverAPI.KindNew, []*gomatrixserverlib.HeaderedEvent{e}, cfg.Matrix.ServerName, nil); err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Errorf("failed to SendEvents")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
|
|
@ -68,18 +68,18 @@ func (r *SharedSecretRegistration) IsValidMacLogin(
|
|||
) (bool, error) {
|
||||
// Check that shared secret registration isn't disabled.
|
||||
if r.sharedSecret == "" {
|
||||
return false, errors.New("Shared secret registration is disabled")
|
||||
return false, errors.New("shared secret registration is disabled")
|
||||
}
|
||||
if !r.validNonce(nonce) {
|
||||
return false, fmt.Errorf("Incorrect or expired nonce: %s", nonce)
|
||||
return false, fmt.Errorf("incorrect or expired nonce: %s", nonce)
|
||||
}
|
||||
|
||||
// Check that username/password don't contain the HMAC delimiters.
|
||||
if strings.Contains(username, "\x00") {
|
||||
return false, errors.New("Username contains invalid character")
|
||||
return false, errors.New("username contains invalid character")
|
||||
}
|
||||
if strings.Contains(password, "\x00") {
|
||||
return false, errors.New("Password contains invalid character")
|
||||
return false, errors.New("password contains invalid character")
|
||||
}
|
||||
|
||||
adminString := "notadmin"
|
||||
|
|
|
@ -81,7 +81,7 @@ func CreateSession(
|
|||
|
||||
// Error if the status isn't OK
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return "", fmt.Errorf("Could not create a session on the server %s", req.IDServer)
|
||||
return "", fmt.Errorf("could not create a session on the server %s", req.IDServer)
|
||||
}
|
||||
|
||||
// Extract the SID from the response and return it
|
||||
|
@ -168,7 +168,7 @@ func PublishAssociation(creds Credentials, userID string, cfg *config.ClientAPI)
|
|||
|
||||
// Error if the status isn't OK
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("Could not publish the association on the server %s", creds.IDServer)
|
||||
return fmt.Errorf("could not publish the association on the server %s", creds.IDServer)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -31,11 +31,11 @@ func ParseUsernameParam(usernameParam string, expectedServerName *gomatrixserver
|
|||
lp, domain, err := gomatrixserverlib.SplitID('@', usernameParam)
|
||||
|
||||
if err != nil {
|
||||
return "", errors.New("Invalid username")
|
||||
return "", errors.New("invalid username")
|
||||
}
|
||||
|
||||
if expectedServerName != nil && domain != *expectedServerName {
|
||||
return "", errors.New("User ID does not belong to this server")
|
||||
return "", errors.New("user ID does not belong to this server")
|
||||
}
|
||||
|
||||
localpart = lp
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue