bryancall commented on code in PR #12948: URL: https://github.com/apache/trafficserver/pull/12948#discussion_r2927976761
########## plugins/header_rewrite/generate_test_mmdb.py: ########## @@ -0,0 +1,103 @@ +#!/usr/bin/env python3 +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +""" +Generate test MMDB files for header_rewrite geo lookup unit tests. + +Two schemas exist in the wild: + + Nested (GeoLite2/GeoIP2/DBIP): country -> iso_code + Flat (vendor-specific): country_code (top-level) + +This script generates one MMDB file for each schema so the C++ test +can verify that auto-detection works for both. + +Requires: pip install mmdb-writer +""" + +import os +import sys + +try: + from mmdb_writer import MMDBWriter, MmdbU32 + import netaddr +except ImportError: + print("SKIP: mmdb-writer or netaddr not installed (pip install mmdb-writer)", file=sys.stderr) + sys.exit(0) + + +def net(cidr): + return netaddr.IPSet([netaddr.IPNetwork(cidr)]) + + +def generate_flat(path): + """Flat schema: country_code at top level (vendor databases).""" + w = MMDBWriter(ip_version=4, database_type="Test-Flat-GeoIP") + w.insert_network( + net("8.8.8.0/24"), { + "country_code": "US", + "autonomous_system_number": MmdbU32(15169), + "autonomous_system_organization": "GOOGLE", + }) + w.insert_network( + net("1.2.3.0/24"), { + "country_code": "KR", + "autonomous_system_number": MmdbU32(9286), + "autonomous_system_organization": "KINX", + }) + w.to_db_file(path) + + +def generate_nested(path): + """Nested schema: country/iso_code (GeoLite2, GeoIP2, DBIP).""" + w = MMDBWriter(ip_version=4, database_type="Test-Nested-GeoIP2") Review Comment: There is no such convention in the ATS repo — the referenced `.github/instructions/HRW.instructions.md` does not exist and other Python scripts in the tree do not use type hints. This is a small build helper; not adding type annotations. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
