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

Function parseSSHConfigFile

agent/app/service/ssh.go:861–925  ·  view source on GitHub ↗
(
	fileName string,
	inMatch bool,
	visited map[string]bool,
	directives *[]sshDirective,
	fileList *[]sshConfigFile,
	order *int,
	priority *int,
)

Source from the content-addressed store, hash-verified

859}
860
861func parseSSHConfigFile(
862 fileName string,
863 inMatch bool,
864 visited map[string]bool,
865 directives *[]sshDirective,
866 fileList *[]sshConfigFile,
867 order *int,
868 priority *int,
869) error {
870 absolutePath, err := filepath.Abs(fileName)
871 if err != nil {
872 return err
873 }
874 if visited[absolutePath] {
875 return nil
876 }
877 visited[absolutePath] = true
878
879 content, err := os.ReadFile(absolutePath)
880 if err != nil {
881 return err
882 }
883
884 lines := strings.Split(string(content), "\n")
885 currentMatch := inMatch
886 fileRegistered := false
887 for index, rawLine := range lines {
888 line := strings.TrimSpace(rawLine)
889 if line == "" || strings.HasPrefix(line, "#") {
890 continue
891 }
892 key, value, ok := parseSSHConfigLine(line)
893 if !ok {
894 continue
895 }
896 if strings.EqualFold(key, "Match") {
897 currentMatch = true
898 continue
899 }
900 if strings.EqualFold(key, "Include") {
901 for _, includePath := range expandSSHIncludePaths(absolutePath, value) {
902 if err := parseSSHConfigFile(includePath, currentMatch, visited, directives, fileList, order, priority); err != nil {
903 global.LOG.Warnf("parse ssh include %s failed, err: %v", includePath, err)
904 }
905 }
906 continue
907 }
908 if !fileRegistered {
909 registerSSHConfigFile(absolutePath, fileList, priority)
910 fileRegistered = true
911 }
912 *order++
913 *directives = append(*directives, sshDirective{
914 Key: key,
915 Value: normalizeSSHDirectiveValue(key, value),
916 File: absolutePath,
917 Line: index,
918 InMatch: currentMatch,

Callers 1

parseSSHConfigTreeFunction · 0.85

Calls 4

parseSSHConfigLineFunction · 0.85
expandSSHIncludePathsFunction · 0.85
registerSSHConfigFileFunction · 0.85

Tested by

no test coverage detected