Repository navigation
Conversation
Add new serverpod_cloud_storage_s3_compat package with endpoint configuration abstractions for S3-compatible storage providers. This introduces: - S3EndpointConfig abstract interface for URL building - AwsEndpointConfig for AWS S3 (virtual-hosted style) - GcpEndpointConfig for GCP S3-compatible API (path-style) - CustomEndpointConfig for MinIO and other providers Part of #4623
Add upload strategy pattern to support different upload mechanisms: - S3UploadStrategy abstract interface - MultipartPostUploadStrategy for POST with presigned policy - Policy class for generating presigned POST policies This enables supporting providers with different upload methods (POST vs PUT) through the same CloudStorage interface. Part of #4623
Add parameterized S3 client that uses endpoint configuration: - S3Client for GET, HEAD, DELETE operations with SigV4 signing - S3Exception and NoPermissionsException for error handling - Support for non-standard ports (MinIO, LocalStack) Part of #4623
Add base CloudStorage implementation that uses the S3 abstractions: - S3CompatCloudStorage implements all CloudStorage methods - Uses S3EndpointConfig for URL building - Uses S3UploadStrategy for file uploads - Uses S3Client for API requests This enables building provider-specific implementations as thin configuration wrappers around the base class. Part of #4623
…ackage S3CloudStorage now extends S3CompatCloudStorage from the new serverpod_cloud_storage_s3_compat package. This eliminates the duplicated AWS S3 client and upload code. - Remove aws_s3_client directory (moved to s3_compat) - Remove aws_s3_upload directory (moved to s3_compat) - S3CloudStorage is now a thin wrapper that configures credentials and endpoints for AWS S3 - Maintains backwards compatibility with existing API
…package GoogleCloudStorage now extends S3CompatCloudStorage from the new serverpod_cloud_storage_s3_compat package. This eliminates the duplicated S3-compatible client and upload code. - Remove aws_s3_client directory (moved to s3_compat) - Remove aws_s3_upload directory (moved to s3_compat) - GoogleCloudStorage is now a thin wrapper that configures HMAC credentials and GCP endpoints - Maintains backwards compatibility with existing API
Adds a new cloud storage implementation that uses Google Cloud's native JSON API instead of the S3-compatible layer. This provides: - Native GCP authentication using service account credentials - Full access to GCP-specific features via googleapis package - Service account JSON loaded from Serverpod's password system The package now exports both implementations: - GoogleCloudStorage: S3-compatible API with HMAC credentials (existing) - NativeGoogleCloudStorage: Native GCP API with service account (new) Note: Direct upload (createDirectFileUploadDescription) is not yet implemented for the native implementation. Users who need direct upload should continue using GoogleCloudStorage.
Replace setUpAll with setUp to follow the project's testing conventions.
Add comprehensive unit tests for the native GCP cloud storage implementation using mocktail to mock the StorageApi. Tests cover: - File existence checking (exists, not found, error handling) - File storage (public and private ACLs) - File retrieval (success and not found) - Public URL generation (default and custom hosts) - File deletion (success, already deleted, error handling) - Direct upload (returns null - not yet implemented) - Upload verification Also adds withStorageApi constructor for testing purposes.
Add the new serverpod_cloud_storage_s3_compat package as a dependency override in test server pubspecs to resolve package resolution errors. Updated: - tests/serverpod_test_server/pubspec.yaml - tests/serverpod_test_nonvector/serverpod_test_nonvector_server/pubspec.yaml - tests/serverpod_auth_test/serverpod_auth_test_server/pubspec.yaml - Corresponding template files
The URL returned by uploadData was never used by callers. Removing it avoids returning potentially incorrect URLs for path-style endpoints.
- Move setup code from group level into setUp() callbacks - Use groups with setUp() when tests share common setup - Use standalone multiline tests when no shared setup needed - Fix When-Then ordering (was Then-When in some places) - Remove redundant 'for X tests' from group descriptions
…criptions The createDirectFileUploadDescription method was ignoring the public configuration flag, causing all direct uploads to use the default ACL. This fix: - Sets x-goog-acl header based on public setting (public-read or private) - Includes content-type and x-goog-acl in the signed URL headers - Returns the ACL header in the upload description for clients to send
Add real integration tests for AWS S3, Cloudflare R2, and GCP cloud storage that run against actual cloud services with credentials from environment variables or GitHub secrets. - Add shared test helper in s3_compat package for all S3-compatible providers - Add integration tests for AWS S3, Cloudflare R2, and GCP (HMAC) - Add GitHub Actions workflow with matrix for all providers - Add local test runner script (util/run_tests_integration_cloud) - Add INTEGRATION_TESTING.md with setup instructions Tests automatically skip when credentials are not configured.
…orageAccess Add optional maxFileSize, expirationDuration, and contentLength parameters to StorageAccess.createDirectFileUploadDescription, forwarding them to the underlying CloudStorage implementations. When contentLength is provided: - Validated against maxFileSize (throws if exceeded) - Signed into presigned PUT URLs for R2 and NativeGCS, enabling server-side enforcement of exact file size - For S3/GCP HMAC (multipart POST), content-length-range policy already enforces maxFileSize When contentLength is omitted, behavior is unchanged (backwards compatible). Closes: #4733
…ctFileUpload integration tests
Replace googleapis_auth 2.1.0 built-in signing with: - pointycastle RSA-SHA256 for service account credentials (local signing) - IAM signBlob API for Application Default Credentials (remote signing) - GCE metadata server for service account email discovery This avoids the googleapis_auth ^2.1.0 -> google_cloud ^0.3.0 -> meta ^1.18.1 transitive dependency chain that forces Flutter 3.38.1+.
Add optional named preventOverwrite parameter to both storeFile and createDirectFileUploadDescription. If set to `true` it prevents uploading to a path where an object already exists, if supported by the specific provider. - GCS native: ifGenerationMatch: '0' (storeFile) / x-goog-if-generation-match: 0 (direct upload) - S3 presigned PUT (AWS, R2): If-None-Match: * header - S3 multipart POST: not supported (flag is accepted but ignored)
Constructors that perform async initialization (service account JSON, ADC) are now static async factory methods that return a fully-initialized instance. This eliminates the race between isCompleted checks and async init, and removes the ambiguity between "not configured" and "still initializing". - create(): loads credentials from Serverpod password system - fromServiceAccountJson(): authenticates with explicit JSON - fromApplicationDefaultCredentials(): uses ADC - withStorageApi / withSigningCredentials: remain sync (test-only) - withAuthClient: new test constructor for ADC signing path Also add unit tests for the IAM signBlob signing path via the withAuthClient constructor and a MockAuthClient.
Replace _detectMimeType in both NativeGoogleCloudStorage and PresignedPutUploadStrategy with lookupMimeType from the mime package. The mime package was already a transitive dependency and provides a more comprehensive and maintained MIME type database. Also fix integration test to use async fromServiceAccountJson factory.
- Fix silent error swallowing: retrieveFile, fileExists, and deleteFile now properly distinguish 404 from server errors (5xx) instead of treating all non-200 responses as 'not found' - Add public check to getPublicUrl to skip HEAD request for non-public storage (matching NativeGoogleCloudStorage behavior) - Fix HTTP client leak in PresignedPutUploadStrategy.uploadData by properly creating and closing an http.Client instead of using the global http.put() function - Add close() to S3Client and S3CompatCloudStorage for resource cleanup - Fix ByteData buffer aliasing in retrieveFile by using ByteData.sublistView instead of ByteData.view(bytes.buffer) - Fix Policy expiration to use proper ISO 8601 formatting instead of relying on DateTime.toString() which produces microsecond precision - Rename misnamed cloud_storage.dart directory to cloud_storage in S3 package and replace placeholder library docs - Improve GCP HMAC credential error messages to include env var hints - Document MultipartPostUploadStrategy preventOverwrite limitation
Collaborator
Author
|
Supersedes #4675 |
Collaborator
Author
|
Rewrote history for easier review. |
8 tasks done
Collaborator
Author
|
Closing as github broke when rebasing 🙄 - this is getting old fast. Will open a new identical one shortly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactor cloud storage with shared S3-compatible base package
Introduces a layered architecture for cloud storage integrations, eliminating code duplication between S3 and GCP packages while adding support for new providers.
Shared base package (
serverpod_cloud_storage_s3_compat)S3CompatCloudStoragebase implementation using configurable abstractionsS3EndpointConfiginterface with implementations for AWS, GCP, R2, and custom endpointsS3UploadStrategyinterface with multipart POST (AWS/GCP/MinIO) and presigned PUT (R2) strategiesS3Clientfor signed S3 API requests with proper resource lifecycle (close())Native Google Cloud Storage (
NativeGoogleCloudStorage)signBlobAPI and GCE metadata serverpointycastle(avoidsgoogleapis_auth^2.1.0 dependency chain that forces Flutter 3.38.1+)create(),fromServiceAccountJson(),fromApplicationDefaultCredentials()New features
preventOverwriteparameter onstoreFileandcreateDirectFileUploadDescription— prevents uploading to an existing path (GCS native:ifGenerationMatch: '0'; S3 presigned PUT:If-None-Match: *; S3 multipart POST: not supported)maxFileSize,expirationDuration, andcontentLengthexposed onStorageAccess.createDirectFileUploadDescription. WhencontentLengthis provided it is validated againstmaxFileSizeand signed into presigned PUT URLs, enabling server-side enforcement of exact file sizeserverpod_cloud_storage_r2package for Cloudflare R2 supportFileUploaderupdated to support PUT method and custom headers for R2-style uploadsHardening & cleanup
retrieveFile,fileExists, anddeleteFilenow properly distinguish 404 from 5xx errorsPresignedPutUploadStrategy.uploadDataByteDatabuffer aliasing inretrieveFileusingByteData.sublistViewPolicyexpiration to use proper ISO 8601 formattingclose()toS3ClientandS3CompatCloudStoragefor resource cleanupmimepackageCompleterpattern with async factory constructors (eliminates race betweenisCompletedchecks and async init)Fixes #4623
Fixes #4588
Fixes #4733
Related:
Pre-launch Checklist
///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.If you need help, consider asking for advice on the discussion board.
Breaking changes
None. Refactored packages maintain full backwards compatibility with same constructor parameters and environment variable names.