// InitJujuHome initializes the charm, environs/config and utils/ssh packages // to use default paths based on the $JUJU_HOME or $HOME environment variables. // This function should be called before calling NewConn or Conn.Deploy. func InitJujuHome() error { jujuHome := osenv.JujuHomeDir() if jujuHome == "" { return stderrors.New( "cannot determine juju home, required environment variables are not set") } osenv.SetJujuHome(jujuHome) charm.CacheDir = osenv.JujuHomePath("charmcache") if err := ssh.LoadClientKeys(osenv.JujuHomePath("ssh")); err != nil { return fmt.Errorf("cannot load ssh client keys: %v", err) } return nil }
func (s *AuthKeysSuite) TestReadAuthorizedKeysClientKeys(c *gc.C) { keydir := filepath.Join(s.dotssh, "juju") err := ssh.LoadClientKeys(keydir) // auto-generates a key pair c.Assert(err, gc.IsNil) pubkeyFiles := ssh.PublicKeyFiles() c.Assert(pubkeyFiles, gc.HasLen, 1) data, err := ioutil.ReadFile(pubkeyFiles[0]) c.Assert(err, gc.IsNil) prefix := strings.Trim(string(data), "\n") + "\n" writeFile(c, filepath.Join(s.dotssh, "id_rsa.pub"), "id_rsa") writeFile(c, filepath.Join(s.dotssh, "test.pub"), "test") keys, err := config.ReadAuthorizedKeys("") c.Assert(err, gc.IsNil) c.Assert(keys, gc.Equals, prefix+"id_rsa\n") keys, err = config.ReadAuthorizedKeys("test.pub") c.Assert(err, gc.IsNil) c.Assert(keys, gc.Equals, prefix+"test\n") keys, err = config.ReadAuthorizedKeys("notthere.pub") c.Assert(err, gc.IsNil) c.Assert(keys, gc.Equals, prefix) }