MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / LoadSSHFile

Method LoadSSHFile

agent/app/service/ssh.go:746–785  ·  view source on GitHub ↗
(name string)

Source from the content-addressed store, hash-verified

744}
745
746func (u *SSHService) LoadSSHFile(name string) (string, error) {
747 var fileName string
748 switch name {
749 case "authKeys":
750 currentUser, err := user.Current()
751 if err != nil {
752 return "", fmt.Errorf("load current user failed, err: %v", err)
753 }
754 fileName = currentUser.HomeDir + "/.ssh/authorized_keys"
755 case "sshdConf":
756 fileName = "/etc/ssh/sshd_config"
757 case "sshdConfOptions":
758 _, fileList, err := parseSSHConfigTree(sshPath)
759 if err != nil {
760 return "", err
761 }
762 content, err := json.Marshal(fileList)
763 if err != nil {
764 return "", err
765 }
766 return string(content), nil
767 default:
768 if strings.HasPrefix(name, "sshdConfPath:") {
769 fileName = strings.TrimPrefix(name, "sshdConfPath:")
770 if !isSSHConfigPathAllowed(fileName) {
771 return "", buserr.WithName("ErrNotSupportType", name)
772 }
773 } else {
774 return "", buserr.WithName("ErrNotSupportType", name)
775 }
776 }
777 if _, err := os.Stat(fileName); err != nil {
778 return "", buserr.WithErr("ErrHttpReqNotFound", err)
779 }
780 content, err := os.ReadFile(fileName)
781 if err != nil {
782 return "", err
783 }
784 return string(content), nil
785}
786
787func (u *SSHService) UpdateByFile(req dto.SSHConfUpdate) error {
788 var fileName string

Callers

nothing calls this directly

Calls 3

parseSSHConfigTreeFunction · 0.85
isSSHConfigPathAllowedFunction · 0.85
StatMethod · 0.45

Tested by

no test coverage detected