// Contains returns true if the given text is present in the authorized keys file. func (manager *AuthorizedKeysManager) Contains(text string) bool { home := utils.FindUserHome() file, err := os.Open(home + "/.ssh/authorized_keys") if err != nil { panic(err) } defer file.Close() scanner := bufio.NewScanner(file) for scanner.Scan() { if strings.Contains(scanner.Text(), text) { return true } } return false }
// WriteToDefaultLocation writes the authorized keys to ~/.ssh/authorized_keys func (manager *AuthorizedKeysManager) WriteToDefaultLocation() error { home := utils.FindUserHome() // FIXME: create the .ssh dir if it doesn't exist. filename := home + "/.ssh/authorized_keys" file, err := os.Create(filename) if err != nil { return err } defer file.Close() err = manager.Write(file) if err != nil { return err } return os.Chmod(filename, 0600) }
package ssh import ( "io/ioutil" "os" "github.com/dcu/onetouch-ssh/utils" "gopkg.in/yaml.v2" ) var ( DataPath = utils.FindUserHome() + "/.authy-onetouch" ) // Config contains the configuration of the app. type Config struct { APIKey string `yaml:"api_key"` ShellPath string `yaml:"shell"` ShellArgs []string `yaml:"shell_args"` } func NewConfig(apiKey string) *Config { config := &Config{ APIKey: apiKey, } // Find some other safe default? config.ShellPath = "/bin/sh" config.ShellArgs = make([]string, 0) return config