根据参数,从数据库或者其他参数中加载远程服务器的信息
(fflags *pflag.FlagSet)
| 574 | |
| 575 | // 根据参数,从数据库或者其他参数中加载远程服务器的信息 |
| 576 | func getRemoteAndValid(fflags *pflag.FlagSet) (remoteInfo *workspace.RemoteInfo, err error) { |
| 577 | |
| 578 | host, _ := fflags.GetString(flag_host) |
| 579 | userName, _ := fflags.GetString(flag_username) |
| 580 | |
| 581 | // 指定了host信息,尝试从数据库中加载 |
| 582 | if common.IsNumber(host) { |
| 583 | remoteId, err := strconv.Atoi(host) |
| 584 | if err != nil { |
| 585 | return nil, err |
| 586 | } |
| 587 | remoteInfo, err = dal.GetRemoteById(remoteId) |
| 588 | if err != nil { |
| 589 | return nil, err |
| 590 | } |
| 591 | |
| 592 | if remoteInfo == nil { |
| 593 | return nil, errors.New(i18nInstance.Host.Err_host_data_not_exit) |
| 594 | } |
| 595 | } else { |
| 596 | remoteInfo, err = dal.GetRemoteByHost(host, userName) |
| 597 | |
| 598 | // 如果在sqlite中有缓存数据,就不需要用户名、密码 |
| 599 | if remoteInfo != nil && remoteInfo.UserName == flag_username { |
| 600 | checkFlagUnnecessary(fflags, flag_username, flag_host) |
| 601 | checkFlagUnnecessary(fflags, flag_password, flag_host) |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | // 从参数中加载 |
| 606 | if remoteInfo == nil { |
| 607 | remoteInfo = &workspace.RemoteInfo{} |
| 608 | // 必填字段验证 |
| 609 | err = checkFlagRequired(fflags, flag_host) |
| 610 | if err != nil { |
| 611 | return remoteInfo, &FriendlyError{Err: err} |
| 612 | } |
| 613 | err = checkFlagRequired(fflags, flag_username) |
| 614 | if err != nil { |
| 615 | return remoteInfo, &FriendlyError{Err: err} |
| 616 | } |
| 617 | |
| 618 | remoteInfo.Addr = host |
| 619 | remoteInfo.UserName = getFlagValue(fflags, flag_username) |
| 620 | remoteInfo.SSHPort, err = fflags.GetInt(flag_port) //strconv.Atoi(getFlagValue(fflags, flag_port)) |
| 621 | common.CheckError(err) |
| 622 | if remoteInfo.SSHPort <= 0 { |
| 623 | remoteInfo.SSHPort = model.CONST_Container_SSHPort |
| 624 | } |
| 625 | // 认证类型 |
| 626 | if fflags.Changed(flag_password) { |
| 627 | remoteInfo.Password = getFlagValue(fflags, flag_password) |
| 628 | remoteInfo.AuthType = workspace.RemoteAuthType_Password |
| 629 | } else { |
| 630 | remoteInfo.AuthType = workspace.RemoteAuthType_SSH |
| 631 | } |
| 632 | |
| 633 | } |
no test coverage detected