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

Commit

Permalink
Merge branch 'master' into txn_idempotency
Browse files Browse the repository at this point in the history
  • Loading branch information
APwhitehat authored Mar 14, 2018
2 parents c322155 + c9add39 commit 78e8e16
Show file tree
Hide file tree
Showing 47 changed files with 322 additions and 309 deletions.
6 changes: 4 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ instance of dendrite, and [CODE_STYLE.md](CODE_STYLE.md) for the code style
guide.

We use `gb` for managing our dependencies, so `gb build` and `gb test` is how
to build dendrite and run the unit tests respectively. There are [scripts](scripts)
for [linting](scripts/find-lint.sh) and doing a [build/test/lint run](scripts/build-test-lint.sh).
to build dendrite and run the unit tests respectively. Be aware that a list of
all dendrite packages is the expected output for all tests succeeding with `gb
test`. There are also [scripts](scripts) for [linting](scripts/find-lint.sh)
and doing a [build/test/lint run](scripts/build-test-lint.sh).


## Picking Things To Do
Expand Down
8 changes: 8 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ kafka/bin/zookeeper-server-start.sh -daemon kafka/config/zookeeper.properties
kafka/bin/kafka-server-start.sh -daemon kafka/config/server.properties
```

On MacOS, you can use [homebrew](https://brew.sh/) for easier setup of kafka

```bash
brew install kafka
brew services start zookeeper
brew services start kafka
```

## Configuration

### Postgres database setup
Expand Down
4 changes: 2 additions & 2 deletions src/github.com/matrix-org/dendrite/clientapi/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func VerifyAccessToken(req *http.Request, deviceDB DeviceDatabase) (device *auth
token, err := extractAccessToken(req)
if err != nil {
resErr = &util.JSONResponse{
Code: 401,
Code: http.StatusUnauthorized,
JSON: jsonerror.MissingToken(err.Error()),
}
return
Expand All @@ -59,7 +59,7 @@ func VerifyAccessToken(req *http.Request, deviceDB DeviceDatabase) (device *auth
if err != nil {
if err == sql.ErrNoRows {
resErr = &util.JSONResponse{
Code: 401,
Code: http.StatusUnauthorized,
JSON: jsonerror.UnknownToken("Unknown token"),
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func UnmarshalJSONRequest(req *http.Request, iface interface{}) *util.JSONRespon
// debugging because an error will be produced for both invalid/malformed JSON AND
// valid JSON with incorrect types for values.
return &util.JSONResponse{
Code: 400,
Code: http.StatusBadRequest,
JSON: jsonerror.BadJSON("The request body could not be decoded into valid JSON. " + err.Error()),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package jsonerror

import (
"fmt"
"net/http"

"github.com/matrix-org/util"
)
Expand All @@ -35,7 +36,7 @@ func (e *MatrixError) Error() string {
// format.
func InternalServerError() util.JSONResponse {
return util.JSONResponse{
Code: 500,
Code: http.StatusInternalServerError,
JSON: Unknown("Internal Server Error"),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ func SaveAccountData(
req *http.Request, accountDB *accounts.Database, device *authtypes.Device,
userID string, roomID string, dataType string, syncProducer *producers.SyncAPIProducer,
) util.JSONResponse {
if req.Method != "PUT" {
if req.Method != http.MethodPut {
return util.JSONResponse{
Code: 405,
Code: http.StatusMethodNotAllowed,
JSON: jsonerror.NotFound("Bad method"),
}
}

if userID != device.UserID {
return util.JSONResponse{
Code: 403,
Code: http.StatusForbidden,
JSON: jsonerror.Forbidden("userID does not match the current user"),
}
}
Expand Down Expand Up @@ -70,7 +70,7 @@ func SaveAccountData(
}

return util.JSONResponse{
Code: 200,
Code: http.StatusOK,
JSON: struct{}{},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (r createRoomRequest) Validate() *util.JSONResponse {
// Synapse doesn't check for ':' but we will else it will break parsers badly which split things into 2 segments.
if strings.ContainsAny(r.RoomAliasName, whitespace+":") {
return &util.JSONResponse{
Code: 400,
Code: http.StatusBadRequest,
JSON: jsonerror.BadJSON("room_alias_name cannot contain whitespace"),
}
}
Expand All @@ -82,7 +82,7 @@ func (r createRoomRequest) Validate() *util.JSONResponse {
// https://github.com/matrix-org/synapse/blob/v0.19.2/synapse/types.py#L92
if _, _, err := gomatrixserverlib.SplitID('@', userID); err != nil {
return &util.JSONResponse{
Code: 400,
Code: http.StatusBadRequest,
JSON: jsonerror.BadJSON("user id must be in the form @localpart:domain"),
}
}
Expand All @@ -92,7 +92,7 @@ func (r createRoomRequest) Validate() *util.JSONResponse {
break
default:
return &util.JSONResponse{
Code: 400,
Code: http.StatusBadRequest,
JSON: jsonerror.BadJSON("preset must be any of 'private_chat', 'trusted_private_chat', 'public_chat'"),
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/github.com/matrix-org/dendrite/clientapi/routing/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ func GetDeviceByID(
dev, err := deviceDB.GetDeviceByID(ctx, localpart, deviceID)
if err == sql.ErrNoRows {
return util.JSONResponse{
Code: 404,
Code: http.StatusNotFound,
JSON: jsonerror.NotFound("Unknown device"),
}
} else if err != nil {
return httputil.LogThenError(req, err)
}

return util.JSONResponse{
Code: 200,
Code: http.StatusOK,
JSON: deviceJSON{
DeviceID: dev.ID,
UserID: dev.UserID,
Expand Down Expand Up @@ -96,7 +96,7 @@ func GetDevicesByLocalpart(
}

return util.JSONResponse{
Code: 200,
Code: http.StatusOK,
JSON: res,
}
}
Expand All @@ -106,9 +106,9 @@ func UpdateDeviceByID(
req *http.Request, deviceDB *devices.Database, device *authtypes.Device,
deviceID string,
) util.JSONResponse {
if req.Method != "PUT" {
if req.Method != http.MethodPut {
return util.JSONResponse{
Code: 405,
Code: http.StatusMethodNotAllowed,
JSON: jsonerror.NotFound("Bad Method"),
}
}
Expand All @@ -122,7 +122,7 @@ func UpdateDeviceByID(
dev, err := deviceDB.GetDeviceByID(ctx, localpart, deviceID)
if err == sql.ErrNoRows {
return util.JSONResponse{
Code: 404,
Code: http.StatusNotFound,
JSON: jsonerror.NotFound("Unknown device"),
}
} else if err != nil {
Expand All @@ -131,7 +131,7 @@ func UpdateDeviceByID(

if dev.UserID != device.UserID {
return util.JSONResponse{
Code: 403,
Code: http.StatusForbidden,
JSON: jsonerror.Forbidden("device not owned by current user"),
}
}
Expand All @@ -149,7 +149,7 @@ func UpdateDeviceByID(
}

return util.JSONResponse{
Code: 200,
Code: http.StatusOK,
JSON: struct{}{},
}
}
20 changes: 10 additions & 10 deletions src/github.com/matrix-org/dendrite/clientapi/routing/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func DirectoryRoom(
_, domain, err := gomatrixserverlib.SplitID('#', roomAlias)
if err != nil {
return util.JSONResponse{
Code: 400,
Code: http.StatusBadRequest,
JSON: jsonerror.BadJSON("Room alias must be in the form '#localpart:domain'"),
}
}
Expand All @@ -61,7 +61,7 @@ func DirectoryRoom(
} else {
// If the response doesn't contain a non-empty string, return an error
return util.JSONResponse{
Code: 404,
Code: http.StatusNotFound,
JSON: jsonerror.NotFound("Room alias " + roomAlias + " not found."),
}
}
Expand All @@ -70,9 +70,9 @@ func DirectoryRoom(
if err != nil {
switch x := err.(type) {
case gomatrix.HTTPError:
if x.Code == 404 {
if x.Code == http.StatusNotFound {
return util.JSONResponse{
Code: 404,
Code: http.StatusNotFound,
JSON: jsonerror.NotFound("Room alias not found"),
}
}
Expand All @@ -84,7 +84,7 @@ func DirectoryRoom(
}

return util.JSONResponse{
Code: 200,
Code: http.StatusOK,
JSON: resp,
}
}
Expand All @@ -101,14 +101,14 @@ func SetLocalAlias(
_, domain, err := gomatrixserverlib.SplitID('#', alias)
if err != nil {
return util.JSONResponse{
Code: 400,
Code: http.StatusBadRequest,
JSON: jsonerror.BadJSON("Room alias must be in the form '#localpart:domain'"),
}
}

if domain != cfg.Matrix.ServerName {
return util.JSONResponse{
Code: 403,
Code: http.StatusForbidden,
JSON: jsonerror.Forbidden("Alias must be on local homeserver"),
}
}
Expand All @@ -132,13 +132,13 @@ func SetLocalAlias(

if queryRes.AliasExists {
return util.JSONResponse{
Code: 409,
Code: http.StatusConflict,
JSON: jsonerror.Unknown("The alias " + alias + " already exists."),
}
}

return util.JSONResponse{
Code: 200,
Code: http.StatusOK,
JSON: struct{}{},
}
}
Expand All @@ -161,7 +161,7 @@ func RemoveLocalAlias(
}

return util.JSONResponse{
Code: 200,
Code: http.StatusOK,
JSON: struct{}{},
}
}
16 changes: 8 additions & 8 deletions src/github.com/matrix-org/dendrite/clientapi/routing/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ func GetFilter(
) util.JSONResponse {
if req.Method != http.MethodGet {
return util.JSONResponse{
Code: 405,
Code: http.StatusMethodNotAllowed,
JSON: jsonerror.NotFound("Bad method"),
}
}
if userID != device.UserID {
return util.JSONResponse{
Code: 403,
Code: http.StatusForbidden,
JSON: jsonerror.Forbidden("Cannot get filters for other users"),
}
}
Expand All @@ -55,7 +55,7 @@ func GetFilter(
// but if there are obscure db errors, this will also be returned,
// even though it is not correct.
return util.JSONResponse{
Code: 400,
Code: http.StatusBadRequest,
JSON: jsonerror.NotFound("No such filter"),
}
}
Expand All @@ -66,7 +66,7 @@ func GetFilter(
}

return util.JSONResponse{
Code: 200,
Code: http.StatusOK,
JSON: filter,
}
}
Expand All @@ -81,13 +81,13 @@ func PutFilter(
) util.JSONResponse {
if req.Method != http.MethodPost {
return util.JSONResponse{
Code: 405,
Code: http.StatusMethodNotAllowed,
JSON: jsonerror.NotFound("Bad method"),
}
}
if userID != device.UserID {
return util.JSONResponse{
Code: 403,
Code: http.StatusForbidden,
JSON: jsonerror.Forbidden("Cannot create filters for other users"),
}
}
Expand All @@ -106,7 +106,7 @@ func PutFilter(
filterArray, err := json.Marshal(filter)
if err != nil {
return util.JSONResponse{
Code: 400,
Code: http.StatusBadRequest,
JSON: jsonerror.BadJSON("Filter is malformed"),
}
}
Expand All @@ -117,7 +117,7 @@ func PutFilter(
}

return util.JSONResponse{
Code: 200,
Code: http.StatusOK,
JSON: filterResponse{FilterID: filterID},
}
}
Loading

0 comments on commit 78e8e16

Please sign in to comment.