Organize device inventory by customer and restrict token access to its audience
This commit is contained in:
+29
-14
@@ -38,9 +38,21 @@ struct Devices {
|
||||
}
|
||||
#[derive(Deserialize, schemars::JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct Fleet {
|
||||
tenant_id: Option<Uuid>,
|
||||
cursor: Option<String>,
|
||||
limit: Option<u16>,
|
||||
#[serde(default)]
|
||||
view: crate::devices::View,
|
||||
status: Option<crate::devices::Status>,
|
||||
q: Option<String>,
|
||||
}
|
||||
#[derive(Deserialize, schemars::JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct Device {
|
||||
tenant_id: Uuid,
|
||||
asset_id: Uuid,
|
||||
agent_id: Option<Uuid>,
|
||||
}
|
||||
#[derive(Deserialize, schemars::JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
@@ -96,9 +108,9 @@ fn tools() -> Vec<Tool> {
|
||||
"tenants.list",
|
||||
"List only the authenticated identity's tenants.",
|
||||
),
|
||||
tool::<Devices>(
|
||||
tool::<Fleet>(
|
||||
"inventory.list_devices",
|
||||
"Stored inventory with source, completeness and timestamps; no live collection.",
|
||||
"List current, previously connected devices. Omit tenant_id for all authorized customers. Use view=history for retired or never-seen installations.",
|
||||
),
|
||||
tool::<Device>(
|
||||
"inventory.get_device",
|
||||
@@ -195,29 +207,32 @@ impl Adapter {
|
||||
.0)
|
||||
}
|
||||
"inventory.list_devices" => {
|
||||
let i: Devices = parse(args)?;
|
||||
Ok(crate::api::devices_page(
|
||||
State(self.state.clone()),
|
||||
h,
|
||||
Path(i.tenant_id),
|
||||
axum::extract::Query(crate::pagination::PageQuery {
|
||||
let i: Fleet = parse(args)?;
|
||||
crate::devices::list(
|
||||
&self.state,
|
||||
&h,
|
||||
i.tenant_id,
|
||||
crate::devices::Filters {
|
||||
cursor: i.cursor,
|
||||
limit: i.limit,
|
||||
}),
|
||||
view: i.view,
|
||||
status: i.status,
|
||||
q: i.q,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map_err(map_http)?
|
||||
.0)
|
||||
}
|
||||
"inventory.get_device" => {
|
||||
let i: Device = parse(args)?;
|
||||
Ok(crate::api::device(
|
||||
Ok(crate::devices::detail(
|
||||
State(self.state.clone()),
|
||||
h,
|
||||
Path((i.tenant_id, i.asset_id)),
|
||||
axum::extract::Query(crate::devices::DetailQuery {
|
||||
agent_id: i.agent_id,
|
||||
}),
|
||||
)
|
||||
.await
|
||||
.map_err(map_http)?
|
||||
.await?
|
||||
.0)
|
||||
}
|
||||
"monitoring.get_health" => {
|
||||
|
||||
Reference in New Issue
Block a user