]> Sergey Matveev's repositories - mmc.git/commitdiff
internal package master
authorSergey Matveev <stargrave@stargrave.org>
Mon, 29 Apr 2024 12:42:58 +0000 (15:42 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 29 Apr 2024 12:42:58 +0000 (15:42 +0300)
cmd/ch-leave/main.go
cmd/mmc/main.go
cmd/mmc/post.go
cmd/rd/main.go
cmd/sb/main.go
internal/cert.go [new file with mode: 0644]
internal/lock.go [moved from lock.go with 100% similarity]
internal/post.go [moved from common.go with 57% similarity]
internal/users.go [new file with mode: 0644]
internal/var.go [new file with mode: 0644]

index d9e3385413dd791e9752b1ee42894d657557a3c2..e182983ba9aee26c41d071caa1ea765c23e562b1 100644 (file)
@@ -23,7 +23,7 @@ import (
 
        "github.com/mattermost/mattermost-server/v6/model"
        "go.cypherpunks.ru/netrc"
-       "go.stargrave.org/mmc"
+       "go.stargrave.org/mmc/internal"
 )
 
 func main() {
index 069f0e41ef7b2b6ff5c65d47d4482e4c49b12a03..3e8900927c1bf4f3172e3dd805a194d64a202cc0 100644 (file)
@@ -43,7 +43,7 @@ import (
        "github.com/gorilla/websocket"
        "github.com/mattermost/mattermost-server/v6/model"
        "go.cypherpunks.ru/netrc"
-       "go.stargrave.org/mmc"
+       "go.stargrave.org/mmc/internal"
 )
 
 var (
index 6506303ab02ed9b1fdff1cb414c49bba5e9470ff..b18a4864932c5c17e76fb95f4801557f302d6b0e 100644 (file)
@@ -27,7 +27,7 @@ import (
        "github.com/davecgh/go-spew/spew"
        "github.com/mattermost/mattermost-server/v6/model"
        "go.cypherpunks.ru/recfile"
-       "go.stargrave.org/mmc"
+       "go.stargrave.org/mmc/internal"
 )
 
 const CmdFile = "/FILE "
index 74f613a6f7b2b7965143284ca9d1c192110ab2ff..535332ff64a2c57f10f6e9d4956c4b8d59c5e3f6 100644 (file)
@@ -29,7 +29,7 @@ import (
        "github.com/fsnotify/fsnotify"
        "github.com/mattermost/mattermost-server/v6/model"
        "go.cypherpunks.ru/recfile"
-       "go.stargrave.org/mmc"
+       "go.stargrave.org/mmc/internal"
 )
 
 var Threads = make(map[string]string)
index 9e987a97e92db90aab4450835700ed8cfeced339..b1901c9338ffe08f580cc697f32d85819684fff2 100644 (file)
@@ -26,7 +26,7 @@ import (
        "github.com/mattermost/mattermost-server/v6/model"
        "go.cypherpunks.ru/netrc"
        "go.cypherpunks.ru/recfile"
-       "go.stargrave.org/mmc"
+       "go.stargrave.org/mmc/internal"
 )
 
 func main() {
diff --git a/internal/cert.go b/internal/cert.go
new file mode 100644 (file)
index 0000000..aa2f39b
--- /dev/null
@@ -0,0 +1,43 @@
+// mmc -- Mattermost client
+// Copyright (C) 2023-2024 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+package mmc
+
+import (
+       "crypto/sha256"
+       "crypto/x509"
+       "encoding/hex"
+       "errors"
+)
+
+func NewVerifyPeerCertificate(hashExpected string) func(
+       rawCerts [][]byte, verifiedChains [][]*x509.Certificate,
+) error {
+       return func(
+               rawCerts [][]byte, verifiedChains [][]*x509.Certificate,
+       ) error {
+               cer, err := x509.ParseCertificate(rawCerts[0])
+               if err != nil {
+                       return err
+               }
+               spki := cer.RawSubjectPublicKeyInfo
+               hsh := sha256.Sum256(spki)
+               if hashExpected != hex.EncodeToString(hsh[:]) {
+                       return errors.New("server certificate's SPKI hash mismatch")
+               }
+               return nil
+       }
+}
similarity index 100%
rename from lock.go
rename to internal/lock.go
similarity index 57%
rename from common.go
rename to internal/post.go
index ce84af61c5cfb6fcafc871c25a499b8ad6a21826..106a06537d025eeb54a113e3b2ddf65be8dfa50f 100644 (file)
--- a/common.go
 package mmc
 
 import (
-       "crypto/sha256"
-       "crypto/x509"
-       "encoding/hex"
-       "errors"
-       "os"
        "strings"
        "time"
 
-       "github.com/davecgh/go-spew/spew"
        "github.com/mattermost/mattermost-server/v6/model"
        "go.cypherpunks.ru/recfile"
 )
 
-const (
-       PerPage    = 100
-       OutRec     = "out.rec"
-       OutRecLock = "out.rec.lock"
-       Last       = "last"
-)
-
-var SleepTime = 250 * time.Millisecond
-
 type Post struct {
        P *model.Post
        E string
@@ -81,62 +66,3 @@ func PostToRec(w *recfile.Writer, users map[string]*model.User, post Post) error
        _, err = w.WriteFieldMultiline("Text", strings.Split(post.P.Message, "\n"))
        return err
 }
-
-func GetUsers(c *model.Client4, debugFd *os.File) (map[string]*model.User, error) {
-       users := make(map[string]*model.User)
-       for n := 0; ; n++ {
-               time.Sleep(SleepTime)
-               page, resp, err := c.GetUsers(n, PerPage, "")
-               if err != nil {
-                       if debugFd != nil {
-                               spew.Fdump(debugFd, resp)
-                       }
-                       return nil, err
-               }
-               if debugFd != nil {
-                       spew.Fdump(debugFd, page)
-               }
-               for _, u := range page {
-                       users[u.Id] = u
-               }
-               if len(page) < PerPage {
-                       break
-               }
-       }
-       return users, nil
-}
-
-func GetEntrypoint() string {
-       s := os.Getenv("MMC_ENTRYPOINT")
-       if s == "" {
-               return "http://mm.invalid"
-       }
-       return s
-}
-
-func GetSPKIHash() string {
-       s := os.Getenv("MMC_SPKI")
-       if s == "" {
-               return "deadbeef"
-       }
-       return s
-}
-
-func NewVerifyPeerCertificate(hashExpected string) func(
-       rawCerts [][]byte, verifiedChains [][]*x509.Certificate,
-) error {
-       return func(
-               rawCerts [][]byte, verifiedChains [][]*x509.Certificate,
-       ) error {
-               cer, err := x509.ParseCertificate(rawCerts[0])
-               if err != nil {
-                       return err
-               }
-               spki := cer.RawSubjectPublicKeyInfo
-               hsh := sha256.Sum256(spki)
-               if hashExpected != hex.EncodeToString(hsh[:]) {
-                       return errors.New("server certificate's SPKI hash mismatch")
-               }
-               return nil
-       }
-}
diff --git a/internal/users.go b/internal/users.go
new file mode 100644 (file)
index 0000000..83802e7
--- /dev/null
@@ -0,0 +1,49 @@
+// mmc -- Mattermost client
+// Copyright (C) 2023-2024 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+package mmc
+
+import (
+       "os"
+       "time"
+
+       "github.com/davecgh/go-spew/spew"
+       "github.com/mattermost/mattermost-server/v6/model"
+)
+
+func GetUsers(c *model.Client4, debugFd *os.File) (map[string]*model.User, error) {
+       users := make(map[string]*model.User)
+       for n := 0; ; n++ {
+               time.Sleep(SleepTime)
+               page, resp, err := c.GetUsers(n, PerPage, "")
+               if err != nil {
+                       if debugFd != nil {
+                               spew.Fdump(debugFd, resp)
+                       }
+                       return nil, err
+               }
+               if debugFd != nil {
+                       spew.Fdump(debugFd, page)
+               }
+               for _, u := range page {
+                       users[u.Id] = u
+               }
+               if len(page) < PerPage {
+                       break
+               }
+       }
+       return users, nil
+}
diff --git a/internal/var.go b/internal/var.go
new file mode 100644 (file)
index 0000000..ece260c
--- /dev/null
@@ -0,0 +1,47 @@
+// mmc -- Mattermost client
+// Copyright (C) 2023-2024 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+package mmc
+
+import (
+       "os"
+       "time"
+)
+
+const (
+       PerPage    = 100
+       OutRec     = "out.rec"
+       OutRecLock = "out.rec.lock"
+       Last       = "last"
+)
+
+var SleepTime = 250 * time.Millisecond
+
+func GetEntrypoint() string {
+       s := os.Getenv("MMC_ENTRYPOINT")
+       if s == "" {
+               return "http://mm.invalid"
+       }
+       return s
+}
+
+func GetSPKIHash() string {
+       s := os.Getenv("MMC_SPKI")
+       if s == "" {
+               return "deadbeef"
+       }
+       return s
+}