NewShell initializes a new shell to the given address.
(user, address string, opts ...ShellOption)
| 109 | |
| 110 | // NewShell initializes a new shell to the given address. |
| 111 | func NewShell(user, address string, opts ...ShellOption) (*Shell, error) { |
| 112 | address = formatAddress(address) |
| 113 | |
| 114 | // Use known_host as HostKeyCallback |
| 115 | knownHosts, err := knownhosts.New(filepath.Join(step.Home(), ".ssh", "known_hosts")) |
| 116 | if err != nil { |
| 117 | return nil, errors.Wrap(err, "error reading known_hosts") |
| 118 | } |
| 119 | |
| 120 | shell := &Shell{ |
| 121 | user: user, |
| 122 | address: address, |
| 123 | } |
| 124 | if err := shell.apply(opts); err != nil { |
| 125 | return nil, err |
| 126 | } |
| 127 | |
| 128 | if len(shell.authMethods) == 0 { |
| 129 | if err := withDefaultAuthMethod()(shell); err != nil { |
| 130 | return nil, err |
| 131 | } |
| 132 | } |
| 133 | if shell.dialer == nil { |
| 134 | if err := withDefaultDialer(user, address)(shell); err != nil { |
| 135 | return nil, err |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | if shell.client, err = shell.dialer(knownHosts); err != nil { |
| 140 | return nil, err |
| 141 | } |
| 142 | |
| 143 | return shell, nil |
| 144 | } |
| 145 | |
| 146 | func (s *Shell) apply(opts []ShellOption) error { |
| 147 | for _, fn := range opts { |
nothing calls this directly
no test coverage detected
searching dependent graphs…