Skip to content

Commit

Permalink
Catch OS errors when loading private key and certificate files. (e.g.… (
Browse files Browse the repository at this point in the history
#128)

* Catch OS errors when loading private key and certificate files. (e.g. Path too long)
* Add is_enabled method to edge/snmp module
  • Loading branch information
saimonation committed Jul 6, 2021
1 parent 3ac1937 commit e5b333c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
9 changes: 9 additions & 0 deletions cterasdk/edge/snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
class SNMP(BaseCommand):
""" Edge Filer SNMP Configuration APIs """

def is_enabled(self):
"""
Check if SNMP is enabled
:return: True is SNMP is enabled, else False
:rtype: bool
"""
return self._gateway.get('/config/snmp/mode') == enum.Mode.Enabled

def enable(self, port=161, community_str=None, username=None, password=None):
"""
Enable SNMP
Expand Down
4 changes: 2 additions & 2 deletions cterasdk/lib/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def load_private_key(key, password=None):
try:
FileSystem.instance().get_local_file_info(key)
return PrivateKey.from_file(key, password)
except LocalFileNotFound:
except (OSError, LocalFileNotFound):
return PrivateKey.from_string(key, password)


Expand Down Expand Up @@ -156,7 +156,7 @@ def load_certificate(cert):
try:
FileSystem.instance().get_local_file_info(cert)
return X509Certificate.from_file(cert)
except LocalFileNotFound:
except (OSError, LocalFileNotFound):
return X509Certificate.from_string(cert)

def __str__(self):
Expand Down
7 changes: 7 additions & 0 deletions docs/source/user_guides/Gateway/Gateway.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,13 @@ Power Management
SNMP
====

.. automethod:: cterasdk.edge.snmp.SNMP.is_enabled
:noindex:

.. code-block:: python
filer.snmp.is_enabled()
.. automethod:: cterasdk.edge.snmp.SNMP.enable
:noindex:

Expand Down

0 comments on commit e5b333c

Please sign in to comment.