Skip to content

Commit 51e684c

Browse files
authored
Ronerez/sdk 219 ransomware protect (#215)
1 parent 7ccaef1 commit 51e684c

File tree

8 files changed

+105
-8
lines changed

8 files changed

+105
-8
lines changed

cterasdk/edge/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
'query',
2727
'remote',
2828
'rsync',
29+
'ransom_protect',
2930
'services',
3031
'session',
3132
'shares',

cterasdk/edge/query.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
from ..lib import Iterator, Command
12
from ..common import Object
23
from ..convert import tojsonstr
34

45

56
def query(CTERAHost, path, key, value):
7+
"""Query based on key and value"""
68
param = Object()
79
param.key = key
810
param.value = value
@@ -13,6 +15,17 @@ def show(CTERAHost, path, key, value):
1315
print(tojsonstr(query(CTERAHost, path, key, value), no_log=False))
1416

1517

18+
def query_page(CTERAHost, path, name, param):
19+
"""Query a page"""
20+
response = CTERAHost.execute(path, name, param)
21+
return response.hasMore, response.objects
22+
23+
24+
def iterator(CTERAHost, path, param, name=None):
25+
function = Command(query_page, CTERAHost, path, name)
26+
return Iterator(function, param)
27+
28+
1629
class QueryParam(Object):
1730

1831
def __init__(self):

cterasdk/edge/ransom_protect.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import logging
2+
from .base_command import BaseCommand
3+
from . import query
4+
from ..exception import CTERAException
5+
6+
7+
class RansomProtect(BaseCommand):
8+
"""
9+
Ransomware Protect APIs
10+
"""
11+
12+
def get_configuration(self):
13+
"""
14+
Get Ransom Protect Configuration
15+
16+
:return cterasdk.common.object.Object: Configuration
17+
"""
18+
return self._gateway.get('/config/ransomProtect/')
19+
20+
def enable(self):
21+
"""Enable Ransom Protect service"""
22+
logging.getLogger().info('Enabling Ransom Protect.')
23+
self._gateway.put('/config/ransomProtect/enabled', True)
24+
logging.getLogger().info('Ransom Protect enabled.')
25+
26+
def disable(self):
27+
"""Enable Ransom Protect service"""
28+
logging.getLogger().info('Disabling Ransom Protect.')
29+
self._gateway.put('/config/ransomProtect/enabled', False)
30+
logging.getLogger().info('Ransom Protect disabled.')
31+
32+
def is_disabled(self):
33+
"""Check if Ransom Protect is disabled"""
34+
return self._gateway.get('/config/ransomProtect/enabled') is not True
35+
36+
def modify(self, block_users=None, detection_threshold=None, detection_interval=None):
37+
"""
38+
Modify Ransom Protect Configuration.
39+
40+
:param bool,optional block_users: Enable/Disable Block Users
41+
:param int,optional detection_threshold: Detection threshold (number of events)
42+
:param int,optional detection_interval: Detection interval (seconds)
43+
"""
44+
param = self.get_configuration()
45+
if not param.enabled:
46+
raise CTERAException('Ransom Protect must be enabled to modify its configuration')
47+
if block_users is not None:
48+
param.shouldBlockUser = block_users
49+
if detection_threshold is not None:
50+
param.minimalNumOfFilesForPositiveDetection = detection_threshold
51+
if detection_interval is not None:
52+
param.detectionInterval = detection_interval
53+
self._gateway.put('/config/ransomProtect/', param)
54+
55+
def incidents(self):
56+
"""
57+
List Ransomware Incidents
58+
59+
:return list[cterasdk.common.object.Object]: List of incidents
60+
"""
61+
return self._gateway.execute('/proc/rpsrv', 'getListOfIncidents')
62+
63+
def details(self, incident):
64+
"""
65+
Retrieve Ransomware Incident Details
66+
67+
:param int incident: Incident identifier, or an incident object
68+
"""
69+
param = query.QueryParamBuilder()
70+
param.put('incidentId', incident if isinstance(incident, int) else incident.incident_id)
71+
return query.iterator(self._gateway, '/proc/rpsrv', param.build(), 'getIncidentDetails')

cterasdk/object/Gateway.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from ..edge import query
2929
from ..edge import remote
3030
from ..edge import rsync
31+
from ..edge import ransom_protect
3132
from ..edge import services
3233
from ..edge import session
3334
from ..edge import shares
@@ -74,6 +75,7 @@ class Gateway(CTERAHost): # pylint: disable=too-many-instance-attributes
7475
:ivar cterasdk.edge.nfs.NFS nfs: Object holding the Gateway NFS APIs
7576
:ivar cterasdk.edge.ntp.NTP ntp: Object holding the Gateway NTP APIs
7677
:ivar cterasdk.edge.power.Power power: Object holding the Gateway Power APIs
78+
:ivar cterasdk.edge.ransom_protect.RansomProtect ransom_protect: Object holding the Edge Filer's Ransom Protect APIs
7779
:ivar cterasdk.edge.rsync.RSync rsync: Object holding the Gateway RSync APIs
7880
:ivar cterasdk.edge.services.Services services: Object holding the Gateway Services APIs
7981
:ivar cterasdk.edge.shares.Shares shares: Object holding the Gateway Shares APIs
@@ -128,6 +130,7 @@ def __init__(self, host=None, port=None, https=False, Portal=None, *, url=None):
128130
self.nfs = nfs.NFS(self)
129131
self.ntp = ntp.NTP(self)
130132
self.power = power.Power(self)
133+
self.ransom_protect = ransom_protect.RansomProtect(self)
131134
self.rsync = rsync.RSync(self)
132135
self.services = services.Services(self)
133136
self.shares = shares.Shares(self)
@@ -187,6 +190,7 @@ def _omit_fields(self):
187190
'nfs',
188191
'ntp',
189192
'power',
193+
'ransom_protect',
190194
'rsync',
191195
'services',
192196
'shares',
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cterasdk.edge.ctera_migrate module
2+
==================================
3+
4+
.. automodule:: cterasdk.edge.ctera_migrate
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
cterasdk.edge.migration_tool module
1+
cterasdk.edge.ransom_protect module
22
===================================
33

4-
.. automodule:: cterasdk.edge.migration_tool
4+
.. automodule:: cterasdk.edge.ransom_protect
55
:members:
66
:undoc-members:
77
:show-inheritance:

docs/source/api/cterasdk.edge.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,35 @@ Submodules
2828
cterasdk.edge.cli
2929
cterasdk.edge.config
3030
cterasdk.edge.connection
31+
cterasdk.edge.ctera_migrate
3132
cterasdk.edge.decorator
3233
cterasdk.edge.dedup
3334
cterasdk.edge.directoryservice
3435
cterasdk.edge.drive
3536
cterasdk.edge.enum
36-
cterasdk.edge.ftp
3737
cterasdk.edge.firmware
38+
cterasdk.edge.ftp
3839
cterasdk.edge.groups
3940
cterasdk.edge.licenses
4041
cterasdk.edge.login
4142
cterasdk.edge.logs
4243
cterasdk.edge.mail
43-
cterasdk.edge.migration_tool
4444
cterasdk.edge.network
4545
cterasdk.edge.nfs
4646
cterasdk.edge.ntp
47-
cterasdk.edge.snmp
48-
cterasdk.edge.ssh
49-
cterasdk.edge.ssl
5047
cterasdk.edge.power
5148
cterasdk.edge.query
49+
cterasdk.edge.ransom_protect
5250
cterasdk.edge.remote
5351
cterasdk.edge.rsync
5452
cterasdk.edge.services
5553
cterasdk.edge.session
5654
cterasdk.edge.shares
5755
cterasdk.edge.shell
5856
cterasdk.edge.smb
57+
cterasdk.edge.snmp
58+
cterasdk.edge.ssh
59+
cterasdk.edge.ssl
5960
cterasdk.edge.support
6061
cterasdk.edge.sync
6162
cterasdk.edge.syslog

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ allowlist_externals=
3636
commands=
3737
mkdir -p reports
3838
nose2 --config=tests/ut/nose2.cfg --verbose --project-directory . {posargs}
39-
coverage html --fail-under=41 -d reports/coverage
39+
coverage html --fail-under=70 -d reports/coverage
4040

4141
[testenv:coveralls]
4242
passenv = TRAVIS TRAVIS_*

0 commit comments

Comments
 (0)