MCPcopy Index your code
hub / github.com/coder/coder / mergeSSHOptions

Function mergeSSHOptions

cli/configssh.go:576–635  ·  view source on GitHub ↗
(
	user sshConfigOptions, coderd codersdk.SSHConfigResponse, globalConfigPath, coderBinaryPath string,
)

Source from the content-addressed store, hash-verified

574}
575
576func mergeSSHOptions(
577 user sshConfigOptions, coderd codersdk.SSHConfigResponse, globalConfigPath, coderBinaryPath string,
578) (
579 sshConfigOptions, error,
580) {
581 if err := coderd.Validate(); err != nil {
582 return sshConfigOptions{}, xerrors.Errorf("invalid ssh config from coderd: %w", err)
583 }
584
585 // Write agent configuration.
586 defaultOptions := []string{
587 "ConnectTimeout=0",
588 "StrictHostKeyChecking=no",
589 // Without this, the "REMOTE HOST IDENTITY CHANGED"
590 // message will appear.
591 "UserKnownHostsFile=/dev/null",
592 // This disables the "Warning: Permanently added 'hostname' (RSA) to the list of known hosts."
593 // message from appearing on every SSH. This happens because we ignore the known hosts.
594 "LogLevel ERROR",
595 }
596
597 // Create a copy of the options so we can modify them.
598 configOptions := user
599 configOptions.sshOptions = nil
600
601 configOptions.globalConfigPath = globalConfigPath
602 configOptions.coderBinaryPath = coderBinaryPath
603 // user config takes precedence
604 if user.userHostPrefix == "" {
605 configOptions.userHostPrefix = coderd.HostnamePrefix
606 }
607 if user.hostnameSuffix == "" {
608 configOptions.hostnameSuffix = coderd.HostnameSuffix
609 }
610
611 // User options first (SSH only uses the first
612 // option unless it can be given multiple times)
613 for _, opt := range user.sshOptions {
614 err := configOptions.addOptions(opt)
615 if err != nil {
616 return sshConfigOptions{}, xerrors.Errorf("add flag config option %q: %w", opt, err)
617 }
618 }
619
620 // Deployment options second, allow them to
621 // override standard options.
622 for k, v := range coderd.SSHConfigOptions {
623 opt := fmt.Sprintf("%s %s", k, v)
624 err := configOptions.addOptions(opt)
625 if err != nil {
626 return sshConfigOptions{}, xerrors.Errorf("add coderd config option %q: %w", opt, err)
627 }
628 }
629
630 // Finally, add the standard options.
631 if err := configOptions.addOptions(defaultOptions...); err != nil {
632 return sshConfigOptions{}, err
633 }

Calls 3

addOptionsMethod · 0.80
ValidateMethod · 0.65
ErrorfMethod · 0.45