Compare commits

..

No commits in common. "master" and "v0.2.0" have entirely different histories.

24
main.go
View File

@ -9,7 +9,6 @@ import (
"os"
"os/user"
"path/filepath"
"strconv"
"strings"
"github.com/spf13/cobra"
@ -52,7 +51,7 @@ Label:
func createAutorizationFile(authorizedKeyFile string) error {
err := os.MkdirAll(filepath.Dir(authorizedKeyFile), 0700)
err := os.MkdirAll(filepath.Dir(authorizedKeyFile), 700)
if err != nil {
return err
}
@ -208,10 +207,10 @@ func rootCmd(cmd *cobra.Command, args []string) error {
userAuthorizedKeys = addSSHKeys(userAuthorizedKeys, etcAuthorizedKeys)
}
return writeSSHKeysFile(user, userAuthorizedKeyFile, userAuthorizedKeys)
return writeSSHKeysFile(userAuthorizedKeyFile, userAuthorizedKeys)
}
func writeSSHKeysFile(u *user.User, authorizedKeyFile string, sshKeys []*sshKey) error {
func writeSSHKeysFile(authorizedKeyFile string, sshKeys []*sshKey) error {
if err := createAutorizationFile(authorizedKeyFile); err != nil {
return err
}
@ -222,22 +221,7 @@ func writeSSHKeysFile(u *user.User, authorizedKeyFile string, sshKeys []*sshKey)
}
defer f.Close()
err = writeSSHKeys(f, sshKeys)
if err != nil {
return err
}
uid, err := strconv.Atoi(u.Uid)
if err != nil {
return err
}
gid, err := strconv.Atoi(u.Gid)
if err != nil {
return err
}
return os.Chown(authorizedKeyFile, uid, gid)
return writeSSHKeys(f, sshKeys)
}
func writeSSHKeys(w io.Writer, sshKeys []*sshKey) error {