Skip to content

Commit cd360d0

Browse files
committed
refactor(server): use protos for stored policy records
1 parent cad4ed3 commit cd360d0

2 files changed

Lines changed: 38 additions & 42 deletions

File tree

crates/openshell-server/src/persistence/mod.rs

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
mod postgres;
77
mod sqlite;
88

9+
pub use openshell_core::proto::{
10+
StoredDraftChunk as DraftChunkRecord, StoredPolicyRevision as PolicyRecord,
11+
};
12+
913
use openshell_core::{
1014
Error as CoreError, Result as CoreResult,
1115
proto::{
@@ -81,48 +85,6 @@ pub struct ObjectRecord {
8185
pub labels: Option<String>,
8286
}
8387

84-
/// Stored sandbox policy revision record.
85-
#[derive(Debug, Clone)]
86-
pub struct PolicyRecord {
87-
pub id: String,
88-
pub sandbox_id: String,
89-
pub version: i64,
90-
pub policy_payload: Vec<u8>,
91-
pub policy_hash: String,
92-
pub status: String,
93-
pub load_error: Option<String>,
94-
pub created_at_ms: i64,
95-
pub loaded_at_ms: Option<i64>,
96-
}
97-
98-
/// Stored draft policy chunk record.
99-
#[derive(Debug, Clone)]
100-
pub struct DraftChunkRecord {
101-
pub id: String,
102-
pub sandbox_id: String,
103-
pub draft_version: i64,
104-
pub status: String,
105-
pub rule_name: String,
106-
pub proposed_rule: Vec<u8>,
107-
pub rationale: String,
108-
pub security_notes: String,
109-
pub confidence: f64,
110-
pub created_at_ms: i64,
111-
pub decided_at_ms: Option<i64>,
112-
/// Denormalized endpoint host (lowercase) for DB-level dedup.
113-
pub host: String,
114-
/// Denormalized endpoint port for DB-level dedup.
115-
pub port: i32,
116-
/// Binary path that triggered the denial (for per-binary dedup).
117-
pub binary: String,
118-
/// How many times this endpoint has been seen across denial flush cycles.
119-
pub hit_count: i32,
120-
/// First time this endpoint was proposed (ms since epoch).
121-
pub first_seen_ms: i64,
122-
/// Most recent time this endpoint was re-proposed (ms since epoch).
123-
pub last_seen_ms: i64,
124-
}
125-
12688
/// Persistence store implementations.
12789
#[derive(Debug, Clone)]
12890
pub enum Store {

proto/openshell.proto

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,3 +1172,37 @@ message DraftChunkPayload {
11721172
// Current draft version for the owning sandbox.
11731173
int64 draft_version = 10;
11741174
}
1175+
1176+
// Internal stored policy revision row materialized from the generic objects table.
1177+
message StoredPolicyRevision {
1178+
string id = 1;
1179+
string sandbox_id = 2;
1180+
int64 version = 3;
1181+
bytes policy_payload = 4;
1182+
string policy_hash = 5;
1183+
string status = 6;
1184+
optional string load_error = 7;
1185+
int64 created_at_ms = 8;
1186+
optional int64 loaded_at_ms = 9;
1187+
}
1188+
1189+
// Internal stored draft chunk row materialized from the generic objects table.
1190+
message StoredDraftChunk {
1191+
string id = 1;
1192+
string sandbox_id = 2;
1193+
int64 draft_version = 3;
1194+
string status = 4;
1195+
string rule_name = 5;
1196+
bytes proposed_rule = 6;
1197+
string rationale = 7;
1198+
string security_notes = 8;
1199+
double confidence = 9;
1200+
int64 created_at_ms = 10;
1201+
optional int64 decided_at_ms = 11;
1202+
string host = 12;
1203+
int32 port = 13;
1204+
string binary = 14;
1205+
int32 hit_count = 15;
1206+
int64 first_seen_ms = 16;
1207+
int64 last_seen_ms = 17;
1208+
}

0 commit comments

Comments
 (0)