Created
November 28, 2024 03:07
-
-
Save chobits/3416c482f5470d1458056c77f396c82b to your computer and use it in GitHub Desktop.
Generate 100 routes associated with the Rate Limiting Advanced (RLA) plugin for Konnect.
This file contains hidden or 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
import yaml | |
# Configuration | |
num_services = 100 | |
backend_url = "http://mockbin.org/request" | |
# YAML Structure | |
kong_config = { | |
"_format_version": "3.0", | |
"services": [] | |
} | |
# Generate services and routes | |
for s in range(1, num_services + 1): | |
service = { | |
"name": f"service_{s}", | |
"url": backend_url, | |
"routes": [ | |
{ | |
"name": f"route_{s}", | |
"paths": [f"/service{s}"], | |
"methods": ["GET", "POST"], | |
"plugins": [ | |
{ | |
"name": "rate-limiting-advanced", | |
"enabled": True, | |
"protocols": ["grpc", "grpcs", "http", "https"], | |
"config": { | |
"dictionary_name": "kong_rate_limiting_counters", | |
"disable_penalty": False, | |
"enforce_consumer_groups": False, | |
"error_code": 429, | |
"error_message": "API rate limit exceeded", | |
"hide_client_headers": False, | |
"identifier": "consumer", | |
"limit": [100], | |
"lock_dictionary_name": "kong_locks", | |
"redis": { | |
"cluster_max_redirections": 5, | |
"cluster_nodes": None, | |
"connect_timeout": 2000, | |
"connection_is_proxied": False, | |
"database": 0, | |
"host": "127.0.0.1", | |
"keepalive_pool_size": 256, | |
"port": 6379, | |
"read_timeout": 2000, | |
"send_timeout": 2000, | |
"sentinel_nodes": None, | |
"ssl": False, | |
"ssl_verify": False | |
}, | |
"retry_after_jitter_max": 0, | |
"strategy": "local", | |
"window_size": [3600], | |
"window_type": "sliding" | |
} | |
} | |
] | |
} | |
] | |
} | |
kong_config["services"].append(service) | |
# Save to YAML file | |
with open("kong_config.yaml", "w") as file: | |
yaml.dump(kong_config, file, sort_keys=False, default_flow_style=False) | |
print("Kong configuration saved to 'kong_config.yaml'") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment