-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileservice.py
110 lines (86 loc) · 3.39 KB
/
fileservice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""
Core module for External File Service Interface.
This module defines the base External File Service Interface used by data/file
providers such as Amazon S3, Microsoft Azure, Google Drive, etc. access modules.
Created: 08/11/2016
Creator: Nathan Palmer
"""
from abc import ABCMeta, abstractmethod
class fileServiceInterface(metaclass=ABCMeta):
"""External File Service Interface.
Initializers for derived classes are required to accept the following arguments:
config_fields (dict): Configuration dictionary loaded from file.
logging (log): Standard python logging interface
"""
@staticmethod
@abstractmethod
def get_service_type():
"""Return a string id for the file service type handled."""
raise NotImplementedError
@abstractmethod
def convert_file(self, item):
"""
Convert from service specfic file format to cazobject file format.
Args:
item (object): Service specific representation of a file.
Returns:
cazobject.CazFile
"""
raise NotImplementedError
def convert_files(self, items):
"""
Convert a list of service specfic file entries to cazobject entries.
Args:
items (object[]): Service specific representation of a list of files.
Returns:
List of cazobject.CazFile entries
"""
results = []
for i in items:
results.append(self.convert_file(i))
return results
@abstractmethod
def scan_files(self, temp_dir, expressions):
"""
Scan all files for any content matches.
Args:
temp_dir (str): Path to the temporary directory to hold files for comparison
expressions (CazRegExp[]): List of regular expressions for content comparison
"""
raise NotImplementedError
@abstractmethod
def find_file(self, name=None, md5=None, sha1=None):
"""
Search for a file by name or hash.
If a mixture of input parameters are included then the search
will walk through in the following manner:
1. If name is defined then look by name
2. If not found and md5 is defined then look by md5
3. If not found and sha1 is defined then look by sha1
4. If not found raise.
Args:
name (string): Filename to find.
md5 (string): MD5 hash of the file to find.
sha1 (string): SHA1 hash of the file to find.
Returns:
List of CazFile objects matching the request parameters.
"""
raise NotImplementedError
@abstractmethod
def get_file(self, name=None, md5=None, sha1=None):
"""
Search for a file by name or hash and download a copy.
If a mixture of input parameters are included then the search
will walk through in the following manner:
1. If name is defined then look by name
2. If not found and md5 is defined then look by md5
3. If not found and sha1 is defined then look by sha1
4. If not found raise.
Args:
name (string): Filename to find.
md5 (string): MD5 hash of the file to find.
sha1 (string): SHA1 hash of the file to find.
Returns:
List of files matching the request parameters.
"""
raise NotImplementedError