]> Cypherpunks.ru repositories - gocheese.git/blob - passwd.go
Fix workability to password refreshing
[gocheese.git] / passwd.go
1 /*
2 GoCheese -- Python private package repository and caching proxy
3 Copyright (C) 2019 Sergey Matveev <stargrave@stargrave.org>
4               2019 Elena Balakhonova <balakhonova_e@riseup.net>
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, version 3 of the License.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 package main
20
21 import (
22         "io/ioutil"
23         "log"
24         "strings"
25 )
26
27 func refreshPasswd() {
28         passwd, err := ioutil.ReadFile(*passwdPath)
29         if err != nil {
30                 log.Fatal(err)
31         }
32         passwordsNew := make(map[string]Auther)
33         for i, credentials := range strings.Split(strings.TrimRight(string(passwd), "\n"), "\n") {
34                 splitted := strings.Split(credentials, ":")
35                 if len(splitted) != 2 {
36                         log.Fatalf("%s:%d: Wrong login:password format", *passwdPath, i)
37                 }
38                 login := splitted[0]
39                 if _, exists := passwordsNew[login]; exists {
40                         log.Fatalf("%s:%d: %s: already exists", *passwdPath, i, login)
41                 }
42                 _, auther, err := strToAuther(splitted[1])
43                 if err != nil {
44                         log.Fatalf("%s:%d: %s: %s", *passwdPath, i, login, err)
45                 }
46                 passwordsNew[login] = auther
47                 log.Println("Added password for " + login)
48         }
49         passwords = passwordsNew
50 }