ashb commented on a change in pull request #3945: [AIRFLOW-3112] Make SFTP hook
to inherit SSH hook
URL: https://github.com/apache/incubator-airflow/pull/3945#discussion_r220304858
##########
File path: airflow/contrib/hooks/sftp_hook.py
##########
@@ -40,42 +43,47 @@ class SFTPHook(BaseHook):
"""
def __init__(self, ftp_conn_id='sftp_default'):
- self.ftp_conn_id = ftp_conn_id
- self.conn = None
+ super(SFTPHook, self).__init__(ftp_conn_id)
+
+ if self.ssh_conn_id is not None:
+ conn = self.get_connection(self.ssh_conn_id)
+ if conn.extra is not None:
+ extra_options = conn.extra_dejson
+ self.private_key_pass = extra_options.get('private_key_pass',
None)
def get_conn(self):
"""
Returns an SFTP connection object
"""
- if self.conn is None:
- params = self.get_connection(self.ftp_conn_id)
+ if self.client is None:
cnopts = pysftp.CnOpts()
- if ('ignore_hostkey_verification' in params.extra_dejson and
- params.extra_dejson['ignore_hostkey_verification']):
+ if self.no_host_key_check:
cnopts.hostkeys = None
+ cnopts.compression = self.compress
conn_params = {
- 'host': params.host,
- 'port': params.port,
- 'username': params.login,
+ 'host': self.remote_host,
+ 'port': self.port,
+ 'username': self.username,
'cnopts': cnopts
}
- if params.password is not None:
- conn_params['password'] = params.password
- if 'private_key' in params.extra_dejson:
- conn_params['private_key'] = params.extra_dejson['private_key']
- if 'private_key_pass' in params.extra_dejson:
- conn_params['private_key_pass'] =
params.extra_dejson['private_key_pass']
- self.conn = pysftp.Connection(**conn_params)
- return self.conn
+ if self.password and self.password.strip():
+ conn_params['password'] = self.password
+ if self.key_file:
+ conn_params['private_key'] = self.key_file
+ if self.private_key_pass:
+ conn_params['private_key_pass'] = self.private_key_pass
+
+ self.client = pysftp.Connection(**conn_params)
+ return self.client
Review comment:
Back compat: this used be accessible as `sftp_hook.conn` (and it wasn't
prefixed with `_` so isn't "private")
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services