Skip to content

Commit 3e3f690

Browse files
lxsaahCopilot
andauthored
36 cross process cli for aimdb introspection (#42)
* optimize timestamp generation * change timestamp type to f64 for accurate Unix timestamp representation * initial implementation aimdb cli * update dependencies and enhance security checks in Makefile and deny.toml * Update examples/remote-access-demo/src/server.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix clippy error --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent a791755 commit 3e3f690

22 files changed

Lines changed: 2075 additions & 20 deletions

File tree

Cargo.lock

Lines changed: 338 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# AimDB Makefile
22
# Simple automation for common development tasks
33

4-
.PHONY: help build test clean fmt fmt-check clippy doc all check test-embedded examples
4+
.PHONY: help build test clean fmt fmt-check clippy doc all check test-embedded examples deny audit security
55
.DEFAULT_GOAL := help
66

77
# Colors for output
@@ -29,6 +29,11 @@ help:
2929
@printf " check Comprehensive development check (fmt + clippy + all tests)\n"
3030
@printf " test-embedded Test embedded/MCU cross-compilation compatibility\n"
3131
@printf "\n"
32+
@printf " $(YELLOW)Security & Quality:$(NC)\n"
33+
@printf " deny Check dependencies (licenses, advisories, bans)\n"
34+
@printf " audit Audit dependencies for known vulnerabilities\n"
35+
@printf " security Run all security checks (deny + audit)\n"
36+
@printf "\n"
3237
@printf " $(YELLOW)Convenience:$(NC)\n"
3338
@printf " all Build everything\n"
3439

@@ -146,13 +151,40 @@ examples:
146151
cargo build --package embassy-mqtt-connector-demo --target thumbv7em-none-eabihf
147152
@printf "$(GREEN)All examples built successfully!$(NC)\n"
148153

154+
## Security & Quality commands
155+
deny:
156+
@printf "$(GREEN)Checking dependencies with cargo-deny...$(NC)\n"
157+
@if ! command -v cargo-deny >/dev/null 2>&1; then \
158+
printf "$(YELLOW) ⚠ cargo-deny not found, installing...$(NC)\n"; \
159+
cargo install cargo-deny --locked; \
160+
fi
161+
@printf "$(YELLOW) → Checking licenses$(NC)\n"
162+
@printf "$(YELLOW) → Checking security advisories$(NC)\n"
163+
@printf "$(YELLOW) → Checking banned dependencies$(NC)\n"
164+
@printf "$(YELLOW) → Checking dependency sources$(NC)\n"
165+
cargo deny check
166+
167+
audit:
168+
@printf "$(GREEN)Auditing dependencies for vulnerabilities...$(NC)\n"
169+
@if ! command -v cargo-audit >/dev/null 2>&1; then \
170+
printf "$(YELLOW) ⚠ cargo-audit not found, installing...$(NC)\n"; \
171+
cargo install cargo-audit --locked; \
172+
fi
173+
cargo audit
174+
175+
security: deny audit
176+
@printf "$(GREEN)All security checks completed!$(NC)\n"
177+
@printf "$(BLUE)✓ Dependencies verified (licenses, advisories, bans)$(NC)\n"
178+
@printf "$(BLUE)✓ Known vulnerabilities checked$(NC)\n"
179+
149180
## Convenience commands
150-
check: fmt-check clippy test test-embedded
181+
check: fmt-check clippy test test-embedded deny
151182
@printf "$(GREEN)Comprehensive development checks completed!$(NC)\n"
152183
@printf "$(BLUE)✓ Code formatting verified$(NC)\n"
153184
@printf "$(BLUE)✓ Linter passed$(NC)\n"
154185
@printf "$(BLUE)✓ All valid feature combinations tested$(NC)\n"
155186
@printf "$(BLUE)✓ Embedded target compatibility verified$(NC)\n"
187+
@printf "$(BLUE)✓ Dependencies verified (deny)$(NC)\n"
156188

157189
all: build test examples
158190
@printf "$(GREEN)Build and test completed!$(NC)\n"

aimdb-core/src/remote/handler.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,12 +1059,10 @@ async fn stream_subscription_events(
10591059

10601060
while let Some(json_value) = value_rx.recv().await {
10611061
// Generate timestamp in "secs.nanosecs" format
1062-
let timestamp = format!(
1063-
"{:?}",
1064-
std::time::SystemTime::now()
1065-
.duration_since(std::time::UNIX_EPOCH)
1066-
.unwrap_or_default()
1067-
);
1062+
let duration = std::time::SystemTime::now()
1063+
.duration_since(std::time::UNIX_EPOCH)
1064+
.unwrap_or_default();
1065+
let timestamp = format!("{}.{:09}", duration.as_secs(), duration.subsec_nanos());
10681066

10691067
// Create event
10701068
let event = Event {

aimdb-core/src/remote/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ mod protocol;
4141
pub use config::{AimxConfig, SecurityPolicy};
4242
pub use error::{RemoteError, RemoteResult};
4343
pub use metadata::RecordMetadata;
44-
pub use protocol::{Event, HelloMessage, Request, Response, WelcomeMessage};
44+
pub use protocol::{ErrorObject, Event, HelloMessage, Request, Response, WelcomeMessage};
4545

4646
// Internal exports for implementation
4747
pub(crate) mod handler;

deny.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ allow = [
88
"ISC", # ISC License - used by ring, rustls-webpki, untrusted
99
"0BSD", # BSD Zero Clause License - used by embassy-net dependencies
1010
"Unicode-3.0",
11+
"MPL-2.0", # Mozilla Public License 2.0 - used by colored crate (CLI only)
1112
]
1213

1314
confidence-threshold = 0.8

examples/remote-access-demo/src/server.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use tracing::info;
2424
struct Temperature {
2525
sensor_id: String,
2626
celsius: f64,
27-
timestamp: u64,
27+
timestamp: f64, // Unix timestamp as f64 (seconds since epoch with fractional nanoseconds, e.g., 1730379296.123456789)
2828
}
2929

3030
/// System status information
@@ -130,11 +130,17 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
130130

131131
// Produce some initial data
132132
let temp_producer = db.producer::<Temperature>();
133+
let initial_duration = std::time::SystemTime::now()
134+
.duration_since(std::time::UNIX_EPOCH)
135+
.unwrap();
136+
let initial_timestamp = initial_duration.as_secs() as f64
137+
+ initial_duration.subsec_nanos() as f64 / 1_000_000_000.0;
138+
133139
temp_producer
134140
.produce(Temperature {
135141
sensor_id: "sensor-01".to_string(),
136142
celsius: 22.5,
137-
timestamp: 1698764400,
143+
timestamp: initial_timestamp,
138144
})
139145
.await?;
140146

@@ -180,13 +186,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
180186
counter += 1;
181187
let temp = 20.0 + (counter as f64 * 0.5) + (counter as f64 % 10.0);
182188

189+
let duration = std::time::SystemTime::now()
190+
.duration_since(std::time::UNIX_EPOCH)
191+
.unwrap();
192+
let timestamp =
193+
duration.as_secs() as f64 + duration.subsec_nanos() as f64 / 1_000_000_000.0;
194+
183195
let reading = Temperature {
184196
sensor_id: format!("sensor-{:02}", (counter % 3) + 1),
185197
celsius: temp,
186-
timestamp: std::time::SystemTime::now()
187-
.duration_since(std::time::UNIX_EPOCH)
188-
.unwrap()
189-
.as_secs(),
198+
timestamp,
190199
};
191200

192201
if let Err(e) = temp_producer_clone.produce(reading.clone()).await {

tools/aimdb-cli/Cargo.toml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,46 @@ edition.workspace = true
55
license.workspace = true
66
description = "Command-line interface for AimDB - development and administration tool"
77

8+
[[bin]]
9+
name = "aimdb"
10+
path = "src/main.rs"
11+
812
[dependencies]
13+
# Core dependencies - reuse protocol types from aimdb-core
14+
aimdb-core = { path = "../../aimdb-core", features = ["std"] }
15+
serde = { version = "1", features = ["derive"] }
16+
serde_json = "1"
17+
18+
# CLI framework
19+
clap = { version = "4", features = ["derive", "cargo"] }
20+
21+
# Async runtime (must match AimDB runtime)
22+
tokio = { version = "1", features = [
23+
"net",
24+
"io-util",
25+
"rt-multi-thread",
26+
"signal",
27+
"macros",
28+
"time",
29+
"fs",
30+
] }
31+
32+
# Error handling
33+
anyhow = "1"
34+
thiserror = "1"
35+
36+
# Output formatting
37+
tabled = "0.20"
38+
colored = "3"
39+
chrono = "0.4"
40+
41+
# Optional: YAML output
42+
serde_yaml = { version = "0.9", optional = true }
43+
44+
[features]
45+
default = []
46+
yaml = ["serde_yaml"]
47+
48+
[dev-dependencies]
49+
tokio-test = "0.4"
50+
tempfile = "3"

0 commit comments

Comments
 (0)