| 160 | } |
| 161 | |
| 162 | func removeSSHHostEntry(configPath, instanceID string) error { |
| 163 | if _, err := os.Stat(configPath); os.IsNotExist(err) { |
| 164 | return nil |
| 165 | } |
| 166 | |
| 167 | data, err := os.ReadFile(configPath) |
| 168 | if err != nil { |
| 169 | return err |
| 170 | } |
| 171 | |
| 172 | hostName := fmt.Sprintf("tnr-%s", instanceID) |
| 173 | result := filterSSHHostBlock(string(data), hostName) |
| 174 | return os.WriteFile(configPath, []byte(result), 0o600) |
| 175 | } |
| 176 | |
| 177 | // filterSSHHostBlock removes a Host block (header + indented body) from SSH config content. |
| 178 | // Returns the filtered content with a trailing newline. |