MCPcopy Create free account
hub / github.com/Thunder-Compute/thunder-cli / cleanupSSHConfig

Function cleanupSSHConfig

cmd/delete.go:140–160  ·  view source on GitHub ↗
(instanceID, ipAddress string)

Source from the content-addressed store, hash-verified

138}
139
140func cleanupSSHConfig(instanceID, ipAddress string) error {
141 homeDir, err := os.UserHomeDir()
142 if err != nil {
143 return fmt.Errorf("failed to get home directory: %w", err)
144 }
145
146 sshConfigPath := filepath.Join(homeDir, ".ssh", "config")
147
148 if err := removeSSHHostEntry(sshConfigPath, instanceID); err != nil {
149 return fmt.Errorf("failed to clean SSH config: %w", err)
150 }
151
152 if ipAddress != "" {
153 cmd := exec.Command("ssh-keygen", "-R", ipAddress)
154 cmd.Stdout = nil
155 cmd.Stderr = nil
156 _ = cmd.Run() //nolint:errcheck // known_hosts cleanup failure is non-fatal
157 }
158
159 return nil
160}
161
162func removeSSHHostEntry(configPath, instanceID string) error {
163 if _, err := os.Stat(configPath); os.IsNotExist(err) {

Callers 5

runDeleteFunction · 0.85
TestCleanupSSHConfigFunction · 0.85

Calls 1

removeSSHHostEntryFunction · 0.85

Tested by 4

TestCleanupSSHConfigFunction · 0.68