-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from DS4SD/add-target-options
Add export target options for document conversion
- Loading branch information
Showing
6 changed files
with
277 additions
and
153 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
from enum import Enum | ||
from typing import List, Literal, Optional, Set, Union | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
|
||
class S3Coordinates(BaseModel): | ||
host: str | ||
port: int | ||
|
||
ssl: bool | ||
verify_ssl: bool | ||
|
||
access_key: str | ||
secret_key: str | ||
|
||
bucket: str | ||
location: str | ||
key_prefix: str = "" | ||
|
||
external_endpoint: Optional[str] = None | ||
|
||
|
||
class DocumentExistsInTargetAction(str, Enum): | ||
""" | ||
What to do if the document already exists on the target. | ||
- `replace` will replace the document, destroying any external modifications. | ||
- `merge` will try to merge the updated contents with the already-present document. | ||
- `skip` will not touch the document on the target, leaving it as-is. | ||
Using `skip` will incur in a performance increase, however, if the document | ||
is modified externally, CCS will not update it back to the original state. | ||
""" | ||
|
||
REPLACE = "replace" | ||
MERGE = "merge" | ||
SKIP = "skip" | ||
|
||
|
||
class MongoCollectionCoordinates(BaseModel): | ||
uri: str | ||
database: str | ||
collection: str | ||
|
||
|
||
class MongoS3TargetCoordinates(BaseModel): | ||
"""Coordinates to a Mongo collection, and optionally, an S3 bucket""" | ||
|
||
mongo: MongoCollectionCoordinates | ||
s3: Optional[S3Coordinates] | ||
|
||
|
||
class MongoS3Target(BaseModel): | ||
type: Literal["mongo_s3"] = "mongo_s3" | ||
|
||
# Coordinates for the export | ||
coordinates: MongoS3TargetCoordinates | ||
|
||
if_document_exists: DocumentExistsInTargetAction = ( | ||
DocumentExistsInTargetAction.MERGE | ||
) | ||
|
||
|
||
class ZipPackageContentType(str, Enum): | ||
"""Specify the content type for the documents in the Zip file.""" | ||
|
||
JSON = "json" | ||
HTML = "html" | ||
|
||
|
||
class ZipTarget(BaseModel): | ||
""" | ||
Specify how the documents should be exported to a Zip file. | ||
If the [coordinates] are not specified, the project's coordinates | ||
will be used. | ||
""" | ||
|
||
type: Literal["zip"] = "zip" | ||
|
||
content_type: ZipPackageContentType = ZipPackageContentType.JSON | ||
|
||
add_cells: bool = True | ||
|
||
|
||
class ElasticIndexCoordinates(BaseModel): | ||
hosts: List[str] | ||
dangerously_disable_ssl_validation: bool = False | ||
ca_certificate_base64: Optional[str] = None | ||
index: str | ||
|
||
|
||
class ElasticS3TargetCoordinates(BaseModel): | ||
elastic: ElasticIndexCoordinates | ||
s3: Optional[S3Coordinates] | ||
|
||
|
||
class ElasticS3Target(BaseModel): | ||
type: Literal["elastic_s3"] = "elastic_s3" | ||
|
||
coordinates: ElasticS3TargetCoordinates | ||
|
||
if_document_exists: DocumentExistsInTargetAction = ( | ||
DocumentExistsInTargetAction.MERGE | ||
) | ||
|
||
escape_ref_fields: bool = Field( | ||
default=True, | ||
description="If true, `$ref` fields are renamed to `__ref`. This allows the data to then be written into a MongoDB collection.", | ||
) | ||
|
||
|
||
ExportTarget = Union[ | ||
ZipTarget, | ||
MongoS3Target, | ||
ElasticS3Target, | ||
] |
Oops, something went wrong.