k8s模式将ssh-key 写入本地
(workspaceInfo workspace.WorkspaceInfo, host string, token string, ownerGuid string)
| 301 | |
| 302 | // k8s模式将ssh-key 写入本地 |
| 303 | func execSSHPolicy(workspaceInfo workspace.WorkspaceInfo, host string, token string, ownerGuid string) { |
| 304 | if ws, err := common.GetWSPolicies("2", host, token, ownerGuid); err == nil { |
| 305 | if len(ws) > 0 { |
| 306 | i := -1 |
| 307 | for index, wp := range ws { |
| 308 | if wp.ID == workspaceInfo.ServerWorkSpace.SshCredentialId { |
| 309 | i = index |
| 310 | } |
| 311 | } |
| 312 | if i == -1 { |
| 313 | for index, wp := range ws { |
| 314 | if wp.IsDefault { |
| 315 | i = index |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | detail := common.Detail{} |
| 320 | if i >= 0 { |
| 321 | if ws[i].Detail != "" { |
| 322 | if err := json.Unmarshal([]byte(ws[i].Detail), &detail); err == nil { |
| 323 | idRsa := detail.IdRsa |
| 324 | idRsaPub := detail.IdRsaPub |
| 325 | if homeDir, err := os.UserHomeDir(); err == nil { |
| 326 | path := filepath.Join(homeDir, ".ssh") |
| 327 | if _, err := common.PathExists(path, 0700); err == nil { |
| 328 | |
| 329 | commad := `echo -e 'Host *\n StrictHostKeyChecking no' >> ~/.ssh/config && sudo chmod 700 ~/.ssh/config` |
| 330 | common.RunCmd(commad, true) |
| 331 | commad = fmt.Sprintf(`echo -e '%v' >> ~/.ssh/id_rsa && sudo chmod 600 ~/.ssh/id_rsa`, idRsa) |
| 332 | common.RunCmd(commad, true) |
| 333 | commad = fmt.Sprintf(`echo -e '%v' >> ~/.ssh/id_rsa.pub && sudo chmod 644 ~/.ssh/id_rsa.pub`, idRsaPub) |
| 334 | common.RunCmd(commad, true) |
| 335 | |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | // 更新Port信息 |
| 348 | func updatePortInfo(availableClientPort int, hostOriginPort int, workspaceInfo *workspace.WorkspaceInfo, index int) { |
no test coverage detected