dserver-signed-url-plugin 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,33 @@
1
+ """Configuration for dserver-signed-url-plugin."""
2
+
3
+ import os
4
+
5
+
6
+ AFFIRMATIVE_EXPRESSIONS = ['true', '1', 'y', 'yes', 'on']
7
+
8
+
9
+ CONFIG_SECRETS_TO_OBFUSCATE = []
10
+
11
+
12
+ class Config:
13
+ """Configuration for signed URL generation."""
14
+
15
+ # Default expiry time for read URLs (1 hour)
16
+ SIGNED_URL_READ_EXPIRY_SECONDS = int(
17
+ os.environ.get('SIGNED_URL_READ_EXPIRY_SECONDS', '3600')
18
+ )
19
+
20
+ # Default expiry time for write URLs (4 hours)
21
+ SIGNED_URL_WRITE_EXPIRY_SECONDS = int(
22
+ os.environ.get('SIGNED_URL_WRITE_EXPIRY_SECONDS', '14400')
23
+ )
24
+
25
+ # dtool config path (for storage broker initialization)
26
+ DTOOL_CONFIG_PATH = os.environ.get('DTOOL_CONFIG_PATH', None)
27
+
28
+ # URL rewriting for signed URLs
29
+ # When dserver runs in a container, the internal endpoint (e.g., http://minio:9000)
30
+ # may not be accessible from outside. This allows rewriting URLs for external access.
31
+ # Format: "internal_base_url|external_base_url"
32
+ # Example: "http://minio:9000|http://localhost:9000"
33
+ SIGNED_URL_HOST_REWRITE = os.environ.get('SIGNED_URL_HOST_REWRITE', None)
@@ -0,0 +1,92 @@
1
+ """Marshmallow schemas for dserver-signed-url-plugin."""
2
+
3
+ from marshmallow import Schema, fields
4
+
5
+
6
+ class SignedURLsResponseSchema(Schema):
7
+ """Schema for signed URLs response."""
8
+ uri = fields.Str(required=True, metadata={"description": "Dataset URI"})
9
+ expiry_seconds = fields.Int(required=True, metadata={"description": "URL expiry time in seconds"})
10
+ expiry_timestamp = fields.Str(required=True, metadata={"description": "ISO format expiry timestamp"})
11
+ admin_metadata_url = fields.Str(required=True, metadata={"description": "Signed URL for admin metadata"})
12
+ manifest_url = fields.Str(required=True, metadata={"description": "Signed URL for manifest"})
13
+ readme_url = fields.Str(required=True, metadata={"description": "Signed URL for README"})
14
+ item_urls = fields.Dict(keys=fields.Str(), values=fields.Str(), metadata={"description": "Item identifier to signed URL mapping"})
15
+ overlay_urls = fields.Dict(keys=fields.Str(), values=fields.Str(), metadata={"description": "Overlay name to signed URL mapping"})
16
+ annotation_urls = fields.Dict(keys=fields.Str(), values=fields.Str(), metadata={"description": "Annotation name to signed URL mapping"})
17
+ tags = fields.List(fields.Str(), metadata={"description": "Dataset tags"})
18
+
19
+
20
+ class SignedItemURLResponseSchema(Schema):
21
+ """Schema for single item signed URL response."""
22
+ uri = fields.Str(required=True, metadata={"description": "Dataset URI"})
23
+ identifier = fields.Str(required=True, metadata={"description": "Item identifier"})
24
+ expiry_seconds = fields.Int(required=True, metadata={"description": "URL expiry time in seconds"})
25
+ expiry_timestamp = fields.Str(required=True, metadata={"description": "ISO format expiry timestamp"})
26
+ url = fields.Str(required=True, metadata={"description": "Signed URL for the item"})
27
+
28
+
29
+ class UploadItemSchema(Schema):
30
+ """Schema for an item to upload - includes full metadata for manifest generation."""
31
+ relpath = fields.Str(required=True, metadata={"description": "Relative path of the item"})
32
+ size_in_bytes = fields.Int(required=True, metadata={"description": "Size of the item in bytes"})
33
+ hash = fields.Str(required=True, metadata={"description": "Hash of the item content"})
34
+ utc_timestamp = fields.Float(required=True, metadata={"description": "UTC timestamp of the item"})
35
+
36
+
37
+ class UploadRequestSchema(Schema):
38
+ """Schema for upload URL request.
39
+
40
+ The server uses this metadata to create admin_metadata, manifest, structure,
41
+ tags, and annotations directly in storage. Only README and items need
42
+ separate uploads via signed URLs.
43
+ """
44
+ uuid = fields.Str(required=True, metadata={"description": "Dataset UUID"})
45
+ name = fields.Str(required=True, metadata={"description": "Dataset name"})
46
+ creator_username = fields.Str(required=True, metadata={"description": "Username of the dataset creator"})
47
+ frozen_at = fields.Float(required=True, metadata={"description": "UTC timestamp when dataset was frozen"})
48
+ hash_function = fields.Str(load_default="md5sum_hexdigest", metadata={"description": "Name of the hash function used for item hashes"})
49
+ items = fields.List(fields.Nested(UploadItemSchema), metadata={"description": "List of items with full metadata"})
50
+ tags = fields.List(fields.Str(), load_default=[], metadata={"description": "List of tags"})
51
+ annotations = fields.Dict(keys=fields.Str(), values=fields.Raw(), load_default={}, metadata={"description": "Annotations as key-value pairs"})
52
+ overlays = fields.Dict(keys=fields.Str(), values=fields.Dict(keys=fields.Str(), values=fields.Raw()), load_default={}, metadata={"description": "Overlays as overlay name to item identifier/value mapping"})
53
+
54
+
55
+ class UploadItemURLSchema(Schema):
56
+ """Schema for an item upload URL."""
57
+ url = fields.Str(required=True, metadata={"description": "Signed URL for uploading the item"})
58
+ relpath = fields.Str(required=True, metadata={"description": "Relative path of the item"})
59
+ headers = fields.Dict(keys=fields.Str(), values=fields.Str(), load_default={}, metadata={"description": "Headers that must be sent verbatim with the PUT request"})
60
+
61
+
62
+ class UploadURLsSchema(Schema):
63
+ """Schema for upload structure URLs.
64
+
65
+ Only includes URLs for README and items - other metadata is written
66
+ directly by the server.
67
+ """
68
+ readme = fields.Str(required=True, metadata={"description": "Signed URL for README"})
69
+ items = fields.Dict(keys=fields.Str(), values=fields.Nested(UploadItemURLSchema), metadata={"description": "Item identifier to upload URL mapping"})
70
+
71
+
72
+ class UploadURLsResponseSchema(Schema):
73
+ """Schema for upload URLs response."""
74
+ uuid = fields.Str(required=True, metadata={"description": "Dataset UUID"})
75
+ uri = fields.Str(required=True, metadata={"description": "Dataset URI"})
76
+ base_uri = fields.Str(required=True, metadata={"description": "Base URI"})
77
+ expiry_seconds = fields.Int(required=True, metadata={"description": "URL expiry time in seconds"})
78
+ expiry_timestamp = fields.Str(required=True, metadata={"description": "ISO format expiry timestamp"})
79
+ upload_urls = fields.Nested(UploadURLsSchema, metadata={"description": "Upload URLs"})
80
+
81
+
82
+ class UploadCompleteRequestSchema(Schema):
83
+ """Schema for upload complete request."""
84
+ uri = fields.Str(required=True, metadata={"description": "Dataset URI"})
85
+
86
+
87
+ class UploadCompleteResponseSchema(Schema):
88
+ """Schema for upload complete response."""
89
+ uri = fields.Str(required=True, metadata={"description": "Dataset URI"})
90
+ status = fields.Str(required=True, metadata={"description": "Registration status"})
91
+ name = fields.Str(required=True, metadata={"description": "Dataset name"})
92
+ uuid = fields.Str(required=True, metadata={"description": "Dataset UUID"})
@@ -0,0 +1,47 @@
1
+ """Database models for pending uploads."""
2
+
3
+ from datetime import datetime, timezone
4
+
5
+ from dservercore import sql_db as db
6
+
7
+
8
+ class PendingUpload(db.Model):
9
+ """Track pending dataset uploads that have not yet been finalized.
10
+
11
+ When a client initiates an upload via the signed URL plugin, a proto-dataset
12
+ is created in storage and a PendingUpload record is created here. This record
13
+ stores the manifest and other metadata needed to freeze the dataset when the
14
+ upload is completed.
15
+
16
+ This allows:
17
+ 1. Detection of incomplete/abandoned uploads
18
+ 2. Persistence across server restarts
19
+ 3. Cleanup of stale uploads
20
+ """
21
+ __tablename__ = "pending_upload"
22
+
23
+ id = db.Column(db.Integer, primary_key=True)
24
+ uuid = db.Column(db.String(36), index=True, unique=True, nullable=False)
25
+ uri = db.Column(db.String(255), index=True, nullable=False)
26
+ base_uri = db.Column(db.String(255), index=True, nullable=False)
27
+ name = db.Column(db.String(80), nullable=False)
28
+ creator_username = db.Column(db.String(255), nullable=False)
29
+ created_at = db.Column(db.DateTime(), nullable=False, default=lambda: datetime.now(timezone.utc))
30
+ frozen_at = db.Column(db.Float, nullable=False) # Timestamp to use when freezing
31
+ manifest = db.Column(db.JSON, nullable=False) # Native JSON field for manifest
32
+
33
+ def __repr__(self):
34
+ return f"<PendingUpload {self.uuid} ({self.name})>"
35
+
36
+ def as_dict(self):
37
+ """Return pending upload as dictionary."""
38
+ return {
39
+ "uuid": self.uuid,
40
+ "uri": self.uri,
41
+ "base_uri": self.base_uri,
42
+ "name": self.name,
43
+ "creator_username": self.creator_username,
44
+ "created_at": self.created_at.isoformat() if self.created_at else None,
45
+ "frozen_at": self.frozen_at,
46
+ "manifest": self.manifest,
47
+ }
@@ -0,0 +1,24 @@
1
+ # file generated by vcs-versioning
2
+ # don't change, don't track in version control
3
+ from __future__ import annotations
4
+
5
+ __all__ = [
6
+ "__version__",
7
+ "__version_tuple__",
8
+ "version",
9
+ "version_tuple",
10
+ "__commit_id__",
11
+ "commit_id",
12
+ ]
13
+
14
+ version: str
15
+ __version__: str
16
+ __version_tuple__: tuple[int | str, ...]
17
+ version_tuple: tuple[int | str, ...]
18
+ commit_id: str | None
19
+ __commit_id__: str | None
20
+
21
+ __version__ = version = '0.1.0'
22
+ __version_tuple__ = version_tuple = (0, 1, 0)
23
+
24
+ __commit_id__ = commit_id = None