-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from DioCrafts/feature/frontend-helm-chart
complete remodeling
- Loading branch information
Showing
14,166 changed files
with
2,192,246 additions
and
9,639 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
[package] | ||
name = "api-gateway" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
# Web framework | ||
actix-web = "4.9.0" | ||
actix-cors = "0.7.0" | ||
|
||
# Async runtime | ||
tokio = { version = "1.41.1", features = ["full"] } | ||
futures = "0.3.31" | ||
|
||
# Serialización/Deserialización | ||
serde = { version = "1.0.215", features = ["derive"] } | ||
serde_json = "1.0.133" | ||
reqwest = { version = "0.12.9", features = ["stream", "json", "rustls-tls"] } | ||
http = "1.1.0" | ||
|
||
# Kubernetes integration | ||
kube = { version = "0.97.0", features = ["runtime", "derive"] } | ||
k8s-openapi = { version = "0.23.0", features = ["v1_27"] } | ||
|
||
# Configuración | ||
config = "0.14.1" | ||
dotenv = "0.15" | ||
num_cpus = "1.16.0" | ||
|
||
# Logging y métricas | ||
tracing = "0.1.41" | ||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } | ||
prometheus = "0.13.4" | ||
|
||
# JWT y autenticación | ||
jsonwebtoken = "9.3.0" | ||
|
||
# Base de datos (si decides usar una) | ||
sqlx = { version = "0.8.2", features = ["runtime-tokio-rustls", "postgres"] } | ||
|
||
# Utilidades | ||
anyhow = "1.0.93" | ||
thiserror = "2.0.3" | ||
uuid = { version = "1.11.0", features = ["v4", "serde"] } | ||
chrono = { version = "0.4.38", features = ["serde"] } | ||
rand = "0.8.5" | ||
lazy_static = "1.5.0" | ||
awc = "3.5.1" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Build stage | ||
FROM rust:latest as builder | ||
|
||
WORKDIR /usr/src/app | ||
|
||
# Install dependencies | ||
RUN apt-get update && \ | ||
apt-get install -y pkg-config libssl-dev && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# Copy manifests | ||
COPY Cargo.toml Cargo.lock ./ | ||
|
||
# Create dummy main.rs to build dependencies | ||
RUN mkdir src && \ | ||
echo "fn main() {}" > src/main.rs | ||
|
||
# Build dependencies | ||
RUN cargo build --release | ||
|
||
# Remove the dummy file | ||
RUN rm -f src/main.rs | ||
|
||
# Copy the actual source code | ||
COPY src/ src/ | ||
|
||
# Build the application | ||
RUN cargo build --release | ||
|
||
# Runtime stage | ||
FROM debian:bookworm-slim | ||
|
||
WORKDIR /app | ||
|
||
# Install runtime dependencies | ||
RUN apt-get update && \ | ||
apt-get install -y ca-certificates libssl3 && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# Copy the built binary | ||
COPY --from=builder /usr/src/app/target/release/api-gateway /app/api-gateway | ||
|
||
# Create non-root user | ||
RUN useradd -m -U -s /bin/false api-gateway && \ | ||
chown -R api-gateway:api-gateway /app | ||
|
||
USER api-gateway | ||
|
||
# Expose port | ||
EXPOSE 3000 | ||
|
||
# Set environment variables | ||
ENV RUST_LOG=info | ||
ENV RUN_MODE=production | ||
|
||
# Run the application | ||
CMD ["./api-gateway"] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// src/config/mod.rs | ||
mod routes; | ||
mod settings; | ||
|
||
pub use routes::{Route, RouteConfig}; | ||
pub use settings::{Settings, ServerSettings, DatabaseSettings, JwtSettings}; | ||
|
||
use anyhow::Result; | ||
|
||
pub fn load_configuration() -> Result<Settings> { | ||
let settings = Settings::new()?; | ||
Ok(settings) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// src/config/routes.rs | ||
use serde::{Deserialize, Serialize}; | ||
use std::collections::HashMap; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Route { | ||
pub id: String, | ||
pub path: String, | ||
pub target_service: String, | ||
pub methods: Vec<String>, | ||
pub auth_required: bool, | ||
pub rate_limit: Option<RateLimit>, | ||
pub timeout: Option<u64>, | ||
pub retry: Option<Retry>, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct RateLimit { | ||
pub requests_per_second: u32, | ||
pub burst_size: u32, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Retry { | ||
pub max_attempts: u32, | ||
pub backoff_ms: u64, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct RouteConfig { | ||
routes: HashMap<String, Route>, | ||
} | ||
|
||
impl RouteConfig { | ||
pub fn new() -> Self { | ||
Self { | ||
routes: HashMap::new(), | ||
} | ||
} | ||
|
||
pub fn add_route(&mut self, route: Route) { | ||
self.routes.insert(route.id.clone(), route); | ||
} | ||
|
||
pub fn get_route(&self, id: &str) -> Option<&Route> { | ||
self.routes.get(id) | ||
} | ||
|
||
pub fn remove_route(&mut self, id: &str) -> Option<Route> { | ||
self.routes.remove(id) | ||
} | ||
|
||
pub fn find_route_by_path(&self, path: &str, method: &str) -> Option<&Route> { | ||
self.routes.values().find(|route| { | ||
route.path == path && route.methods.iter().any(|m| m == method) | ||
}) | ||
} | ||
|
||
pub fn get_all_routes(&self) -> Vec<&Route> { | ||
self.routes.values().collect() | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// src/config/settings.rs | ||
use config::{Config, ConfigError, Environment, File}; | ||
use serde::Deserialize; | ||
use std::env; | ||
|
||
#[derive(Debug, Deserialize, Clone)] | ||
pub struct Settings { | ||
pub server: ServerSettings, | ||
pub database: Option<DatabaseSettings>, | ||
pub jwt: JwtSettings, | ||
pub cors: CorsSettings, | ||
pub metrics: MetricsSettings, | ||
} | ||
|
||
#[derive(Debug, Deserialize, Clone)] | ||
pub struct ServerSettings { | ||
pub host: String, | ||
pub port: u16, | ||
pub workers: usize, | ||
pub timeout: u64, | ||
} | ||
|
||
#[derive(Debug, Deserialize, Clone)] | ||
pub struct DatabaseSettings { | ||
pub url: String, | ||
pub max_connections: u32, | ||
} | ||
|
||
#[derive(Debug, Deserialize, Clone)] | ||
pub struct JwtSettings { | ||
pub secret: String, | ||
pub expiration: i64, | ||
pub refresh_expiration: i64, | ||
} | ||
|
||
#[derive(Debug, Deserialize, Clone)] | ||
pub struct CorsSettings { | ||
pub allowed_origins: Vec<String>, | ||
pub allowed_methods: Vec<String>, | ||
pub allowed_headers: Vec<String>, | ||
pub max_age: u32, | ||
} | ||
|
||
#[derive(Debug, Deserialize, Clone)] | ||
pub struct MetricsSettings { | ||
pub enabled: bool, | ||
pub path: String, | ||
} | ||
|
||
|
||
// src/config/settings.rs | ||
impl Settings { | ||
pub fn new() -> Result<Self, ConfigError> { | ||
let run_mode = env::var("RUN_MODE").unwrap_or_else(|_| "development".into()); | ||
|
||
let s = Config::builder() | ||
// Cambiar la ruta para buscar en el directorio actual | ||
.add_source(File::with_name("./config/default")) | ||
.add_source(File::with_name(&format!("./config/{}", run_mode)).required(false)) | ||
.add_source(Environment::with_prefix("APP")) | ||
.build()?; | ||
|
||
s.try_deserialize() | ||
} | ||
|
||
|
||
|
||
|
||
pub fn from_env() -> Result<Self, ConfigError> { | ||
let s = Config::builder() | ||
.add_source(Environment::with_prefix("APP")) | ||
.build()?; | ||
|
||
s.try_deserialize() | ||
} | ||
|
||
pub fn is_development(&self) -> bool { | ||
env::var("RUN_MODE").unwrap_or_else(|_| "development".into()) == "development" | ||
} | ||
} | ||
|
||
// Implementación de valores por defecto | ||
impl Default for Settings { | ||
fn default() -> Self { | ||
Self { | ||
server: ServerSettings { | ||
host: "127.0.0.1".to_string(), | ||
port: 3000, | ||
workers: num_cpus::get(), | ||
timeout: 30, | ||
}, | ||
database: None, | ||
jwt: JwtSettings { | ||
secret: "your-secret-key".to_string(), | ||
expiration: 3600, | ||
refresh_expiration: 86400, | ||
}, | ||
cors: CorsSettings { | ||
allowed_origins: vec!["http://localhost:5173".to_string()], | ||
allowed_methods: vec!["GET".to_string(), "POST".to_string(), "PUT".to_string(), "DELETE".to_string()], | ||
allowed_headers: vec!["Content-Type".to_string(), "Authorization".to_string()], | ||
max_age: 3600, | ||
}, | ||
metrics: MetricsSettings { | ||
enabled: true, | ||
path: "/metrics".to_string(), | ||
}, | ||
} | ||
} | ||
} |
Oops, something went wrong.