Skip to content

Commit e5b333c

Browse files
authored
Catch OS errors when loading private key and certificate files. (e.g.… (#128)
* Catch OS errors when loading private key and certificate files. (e.g. Path too long) * Add is_enabled method to edge/snmp module
1 parent 3ac1937 commit e5b333c

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

cterasdk/edge/snmp.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
class SNMP(BaseCommand):
1010
""" Edge Filer SNMP Configuration APIs """
1111

12+
def is_enabled(self):
13+
"""
14+
Check if SNMP is enabled
15+
16+
:return: True is SNMP is enabled, else False
17+
:rtype: bool
18+
"""
19+
return self._gateway.get('/config/snmp/mode') == enum.Mode.Enabled
20+
1221
def enable(self, port=161, community_str=None, username=None, password=None):
1322
"""
1423
Enable SNMP

cterasdk/lib/crypto.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def load_private_key(key, password=None):
100100
try:
101101
FileSystem.instance().get_local_file_info(key)
102102
return PrivateKey.from_file(key, password)
103-
except LocalFileNotFound:
103+
except (OSError, LocalFileNotFound):
104104
return PrivateKey.from_string(key, password)
105105

106106

@@ -156,7 +156,7 @@ def load_certificate(cert):
156156
try:
157157
FileSystem.instance().get_local_file_info(cert)
158158
return X509Certificate.from_file(cert)
159-
except LocalFileNotFound:
159+
except (OSError, LocalFileNotFound):
160160
return X509Certificate.from_string(cert)
161161

162162
def __str__(self):

docs/source/user_guides/Gateway/Gateway.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,13 @@ Power Management
11221122
SNMP
11231123
====
11241124

1125+
.. automethod:: cterasdk.edge.snmp.SNMP.is_enabled
1126+
:noindex:
1127+
1128+
.. code-block:: python
1129+
1130+
filer.snmp.is_enabled()
1131+
11251132
.. automethod:: cterasdk.edge.snmp.SNMP.enable
11261133
:noindex:
11271134

0 commit comments

Comments
 (0)