-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.go
31 lines (26 loc) · 897 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 (
stderrors "errors"
"fmt"
"gopkg.in/juju/charm.v4"
"github.com/juju/juju/juju/osenv"
"github.com/juju/juju/utils/ssh"
)
// InitJujuHome initializes the charm cache, 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 running a Juju CLI command.
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
}