style(i18n): translate all code and comments to English
Rename French identifiers to English across all source files: - validate_cidr / validate_ip_in_network (was valider_*) - known_protocol (was protocole_connu) - counter / doubled (was compteur / double) - InvalidCidr / InvalidIp / IpOutsideNetwork (was *Invalide / *HorsReseau) - test names and error messages All comments, doc strings, .expect() messages, and tracing logs converted. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
135
src/models.rs
135
src/models.rs
@@ -1,132 +1,131 @@
|
||||
// models.rs — Modèles de données partagés (server + client)
|
||||
// models.rs — Shared data models (server + client)
|
||||
//
|
||||
// Ce module définit les structs qui représentent les entités métier du projet IPAM.
|
||||
// Ils sont compilés côté serveur ET côté WASM car Leptos en a besoin des deux côtés :
|
||||
// - Serveur : pour lire/écrire en BDD et rendre le HTML
|
||||
// - Client : pour afficher les données dans les composants Leptos
|
||||
// This module defines the structs that represent the IPAM domain entities.
|
||||
// They are compiled for both the server and WASM, because Leptos needs them
|
||||
// on both sides:
|
||||
// - Server : to read/write the database and render HTML
|
||||
// - Client : to display data inside Leptos components
|
||||
//
|
||||
// Chaque struct dérive `Serialize` et `Deserialize` de serde.
|
||||
// C'est obligatoire pour que Leptos puisse transférer les données entre
|
||||
// le serveur et le navigateur via les "server functions" (#[server]).
|
||||
// Each struct derives `Serialize` and `Deserialize` from serde.
|
||||
// This is required for Leptos to transfer data between the server and the
|
||||
// browser through server functions (#[server]).
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// ─── Réseau ───────────────────────────────────────────────────────────────────
|
||||
// ─── Network ──────────────────────────────────────────────────────────────────
|
||||
|
||||
/// Un réseau IP défini par sa plage CIDR.
|
||||
/// An IP network defined by its CIDR range.
|
||||
///
|
||||
/// Exemple : { id: 1, cidr: "192.168.1.0/24" }
|
||||
/// → plage de 192.168.1.0 à 192.168.1.255 (254 hôtes utilisables)
|
||||
/// Example: { id: 1, cidr: "192.168.1.0/24" }
|
||||
/// → covers 192.168.1.0 to 192.168.1.255 (254 usable hosts)
|
||||
///
|
||||
/// La notation CIDR (Classless Inter-Domain Routing) combine l'adresse réseau
|
||||
/// et le masque en un seul champ : <adresse>/<longueur du préfixe>.
|
||||
/// /24 = 24 bits de masque = 255.255.255.0
|
||||
/// CIDR (Classless Inter-Domain Routing) combines the network address and
|
||||
/// the subnet mask into a single field: <address>/<prefix length>.
|
||||
/// /24 = 24-bit mask = 255.255.255.0
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Network {
|
||||
/// Identifiant unique auto-incrémenté par la base de données.
|
||||
/// `i64` est le type entier signé 64 bits — correspond à `BIGINT` en SQL.
|
||||
/// Unique identifier, auto-incremented by the database.
|
||||
/// `i64` is a signed 64-bit integer — maps to `BIGINT` in SQL.
|
||||
pub id: i64,
|
||||
|
||||
/// Plage d'adresses en notation CIDR.
|
||||
/// Ex: "10.0.0.0/8", "172.16.0.0/12", "192.168.1.0/24"
|
||||
/// Address range in CIDR notation.
|
||||
/// Examples: "10.0.0.0/8", "172.16.0.0/12", "192.168.1.0/24"
|
||||
pub cidr: String,
|
||||
}
|
||||
|
||||
// ─── Hôte ─────────────────────────────────────────────────────────────────────
|
||||
// ─── Host ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
/// Un hôte (machine, serveur, équipement réseau) appartenant à un réseau.
|
||||
/// A host (server, workstation, network device) belonging to a network.
|
||||
///
|
||||
/// Contrainte : l'IP doit appartenir à la plage CIDR du réseau référencé
|
||||
/// par `network_id`. Cette contrainte est vérifiée à la création/modification.
|
||||
/// Constraint: the IP address must fall within the CIDR range of the network
|
||||
/// referenced by `network_id`. This is enforced on creation and update.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Host {
|
||||
pub id: i64,
|
||||
|
||||
/// Nom descriptif de l'hôte. Ex: "serveur-web-01", "routeur-principal"
|
||||
/// Human-readable name. Examples: "web-server-01", "main-router"
|
||||
pub name: String,
|
||||
|
||||
/// Adresse IPv4 de l'hôte, stockée en texte.
|
||||
/// Ex: "192.168.1.10"
|
||||
/// On utilise String plutôt que IpAddr pour simplifier la sérialisation
|
||||
/// et le stockage en base de données.
|
||||
/// IPv4 address stored as text. Example: "192.168.1.10"
|
||||
/// We use String instead of IpAddr to simplify serialization
|
||||
/// and database storage.
|
||||
pub ip: String,
|
||||
|
||||
/// Référence vers le réseau auquel appartient cet hôte.
|
||||
/// C'est une "clé étrangère" (Foreign Key) vers la table `networks`.
|
||||
/// Foreign key referencing the network this host belongs to.
|
||||
pub network_id: i64,
|
||||
}
|
||||
|
||||
// ─── Port ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
/// Un port réseau ouvert sur un hôte, avec sa description probable.
|
||||
/// A network port open on a host, with its likely protocol description.
|
||||
///
|
||||
/// Les numéros de ports standards (0–1023) sont des "well-known ports".
|
||||
/// Un port peut être associé à plusieurs applications (association non-stricte).
|
||||
/// Well-known ports (0–1023) have standardized protocol assignments.
|
||||
/// A port can be associated with multiple applications (non-strict relation).
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Port {
|
||||
/// Numéro de port TCP/UDP.
|
||||
/// `u16` : entier non signé 16 bits → plage 0 à 65535.
|
||||
/// C'est exactement la plage valide pour les ports réseau.
|
||||
/// TCP/UDP port number.
|
||||
/// `u16` is an unsigned 16-bit integer → range 0 to 65535,
|
||||
/// which exactly matches the valid range for network ports.
|
||||
pub number: u16,
|
||||
|
||||
/// Description du protocole probable sur ce port.
|
||||
/// `Option<String>` : peut être absent (None) si le protocole est inconnu.
|
||||
/// Ex: Some("SSH"), Some("HTTPS"), None
|
||||
/// Description of the likely protocol on this port.
|
||||
/// `Option<String>`: may be absent (None) when the protocol is unknown.
|
||||
/// Examples: Some("SSH"), Some("HTTPS"), None
|
||||
pub description: Option<String>,
|
||||
|
||||
/// Hôte sur lequel ce port est ouvert.
|
||||
/// The host on which this port is open.
|
||||
pub host_id: i64,
|
||||
}
|
||||
|
||||
impl Port {
|
||||
/// Retourne la description standard pour les ports les plus courants.
|
||||
/// Utilisé pour pré-remplir la description lors de l'ajout d'un port.
|
||||
/// Returns the standard description for common well-known ports.
|
||||
/// Used to pre-fill the description field when adding a port.
|
||||
///
|
||||
/// `match` est l'équivalent Rust d'un switch/case, mais exhaustif :
|
||||
/// le compilateur oblige à gérer tous les cas possibles.
|
||||
pub fn protocole_connu(numero: u16) -> Option<&'static str> {
|
||||
// `&'static str` : référence vers une chaîne qui vit toute la durée du programme
|
||||
// (les littéraux de chaînes comme "SSH" sont stockés dans le binaire compilé)
|
||||
match numero {
|
||||
21 => Some("FTP"),
|
||||
22 => Some("SSH"),
|
||||
23 => Some("Telnet"),
|
||||
25 => Some("SMTP"),
|
||||
53 => Some("DNS"),
|
||||
80 => Some("HTTP"),
|
||||
110 => Some("POP3"),
|
||||
143 => Some("IMAP"),
|
||||
443 => Some("HTTPS"),
|
||||
/// `match` is Rust's exhaustive pattern-matching construct (like switch/case,
|
||||
/// but the compiler enforces that all cases are handled).
|
||||
pub fn known_protocol(number: u16) -> Option<&'static str> {
|
||||
// `&'static str`: a reference to a string that lives for the entire
|
||||
// program lifetime (string literals are stored in the compiled binary).
|
||||
match number {
|
||||
21 => Some("FTP"),
|
||||
22 => Some("SSH"),
|
||||
23 => Some("Telnet"),
|
||||
25 => Some("SMTP"),
|
||||
53 => Some("DNS"),
|
||||
80 => Some("HTTP"),
|
||||
110 => Some("POP3"),
|
||||
143 => Some("IMAP"),
|
||||
443 => Some("HTTPS"),
|
||||
3306 => Some("MySQL"),
|
||||
5432 => Some("PostgreSQL"),
|
||||
6379 => Some("Redis"),
|
||||
8080 => Some("HTTP alternatif"),
|
||||
_ => None, // `_` est le pattern "tout le reste" (wildcard)
|
||||
8080 => Some("HTTP (alternate)"),
|
||||
_ => None, // `_` is the wildcard pattern — matches everything else
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Application ──────────────────────────────────────────────────────────────
|
||||
|
||||
/// Une application qui utilise un ou plusieurs ports.
|
||||
/// An application that uses one or more ports.
|
||||
///
|
||||
/// L'association entre application et port est non-stricte :
|
||||
/// un même port peut être partagé par plusieurs applications.
|
||||
/// Ex: le port 80 peut être utilisé par Nginx ET par un proxy applicatif.
|
||||
/// The association between an application and a port is non-strict:
|
||||
/// the same port can be shared by multiple applications.
|
||||
/// Example: port 80 might be used by both Nginx and an application proxy.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Application {
|
||||
pub id: i64,
|
||||
|
||||
/// Nom de l'application. Ex: "Nginx", "PostgreSQL", "Prometheus"
|
||||
/// Application name. Examples: "Nginx", "PostgreSQL", "Prometheus"
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
// ─── Association Application ↔ Port ──────────────────────────────────────────
|
||||
// ─── ApplicationPort ──────────────────────────────────────────────────────────
|
||||
|
||||
/// Lien entre une application et un port (relation many-to-many).
|
||||
/// Join record linking an application to a port (many-to-many relationship).
|
||||
///
|
||||
/// On utilise un struct dédié plutôt qu'un Vec<Port> dans Application
|
||||
/// pour correspondre directement à la table de jointure en base de données.
|
||||
/// A dedicated struct is used instead of Vec<Port> inside Application
|
||||
/// so it maps directly to the join table in the database.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ApplicationPort {
|
||||
pub application_id: i64,
|
||||
|
||||
Reference in New Issue
Block a user