MCPcopy
hub / github.com/docker/docker-py / _create_paramiko_client

Method _create_paramiko_client

docker/transport/sshconn.py:185–214  ·  view source on GitHub ↗
(self, base_url)

Source from the content-addressed store, hash-verified

183 super().__init__()
184
185 def _create_paramiko_client(self, base_url):
186 logging.getLogger("paramiko").setLevel(logging.WARNING)
187 self.ssh_client = paramiko.SSHClient()
188 base_url = urllib.parse.urlparse(base_url)
189 self.ssh_params = {
190 "hostname": base_url.hostname,
191 "port": base_url.port,
192 "username": base_url.username
193 }
194 ssh_config_file = os.path.expanduser("~/.ssh/config")
195 if os.path.exists(ssh_config_file):
196 conf = paramiko.SSHConfig()
197 with open(ssh_config_file) as f:
198 conf.parse(f)
199 host_config = conf.lookup(base_url.hostname)
200 if 'proxycommand' in host_config:
201 self.ssh_params["sock"] = paramiko.ProxyCommand(
202 host_config['proxycommand']
203 )
204 if 'hostname' in host_config:
205 self.ssh_params['hostname'] = host_config['hostname']
206 if base_url.port is None and 'port' in host_config:
207 self.ssh_params['port'] = host_config['port']
208 if base_url.username is None and 'user' in host_config:
209 self.ssh_params['username'] = host_config['user']
210 if 'identityfile' in host_config:
211 self.ssh_params['key_filename'] = host_config['identityfile']
212
213 self.ssh_client.load_system_host_keys()
214 self.ssh_client.set_missing_host_key_policy(paramiko.RejectPolicy())
215
216 def _connect(self):
217 if self.ssh_client:

Callers 1

__init__Method · 0.95

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected