Skip to content

Commit a2803ad

Browse files
author
Sam Ban
committed
rename read to update
1 parent ca42aa7 commit a2803ad

File tree

2 files changed

+21
-28
lines changed

2 files changed

+21
-28
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ $ sshman register user [email protected] ~/.ssh/user1.pub production-team staging-s
6262
To run auto discovery users on registered servers, or to refresh the configuration if any 3rd party has changed `~/.ssh/authorized_keys` files, run:
6363

6464
```sh
65-
$ sshman read -f
65+
$ sshman update
6666
```
6767

6868
### Adding user to server

cmd/readusers.go

+20-27
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010

1111
// readCmd represents the read command
1212
var readCmd = &cobra.Command{
13-
Use: "read",
14-
Short: "Read all into configuration",
13+
Use: "update",
14+
Short: "Read users into configuration",
1515
Long: `Loop through all servers, download all users from autorized_keys into configuration`,
1616
Run: func(cmd *cobra.Command, _ []string) {
1717
readUsers(cmd, readConfig())
@@ -20,11 +20,9 @@ var readCmd = &cobra.Command{
2020

2121
func init() {
2222
rootCmd.AddCommand(readCmd)
23-
readCmd.Flags().BoolP("force", "f", false, "Force reading configuration")
2423
}
2524

26-
func readUsers(cmd *cobra.Command, C *config) {
27-
force, _ := cmd.Flags().GetBool("force")
25+
func readUsers(_ *cobra.Command, C *config) {
2826
bar := progressbar.Default(int64(len(C.Hosts)))
2927
for alias, host := range C.Hosts {
3028
bar.Add(1)
@@ -45,30 +43,25 @@ func readUsers(cmd *cobra.Command, C *config) {
4543
client.Close()
4644
sum := checksum(string(b))
4745
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,
6962
}
70-
userlist = append(userlist, C.Users[lsum].Email)
7163
}
64+
userlist = append(userlist, C.Users[lsum].Email)
7265
}
7366
host.Checksum = sum
7467
host.Users = userlist

0 commit comments

Comments
 (0)