]> Sergey Matveev's repositories - mmc.git/commitdiff
Ability to connect to http:// entrypoints
authorSergey Matveev <stargrave@stargrave.org>
Mon, 15 Apr 2024 11:23:11 +0000 (14:23 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 15 Apr 2024 11:23:11 +0000 (14:23 +0300)
cmd/ch-leave/main.go
cmd/mmc/main.go
cmd/sb/main.go
common.go

index cdd699d7c95511fa51343a5bb5fb37c3535e7104..d9e3385413dd791e9752b1ee42894d657557a3c2 100644 (file)
@@ -19,6 +19,7 @@ package main
 import (
        "flag"
        "log"
+       "net/url"
 
        "github.com/mattermost/mattermost-server/v6/model"
        "go.cypherpunks.ru/netrc"
@@ -29,13 +30,16 @@ func main() {
        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 {
index 9bf3fb25c587300451787593c03b7dbbc4c0f1e1..79a850ab48a4992096c347bbd54ab4903a0c5d69 100644 (file)
@@ -26,6 +26,7 @@ import (
        "io"
        "io/fs"
        "log"
+       "net/url"
        "os"
        "os/exec"
        "os/signal"
@@ -86,11 +87,15 @@ func main() {
        }
        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 {
@@ -439,7 +444,15 @@ func main() {
        }()
 
        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)
        }
index 63f723f4b45acc53c1ab27e48c1ed50c11207733..9e987a97e92db90aab4450835700ed8cfeced339 100644 (file)
@@ -19,12 +19,13 @@ package main
 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"
 )
 
@@ -38,11 +39,15 @@ func main() {
 
        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 {
index 3e631db52b215564d7993a6995dee0649e392022..f4d6a9d74b6da787780a6c75fafc0e091ce1e758 100644 (file)
--- a/common.go
+++ b/common.go
@@ -105,7 +105,7 @@ func GetUsers(c *model.Client4, debugFd *os.File) (map[string]*model.User, error
 func GetEntrypoint() string {
        s := os.Getenv("MMC_ENTRYPOINT")
        if s == "" {
-               return "mm.invalid"
+               return "http://mm.invalid"
        }
        return s
 }