mirror of
https://github.com/lyx0/nourybot-matrix.git
synced 2024-11-13 19:49:54 +01:00
move to environment variables for secrets
This commit is contained in:
parent
a284e2e591
commit
1e59a7fedb
5 changed files with 29 additions and 13 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -21,3 +21,5 @@ bin/
|
||||||
|
|
||||||
# Go workspace file
|
# Go workspace file
|
||||||
go.work
|
go.work
|
||||||
|
|
||||||
|
.env
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -4,4 +4,4 @@ cup:
|
||||||
sudo docker compose up
|
sudo docker compose up
|
||||||
|
|
||||||
xd:
|
xd:
|
||||||
go build -o ./bin/${BINARY_NAME} && ./bin/${BINARY_NAME} --homeserver="matrix.xxx" --username="xxx" --password="xxx"
|
go build -o ./bin/${BINARY_NAME} && ./bin/${BINARY_NAME}
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -19,6 +19,7 @@ require (
|
||||||
github.com/godbus/dbus/v5 v5.1.0 // indirect
|
github.com/godbus/dbus/v5 v5.1.0 // indirect
|
||||||
github.com/gorilla/mux v1.8.0 // indirect
|
github.com/gorilla/mux v1.8.0 // indirect
|
||||||
github.com/gorilla/websocket v1.5.0 // indirect
|
github.com/gorilla/websocket v1.5.0 // indirect
|
||||||
|
github.com/joho/godotenv v1.5.1 // indirect
|
||||||
github.com/kisielk/sqlstruct v0.0.0-20210630145711-dae28ed37023 // indirect
|
github.com/kisielk/sqlstruct v0.0.0-20210630145711-dae28ed37023 // indirect
|
||||||
github.com/kr/pretty v0.3.1 // indirect
|
github.com/kr/pretty v0.3.1 // indirect
|
||||||
github.com/kr/pty v1.1.8 // indirect
|
github.com/kr/pty v1.1.8 // indirect
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -22,6 +22,8 @@ github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
||||||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
||||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
github.com/kisielk/sqlstruct v0.0.0-20210630145711-dae28ed37023 h1:/pb3UJ+3ZtSEUKWnufwsoVF7f0AX5ytPULbTwHMgbq4=
|
github.com/kisielk/sqlstruct v0.0.0-20210630145711-dae28ed37023 h1:/pb3UJ+3ZtSEUKWnufwsoVF7f0AX5ytPULbTwHMgbq4=
|
||||||
github.com/kisielk/sqlstruct v0.0.0-20210630145711-dae28ed37023/go.mod h1:yyMNCyc/Ib3bDTKd379tNMpB/7/H5TjM2Y9QJ5THLbE=
|
github.com/kisielk/sqlstruct v0.0.0-20210630145711-dae28ed37023/go.mod h1:yyMNCyc/Ib3bDTKd379tNMpB/7/H5TjM2Y9QJ5THLbE=
|
||||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||||
|
|
35
main.go
35
main.go
|
@ -5,11 +5,13 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/chzyer/readline"
|
"github.com/chzyer/readline"
|
||||||
|
"github.com/joho/godotenv"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"maunium.net/go/mautrix"
|
"maunium.net/go/mautrix"
|
||||||
|
@ -18,21 +20,30 @@ import (
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
)
|
)
|
||||||
|
|
||||||
var homeserver = flag.String("homeserver", "", "Matrix homeserver")
|
type config struct {
|
||||||
var username = flag.String("username", "", "Matrix username localpart")
|
matrixHomeserver string
|
||||||
var password = flag.String("password", "", "Matrix passsword")
|
matrixUser string
|
||||||
var database = flag.String("database", "mautrix-example.db", "SQLite database path")
|
matrixPass string
|
||||||
|
database string
|
||||||
|
}
|
||||||
|
|
||||||
var debug = flag.Bool("debug", false, "Enable debug logs")
|
var debug = flag.Bool("debug", false, "Enable debug logs")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if *username == "" || *password == "" || *homeserver == "" {
|
|
||||||
_, _ = fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
|
err := godotenv.Load()
|
||||||
flag.PrintDefaults()
|
if err != nil {
|
||||||
os.Exit(1)
|
log.Fatal("Error loading .env")
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := mautrix.NewClient(*homeserver, "", "")
|
var cfg config
|
||||||
|
cfg.matrixHomeserver = os.Getenv("MATRIX_HOMESERVER")
|
||||||
|
cfg.matrixUser = os.Getenv("MATRIX_USERNAME")
|
||||||
|
cfg.matrixPass = os.Getenv("MATRIX_PASSWORD")
|
||||||
|
cfg.database = os.Getenv("SQLITE_DATABASE")
|
||||||
|
|
||||||
|
client, err := mautrix.NewClient(cfg.matrixHomeserver, "", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -83,15 +94,15 @@ func main() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
cryptoHelper, err := cryptohelper.NewCryptoHelper(client, []byte("meow"), *database)
|
cryptoHelper, err := cryptohelper.NewCryptoHelper(client, []byte("meow"), cfg.database)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cryptoHelper.LoginAs = &mautrix.ReqLogin{
|
cryptoHelper.LoginAs = &mautrix.ReqLogin{
|
||||||
Type: mautrix.AuthTypePassword,
|
Type: mautrix.AuthTypePassword,
|
||||||
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: *username},
|
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: cfg.matrixUser},
|
||||||
Password: *password,
|
Password: cfg.matrixPass,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = cryptoHelper.Init()
|
err = cryptoHelper.Init()
|
||||||
|
|
Loading…
Reference in a new issue