vendor: update cargo-cxcloud-api-gateway-0.1.0
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
use cxcloud_common::config::{env_or, env_port, env_u64, ServiceConfig};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct GatewayConfig {
|
||||
pub base: ServiceConfig,
|
||||
pub port: u16,
|
||||
pub jwt_secret: String,
|
||||
pub jwt_issuer: String,
|
||||
pub jwt_expiry_seconds: u64,
|
||||
pub api_key: String,
|
||||
pub rate_limit_rps: u32,
|
||||
pub rate_limit_burst: u32,
|
||||
pub upstream_input_gateway: String,
|
||||
pub upstream_agent: String,
|
||||
pub upstream_bot: String,
|
||||
pub upstream_human_simulator: String,
|
||||
pub upstream_output: String,
|
||||
}
|
||||
|
||||
impl GatewayConfig {
|
||||
pub fn from_env() -> Self {
|
||||
let agent_host = env_or("AGENT_HOST", "localhost");
|
||||
let agent_port = env_port("AGENT_HTTP_PORT", 8001);
|
||||
let bot_host = env_or("BOT_HOST", "localhost");
|
||||
let bot_port = env_port("BOT_HTTP_PORT", 8002);
|
||||
let input_host = env_or("INPUT_GATEWAY_HOST", "localhost");
|
||||
let input_port = env_port("INPUT_GATEWAY_PORT", 3001);
|
||||
let human_host = env_or("HUMAN_SIMULATOR_HOST", "localhost");
|
||||
let human_port = env_port("HUMAN_SIMULATOR_HTTP_PORT", 3002);
|
||||
let output_host = env_or("OUTPUT_HOST", "localhost");
|
||||
let output_port = env_port("OUTPUT_HTTP_PORT", 8003);
|
||||
|
||||
Self {
|
||||
base: ServiceConfig::from_env("api-gateway"),
|
||||
port: env_port("API_GATEWAY_PORT", 8080),
|
||||
jwt_secret: env_or("JWT_SECRET", "dev-secret-change-me"),
|
||||
jwt_issuer: env_or("JWT_ISSUER", "cxcloud-api-gateway"),
|
||||
jwt_expiry_seconds: env_u64("JWT_EXPIRY_SECONDS", 300),
|
||||
api_key: env_or("API_KEY_DEV", "dev-test-key"),
|
||||
rate_limit_rps: env_u64("RATE_LIMIT_RPS", 10) as u32,
|
||||
rate_limit_burst: env_u64("RATE_LIMIT_BURST", 20) as u32,
|
||||
upstream_input_gateway: format!("http://{input_host}:{input_port}"),
|
||||
upstream_agent: format!("http://{agent_host}:{agent_port}"),
|
||||
upstream_bot: format!("http://{bot_host}:{bot_port}"),
|
||||
upstream_human_simulator: format!("http://{human_host}:{human_port}"),
|
||||
upstream_output: format!("http://{output_host}:{output_port}"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn upstream_for_prefix(&self, prefix: &str) -> Option<&str> {
|
||||
match prefix {
|
||||
"webhook" => Some(&self.upstream_input_gateway),
|
||||
"agent" => Some(&self.upstream_agent),
|
||||
"bot" => Some(&self.upstream_bot),
|
||||
"policies" => Some(&self.upstream_human_simulator),
|
||||
"deliver" => Some(&self.upstream_output),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user