Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Mautrix + deps & debug API #42

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions config/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ type BridgeConfig struct {
DefaultBridgeReceipts bool `yaml:"default_bridge_receipts"`
DefaultBridgePresence bool `yaml:"default_bridge_presence"`

DoublePuppetServerMap map[string]string `yaml:"double_puppet_server_map"`
DoublePuppetAllowDiscovery bool `yaml:"double_puppet_allow_discovery"`
LoginSharedSecretMap map[string]string `yaml:"login_shared_secret_map"`
DoublePuppetConfig bridgeconfig.DoublePuppetConfig `yaml:",inline"`

MessageHandlingTimeout struct {
ErrorAfterStr string `yaml:"error_after"`
Expand All @@ -95,8 +93,9 @@ type BridgeConfig struct {
Encryption bridgeconfig.EncryptionConfig `yaml:"encryption"`

Provisioning struct {
Prefix string `yaml:"prefix"`
SharedSecret string `yaml:"shared_secret"`
Prefix string `yaml:"prefix"`
SharedSecret string `yaml:"shared_secret"`
DebugEndpoints bool `yaml:"debug_endpoints"`
} `yaml:"provisioning"`

Permissions bridgeconfig.PermissionConfig `yaml:"permissions"`
Expand Down Expand Up @@ -154,6 +153,10 @@ func (bc *BridgeConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {

var _ bridgeconfig.BridgeConfig = (*BridgeConfig)(nil)

func (bc BridgeConfig) GetDoublePuppetConfig() bridgeconfig.DoublePuppetConfig {
return bc.DoublePuppetConfig
}

func (bc BridgeConfig) GetEncryptionConfig() bridgeconfig.EncryptionConfig {
return bc.Encryption
}
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Config struct {

func (config *Config) CanAutoDoublePuppet(userID id.UserID) bool {
_, homeserver, _ := userID.Parse()
_, hasSecret := config.Bridge.LoginSharedSecretMap[homeserver]
_, hasSecret := config.Bridge.DoublePuppetConfig.SharedSecretMap[homeserver]

return hasSecret
}
15 changes: 11 additions & 4 deletions config/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package config

import (
up "go.mau.fi/util/configupgrade"
"go.mau.fi/util/random"
"maunium.net/go/mautrix/bridge/bridgeconfig"
"maunium.net/go/mautrix/util"
up "maunium.net/go/mautrix/util/configupgrade"
)

func DoUpgrade(helper *up.Helper) {
Expand Down Expand Up @@ -50,7 +50,13 @@ func DoUpgrade(helper *up.Helper) {
helper.Copy(up.Bool, "bridge", "default_bridge_presence")
helper.Copy(up.Map, "bridge", "double_puppet_server_map")
helper.Copy(up.Bool, "bridge", "double_puppet_allow_discovery")
helper.Copy(up.Map, "bridge", "login_shared_secret_map")
if legacySecret, ok := helper.Get(up.Str, "bridge", "login_shared_secret"); ok && len(legacySecret) > 0 {
baseNode := helper.GetBaseNode("bridge", "login_shared_secret_map")
baseNode.Map[helper.GetBase("homeserver", "domain")] = up.StringNode(legacySecret)
baseNode.UpdateContent()
} else {
helper.Copy(up.Map, "bridge", "login_shared_secret_map")
}
Comment on lines +53 to +59
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary since slack never used the legacy field

helper.Copy(up.Map, "bridge", "message_handling_timeout")
helper.Copy(up.Str, "bridge", "command_prefix")
helper.Copy(up.Str, "bridge", "management_room_text", "welcome")
Expand Down Expand Up @@ -85,11 +91,12 @@ func DoUpgrade(helper *up.Helper) {

helper.Copy(up.Str, "bridge", "provisioning", "prefix")
if secret, ok := helper.Get(up.Str, "bridge", "provisioning", "shared_secret"); !ok || secret == "generate" {
sharedSecret := util.RandomString(64)
sharedSecret := random.String(64)
helper.Set(up.Str, sharedSecret, "bridge", "provisioning", "shared_secret")
} else {
helper.Copy(up.Str, "bridge", "provisioning", "shared_secret")
}
helper.Copy(up.Bool, "bridge", "provisioning", "debug_endpoints")

helper.Copy(up.Map, "bridge", "permissions")
//helper.Copy(up.Bool, "bridge", "relay", "enabled")
Expand Down
16 changes: 8 additions & 8 deletions custompuppet.go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ func (br *SlackBridge) newDoublePuppetClient(mxid id.UserID, accessToken string)
return nil, err
}

homeserverURL, found := br.Config.Bridge.DoublePuppetServerMap[homeserver]
homeserverURL, found := br.Config.Bridge.DoublePuppetConfig.ServerMap[homeserver]
if !found {
if homeserver == br.AS.HomeserverDomain {
homeserverURL = ""
} else if br.Config.Bridge.DoublePuppetAllowDiscovery {
} else if br.Config.Bridge.DoublePuppetConfig.AllowDiscovery {
resp, err := mautrix.DiscoverClientAPI(homeserver)
if err != nil {
return nil, fmt.Errorf("failed to find homeserver URL for %s: %v", homeserver, err)
Expand Down Expand Up @@ -173,7 +173,7 @@ func (puppet *Puppet) LoadRoom(_ id.RoomID) *mautrix.Room {
// /////////////////////////////////////////////////////////////////////////////
// additional puppet api
// /////////////////////////////////////////////////////////////////////////////
func (puppet *Puppet) clearCustomMXID() {
func (puppet *Puppet) ClearCustomMXID() {
puppet.CustomMXID = ""
puppet.AccessToken = ""
puppet.customIntent = nil
Expand Down Expand Up @@ -204,29 +204,29 @@ func (puppet *Puppet) newCustomIntent() (*appservice.IntentAPI, error) {

func (puppet *Puppet) StartCustomMXID(reloginOnFail bool) error {
if puppet.CustomMXID == "" {
puppet.clearCustomMXID()
puppet.ClearCustomMXID()

return nil
}

intent, err := puppet.newCustomIntent()
if err != nil {
puppet.clearCustomMXID()
puppet.ClearCustomMXID()

return err
}

resp, err := intent.Whoami()
if err != nil {
if !reloginOnFail || (errors.Is(err, mautrix.MUnknownToken) && !puppet.tryRelogin(err, "initializing double puppeting")) {
puppet.clearCustomMXID()
puppet.ClearCustomMXID()

return err
}

intent.AccessToken = puppet.AccessToken
} else if resp.UserID != puppet.CustomMXID {
puppet.clearCustomMXID()
puppet.ClearCustomMXID()

return ErrMismatchingMXID
}
Expand Down Expand Up @@ -287,7 +287,7 @@ func (puppet *Puppet) loginWithSharedSecret(mxid id.UserID, teamID string) (stri

puppet.log.Debugfln("Logging into %s with shared secret", mxid)

loginSecret := puppet.bridge.Config.Bridge.LoginSharedSecretMap[homeserver]
loginSecret := puppet.bridge.Config.Bridge.DoublePuppetConfig.SharedSecretMap[homeserver]

client, err := puppet.bridge.newDoublePuppetClient(mxid, "")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion database/attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (

log "maunium.net/go/maulogger/v2"

"go.mau.fi/util/dbutil"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util/dbutil"
)

type Attachment struct {
Expand Down
2 changes: 1 addition & 1 deletion database/backfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

log "maunium.net/go/maulogger/v2"

"maunium.net/go/mautrix/util/dbutil"
"go.mau.fi/util/dbutil"
)

type BackfillQuery struct {
Expand Down
2 changes: 1 addition & 1 deletion database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"

"maunium.net/go/mautrix/util/dbutil"
"go.mau.fi/util/dbutil"

"go.mau.fi/mautrix-slack/database/upgrades"
"maunium.net/go/maulogger/v2"
Expand Down
2 changes: 1 addition & 1 deletion database/emoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

log "maunium.net/go/maulogger/v2"

"go.mau.fi/util/dbutil"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util/dbutil"
)

type EmojiQuery struct {
Expand Down
2 changes: 1 addition & 1 deletion database/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (

log "maunium.net/go/maulogger/v2"

"go.mau.fi/util/dbutil"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util/dbutil"
)

type Message struct {
Expand Down
2 changes: 1 addition & 1 deletion database/portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (

log "maunium.net/go/maulogger/v2"

"go.mau.fi/util/dbutil"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util/dbutil"
)

type ChannelType int64
Expand Down
2 changes: 1 addition & 1 deletion database/puppet.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (

log "maunium.net/go/maulogger/v2"

"go.mau.fi/util/dbutil"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util/dbutil"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion database/reaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (

log "maunium.net/go/maulogger/v2"

"go.mau.fi/util/dbutil"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util/dbutil"
)

type Reaction struct {
Expand Down
2 changes: 1 addition & 1 deletion database/teaminfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (

log "maunium.net/go/maulogger/v2"

"go.mau.fi/util/dbutil"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util/dbutil"
)

type TeamInfoQuery struct {
Expand Down
2 changes: 1 addition & 1 deletion database/upgrades/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"embed"
"errors"

"maunium.net/go/mautrix/util/dbutil"
"go.mau.fi/util/dbutil"
)

var Table dbutil.UpgradeTable
Expand Down
2 changes: 1 addition & 1 deletion database/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (

log "maunium.net/go/maulogger/v2"

"go.mau.fi/util/dbutil"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util/dbutil"
)

type User struct {
Expand Down
2 changes: 1 addition & 1 deletion database/userteam.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (

log "maunium.net/go/maulogger/v2"

"go.mau.fi/util/dbutil"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util/dbutil"

"github.com/slack-go/slack"
)
Expand Down
2 changes: 2 additions & 0 deletions example-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ bridge:
# Shared secret for authentication. If set to "generate", a random secret will be generated,
# or if set to "disable", the provisioning API will be disabled.
shared_secret: generate
# Enable debug API at /debug with provisioning authentication.
debug_endpoints: false

# Permissions for using the bridge.
# Permitted values:
Expand Down
4 changes: 2 additions & 2 deletions formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import (
"github.com/yuin/goldmark/text"
goldmarkUtil "github.com/yuin/goldmark/util"
"go.mau.fi/mautrix-slack/database"
"go.mau.fi/util/exmime"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/format"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix/util"
)

var escapeFixer = regexp.MustCompile(`\\(__[^_]|\*\*[^*])`)
Expand Down Expand Up @@ -79,7 +79,7 @@ func (portal *Portal) renderSlackFile(file slack.File) event.MessageEventContent
content.Body = mimeClass
}

content.Body += util.ExtensionFromMimetype(file.Mimetype)
content.Body += exmime.ExtensionFromMimetype(file.Mimetype)
}

if strings.HasPrefix(file.Mimetype, "image") {
Expand Down
24 changes: 13 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,30 @@ go 1.19
require (
github.com/gorilla/websocket v1.5.0
github.com/lib/pq v1.10.9
github.com/mattn/go-sqlite3 v1.14.17
github.com/mattn/go-sqlite3 v1.14.18
github.com/slack-go/slack v0.10.3
github.com/yuin/goldmark v1.5.4
github.com/yuin/goldmark v1.6.0
maunium.net/go/maulogger/v2 v2.4.1
maunium.net/go/mautrix v0.15.4
maunium.net/go/mautrix v0.16.2
)

require go.mau.fi/util v0.2.1

require (
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/rs/zerolog v1.29.1 // indirect
github.com/tidwall/gjson v1.14.4 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/rs/zerolog v1.31.0 // indirect
github.com/tidwall/gjson v1.17.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
go.mau.fi/zeroconfig v0.1.2 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
golang.org/x/net v0.18.0 // indirect
golang.org/x/sys v0.14.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
maunium.net/go/mauflag v1.0.0 // indirect
Expand Down
Loading