mirror of
https://github.com/BetterCorp/BetterFrame.git
synced 2026-05-26 17:56:34 +00:00
feat(kiosk): include kiosk_id in Axiom log entries after pairing
After successful claim, kiosk_id from server response is stored globally and included in all subsequent Axiom log entries for kiosk identification. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
05853473a1
commit
5768e325b1
2 changed files with 17 additions and 0 deletions
|
|
@ -19,6 +19,13 @@ pub struct AxiomLayer {
|
||||||
dataset: String,
|
dataset: String,
|
||||||
buffer: Arc<Mutex<Vec<serde_json::Value>>>,
|
buffer: Arc<Mutex<Vec<serde_json::Value>>>,
|
||||||
hostname: String,
|
hostname: String,
|
||||||
|
kiosk_id: Arc<Mutex<Option<String>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
static GLOBAL_KIOSK_ID: Mutex<Option<String>> = Mutex::new(None);
|
||||||
|
|
||||||
|
pub fn set_kiosk_id(id: String) {
|
||||||
|
*GLOBAL_KIOSK_ID.lock().unwrap() = Some(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AxiomLayer {
|
impl AxiomLayer {
|
||||||
|
|
@ -39,6 +46,7 @@ impl AxiomLayer {
|
||||||
dataset,
|
dataset,
|
||||||
buffer: Arc::new(Mutex::new(Vec::with_capacity(BATCH_SIZE))),
|
buffer: Arc::new(Mutex::new(Vec::with_capacity(BATCH_SIZE))),
|
||||||
hostname,
|
hostname,
|
||||||
|
kiosk_id: Arc::new(Mutex::new(None)),
|
||||||
};
|
};
|
||||||
|
|
||||||
let flush_buffer = layer.buffer.clone();
|
let flush_buffer = layer.buffer.clone();
|
||||||
|
|
@ -125,6 +133,10 @@ impl<S: Subscriber> Layer<S> for AxiomLayer {
|
||||||
.remove("message")
|
.remove("message")
|
||||||
.unwrap_or(serde_json::Value::String(String::new()));
|
.unwrap_or(serde_json::Value::String(String::new()));
|
||||||
|
|
||||||
|
let kiosk_id = GLOBAL_KIOSK_ID.lock().ok()
|
||||||
|
.and_then(|g| g.clone())
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
let entry = serde_json::json!({
|
let entry = serde_json::json!({
|
||||||
"_time": chrono_now(),
|
"_time": chrono_now(),
|
||||||
"level": level,
|
"level": level,
|
||||||
|
|
@ -132,6 +144,7 @@ impl<S: Subscriber> Layer<S> for AxiomLayer {
|
||||||
"target": target,
|
"target": target,
|
||||||
"host": self.hostname,
|
"host": self.hostname,
|
||||||
"service": "betterframe-kiosk",
|
"service": "betterframe-kiosk",
|
||||||
|
"kiosk_id": kiosk_id,
|
||||||
"fields": serde_json::Value::Object(fields),
|
"fields": serde_json::Value::Object(fields),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -271,6 +271,7 @@ fn encrypt_key_file() -> PathBuf {
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct ClaimResp {
|
struct ClaimResp {
|
||||||
status: String,
|
status: String,
|
||||||
|
kiosk_id: Option<String>,
|
||||||
kiosk_key: Option<String>,
|
kiosk_key: Option<String>,
|
||||||
kiosk_name: Option<String>,
|
kiosk_name: Option<String>,
|
||||||
cluster_key: Option<String>,
|
cluster_key: Option<String>,
|
||||||
|
|
@ -298,6 +299,9 @@ pub fn poll_claim(server: &str, code: &str) -> (String, String) {
|
||||||
if claim.status == "claimed" {
|
if claim.status == "claimed" {
|
||||||
let key = claim.kiosk_key.expect("missing kiosk_key");
|
let key = claim.kiosk_key.expect("missing kiosk_key");
|
||||||
let name = claim.kiosk_name.unwrap_or_else(|| "kiosk".into());
|
let name = claim.kiosk_name.unwrap_or_else(|| "kiosk".into());
|
||||||
|
if let Some(ref id) = claim.kiosk_id {
|
||||||
|
crate::axiom::set_kiosk_id(id.clone());
|
||||||
|
}
|
||||||
crate::at_rest::write_encrypted(&key_file(), key.as_bytes())
|
crate::at_rest::write_encrypted(&key_file(), key.as_bytes())
|
||||||
.expect("failed to save kiosk key");
|
.expect("failed to save kiosk key");
|
||||||
// Store cluster key for backward compat ONVIF password decryption.
|
// Store cluster key for backward compat ONVIF password decryption.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue