Plan device actions exclusively as approved scripts and provide reboot library revisions
This commit is contained in:
@@ -588,11 +588,14 @@ async fn installed(
|
||||
) -> Result<Response, Error> {
|
||||
let (tenant, agent) = device(&s, peer, &headers).await?;
|
||||
let mut tx = rmm_persistence::tenant_tx(&s.pool, tenant).await?;
|
||||
let row = sqlx::query("SELECT reported_agent_version,connection_generation,last_contact_at FROM agent_installations WHERE agent_id=$1 AND revoked_at IS NULL").bind(agent).fetch_one(&mut *tx).await?;
|
||||
let row = sqlx::query("SELECT asset_id,enrollment_generation,assignment_version,capabilities,reported_agent_version,connection_generation,last_contact_at FROM agent_installations WHERE agent_id=$1 AND revoked_at IS NULL").bind(agent).fetch_one(&mut *tx).await?;
|
||||
tx.commit().await?;
|
||||
Ok((
|
||||
[("cache-control", "private, no-store")],
|
||||
Json(json!({"agent_id":agent,
|
||||
Json(json!({"tenant_id":tenant,"asset_id":row.get::<Uuid,_>("asset_id"),"agent_id":agent,
|
||||
"enrollment_generation":row.get::<i64,_>("enrollment_generation"),
|
||||
"assignment_version":row.get::<i64,_>("assignment_version"),
|
||||
"capabilities":row.get::<Value,_>("capabilities"),
|
||||
"agent_version":row.get::<Option<String>,_>("reported_agent_version"),
|
||||
"connection_generation":row.get::<i64,_>("connection_generation"),
|
||||
"last_contact_at":row.get::<Option<chrono::DateTime<chrono::Utc>>,_>("last_contact_at")})),
|
||||
@@ -1256,19 +1259,17 @@ mod tests {
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn plan_request_accepts_release_id_but_never_user_supplied_local_bindings() {
|
||||
fn update_releases_are_not_device_job_plans() {
|
||||
let mut value = json!({"tenant_id":"11111111-1111-4111-8111-111111111111","action":"update_agent","targets":{"asset_ids":["11111111-1111-4111-8111-111111111112"]},
|
||||
"parameters":{"release_id":"11111111-1111-4111-8111-111111111113","execution_identity":"root","timeout_seconds":600,"max_output_bytes":65536},
|
||||
"schedule":{"not_before":"2030-01-01T12:00:00Z","start_before":"2030-01-01T12:10:00Z","offline_policy":"wait_until_deadline"},"rollout":{"max_parallel":1,"halt_after_failures":1},"reason":"codec only"});
|
||||
let parsed: crate::jobs::PlanRequest = serde_json::from_value(value.clone()).unwrap();
|
||||
assert!(matches!(parsed, crate::jobs::PlanRequest::AgentUpdate(_)));
|
||||
// The old synchronous resolver cannot manufacture local state.
|
||||
assert!(
|
||||
parsed
|
||||
.resolve(Uuid::parse_str(value["tenant_id"].as_str().unwrap()).unwrap())
|
||||
.is_err()
|
||||
);
|
||||
value["parameters"]["predecessor"] = json!({"installed_record_sha256":"00".repeat(32)});
|
||||
assert!(serde_json::from_value::<crate::jobs::PlanRequest>(value).is_err());
|
||||
let tenant = Uuid::parse_str(value["tenant_id"].as_str().unwrap()).unwrap();
|
||||
for local_binding in [false, true] {
|
||||
if local_binding {
|
||||
value["parameters"]["predecessor"] = json!({"installed_record_sha256":"00".repeat(32)});
|
||||
}
|
||||
let parsed: crate::jobs::PlanRequest = serde_json::from_value(value.clone()).unwrap();
|
||||
assert_eq!(parsed.resolve(tenant).err().unwrap().1, "SCRIPT_ACTION_REQUIRED");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user