Skip to content

Commit e204a00

Browse files
committed
Removed unecessary of cloudevents env variable overwriting.
1 parent 2841998 commit e204a00

File tree

4 files changed

+2
-62
lines changed

4 files changed

+2
-62
lines changed

eoapi_notifier/outputs/cloudevents.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
Supports standard CloudEvents environment variables and KNative SinkBinding.
66
"""
77

8-
import json
98
import os
109
from typing import Any
1110
from uuid import uuid4
@@ -40,18 +39,9 @@ def validate_endpoint(cls, v: str | None) -> str | None:
4039
@model_validator(mode="after")
4140
def apply_knative_overrides(self) -> "CloudEventsConfig":
4241
"""Apply KNative SinkBinding environment variables as special case."""
43-
# K_SINK overrides endpoint (KNative SinkBinding)
4442
if k_sink := os.getenv("K_SINK"):
4543
self.endpoint = k_sink
4644

47-
# K_SOURCE overrides source
48-
if k_source := os.getenv("K_SOURCE"):
49-
self.source = k_source
50-
51-
# K_TYPE overrides event_type
52-
if k_type := os.getenv("K_TYPE"):
53-
self.event_type = k_type
54-
5545
return self
5646

5747
@classmethod
@@ -207,16 +197,6 @@ def _convert_to_cloudevent(self, event: NotificationEvent) -> CloudEvent:
207197
source = self.config.source
208198
event_type_base = self.config.event_type
209199

210-
# Apply KNative CE overrides if present
211-
ce_overrides = {}
212-
if k_ce_overrides := os.getenv("K_CE_OVERRIDES"):
213-
try:
214-
ce_overrides = json.loads(k_ce_overrides)
215-
except json.JSONDecodeError:
216-
self.logger.warning(
217-
"Invalid K_CE_OVERRIDES JSON, ignoring: %s", k_ce_overrides
218-
)
219-
220200
# Map operation to event type suffix
221201
operation_map = {"INSERT": "created", "UPDATE": "updated", "DELETE": "deleted"}
222202
operation = operation_map.get(event.operation.upper(), event.operation.lower())
@@ -237,9 +217,6 @@ def _convert_to_cloudevent(self, event: NotificationEvent) -> CloudEvent:
237217
if event.collection:
238218
attributes["collection"] = event.collection
239219

240-
# Apply KNative CE overrides
241-
attributes.update(ce_overrides)
242-
243220
# Event data payload
244221
data = {
245222
"id": event.id,

examples/config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ outputs:
5555
endpoint: https://example.com/webhook # CLOUDEVENTS_ENDPOINT or K_SINK
5656

5757
# Optional: CloudEventattributes
58-
# source: "/eoapi/stac" # CLOUDEVENTS_SOURCE or K_SOURCE
59-
# event_type: "org.eoapi.stac" # CLOUDEVENTS_EVENT_TYPE or K_TYPE
58+
# source: "/eoapi/stac" # CLOUDEVENTS_SOURCE
59+
# event_type: "org.eoapi.stac" # CLOUDEVENTS_EVENT_TYPE
6060

6161
# Optional: HTTP settings
6262
# timeout: 30.0 # CLOUDEVENTS_TIMEOUT

helm-chart/eoapi-notifier/values.yaml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,6 @@ secrets:
7878
# KNative Support:
7979
# The cloudevents plugin supports K_SINK variables for KNative SinkBinding:
8080
# - K_SINK: Overrides CLOUDEVENTS_ENDPOINT (automatically set by SinkBinding)
81-
# - K_SOURCE: Overrides CLOUDEVENTS_SOURCE
82-
# - K_TYPE: Overrides CLOUDEVENTS_EVENT_TYPE
83-
#
84-
# For KNative integration, use SinkBinding to automatically inject K_SINK:
85-
# apiVersion: sources.knative.dev/v1beta1
86-
# kind: SinkBinding
87-
# metadata:
88-
# name: eoapi-notifier-binding
89-
# spec:
90-
# subject:
91-
# apiVersion: apps/v1
92-
# kind: Deployment
93-
# name: eoapi-notifier
94-
# sink:
95-
# ref:
96-
# apiVersion: serving.knative.dev/v1
97-
# kind: Service
98-
# name: my-knative-service
9981
env: {}
10082
# Examples - Standard environment variables:
10183
# PGSTAC_HOST: postgresql-service
@@ -111,5 +93,3 @@ env: {}
11193
#
11294
# KNative examples (typically set by SinkBinding):
11395
# K_SINK: https://my-knative-service.default.svc.cluster.local
114-
# K_SOURCE: /eoapi/stac/pgstac
115-
# K_TYPE: org.eoapi.stac

tests/test_cloudevents_output.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -198,23 +198,6 @@ def test_convert_to_cloudevent(
198198
assert cloud_event["subject"] == "test-item"
199199
assert cloud_event["collection"] == "test-collection"
200200

201-
@patch.dict(
202-
os.environ,
203-
{
204-
"K_SOURCE": "/custom/source",
205-
"K_TYPE": "custom.type",
206-
},
207-
)
208-
def test_convert_with_env_vars(self, sample_event: NotificationEvent) -> None:
209-
"""Test CloudEvent conversion with environment variables."""
210-
# Create a new config and adapter after setting environment variables
211-
config = CloudEventsConfig()
212-
adapter = CloudEventsAdapter(config)
213-
cloud_event = adapter._convert_to_cloudevent(sample_event)
214-
215-
assert cloud_event["source"] == "/custom/source"
216-
assert cloud_event["type"] == "custom.type.created"
217-
218201
def test_operation_mapping(self, adapter: CloudEventsAdapter) -> None:
219202
"""Test operation to event type mapping."""
220203
test_cases = [

0 commit comments

Comments
 (0)