MCPcopy Index your code
hub / github.com/devspace-sh/devspace / startSSH

Function startSSH

pkg/devspace/services/ssh/ssh.go:56–145  ·  view source on GitHub ↗
(ctx devspacecontext.Context, name, arch string, sshConfig *latest.SSH, selector targetselector.TargetSelector, parent *tomb.Tomb)

Source from the content-addressed store, hash-verified

54}
55
56func startSSH(ctx devspacecontext.Context, name, arch string, sshConfig *latest.SSH, selector targetselector.TargetSelector, parent *tomb.Tomb) error {
57 if ctx.IsDone() {
58 return nil
59 }
60
61 // configure ssh host
62 sshHost := name + "." + ctx.Config().Config().Name + ".devspace"
63 if sshConfig.LocalHostname != "" {
64 sshHost = sshConfig.LocalHostname
65 }
66
67 // try to find host port
68 homeDir, err := homedir.Dir()
69 if err != nil {
70 return errors.Wrap(err, "get home dir")
71 }
72
73 // get port
74 port := sshConfig.LocalPort
75 if port == 0 {
76 sshDevSpaceConfigPath := filepath.Join(homeDir, ".ssh", "config")
77 if sshConfig.UseInclude {
78 sshDevSpaceConfigPath = filepath.Join(homeDir, ".ssh", "devspace_config")
79 }
80 hosts, err := ParseDevSpaceHosts(sshDevSpaceConfigPath)
81 if err != nil {
82 ctx.Log().Debugf("error parsing %s: %v", sshDevSpaceConfigPath, err)
83 } else {
84 for _, h := range hosts {
85 if h.Host == sshHost {
86 port = h.Port
87 }
88 }
89 }
90
91 if port == 0 {
92 port, err = GetInstance(ctx.Log()).LockPort()
93 if err != nil {
94 return errors.Wrap(err, "find port")
95 }
96
97 // update ssh config
98 err = configureSSHConfig(sshHost, strconv.Itoa(port), sshConfig.UseInclude, ctx.Log())
99 if err != nil {
100 return errors.Wrap(err, "update ssh config")
101 }
102 }
103 } else {
104 err = GetInstance(ctx.Log()).LockSpecificPort(port)
105 if err != nil {
106 return errors.Wrap(err, "find port")
107 }
108
109 // update ssh config
110 err = configureSSHConfig(sshHost, strconv.Itoa(port), sshConfig.UseInclude, ctx.Log())
111 if err != nil {
112 return errors.Wrap(err, "update ssh config")
113 }

Callers 1

StartSSHFunction · 0.85

Calls 13

StartForwardingFunction · 0.92
ParseDevSpaceHostsFunction · 0.85
configureSSHConfigFunction · 0.85
startSSHWithRestartFunction · 0.85
GetInstanceFunction · 0.70
IsDoneMethod · 0.65
ConfigMethod · 0.65
LogMethod · 0.65
LockPortMethod · 0.65
LockSpecificPortMethod · 0.65
ReleasePortMethod · 0.65
DebugfMethod · 0.45

Tested by

no test coverage detected