MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / SSHVolumesConfig

Function SSHVolumesConfig

cli/internal/biz/config/gitconfig.go:81–115  ·  view source on GitHub ↗

注入ssh配置

(isVmCommand bool, service *compose.Service, sshRemote common.SSHRemote, userName string)

Source from the content-addressed store, hash-verified

79
80// 注入ssh配置
81func SSHVolumesConfig(isVmCommand bool, service *compose.Service, sshRemote common.SSHRemote, userName string) {
82
83 var configPaths []string
84
85 // volumes for local windows
86 if runtime.GOOS == "windows" && !isVmCommand {
87 if common.IsExist(filepath.Join(os.Getenv("USERPROFILE"), "/.ssh")) {
88 configPaths = []string{fmt.Sprintf("\\'%v\\.ssh/id_rsa:/home/smartide/.ssh/id_rsa\\'", os.Getenv("USERPROFILE")), fmt.Sprintf("\\'%v\\.ssh/id_rsa.pub:/home/smartide/.ssh/id_rsa.pub\\'", os.Getenv("USERPROFILE"))}
89 }
90 } else {
91 // volumes for linux vm
92 if isVmCommand {
93 if common.SmartIDELog.Ws_id == "" {
94 configPaths = []string{fmt.Sprintf("$HOME/.ssh/id_rsa_%s_%s:/home/smartide/.ssh/id_rsa", userName, common.SmartIDELog.Ws_id), fmt.Sprintf("$HOME/.ssh/id_rsa.pub_%s_%s:/home/smartide/.ssh/id_rsa.pub", userName, common.SmartIDELog.Ws_id), fmt.Sprintf("$HOME/.ssh/authorized_keys_%s_%s:/home/smartide/.ssh/authorized_keys", userName, common.SmartIDELog.Ws_id)}
95 } else {
96 configPaths = []string{"$HOME/smartide-agent:/home/smartide/smartide-agent"}
97 }
98
99 } else {
100 // volumes for local linxu/mac
101 if homeDir, err := os.UserHomeDir(); err == nil {
102 if common.IsExist(filepath.Join(homeDir, "/.ssh")); err == nil {
103 configPaths = []string{"$HOME/.ssh/id_rsa:/home/smartide/.ssh/id_rsa", "$HOME/.ssh/id_rsa.pub:/home/smartide/.ssh/id_rsa.pub"}
104
105 }
106 }
107 }
108
109 }
110 if configPaths != nil {
111 service.Volumes = append(service.Volumes, configPaths...)
112 }
113
114 // return
115}
116
117func GitConfig(isVmCommand bool, containerName string, cli *client.Client,
118 service *compose.Service, sshRemote common.SSHRemote, execRquest k8s.ExecInPodRequest) {

Callers 1

Calls 2

IsExistMethod · 0.80
JoinMethod · 0.45

Tested by

no test coverage detected