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

Method ExecSSHkeyPolicy

cli/pkg/common/sshremote.go:484–614  ·  view source on GitHub ↗
(no string, userName string, host string, token string, ownerGuid string, wspId uint)

Source from the content-addressed store, hash-verified

482}
483
484func (instance *SSHRemote) ExecSSHkeyPolicy(no string, userName string, host string, token string, ownerGuid string, wspId uint) {
485
486 isOverwrite := "y"
487 isAllowCopyPrivateKey := ""
488 // fflags := cmd.Flags()
489 // userName, _ := fflags.GetString(Flags_ServerUserName)
490 commandRsa := fmt.Sprintf(`[[ -f ".ssh/id_rsa_%s_%s" ]] && cat ~/.ssh/id_rsa_%s_%s || echo ""`, userName, no, userName, no)
491 remoteRsaPri, err := instance.ExeSSHCommandConsoleAndEncryptedOutput(commandRsa)
492 CheckError(err)
493 //SmartIDELog.DebugF("%v >> `%v`", commandRsa, "****")
494
495 commandRsaPub := fmt.Sprintf(`[[ -f ".ssh/id_rsa.pub_%s_%s" ]] && cat ~/.ssh/id_rsa.pub_%s_%s || echo ""`, userName, no, userName, no)
496 remoteRsaPub, err := instance.ExeSSHCommandConsoleAndEncryptedOutput(commandRsaPub)
497 CheckError(err)
498 //SmartIDELog.DebugF("%v >> `%v`", commandRsaPub, "****")
499
500 idRsa := ""
501 idRsaPub := ""
502 var ws []WorkspacePolicy
503 i := -1
504 if no != "" {
505 ws, err = GetWSPolicies("2", host, token, ownerGuid)
506 CheckError(err)
507 for index, wp := range ws {
508 if wp.ID == wspId {
509 i = index
510 }
511 }
512 if i == -1 {
513 for index, wp := range ws {
514 if wp.IsDefault {
515 i = index
516 }
517 }
518 }
519 }
520
521 if i >= 0 {
522 detail := Detail{}
523 if ws[i].Detail != "" {
524 err := json.Unmarshal([]byte(ws[i].Detail), &detail)
525 if err != nil {
526 return
527 }
528 idRsa = detail.IdRsa
529 idRsaPub = detail.IdRsaPub
530 }
531
532 }
533 // 远程公私钥都不为空
534 if strings.ReplaceAll(remoteRsaPri, "\n", "") != "" && strings.ReplaceAll(remoteRsaPub, "\n", "") != "" {
535 localRsaPub := ""
536 if no != "" {
537 isAllowCopyPrivateKey = "y"
538 isOverwrite = "y"
539 localRsaPub = idRsaPub
540
541 } else {

Callers 1

ExecuteVmStartCmdFunction · 0.95

Calls 10

ExeSSHCommandConsoleMethod · 0.95
CheckErrorFunction · 0.85
GetWSPoliciesFunction · 0.85
ConsoleMethod · 0.80
DebugMethod · 0.80
DebugFMethod · 0.80
JoinMethod · 0.45

Tested by

no test coverage detected