import (
"flag"
"log"
+ "net/url"
"github.com/mattermost/mattermost-server/v6/model"
"go.cypherpunks.ru/netrc"
entrypoint := flag.String("entrypoint", mmc.GetEntrypoint(), "Entrypoint")
flag.Parse()
log.SetFlags(log.Lshortfile)
-
chId := flag.Arg(0)
- login, password := netrc.Find(*entrypoint)
+ entrypointURL, err := url.Parse(*entrypoint)
+ if err != nil {
+ log.Fatalln(err)
+ }
+ login, password := netrc.Find(entrypointURL.Hostname())
if login == "" || password == "" {
- log.Fatalln("no credentials found for:", *entrypoint)
+ log.Fatalln("no credentials found for:", entrypointURL.Hostname())
}
- c := model.NewAPIv4Client("https://" + *entrypoint)
+ c := model.NewAPIv4Client(*entrypoint)
c.Login(login, password)
me, _, err := c.GetMe("")
if err != nil {
"io"
"io/fs"
"log"
+ "net/url"
"os"
"os/exec"
"os/signal"
}
defer DebugFd.Close()
- login, password := netrc.Find(*entrypoint)
+ entrypointURL, err := url.Parse(*entrypoint)
+ if err != nil {
+ log.Fatalln(err)
+ }
+ login, password := netrc.Find(entrypointURL.Hostname())
if login == "" || password == "" {
- log.Fatalln("no credentials found for:", *entrypoint)
+ log.Fatalln("no credentials found for:", entrypointURL.Hostname())
}
- c := model.NewAPIv4Client("https://" + *entrypoint)
+ c := model.NewAPIv4Client(*entrypoint)
c.Login(login, password)
me, resp, err := c.GetMe("")
if err != nil {
}()
needsShutdown := make(chan os.Signal)
- wc, err := model.NewWebSocketClient4("wss://"+*entrypoint, c.AuthToken)
+ switch entrypointURL.Scheme {
+ case "http":
+ entrypointURL.Scheme = "ws"
+ case "https":
+ entrypointURL.Scheme = "wss"
+ default:
+ log.Println("unhandled scheme:", entrypointURL.Scheme)
+ }
+ wc, err := model.NewWebSocketClient4(entrypointURL.String(), c.AuthToken)
if err != nil {
log.Fatalln(err)
}
import (
"flag"
"log"
+ "net/url"
"os"
"time"
"github.com/mattermost/mattermost-server/v6/model"
- "go.cypherpunks.ru/recfile"
"go.cypherpunks.ru/netrc"
+ "go.cypherpunks.ru/recfile"
"go.stargrave.org/mmc"
)
chId := flag.Arg(0)
postId := flag.Arg(1)
- login, password := netrc.Find(*entrypoint)
+ entrypointURL, err := url.Parse(*entrypoint)
+ if err != nil {
+ log.Fatalln(err)
+ }
+ login, password := netrc.Find(entrypointURL.Hostname())
if login == "" || password == "" {
- log.Fatalln("no credentials found for:", *entrypoint)
+ log.Fatalln("no credentials found for:", entrypointURL.Hostname())
}
- c := model.NewAPIv4Client("https://" + *entrypoint)
+ c := model.NewAPIv4Client(*entrypoint)
c.Login(login, password)
me, _, err := c.GetMe("")
if err != nil {
func GetEntrypoint() string {
s := os.Getenv("MMC_ENTRYPOINT")
if s == "" {
- return "mm.invalid"
+ return "http://mm.invalid"
}
return s
}