Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion data/recipes/gce_disk_export.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"remote_instance_name": "@remote_instance_name",
"all_disks": "@all_disks",
"exported_image_name": "@exported_image_name",
"image_format": "@image_format"
"image_format": "@image_format",
"cloudbuild_zone": "us-central1-a"
}
}
],
Expand Down
9 changes: 7 additions & 2 deletions dftimewolf/lib/exporters/gce_disk_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self,
self._gcs_output_location: str = ''
self._image_format: str = ''
self._exported_image_name: str = ''
self._cloudbuild_zone: str = ''

# pylint: disable=arguments-differ
def SetUp(self,
Expand All @@ -56,7 +57,8 @@ def SetUp(self,
remote_instance_name: str,
all_disks: bool,
exported_image_name: str,
image_format: str) -> None:
image_format: str,
cloudbuild_zone: str) -> None:
"""Sets up a Google Cloud Platform (GCP) Disk Export.

This method creates the required objects to initialize
Expand Down Expand Up @@ -97,10 +99,12 @@ def SetUp(self,
is selected, exported image name as
"exported-image-{TIMESTAMP('%Y%m%d%H%M%S')}".
image_format: The image format to use.
cloudbuild_zone: The zone in which to launch the cloudbuild job.
"""
self._image_format = image_format
self._gcs_output_location = gcs_output_location
self._exported_image_name = exported_image_name
self._cloudbuild_zone = cloudbuild_zone or 'us-central1-a'

self._source_project = gcp_project.GoogleCloudProject(source_project_name)
if analysis_project_name:
Expand Down Expand Up @@ -138,7 +142,8 @@ def Process(self) -> None:
# {src_disk.name}-{TIMESTAMP('%Y%m%d%H%M%S')}.tar.gz
output_url = image_object.ExportImage(self._gcs_output_location,
output_name=self._exported_image_name,
image_format=self._image_format)
image_format=self._image_format,
zone=self._cloudbuild_zone)
image_object.Delete()
self.logger.info(f'Disk was exported to: {output_url}')
container = containers.GCSObject(path=output_url)
Expand Down
16 changes: 8 additions & 8 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ filelock = "^3.30.2"
google-cloud-bigquery = "^3.42.2"
google-cloud-logging = "^3.14.0"
google-generativeai = "^0.8.6"
libcloudforensics = "^20260505"
libcloudforensics = "20260916"
openrelik-api-client = "^0.5.0"
pandas = "^3.0.3"
ratelimit = "^2.2.1"
Expand Down
12 changes: 8 additions & 4 deletions tests/lib/exporters/gce_disk_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def testProcessDiskParams(self,
remote_instance_name='',
all_disks=False,
exported_image_name='image-df-export-temp',
image_format='qcow2')
image_format='qcow2',
cloudbuild_zone='zone1')
FAKE_SOURCE_PROJECT.compute.CreateImageFromDisk = mock_create_image_from_disk
mock_create_image_from_disk.return_value = FAKE_IMAGE
FAKE_IMAGE.ExportImage = mock_export_image
Expand All @@ -72,7 +73,8 @@ def testProcessDiskParams(self,
mock_export_image.assert_called_with(
'gs://fake-bucket',
output_name='image-df-export-temp',
image_format='qcow2')
image_format='qcow2',
zone='zone1')
mock_delete_image.assert_called_once()
output_url = os.path.join(
'gs://fake-bucket', 'image-df-export-temp.tar.gz')
Expand Down Expand Up @@ -107,7 +109,8 @@ def testProcessDiskFromState(self,
remote_instance_name='',
all_disks=False,
exported_image_name='image-df-export-temp',
image_format='qcow2')
image_format='qcow2',
cloudbuild_zone='zone1')

container = containers.GCEDisk(name='fake-source-disk', project='fake-source-project')
container.metadata['SOURCE_MACHINE'] = 'fake-source-machine'
Expand All @@ -124,7 +127,8 @@ def testProcessDiskFromState(self,
mock_export_image.assert_called_with(
'gs://fake-bucket',
output_name='image-df-export-temp',
image_format='qcow2')
image_format='qcow2',
zone='zone1')
mock_delete_image.assert_called_once()
output_url = os.path.join(
'gs://fake-bucket', 'image-df-export-temp.tar.gz')
Expand Down
Loading