brynq-sdk-ftp 3.0.1__tar.gz → 3.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {brynq_sdk_ftp-3.0.1 → brynq_sdk_ftp-3.0.3}/PKG-INFO +1 -1
- {brynq_sdk_ftp-3.0.1 → brynq_sdk_ftp-3.0.3}/brynq_sdk_ftp/sftp.py +47 -16
- {brynq_sdk_ftp-3.0.1 → brynq_sdk_ftp-3.0.3}/brynq_sdk_ftp.egg-info/PKG-INFO +1 -1
- {brynq_sdk_ftp-3.0.1 → brynq_sdk_ftp-3.0.3}/setup.py +1 -1
- {brynq_sdk_ftp-3.0.1 → brynq_sdk_ftp-3.0.3}/brynq_sdk_ftp/__init__.py +0 -0
- {brynq_sdk_ftp-3.0.1 → brynq_sdk_ftp-3.0.3}/brynq_sdk_ftp/ftps.py +0 -0
- {brynq_sdk_ftp-3.0.1 → brynq_sdk_ftp-3.0.3}/brynq_sdk_ftp.egg-info/SOURCES.txt +0 -0
- {brynq_sdk_ftp-3.0.1 → brynq_sdk_ftp-3.0.3}/brynq_sdk_ftp.egg-info/dependency_links.txt +0 -0
- {brynq_sdk_ftp-3.0.1 → brynq_sdk_ftp-3.0.3}/brynq_sdk_ftp.egg-info/not-zip-safe +0 -0
- {brynq_sdk_ftp-3.0.1 → brynq_sdk_ftp-3.0.3}/brynq_sdk_ftp.egg-info/requires.txt +0 -0
- {brynq_sdk_ftp-3.0.1 → brynq_sdk_ftp-3.0.3}/brynq_sdk_ftp.egg-info/top_level.txt +0 -0
- {brynq_sdk_ftp-3.0.1 → brynq_sdk_ftp-3.0.3}/setup.cfg +0 -0
|
@@ -3,7 +3,6 @@ from io import StringIO
|
|
|
3
3
|
from paramiko.client import SSHClient, AutoAddPolicy
|
|
4
4
|
from paramiko import RSAKey
|
|
5
5
|
from paramiko.sftp_attr import SFTPAttributes
|
|
6
|
-
import pysftp
|
|
7
6
|
from typing import Union, List, Literal, Optional
|
|
8
7
|
from stat import S_ISREG
|
|
9
8
|
import os
|
|
@@ -17,25 +16,57 @@ class SFTP(BrynQ):
|
|
|
17
16
|
:param debug: If you want to see debug messages
|
|
18
17
|
"""
|
|
19
18
|
super().__init__()
|
|
20
|
-
credentials = self.interfaces.credentials.get(system="sftp", system_type=system_type)
|
|
21
|
-
credentials = credentials.get('data')
|
|
22
19
|
self.debug = debug
|
|
23
|
-
|
|
24
|
-
print(credentials)
|
|
25
|
-
self.host = credentials['host']
|
|
26
|
-
self.port = 22 if credentials['port'] is None else credentials['port']
|
|
27
|
-
self.username = credentials['username']
|
|
28
|
-
self.password = credentials['password']
|
|
29
|
-
self.cnopts = pysftp.CnOpts()
|
|
30
|
-
self.cnopts.hostkeys = None
|
|
31
|
-
self.private_key_path = credentials.get('private_key_password', None)
|
|
32
|
-
self.private_key_passphrase = credentials.get('private_key_password', None)
|
|
33
|
-
self.private_key = credentials.get('private_key', None)
|
|
34
|
-
if self.private_key:
|
|
35
|
-
self.private_key = RSAKey(file_obj=StringIO(credentials.get('private_key')), password=self.private_key_passphrase)
|
|
20
|
+
|
|
36
21
|
self.client = SSHClient()
|
|
37
22
|
self.client.set_missing_host_key_policy(AutoAddPolicy())
|
|
38
23
|
|
|
24
|
+
# Try to fetch credentials from BrynQ; if not present, attributes remain unset
|
|
25
|
+
try:
|
|
26
|
+
credentials = self.interfaces.credentials.get(system="sftp", system_type=system_type)
|
|
27
|
+
credentials = credentials.get('data')
|
|
28
|
+
if credentials:
|
|
29
|
+
if self.debug:
|
|
30
|
+
print(credentials)
|
|
31
|
+
self.host = credentials['host']
|
|
32
|
+
self.port = 22 if credentials.get('port') is None else credentials.get('port')
|
|
33
|
+
self.username = credentials.get('username')
|
|
34
|
+
self.password = credentials.get('password')
|
|
35
|
+
self.private_key_path = credentials.get('private_key_password', None)
|
|
36
|
+
self.private_key_passphrase = credentials.get('private_key_password', None)
|
|
37
|
+
self.private_key = None
|
|
38
|
+
if credentials.get('private_key'):
|
|
39
|
+
self.private_key = RSAKey(file_obj=StringIO(credentials.get('private_key')), password=self.private_key_passphrase)
|
|
40
|
+
except ValueError:
|
|
41
|
+
print("No credentials found for SFTP. If this was intended, use _set_credentials() to set the credentials to pass variables ['host', 'port', 'username', 'password', 'private_key', 'private_key_password']")
|
|
42
|
+
|
|
43
|
+
def _set_credentials(self, credentials: dict):
|
|
44
|
+
"""
|
|
45
|
+
When a child class(ex:Meta4) needs to set the credentials, use this method.
|
|
46
|
+
Set SFTP connection credentials programmatically.
|
|
47
|
+
|
|
48
|
+
Expected keys in credentials dict:
|
|
49
|
+
- host (str)
|
|
50
|
+
- port (int, optional; defaults to 22)
|
|
51
|
+
- username (str)
|
|
52
|
+
- password (str, optional)
|
|
53
|
+
- private_key (str, optional; PEM string)
|
|
54
|
+
- private_key_password (str, optional; passphrase for private_key)
|
|
55
|
+
"""
|
|
56
|
+
# Core connection parameters
|
|
57
|
+
self.host = credentials['host']
|
|
58
|
+
self.port = 22 if credentials.get('port') is None else credentials.get('port')
|
|
59
|
+
self.username = credentials.get('username')
|
|
60
|
+
self.password = credentials.get('password')
|
|
61
|
+
|
|
62
|
+
# Key options
|
|
63
|
+
self.private_key_path = credentials.get('private_key_password')
|
|
64
|
+
self.private_key_passphrase = credentials.get('private_key_password')
|
|
65
|
+
if credentials.get('private_key'):
|
|
66
|
+
self.private_key = RSAKey(file_obj=StringIO(credentials.get('private_key')), password=self.private_key_passphrase)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
39
70
|
def upload_file(self, local_filepath, remote_filepath, confirm=True) -> SFTPAttributes:
|
|
40
71
|
"""
|
|
41
72
|
Upload a single file to a remote location. If there is no Private key
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|