Skip to content

P2.5: Integrate Google Cloud Storage (GCS) for Artifacts #31

@Virgo-Alpha

Description

@Virgo-Alpha

To handle file uploads in a scalable and secure way, this ticket involves integrating Google Cloud Storage (GCS). All documents uploaded by users (like pitch decks and financials) and large reports generated by the system will be stored in a GCS bucket instead of on the application server's file system.

Implementation Tips

  • Create a GCS Bucket: In your Google Cloud project, create a new GCS bucket to store all project artifacts. Configure its region and storage class.
  • IAM Permissions: Your application's Service Account needs permission to interact with this bucket. In the IAM console, grant the service account the Storage Object Admin role. This will allow it to read, write, and delete files in your GCS buckets.
  • Django Storage Library: Use a library like django-storages to make working with GCS simple. You can configure it so that when you handle a file in Django, the library automatically handles the upload to your GCS bucket in the background.
  • Update Celery Task: Modify the Celery task that handles file uploads (from ticket F2.1). After receiving an uploaded file, the task will use the storage backend to upload the file to GCS. It should then save the GCS path/URL of the file to a field in your Django models, not the file itself.

Acceptance Criteria (Checklist)

  • A new GCS bucket for the Frisque project is created.
  • The application's service account has the correct IAM permissions to access the bucket.
  • The django-storages library (or similar) is installed and configured.
  • When a user uploads a file, it is successfully uploaded to the GCS bucket.
  • The path to the file in GCS is saved in the database (e.g., on the ScanJob model).

Unit Tests

  • Mocking GCS: In your tests, you do not want to make real network calls to GCS. Use the @patch decorator to mock the storage backend's save method.
  • Test the Upload Logic: Write a test for your file-handling Celery task. In the test, assert that the mock storage backend's .save() method was called with the correct filename and content. This proves your upload logic works without needing a real GCS connection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions