"log"
"github.com/mattermost/mattermost-server/v6/model"
+ "go.cypherpunks.ru/netrc"
"go.stargrave.org/mmc"
)
log.SetFlags(log.Lshortfile)
chId := flag.Arg(0)
- login, password := mmc.FindInNetrc(*entrypoint)
+ login, password := netrc.Find(*entrypoint)
if login == "" || password == "" {
log.Fatalln("no credentials found for:", *entrypoint)
}
"github.com/davecgh/go-spew/spew"
"github.com/mattermost/mattermost-server/v6/model"
+ "go.cypherpunks.ru/netrc"
"go.stargrave.org/mmc"
)
}
defer DebugFd.Close()
- login, password := mmc.FindInNetrc(*entrypoint)
+ login, password := netrc.Find(*entrypoint)
if login == "" || password == "" {
log.Fatalln("no credentials found for:", *entrypoint)
}
"github.com/mattermost/mattermost-server/v6/model"
"go.cypherpunks.ru/recfile"
+ "go.cypherpunks.ru/netrc"
"go.stargrave.org/mmc"
)
chId := flag.Arg(0)
postId := flag.Arg(1)
- login, password := mmc.FindInNetrc(*entrypoint)
+ login, password := netrc.Find(*entrypoint)
if login == "" || password == "" {
log.Fatalln("no credentials found for:", *entrypoint)
}
github.com/davecgh/go-spew v1.1.1
github.com/fsnotify/fsnotify v1.6.0
github.com/mattermost/mattermost-server/v6 v6.7.2
+ go.cypherpunks.ru/netrc v0.1.0
go.cypherpunks.ru/recfile v0.7.0
- golang.org/x/sys v0.6.0
+ golang.org/x/sys v0.11.0
)
require (
github.com/yvasiyarov/newrelic_platform_go v0.0.0-20140908184405-b21fdbd4370f/go.mod h1:GlGEuHIJweS1mbCqG+7vt2nvWLzLLnRHbXz5JKd/Qbg=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
gitlab.com/nyarla/go-crypt v0.0.0-20160106005555-d9a5dc2b789b/go.mod h1:T3BPAOm2cqquPa0MKWeNkmOM5RQsRhkrwMWonFMN7fE=
+go.cypherpunks.ru/netrc v0.1.0 h1:dzaSh4lgpPXvLzUME/hTSegg+Uw1aPEmC79fxbPLFGk=
+go.cypherpunks.ru/netrc v0.1.0/go.mod h1:ZmQaL9ENEII++WQooelccr33XZcBhKd8VgtcICf4SIE=
go.cypherpunks.ru/recfile v0.7.0 h1:0R1UnDGKccp7JnC66msslJMlSY02jHx/XkW+ISl0GuY=
go.cypherpunks.ru/recfile v0.7.0/go.mod h1:sR+KajB+vzofL3SFVFwKt3Fke0FaCcN1g3YPNAhU3qI=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220403205710-6acee93ad0eb/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
-golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
+golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
+++ /dev/null
-// mmc -- Mattermost client
-// Copyright (C) 2023 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/>.
-
-// Nearly all code is taken from src/cmd/go/internal/auth/netrc.go
-
-package mmc
-
-import (
- "errors"
- "io/fs"
- "log"
- "os"
- "path/filepath"
- "strings"
-)
-
-func FindInNetrc(host string) (string, string) {
- netrcPath, ok := os.LookupEnv("NETRC")
- if !ok {
- homeDir, err := os.UserHomeDir()
- if err != nil {
- log.Fatalln(err)
- }
- netrcPath = filepath.Join(homeDir, ".netrc")
- }
- data, err := os.ReadFile(netrcPath)
- if err != nil {
- if errors.Is(err, fs.ErrNotExist) {
- return "", ""
- }
- log.Fatalln(err)
- }
- inMacro := false
- var machine, login, password string
- for _, line := range strings.Split(string(data), "\n") {
- if inMacro {
- if line == "" {
- inMacro = false
- }
- continue
- }
- fields := strings.Fields(line)
- i := 0
- for ; i < len(fields)-1; i += 2 {
- switch fields[i] {
- case "machine":
- machine = fields[i+1]
- login = ""
- password = ""
- case "default":
- case "login":
- login = fields[i+1]
- case "password":
- password = fields[i+1]
- case "macdef":
- inMacro = true
- }
- if machine != "" && login != "" && password != "" {
- if machine == host {
- return login, password
- }
- machine, login, password = "", "", ""
- }
- }
- if i < len(fields) && fields[i] == "default" {
- break
- }
- }
- return "", ""
-}