Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
- Removed double imports (#1989)
Browse files Browse the repository at this point in the history
- Lower cased error messages

Signed-off-by: Ryan Whittington <[email protected]>

Co-authored-by: kegsay <[email protected]>
  • Loading branch information
twentybit and kegsay authored Sep 8, 2021
1 parent 7dc8fb1 commit a624eab
Show file tree
Hide file tree
Showing 38 changed files with 162 additions and 177 deletions.
3 changes: 1 addition & 2 deletions build/gobind-pinecone/monolith.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
"golang.org/x/net/http2/h2c"

pineconeMulticast "github.com/matrix-org/pinecone/multicast"
"github.com/matrix-org/pinecone/router"
pineconeRouter "github.com/matrix-org/pinecone/router"
pineconeSessions "github.com/matrix-org/pinecone/sessions"
"github.com/matrix-org/pinecone/types"
Expand Down Expand Up @@ -196,7 +195,7 @@ func (m *DendriteMonolith) RegisterDevice(localpart, deviceID string) (string, e

func (m *DendriteMonolith) staticPeerConnect() {
attempt := func() {
if m.PineconeRouter.PeerCount(router.PeerTypeRemote) == 0 {
if m.PineconeRouter.PeerCount(pineconeRouter.PeerTypeRemote) == 0 {
m.staticPeerMutex.RLock()
uri := m.staticPeerURI
m.staticPeerMutex.RUnlock()
Expand Down
2 changes: 1 addition & 1 deletion clientapi/httputil/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions clientapi/routing/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
Expand All @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions clientapi/routing/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 6 additions & 7 deletions clientapi/routing/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
23 changes: 11 additions & 12 deletions clientapi/routing/membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
}
Expand All @@ -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()
Expand Down
11 changes: 5 additions & 6 deletions clientapi/routing/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions clientapi/routing/redaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -113,15 +112,15 @@ 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{
Code: http.StatusNotFound,
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()
}
Expand Down
8 changes: 4 additions & 4 deletions clientapi/routing/register_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions clientapi/threepid/threepid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions clientapi/userutil/userutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions cmd/dendrite-demo-pinecone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import (
"github.com/matrix-org/gomatrixserverlib"

pineconeMulticast "github.com/matrix-org/pinecone/multicast"
"github.com/matrix-org/pinecone/router"
pineconeRouter "github.com/matrix-org/pinecone/router"
pineconeSessions "github.com/matrix-org/pinecone/sessions"

Expand Down Expand Up @@ -125,7 +124,7 @@ func main() {

connectToStaticPeer := func() {
attempt := func() {
if pRouter.PeerCount(router.PeerTypeRemote) == 0 {
if pRouter.PeerCount(pineconeRouter.PeerTypeRemote) == 0 {
uri := *instancePeer
if uri == "" {
return
Expand Down
2 changes: 1 addition & 1 deletion cmd/dendrite-upgrade-tests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func buildDendrite(httpClient *http.Client, dockerClient *client.Client, tmpDir,
// add top level Dockerfile
err = ioutil.WriteFile(path.Join(*flagHead, "Dockerfile"), []byte(Dockerfile), os.ModePerm)
if err != nil {
return "", fmt.Errorf("Custom HEAD: failed to inject /Dockerfile: %w", err)
return "", fmt.Errorf("custom HEAD: failed to inject /Dockerfile: %w", err)
}
// now tarball it
var buffer bytes.Buffer
Expand Down
2 changes: 1 addition & 1 deletion federationapi/routing/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ withNextEvent:
}

if missing := len(missingAuthEvents); missing > 0 {
return fmt.Errorf("Event refers to %d auth_events which we failed to fetch", missing)
return fmt.Errorf("event refers to %d auth_events which we failed to fetch", missing)
}
return nil
}
Expand Down
Loading

0 comments on commit a624eab

Please sign in to comment.