@@ -10,8 +10,8 @@ import (
10
10
11
11
// readCmd represents the read command
12
12
var readCmd = & cobra.Command {
13
- Use : "read " ,
14
- Short : "Read all into configuration" ,
13
+ Use : "update " ,
14
+ Short : "Read users into configuration" ,
15
15
Long : `Loop through all servers, download all users from autorized_keys into configuration` ,
16
16
Run : func (cmd * cobra.Command , _ []string ) {
17
17
readUsers (cmd , readConfig ())
@@ -20,11 +20,9 @@ var readCmd = &cobra.Command{
20
20
21
21
func init () {
22
22
rootCmd .AddCommand (readCmd )
23
- readCmd .Flags ().BoolP ("force" , "f" , false , "Force reading configuration" )
24
23
}
25
24
26
- func readUsers (cmd * cobra.Command , C * config ) {
27
- force , _ := cmd .Flags ().GetBool ("force" )
25
+ func readUsers (_ * cobra.Command , C * config ) {
28
26
bar := progressbar .Default (int64 (len (C .Hosts )))
29
27
for alias , host := range C .Hosts {
30
28
bar .Add (1 )
@@ -45,30 +43,25 @@ func readUsers(cmd *cobra.Command, C *config) {
45
43
client .Close ()
46
44
sum := checksum (string (b ))
47
45
userlist := []string {}
48
- if host .Checksum != sum || force {
49
- // if host.Checksum != sum {
50
- // slog.Infof("checksum doesn't match for %s %s", alias, sum)
51
- // }
52
- lines := strings .Split (string (b ), "\n " )
53
- for _ , line := range lines {
54
- if len (line ) == 0 {
55
- continue
56
- }
57
- parts := strings .Split (line , " " )
58
- if len (parts ) != 3 {
59
- slog .Errorf ("Not good line: '%s'" , line )
60
- }
61
- lsum := checksum (parts [1 ])
62
- if _ , ok := C .Users [lsum ]; ! ok {
63
- C .Users [lsum ] = user {
64
- KeyType : parts [0 ],
65
- Key : parts [1 ],
66
- Name : parts [2 ],
67
- Email : parts [2 ] + "@" + alias ,
68
- }
46
+ lines := strings .Split (string (b ), "\n " )
47
+ for _ , line := range lines {
48
+ if len (line ) == 0 {
49
+ continue
50
+ }
51
+ parts := strings .Split (line , " " )
52
+ if len (parts ) != 3 {
53
+ slog .Errorf ("Not good line: '%s'" , line )
54
+ }
55
+ lsum := checksum (parts [1 ])
56
+ if _ , ok := C .Users [lsum ]; ! ok {
57
+ C .Users [lsum ] = user {
58
+ KeyType : parts [0 ],
59
+ Key : parts [1 ],
60
+ Name : parts [2 ],
61
+ Email : parts [2 ] + "@" + alias ,
69
62
}
70
- userlist = append (userlist , C .Users [lsum ].Email )
71
63
}
64
+ userlist = append (userlist , C .Users [lsum ].Email )
72
65
}
73
66
host .Checksum = sum
74
67
host .Users = userlist
0 commit comments