Skip to content

Commit

Permalink
Standardized Kafka Event Config Classes (GSI-1407) (#56)
Browse files Browse the repository at this point in the history
* Add standardized topic/type configs

* Update readme

* Fix some typos and exports

* Fix naming inconsistencies

* Remove changes that are for later

* Shorten config field names
  • Loading branch information
TheByronHimes authored Feb 26, 2025
1 parent 23ee005 commit 67f115e
Show file tree
Hide file tree
Showing 9 changed files with 636 additions and 190 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ repos:
- id: no-commit-to-branch
args: [--branch, dev, --branch, int, --branch, main]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.1
rev: v0.9.6
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.14.1
rev: v1.15.0
hooks:
- id: mypy
args: [--no-warn-unused-ignores]
3 changes: 2 additions & 1 deletion .pyproject_generation/pyproject_custom.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[project]
name = "ghga_event_schemas"
version = "4.0.0"
version = "4.1.0"
description = "GHGA Event Schemas: A package that collects schemas used for events exchanged between GHGA service."
dependencies = [
"jsonschema>=4.21.1,<5.0.0",
"pydantic[email]>=2,<3",
"pydantic_settings >=2, <3",
]

[project.urls]
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ We recommend using the provided Docker container.

A pre-build version is available at [docker hub](https://hub.docker.com/repository/docker/ghga/ghga-event-schemas):
```bash
docker pull ghga/ghga-event-schemas:4.0.0
docker pull ghga/ghga-event-schemas:4.1.0
```

Or you can build the container yourself from the [`./Dockerfile`](./Dockerfile):
```bash
# Execute in the repo's root dir:
docker build -t ghga/ghga-event-schemas:4.0.0 .
docker build -t ghga/ghga-event-schemas:4.1.0 .
```

For production-ready deployment, we recommend using Kubernetes, however,
for simple use cases, you could execute the service using docker
on a single server:
```bash
# The entrypoint is preconfigured:
docker run -p 8080:8080 ghga/ghga-event-schemas:4.0.0 --help
docker run -p 8080:8080 ghga/ghga-event-schemas:4.1.0 --help
```

If you prefer not to use containers, you may install the service from source:
Expand Down
353 changes: 179 additions & 174 deletions lock/requirements-dev.txt

Large diffs are not rendered by default.

32 changes: 23 additions & 9 deletions lock/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ annotated-types==0.7.0 \
# via
# -c lock/requirements-dev.txt
# pydantic
attrs==24.3.0 \
--hash=sha256:8f5c07333d543103541ba7be0e2ce16eeee8130cb0b3f9238ab904ce1e85baff \
--hash=sha256:ac96cd038792094f438ad1f6ff80837353805ac950cd2aa0e0625ef19850c308
attrs==25.1.0 \
--hash=sha256:1c97078a80c814273a76b2a298a932eb681c87415c11dee0a6921de7f1b02c3e \
--hash=sha256:c75a69e28a550a7e93789579c22aa26b0f5b83b75dc4e08fe092980051e1090a
# via
# -c lock/requirements-dev.txt
# jsonschema
Expand Down Expand Up @@ -41,12 +41,13 @@ jsonschema-specifications==2024.10.1 \
# via
# -c lock/requirements-dev.txt
# jsonschema
pydantic==2.10.5 \
--hash=sha256:278b38dbbaec562011d659ee05f63346951b3a248a6f3642e1bc68894ea2b4ff \
--hash=sha256:4dd4e322dbe55472cb7ca7e73f4b63574eecccf2835ffa2af9021ce113c83c53
pydantic==2.10.6 \
--hash=sha256:427d664bf0b8a2b34ff5dd0f5a18df00591adcee7198fbd71981054cef37b584 \
--hash=sha256:ca5daa827cce33de7a42be142548b0096bf05a7e7b365aebfa5f8eeec7128236
# via
# -c lock/requirements-dev.txt
# ghga-event-schemas (pyproject.toml)
# pydantic-settings
pydantic-core==2.27.2 \
--hash=sha256:00bad2484fa6bda1e216e7345a798bd37c68fb2d97558edd584942aa41b7d278 \
--hash=sha256:0296abcb83a797db256b773f45773da397da75a08f5fcaef41f2044adec05f50 \
Expand Down Expand Up @@ -151,9 +152,21 @@ pydantic-core==2.27.2 \
# via
# -c lock/requirements-dev.txt
# pydantic
referencing==0.35.1 \
--hash=sha256:25b42124a6c8b632a425174f24087783efb348a6f1e0008e63cd4466fedf703c \
--hash=sha256:eda6d3234d62814d1c64e305c1331c9a3a6132da475ab6382eaa997b21ee75de
pydantic-settings==2.7.1 \
--hash=sha256:10c9caad35e64bfb3c2fbf70a078c0e25cc92499782e5200747f942a065dec93 \
--hash=sha256:590be9e6e24d06db33a4262829edef682500ef008565a969c73d39d5f8bfb3fd
# via
# -c lock/requirements-dev.txt
# ghga-event-schemas (pyproject.toml)
python-dotenv==1.0.1 \
--hash=sha256:e324ee90a023d808f1959c46bcbc04446a10ced277783dc6ee09987c37ec10ca \
--hash=sha256:f7b63ef50f1b690dddf550d03497b66d609393b40b564ed0d674909a68ebf16a
# via
# -c lock/requirements-dev.txt
# pydantic-settings
referencing==0.36.2 \
--hash=sha256:df2e89862cd09deabbdba16944cc3f10feb6b3e6f18e902f7cc25609a34775aa \
--hash=sha256:e8699adbbf8b5c7de96d8ffa0eb5c158b3beafce084968e2ea8bb08c6794dcd0
# via
# -c lock/requirements-dev.txt
# jsonschema
Expand Down Expand Up @@ -273,3 +286,4 @@ typing-extensions==4.12.2 \
# -c lock/requirements-dev.txt
# pydantic
# pydantic-core
# referencing
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ classifiers = [
"Intended Audience :: Developers",
]
name = "ghga_event_schemas"
version = "4.0.0"
version = "4.1.0"
description = "GHGA Event Schemas: A package that collects schemas used for events exchanged between GHGA service."
dependencies = [
"jsonschema>=4.21.1,<5.0.0",
"pydantic[email]>=2,<3",
"pydantic_settings >=2, <3",
]

[project.license]
Expand Down
40 changes: 40 additions & 0 deletions src/ghga_event_schemas/configs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2021 - 2024 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
# for the German Human Genome-Phenome Archive (GHGA)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Standardized topic/type configurations for Kafka events"""

from .stateful import ( # noqa: F401
DatasetEventsConfig,
ResourceEventsConfig,
UserEventsConfig,
)
from .stateless import ( # noqa: F401
AccessRequestCreatedEventsConfig,
AccessRequestDeniedEventsConfig,
DownloadServedEventsConfig,
FileDeletedEventsConfig,
FileDeletionRequestEventsConfig,
FileInternallyRegisteredEventsConfig,
FileInterrogationFailureEventsConfig,
FileInterrogationSuccessEventsConfig,
FileMetadataEventsConfig,
FileRegisteredForDownloadEventsConfig,
FileStagedEventsConfig,
FileStagingRequestedEventsConfig,
FileUploadReceivedEventsConfig,
IvaChangeEventsConfig,
NotificationEventsConfig,
SecondFactorRecreatedEventsConfig,
)
80 changes: 80 additions & 0 deletions src/ghga_event_schemas/configs/stateful.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright 2021 - 2024 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
# for the German Human Genome-Phenome Archive (GHGA)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Config classes for stateful events"""

from pydantic import Field
from pydantic_settings import BaseSettings

__all__ = [
"DatasetEventsConfig",
"ResourceEventsConfig",
"UserEventsConfig",
]


class DatasetEventsConfig(BaseSettings):
"""For dataset change events."""

dataset_change_topic: str = Field(
...,
description="Name of the topic announcing, among other things, the list of"
+ " files included in a new dataset.",
examples=["metadata_datasets"],
)
dataset_deletion_type: str = Field(
...,
description="Type used for events announcing a new dataset overview.",
examples=["dataset_deleted"],
)
dataset_upsertion_type: str = Field(
...,
description="Type used for events announcing a new dataset overview.",
examples=["dataset_created"],
)


class ResourceEventsConfig(BaseSettings):
"""For searchable metadata resource change events."""

resource_change_topic: str = Field(
...,
description="Name of the topic used for events informing other services about"
+ " resource changes, i.e. deletion or insertion.",
examples=["searchable_resources"],
)
resource_deletion_type: str = Field(
...,
description="Type used for events indicating the deletion of a previously"
+ " existing resource.",
examples=["searchable_resource_deleted"],
)
resource_upsertion_type: str = Field(
...,
description="Type used for events indicating the upsert of a resource.",
examples=["searchable_resource_upserted"],
)


class UserEventsConfig(BaseSettings):
"""Config for communication changes to user data, done via outbox.
The upsertion and deletion event types are hardcoded by `hexkit`.
"""

user_topic: str = Field(
default="users",
description="The name of the topic containing user events.",
)
Loading

0 comments on commit 67f115e

Please # to comment.