]> Cypherpunks.ru repositories - gocheese.git/commitdiff
Descriptive passwords parsing
authorElena Balakhonova <balakhonova@rnd.stcnet.ru>
Tue, 3 Dec 2019 13:12:10 +0000 (16:12 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 3 Dec 2019 13:38:04 +0000 (16:38 +0300)
gocheese.go
passwd.go [new file with mode: 0644]

index fa2fb59040de0021f714ccc28b2468f4ffb57c7b..1d8d0b5425b6541b2f9906ef822e7a856c9288fb 100644 (file)
@@ -455,22 +455,7 @@ func main() {
                }
                return
        }
-       passwd, err := ioutil.ReadFile(*passwdPath)
-       if err != nil {
-               log.Fatal(err)
-       }
-       for _, credentials := range strings.Split(strings.TrimRight(string(passwd), "\n"), "\n") {
-               splitted := strings.Split(credentials, ":")
-               if len(splitted) != 2 {
-                       log.Fatal("Wrong login:password format")
-               }
-               _, auther, err := strToAuther(splitted[1])
-               if err != nil {
-                       log.Fatal(err)
-               }
-               passwords[splitted[0]] = auther
-               log.Println("Added password for " + splitted[0])
-       }
+       refreshPasswd()
        log.Println("root:", *root, "bind:", *bind)
        http.HandleFunc(*norefreshURLPath, handler)
        http.HandleFunc(*refreshURLPath, handler)
diff --git a/passwd.go b/passwd.go
new file mode 100644 (file)
index 0000000..2941956
--- /dev/null
+++ b/passwd.go
@@ -0,0 +1,48 @@
+/*
+GoCheese -- Python private package repository and caching proxy
+Copyright (C) 2019 Sergey Matveev <stargrave@stargrave.org>
+              2019 Elena Balakhonova <balakhonova_e@riseup.net>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, 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 General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package main
+
+import (
+       "io/ioutil"
+       "log"
+       "strings"
+)
+
+func refreshPasswd() {
+       passwd, err := ioutil.ReadFile(*passwdPath)
+       if err != nil {
+               log.Fatal(err)
+       }
+       for i, credentials := range strings.Split(strings.TrimRight(string(passwd), "\n"), "\n") {
+               splitted := strings.Split(credentials, ":")
+               if len(splitted) != 2 {
+                       log.Fatalf("%s:%d: Wrong login:password format", *passwdPath, i)
+               }
+               login := splitted[0]
+               if _, exists := passwords[login]; exists {
+                       log.Fatalf("%s:%d: %s: already exists", *passwdPath, i, login)
+               }
+               _, auther, err := strToAuther(splitted[1])
+               if err != nil {
+                       log.Fatalf("%s:%d: %s: %s", *passwdPath, i, login, err)
+               }
+               passwords[login] = auther
+               log.Println("Added password for " + login)
+       }
+}