-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #390 from TEAMSchools/dagster-ssh-resource
Dagster ssh resource
- Loading branch information
Showing
24 changed files
with
129 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,21 @@ | ||
from dagster import ConfigurableResource, InitResourceContext | ||
from dagster_ssh import SSHResource | ||
from pydantic import PrivateAttr | ||
from sshtunnel import SSHTunnelForwarder | ||
|
||
|
||
class SSHConfigurableResource(ConfigurableResource): | ||
remote_host: str | ||
remote_port: str = "22" | ||
username: str = None | ||
password: str = None | ||
key_file: str = None | ||
key_string: str = None | ||
timeout: int = 10 | ||
keepalive_interval: int = 30 | ||
compress: bool = True | ||
no_host_key_check: bool = True | ||
allow_host_key_change: bool = False | ||
tunnel_remote_host: str = "localhost" | ||
class SSHResource(SSHResource): | ||
remote_port = 22 | ||
tunnel_remote_host: str = None | ||
|
||
_internal_resource: SSHResource = PrivateAttr() | ||
|
||
def setup_for_execution(self, context: InitResourceContext) -> None: | ||
self._internal_resource = SSHResource( | ||
remote_host=self.remote_host, | ||
remote_port=int(self.remote_port), | ||
username=self.username, | ||
password=self.password, | ||
key_file=self.key_file, | ||
key_string=self.key_string, | ||
timeout=self.timeout, | ||
keepalive_interval=self.keepalive_interval, | ||
compress=self.compress, | ||
no_host_key_check=self.no_host_key_check, | ||
allow_host_key_change=self.allow_host_key_change, | ||
logger=self.get_resource_context().log, | ||
) | ||
|
||
def get_connection(self): | ||
return self._internal_resource.get_connection() | ||
|
||
def get_tunnel(self, remote_port, remote_host=None, local_port=None): | ||
if remote_host is None: | ||
def get_tunnel( | ||
self, remote_port, remote_host=None, local_port=None | ||
) -> SSHTunnelForwarder: | ||
if remote_host is not None: | ||
pass | ||
elif self.tunnel_remote_host is not None: | ||
remote_host = self.tunnel_remote_host | ||
else: | ||
remote_host = "localhost" | ||
|
||
return self._internal_resource.get_tunnel( | ||
return super().get_tunnel( | ||
remote_port=remote_port, remote_host=remote_host, local_port=local_port | ||
) | ||
|
||
def sftp_get(self, remote_filepath, local_filepath): | ||
return self._internal_resource.sftp_get( | ||
remote_filepath=remote_filepath, local_filepath=local_filepath | ||
) | ||
|
||
def sftp_put(self, remote_filepath, local_filepath, confirm=True): | ||
return self._internal_resource.sftp_put( | ||
remote_filepath=remote_filepath, | ||
local_filepath=local_filepath, | ||
confirm=confirm, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.