-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.go
31 lines (24 loc) · 944 Bytes
/
home.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright 2012, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package juju
import (
"path/filepath"
"github.com/juju/errors"
"github.com/juju/utils/v2/ssh"
"github.com/juju/juju/juju/osenv"
)
// InitJujuXDGDataHome initializes the charm cache, environs/config and utils/ssh packages
// to use default paths based on the $JUJU_DATA or $HOME environment variables.
// This function should be called before running a Juju CLI command.
func InitJujuXDGDataHome() error {
jujuXDGDataHome := osenv.JujuXDGDataHomeDir()
if jujuXDGDataHome == "" {
return errors.New("cannot determine juju data home, required environment variables are not set")
}
sshDir := osenv.JujuXDGDataHomePath("ssh")
if err := ssh.LoadClientKeys(sshDir); err != nil {
return errors.Annotate(err, "cannot load ssh client keys")
}
ssh.SetGoCryptoKnownHostsFile(filepath.Join(sshDir, "gocrypto_known_hosts"))
return nil
}