style: cargo fmt --all — make codebase rustfmt-clean
Some checks failed
Build and Test / Build Server (Linux) (push) Failing after 2m59s
Build and Test / Build Agent (Windows) (push) Has started running
Build and Test / Security Audit (push) Has been cancelled
Build and Test / Build Summary (push) Has been cancelled
Run Tests / Test Server (push) Has been cancelled
Run Tests / Test Agent (push) Has been cancelled
Run Tests / Code Coverage (push) Has been cancelled
Run Tests / Lint and Format Check (push) Has been cancelled
Some checks failed
Build and Test / Build Server (Linux) (push) Failing after 2m59s
Build and Test / Build Agent (Windows) (push) Has started running
Build and Test / Security Audit (push) Has been cancelled
Build and Test / Build Summary (push) Has been cancelled
Run Tests / Test Server (push) Has been cancelled
Run Tests / Test Agent (push) Has been cancelled
Run Tests / Code Coverage (push) Has been cancelled
Run Tests / Lint and Format Check (push) Has been cancelled
First run of the build-and-test CI gate (cargo fmt --all -- --check) surfaced pre-existing formatting drift across the agent and server crates. Apply rustfmt across the workspace so the codebase meets its own CI gate. Pure formatting; no logic changes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,12 +3,12 @@
|
||||
//! Handles generation and validation of 6-digit support codes
|
||||
//! for one-time remote support sessions.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
use chrono::{DateTime, Utc};
|
||||
use rand::Rng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
use uuid::Uuid;
|
||||
|
||||
/// A support session code
|
||||
@@ -27,10 +27,10 @@ pub struct SupportCode {
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum CodeStatus {
|
||||
Pending, // Waiting for client to connect
|
||||
Connected, // Client connected, session active
|
||||
Completed, // Session ended normally
|
||||
Cancelled, // Code cancelled by tech
|
||||
Pending, // Waiting for client to connect
|
||||
Connected, // Client connected, session active
|
||||
Completed, // Session ended normally
|
||||
Cancelled, // Code cancelled by tech
|
||||
}
|
||||
|
||||
/// Request to create a new support code
|
||||
@@ -69,11 +69,11 @@ impl SupportCodeManager {
|
||||
async fn generate_unique_code(&self) -> String {
|
||||
let codes = self.codes.read().await;
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
|
||||
loop {
|
||||
let code: u32 = rng.gen_range(100000..999999);
|
||||
let code_str = code.to_string();
|
||||
|
||||
|
||||
if !codes.contains_key(&code_str) {
|
||||
return code_str;
|
||||
}
|
||||
@@ -84,11 +84,13 @@ impl SupportCodeManager {
|
||||
pub async fn create_code(&self, request: CreateCodeRequest) -> SupportCode {
|
||||
let code = self.generate_unique_code().await;
|
||||
let session_id = Uuid::new_v4();
|
||||
|
||||
|
||||
let support_code = SupportCode {
|
||||
code: code.clone(),
|
||||
session_id,
|
||||
created_by: request.technician_name.unwrap_or_else(|| "Unknown".to_string()),
|
||||
created_by: request
|
||||
.technician_name
|
||||
.unwrap_or_else(|| "Unknown".to_string()),
|
||||
created_at: Utc::now(),
|
||||
status: CodeStatus::Pending,
|
||||
client_name: None,
|
||||
@@ -108,10 +110,12 @@ impl SupportCodeManager {
|
||||
/// Validate a code and return session info
|
||||
pub async fn validate_code(&self, code: &str) -> CodeValidation {
|
||||
let codes = self.codes.read().await;
|
||||
|
||||
|
||||
match codes.get(code) {
|
||||
Some(support_code) => {
|
||||
if support_code.status == CodeStatus::Pending || support_code.status == CodeStatus::Connected {
|
||||
if support_code.status == CodeStatus::Pending
|
||||
|| support_code.status == CodeStatus::Connected
|
||||
{
|
||||
CodeValidation {
|
||||
valid: true,
|
||||
session_id: Some(support_code.session_id.to_string()),
|
||||
@@ -137,7 +141,12 @@ impl SupportCodeManager {
|
||||
}
|
||||
|
||||
/// Mark a code as connected
|
||||
pub async fn mark_connected(&self, code: &str, client_name: Option<String>, client_machine: Option<String>) {
|
||||
pub async fn mark_connected(
|
||||
&self,
|
||||
code: &str,
|
||||
client_name: Option<String>,
|
||||
client_machine: Option<String>,
|
||||
) {
|
||||
let mut codes = self.codes.write().await;
|
||||
if let Some(support_code) = codes.get_mut(code) {
|
||||
support_code.status = CodeStatus::Connected;
|
||||
@@ -180,7 +189,9 @@ impl SupportCodeManager {
|
||||
pub async fn cancel_code(&self, code: &str) -> bool {
|
||||
let mut codes = self.codes.write().await;
|
||||
if let Some(support_code) = codes.get_mut(code) {
|
||||
if support_code.status == CodeStatus::Pending || support_code.status == CodeStatus::Connected {
|
||||
if support_code.status == CodeStatus::Pending
|
||||
|| support_code.status == CodeStatus::Connected
|
||||
{
|
||||
support_code.status = CodeStatus::Cancelled;
|
||||
return true;
|
||||
}
|
||||
@@ -191,13 +202,19 @@ impl SupportCodeManager {
|
||||
/// Check if a code is cancelled
|
||||
pub async fn is_cancelled(&self, code: &str) -> bool {
|
||||
let codes = self.codes.read().await;
|
||||
codes.get(code).map(|c| c.status == CodeStatus::Cancelled).unwrap_or(false)
|
||||
codes
|
||||
.get(code)
|
||||
.map(|c| c.status == CodeStatus::Cancelled)
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Check if a code is valid for connection (exists and is pending)
|
||||
pub async fn is_valid_for_connection(&self, code: &str) -> bool {
|
||||
let codes = self.codes.read().await;
|
||||
codes.get(code).map(|c| c.status == CodeStatus::Pending).unwrap_or(false)
|
||||
codes
|
||||
.get(code)
|
||||
.map(|c| c.status == CodeStatus::Pending)
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
/// List all codes (for dashboard)
|
||||
@@ -209,7 +226,8 @@ impl SupportCodeManager {
|
||||
/// List active codes only
|
||||
pub async fn list_active_codes(&self) -> Vec<SupportCode> {
|
||||
let codes = self.codes.read().await;
|
||||
codes.values()
|
||||
codes
|
||||
.values()
|
||||
.filter(|c| c.status == CodeStatus::Pending || c.status == CodeStatus::Connected)
|
||||
.cloned()
|
||||
.collect()
|
||||
|
||||
Reference in New Issue
Block a user