Skip to content

Commit fa2b840

Browse files
committed
Object Storage Layer for PR #1037
1 parent 581c493 commit fa2b840

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# This file is Copyright 2022 Volatility Foundation and licensed under the Volatility Software License 1.0
2+
# which is available at https://www.volatilityfoundation.org/license/vsl-v1.0
3+
#
4+
5+
import logging
6+
import urllib.parse
7+
from typing import Optional, Any, List
8+
9+
try:
10+
import s3fs
11+
HAS_S3FS = True
12+
except ImportError:
13+
HAS_S3FS = False
14+
15+
try:
16+
import gcsfs
17+
HAS_GCSFS = True
18+
except ImportError:
19+
HAS_GCSFS = False
20+
21+
from volatility3.framework import exceptions
22+
from volatility3.framework.layers import resources
23+
24+
vollog = logging.getLogger(__file__)
25+
26+
class S3FileSystemHandler(resources.VolatilityHandler):
27+
if HAS_S3FS:
28+
@classmethod
29+
def non_cached_schemes(cls) -> List[str]:
30+
return ["s3"]
31+
32+
@staticmethod
33+
def default_open(req: urllib.request.Request) -> Optional[Any]:
34+
"""Handles the request if it's the s3 scheme."""
35+
if req.type == "s3":
36+
object_uri = "://".join(req.full_url.split("://")[1:])
37+
return s3fs.S3FileSystem().open(object_uri)
38+
else:
39+
raise exceptions.LayerException("s3 requirement is missing.")
40+
41+
42+
class GSFileSystemHandler(resources.VolatilityHandler):
43+
if HAS_GCSFS:
44+
@classmethod
45+
def non_cached_schemes(cls) -> List[str]:
46+
return ["gs"]
47+
48+
@staticmethod
49+
def default_open(req: urllib.request.Request) -> Optional[Any]:
50+
"""Handles the request if it's the gs scheme."""
51+
if req.type == "gs":
52+
object_uri = "://".join(req.full_url.split("://")[1:])
53+
return gcsfs.GCSFileSystem().open(object_uri)
54+
return None
55+
else:
56+
raise exceptions.LayerException("gcsfs requirement is missing.")

0 commit comments

Comments
 (0)