-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
54 lines (47 loc) · 1.12 KB
/
common.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package common
import (
"net/url"
"os"
"os/exec"
"strings"
"syscall"
"github.com/pkg/errors"
"github.com/rancher/rancher/pkg/jailer"
)
type HelmPath struct {
// /opt/jail/<app-name>
FullPath string
// /
InJailPath string
// /opt/jail/<app-name>/.kubeconfig
KubeConfigFull string
// /.kubeconfig
KubeConfigInJail string
// /opt/jail/<app-name>/<app-sub>
AppDirFull string
// /<app-sub>
AppDirInJail string
}
func ParseExternalID(externalID string) (string, error) {
values, err := url.Parse(externalID)
if err != nil {
return "", err
}
catalog := values.Query().Get("catalog")
template := values.Query().Get("template")
version := values.Query().Get("version")
return strings.Join([]string{catalog, template, version}, "-"), nil
}
func JailCommand(cmd *exec.Cmd, jailPath string) (*exec.Cmd, error) {
if os.Getenv("CATTLE_DEV_MODE") != "" {
return cmd, nil
}
cred, err := jailer.GetUserCred()
if err != nil {
return nil, errors.WithMessage(err, "get user cred error")
}
cmd.SysProcAttr = &syscall.SysProcAttr{}
cmd.SysProcAttr.Credential = cred
cmd.SysProcAttr.Chroot = jailPath
return cmd, nil
}