pybgpkitstream 0.1.9__tar.gz → 0.2.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pybgpkitstream
3
- Version: 0.1.9
3
+ Version: 0.2.0
4
4
  Summary: Drop-in replacement for PyBGPStream using BGPKIT
5
5
  Author: JustinLoye
6
6
  Author-email: JustinLoye <jloye@iij.ad.jp>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pybgpkitstream"
3
- version = "0.1.9"
3
+ version = "0.2.0"
4
4
  description = "Drop-in replacement for PyBGPStream using BGPKIT"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -1,7 +1,7 @@
1
1
  import datetime
2
2
  import importlib
3
3
  import shutil
4
- from pydantic import BaseModel, Field, DirectoryPath, field_validator
4
+ from pydantic import BaseModel, Field, DirectoryPath, field_validator, model_validator
5
5
  from typing import Literal
6
6
  from ipaddress import IPv4Address, IPv6Address
7
7
 
@@ -131,7 +131,7 @@ class PyBGPKITStreamConfig(BaseModel):
131
131
  )
132
132
 
133
133
  elif parser == "bgpkit":
134
- if shutil.which("bgpkit") is None:
134
+ if shutil.which("bgpkit-parser") is None:
135
135
  raise ValueError(
136
136
  "bgpkit binary not found in PATH. "
137
137
  "Install from: https://github.com/bgpkit/bgpkit-parser "
@@ -140,3 +140,21 @@ class PyBGPKITStreamConfig(BaseModel):
140
140
 
141
141
  # Return the parser value if validation passes
142
142
  return parser
143
+
144
+ @model_validator(mode='before')
145
+ @classmethod
146
+ def nest_bgpstream_params(cls, data: dict) -> dict:
147
+ """Allow to define a flat config"""
148
+ # If the user already provided 'bgpstream_config', do nothing
149
+ if "bgpstream_config" in data:
150
+ return data
151
+
152
+ # Define which fields belong to the inner BGPStreamConfig
153
+ stream_fields = {"start_time", "end_time", "collectors", "data_types", "filters"}
154
+
155
+ # Extract those fields from the flat input
156
+ inner_data = {k: data.pop(k) for k in stream_fields if k in data}
157
+
158
+ # Nest them back into the dictionary
159
+ data["bgpstream_config"] = inner_data
160
+ return data
File without changes