* Marks the RemoteTeamId field of RemoteClusters as deprecated The `RemoteTeamId` was used both in the `RemoteCluster` model and as part of remote invites. It existed so two different remotes could have multiple secure connections between them, and have each of those connections scoped to a team, sharing through each only the channels that belong to their corresponding team. The way that we're thinking on the feature currently only contemplates one secure connection between two servers, and shares all the channels through that secure connection, so this field is no longer needed. As we don't have a system in place for the user to choose in which team a channel should be created from an invite, this change adds a mechanism that checks the invite for a teamId, and if it's not present, fetches a team from the database to create the channel into. This makes the change backwards compatible for secure connections that already have an established behavior and allows us to move forward with the implementation of an alternative. * Mark invite teamId field as deprecated --------- Co-authored-by: Mattermost Build <build@mattermost.com>
78 строки
2.4 KiB
Go
78 строки
2.4 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package remotecluster
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/mattermost/mattermost/server/public/model"
|
|
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
|
)
|
|
|
|
// ReceiveIncomingMsg is called by the Rest API layer, or websocket layer (future), when a Remote Cluster
|
|
// message is received. Here we route the message to any topic listeners.
|
|
// `rc` and `msg` cannot be nil.
|
|
func (rcs *Service) ReceiveIncomingMsg(rc *model.RemoteCluster, msg model.RemoteClusterMsg) Response {
|
|
rcs.mux.RLock()
|
|
defer rcs.mux.RUnlock()
|
|
|
|
if metrics := rcs.server.GetMetrics(); metrics != nil {
|
|
metrics.IncrementRemoteClusterMsgReceivedCounter(rc.RemoteId)
|
|
}
|
|
|
|
rcSanitized := *rc
|
|
rcSanitized.Token = ""
|
|
rcSanitized.RemoteToken = ""
|
|
|
|
var response Response
|
|
response.Status = ResponseStatusOK
|
|
|
|
listeners := rcs.getTopicListeners(msg.Topic)
|
|
|
|
for _, l := range listeners {
|
|
if err := callback(l, msg, &rcSanitized, &response); err != nil {
|
|
rcs.server.Log().Log(mlog.LvlRemoteClusterServiceError, "Error from remote cluster message listener",
|
|
mlog.String("msgId", msg.Id), mlog.String("topic", msg.Topic), mlog.String("remote", rc.DisplayName), mlog.Err(err))
|
|
|
|
response.Status = ResponseStatusFail
|
|
response.Err = err.Error()
|
|
}
|
|
}
|
|
return response
|
|
}
|
|
|
|
func callback(listener TopicListener, msg model.RemoteClusterMsg, rc *model.RemoteCluster, resp *Response) (err error) {
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
err = fmt.Errorf("%v", r)
|
|
}
|
|
}()
|
|
err = listener(msg, rc, resp)
|
|
return
|
|
}
|
|
|
|
// ReceiveInviteConfirmation is called by the Rest API layer when a Remote Cluster accepts an invitation from this
|
|
// local cluster.
|
|
func (rcs *Service) ReceiveInviteConfirmation(confirm model.RemoteClusterInvite) (*model.RemoteCluster, error) {
|
|
store := rcs.server.GetStore().RemoteCluster()
|
|
|
|
rc, err := store.Get(confirm.RemoteId)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot accept invite confirmation for remote %s: %w", confirm.RemoteId, err)
|
|
}
|
|
|
|
rc.SiteURL = confirm.SiteURL
|
|
rc.RemoteToken = confirm.Token
|
|
|
|
rcUpdated, err := store.Update(rc)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot apply invite confirmation for remote %s: %w", confirm.RemoteId, err)
|
|
}
|
|
|
|
// issue the first ping right away. The goroutine will exit when ping completes or PingTimeout exceeded.
|
|
go rcs.PingNow(rcUpdated)
|
|
|
|
return rcUpdated, nil
|
|
}
|