brynq-sdk-ftp 3.0.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: brynq_sdk_ftp
3
- Version: 3.0.2
3
+ Version: 3.0.3
4
4
  Summary: FTP wrapper from BrynQ
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -16,23 +16,57 @@ class SFTP(BrynQ):
16
16
  :param debug: If you want to see debug messages
17
17
  """
18
18
  super().__init__()
19
- credentials = self.interfaces.credentials.get(system="sftp", system_type=system_type)
20
- credentials = credentials.get('data')
21
19
  self.debug = debug
22
- if self.debug:
23
- print(credentials)
24
- self.host = credentials['host']
25
- self.port = 22 if credentials['port'] is None else credentials['port']
26
- self.username = credentials['username']
27
- self.password = credentials['password']
28
- self.private_key_path = credentials.get('private_key_password', None)
29
- self.private_key_passphrase = credentials.get('private_key_password', None)
30
- self.private_key = credentials.get('private_key', None)
31
- if self.private_key:
32
- self.private_key = RSAKey(file_obj=StringIO(credentials.get('private_key')), password=self.private_key_passphrase)
20
+
33
21
  self.client = SSHClient()
34
22
  self.client.set_missing_host_key_policy(AutoAddPolicy())
35
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
+
36
70
  def upload_file(self, local_filepath, remote_filepath, confirm=True) -> SFTPAttributes:
37
71
  """
38
72
  Upload a single file to a remote location. If there is no Private key
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: brynq-sdk-ftp
3
- Version: 3.0.2
3
+ Version: 3.0.3
4
4
  Summary: FTP wrapper from BrynQ
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -2,7 +2,7 @@ from setuptools import setup, find_namespace_packages
2
2
 
3
3
  setup(
4
4
  name='brynq_sdk_ftp',
5
- version='3.0.2',
5
+ version='3.0.3',
6
6
  description='FTP wrapper from BrynQ',
7
7
  long_description='FTP wrapper from Brynq',
8
8
  author='BrynQ',
File without changes