mirror of
https://github.com/matrix-org/dendrite.git
synced 2024-11-22 14:21:55 -06:00
Fix lint errors
This commit is contained in:
parent
6c95f9b535
commit
d983d17355
|
@ -62,7 +62,7 @@ func (t *LoginTypePassword) LoginFromJSON(ctx context.Context, reqBytes []byte)
|
||||||
|
|
||||||
func (t *LoginTypePassword) Login(ctx context.Context, req interface{}) (*Login, *util.JSONResponse) {
|
func (t *LoginTypePassword) Login(ctx context.Context, req interface{}) (*Login, *util.JSONResponse) {
|
||||||
r := req.(*PasswordRequest)
|
r := req.(*PasswordRequest)
|
||||||
username := strings.ToLower(r.Username())
|
username := strings.ToLower(r.Username())
|
||||||
if username == "" {
|
if username == "" {
|
||||||
return nil, &util.JSONResponse{
|
return nil, &util.JSONResponse{
|
||||||
Code: http.StatusUnauthorized,
|
Code: http.StatusUnauthorized,
|
||||||
|
|
|
@ -223,6 +223,7 @@ func (a *KeyInternalAPI) QueryDeviceMessages(ctx context.Context, req *api.Query
|
||||||
res.StreamID = maxStreamID
|
res.StreamID = maxStreamID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nolint:gocyclo
|
||||||
func (a *KeyInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysRequest, res *api.QueryKeysResponse) {
|
func (a *KeyInternalAPI) QueryKeys(ctx context.Context, req *api.QueryKeysRequest, res *api.QueryKeysResponse) {
|
||||||
res.DeviceKeys = make(map[string]map[string]json.RawMessage)
|
res.DeviceKeys = make(map[string]map[string]json.RawMessage)
|
||||||
res.MasterKeys = make(map[string]gomatrixserverlib.CrossSigningKey)
|
res.MasterKeys = make(map[string]gomatrixserverlib.CrossSigningKey)
|
||||||
|
|
|
@ -102,4 +102,3 @@ func (a AliasEvent) Valid() bool {
|
||||||
}
|
}
|
||||||
return a.Alias == "" || validateAliasRegex.MatchString(a.Alias)
|
return a.Alias == "" || validateAliasRegex.MatchString(a.Alias)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,29 +22,29 @@ func TestAliasEvent_Valid(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "empty alias, invalid alt aliases",
|
name: "empty alias, invalid alt aliases",
|
||||||
fields: fields{
|
fields: fields{
|
||||||
Alias: "",
|
Alias: "",
|
||||||
AltAliases: []string{ "%not:valid.local"},
|
AltAliases: []string{"%not:valid.local"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "valid alias, invalid alt aliases",
|
name: "valid alias, invalid alt aliases",
|
||||||
fields: fields{
|
fields: fields{
|
||||||
Alias: "#valid:test.local",
|
Alias: "#valid:test.local",
|
||||||
AltAliases: []string{ "%not:valid.local"},
|
AltAliases: []string{"%not:valid.local"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "empty alias, invalid alt aliases",
|
name: "empty alias, invalid alt aliases",
|
||||||
fields: fields{
|
fields: fields{
|
||||||
Alias: "",
|
Alias: "",
|
||||||
AltAliases: []string{ "%not:valid.local"},
|
AltAliases: []string{"%not:valid.local"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid alias",
|
name: "invalid alias",
|
||||||
fields: fields{
|
fields: fields{
|
||||||
Alias: "%not:valid.local",
|
Alias: "%not:valid.local",
|
||||||
AltAliases: []string{ },
|
AltAliases: []string{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,12 +173,15 @@ func (r *RoomserverInternalAPI) RemoveRoomAlias(
|
||||||
}
|
}
|
||||||
|
|
||||||
if creatorID != request.UserID {
|
if creatorID != request.UserID {
|
||||||
plEvent, err := r.DB.GetStateEvent(ctx, roomID, gomatrixserverlib.MRoomPowerLevels, "")
|
var plEvent *gomatrixserverlib.HeaderedEvent
|
||||||
|
var pls *gomatrixserverlib.PowerLevelContent
|
||||||
|
|
||||||
|
plEvent, err = r.DB.GetStateEvent(ctx, roomID, gomatrixserverlib.MRoomPowerLevels, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("r.DB.GetStateEvent: %w", err)
|
return fmt.Errorf("r.DB.GetStateEvent: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pls, err := plEvent.PowerLevels()
|
pls, err = plEvent.PowerLevels()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("plEvent.PowerLevels: %w", err)
|
return fmt.Errorf("plEvent.PowerLevels: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -223,7 +226,7 @@ func (r *RoomserverInternalAPI) RemoveRoomAlias(
|
||||||
}
|
}
|
||||||
|
|
||||||
stateRes := &api.QueryLatestEventsAndStateResponse{}
|
stateRes := &api.QueryLatestEventsAndStateResponse{}
|
||||||
if err := helpers.QueryLatestEventsAndState(ctx, r.DB, &api.QueryLatestEventsAndStateRequest{RoomID: roomID, StateToFetch: eventsNeeded.Tuples()}, stateRes); err != nil {
|
if err = helpers.QueryLatestEventsAndState(ctx, r.DB, &api.QueryLatestEventsAndStateRequest{RoomID: roomID, StateToFetch: eventsNeeded.Tuples()}, stateRes); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,7 @@ func (s *eventStateKeyStatements) BulkSelectEventStateKey(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer selectPrep.Close()
|
defer internal.CloseAndLogIfError(ctx, selectPrep, "selectPrep.close() failed")
|
||||||
stmt := sqlutil.TxStmt(txn, selectPrep)
|
stmt := sqlutil.TxStmt(txn, selectPrep)
|
||||||
rows, err := stmt.QueryContext(ctx, iEventStateKeyNIDs...)
|
rows, err := stmt.QueryContext(ctx, iEventStateKeyNIDs...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -128,7 +128,7 @@ func (s *eventTypeStatements) BulkSelectEventTypeNID(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer selectPrep.Close()
|
defer internal.CloseAndLogIfError(ctx, selectPrep, "selectPrep.close() failed")
|
||||||
stmt := sqlutil.TxStmt(txn, selectPrep)
|
stmt := sqlutil.TxStmt(txn, selectPrep)
|
||||||
///////////////
|
///////////////
|
||||||
|
|
||||||
|
|
|
@ -567,7 +567,7 @@ func (s *eventStatements) SelectMaxEventDepth(ctx context.Context, txn *sql.Tx,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
defer sqlPrep.Close()
|
defer internal.CloseAndLogIfError(ctx, sqlPrep, "sqlPrep.close() failed")
|
||||||
err = sqlutil.TxStmt(txn, sqlPrep).QueryRowContext(ctx, iEventIDs...).Scan(&result)
|
err = sqlutil.TxStmt(txn, sqlPrep).QueryRowContext(ctx, iEventIDs...).Scan(&result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("sqlutil.TxStmt.QueryRowContext: %w", err)
|
return 0, fmt.Errorf("sqlutil.TxStmt.QueryRowContext: %w", err)
|
||||||
|
@ -583,7 +583,7 @@ func (s *eventStatements) SelectRoomNIDsForEventNIDs(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer sqlPrep.Close()
|
defer internal.CloseAndLogIfError(ctx, sqlPrep, "sqlPrep.close() failed")
|
||||||
sqlStmt := sqlutil.TxStmt(txn, sqlPrep)
|
sqlStmt := sqlutil.TxStmt(txn, sqlPrep)
|
||||||
iEventNIDs := make([]interface{}, len(eventNIDs))
|
iEventNIDs := make([]interface{}, len(eventNIDs))
|
||||||
for i, v := range eventNIDs {
|
for i, v := range eventNIDs {
|
||||||
|
|
|
@ -283,11 +283,7 @@ func (w *walker) walk() util.JSONResponse {
|
||||||
if !roomExists {
|
if !roomExists {
|
||||||
// attempt to query this room over federation, as either we've never heard of it before
|
// attempt to query this room over federation, as either we've never heard of it before
|
||||||
// or we've left it and hence are not authorised (but info may be exposed regardless)
|
// or we've left it and hence are not authorised (but info may be exposed regardless)
|
||||||
fedRes, err := w.federatedRoomInfo(rv.roomID, rv.vias)
|
fedRes := w.federatedRoomInfo(rv.roomID, rv.vias)
|
||||||
if err != nil {
|
|
||||||
util.GetLogger(w.ctx).WithError(err).WithField("room_id", rv.roomID).Errorf("failed to query federated spaces")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if fedRes != nil {
|
if fedRes != nil {
|
||||||
discoveredChildEvents = fedRes.Room.ChildrenState
|
discoveredChildEvents = fedRes.Room.ChildrenState
|
||||||
discoveredRooms = append(discoveredRooms, fedRes.Room)
|
discoveredRooms = append(discoveredRooms, fedRes.Room)
|
||||||
|
@ -420,15 +416,15 @@ func (w *walker) publicRoomsChunk(roomID string) *gomatrixserverlib.PublicRoom {
|
||||||
|
|
||||||
// federatedRoomInfo returns more of the spaces graph from another server. Returns nil if this was
|
// federatedRoomInfo returns more of the spaces graph from another server. Returns nil if this was
|
||||||
// unsuccessful.
|
// unsuccessful.
|
||||||
func (w *walker) federatedRoomInfo(roomID string, vias []string) (*gomatrixserverlib.MSC2946SpacesResponse, error) {
|
func (w *walker) federatedRoomInfo(roomID string, vias []string) *gomatrixserverlib.MSC2946SpacesResponse {
|
||||||
// only do federated requests for client requests
|
// only do federated requests for client requests
|
||||||
if w.caller == nil {
|
if w.caller == nil {
|
||||||
return nil, nil
|
return nil
|
||||||
}
|
}
|
||||||
resp, ok := w.cache.GetSpaceSummary(roomID)
|
resp, ok := w.cache.GetSpaceSummary(roomID)
|
||||||
if ok {
|
if ok {
|
||||||
util.GetLogger(w.ctx).Debugf("Returning cached response for %s", roomID)
|
util.GetLogger(w.ctx).Debugf("Returning cached response for %s", roomID)
|
||||||
return &resp, nil
|
return &resp
|
||||||
}
|
}
|
||||||
util.GetLogger(w.ctx).Debugf("Querying %s via %+v", roomID, vias)
|
util.GetLogger(w.ctx).Debugf("Querying %s via %+v", roomID, vias)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
@ -455,9 +451,9 @@ func (w *walker) federatedRoomInfo(roomID string, vias []string) (*gomatrixserve
|
||||||
}
|
}
|
||||||
w.cache.StoreSpaceSummary(roomID, res)
|
w.cache.StoreSpaceSummary(roomID, res)
|
||||||
|
|
||||||
return &res, nil
|
return &res
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *walker) roomExists(roomID string) bool {
|
func (w *walker) roomExists(roomID string) bool {
|
||||||
|
@ -717,23 +713,6 @@ func stripped(ev *gomatrixserverlib.Event) *gomatrixserverlib.MSC2946StrippedEve
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func eventKey(event *gomatrixserverlib.MSC2946StrippedEvent) string {
|
|
||||||
return event.RoomID + "|" + event.Type + "|" + event.StateKey
|
|
||||||
}
|
|
||||||
|
|
||||||
func spaceTargetStripped(event *gomatrixserverlib.MSC2946StrippedEvent) string {
|
|
||||||
if event.StateKey == "" {
|
|
||||||
return "" // no-op
|
|
||||||
}
|
|
||||||
switch event.Type {
|
|
||||||
case ConstSpaceParentEventType:
|
|
||||||
return event.StateKey
|
|
||||||
case ConstSpaceChildEventType:
|
|
||||||
return event.StateKey
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseInt(intstr string, defaultVal int) int {
|
func parseInt(intstr string, defaultVal int) int {
|
||||||
i, err := strconv.ParseInt(intstr, 10, 32)
|
i, err := strconv.ParseInt(intstr, 10, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -472,7 +472,7 @@ func (s *outputRoomEventsStatements) SelectContextBeforeEvent(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer internal.CloseAndLogIfError(ctx, rows, "rows.close() failed")
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var (
|
var (
|
||||||
|
@ -504,7 +504,7 @@ func (s *outputRoomEventsStatements) SelectContextAfterEvent(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer internal.CloseAndLogIfError(ctx, rows, "rows.close() failed")
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -514,7 +514,7 @@ func (s *outputRoomEventsStatements) SelectContextBeforeEvent(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer internal.CloseAndLogIfError(ctx, rows, "rows.close() failed")
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var (
|
var (
|
||||||
|
@ -550,7 +550,7 @@ func (s *outputRoomEventsStatements) SelectContextAfterEvent(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer internal.CloseAndLogIfError(ctx, rows, "rows.close() failed")
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var (
|
var (
|
||||||
|
|
Loading…
Reference in a new issue