Add versioned script library, reconcile permit refusals and compact helper captures
This commit is contained in:
+23
-18
@@ -53,7 +53,11 @@ pub fn scope(p: &Principal, tenant: Uuid, write: bool) -> Result<()> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
async fn principal(state: &crate::State, h: &HeaderMap, write: bool) -> Result<Principal> {
|
||||
pub(crate) async fn principal(
|
||||
state: &crate::State,
|
||||
h: &HeaderMap,
|
||||
write: bool,
|
||||
) -> Result<Principal> {
|
||||
state
|
||||
.auth
|
||||
.principal(state, h, write)
|
||||
@@ -420,7 +424,7 @@ pub async fn plan_request(
|
||||
reason: input.reason,
|
||||
artifact_ids: Vec::new(),
|
||||
};
|
||||
plan_resolved(state, p, tenant, resolved, Some(updates)).await
|
||||
plan_resolved(state, p, tenant, resolved, Some(updates), None).await
|
||||
}
|
||||
fn validate_variants(variants: &[Variant]) -> Result<()> {
|
||||
if variants.is_empty() || variants.len() > 2 {
|
||||
@@ -531,9 +535,9 @@ pub async fn plan(
|
||||
"AGENT_UPDATE_RELEASE_ID_REQUIRED",
|
||||
));
|
||||
}
|
||||
plan_resolved(state, p, tenant, input, None).await
|
||||
plan_resolved(state, p, tenant, input, None, None).await
|
||||
}
|
||||
async fn plan_resolved(
|
||||
pub(crate) async fn plan_resolved(
|
||||
state: &crate::State,
|
||||
p: &Principal,
|
||||
tenant: Uuid,
|
||||
@@ -541,6 +545,7 @@ async fn plan_resolved(
|
||||
updates: Option<
|
||||
std::collections::BTreeMap<Uuid, rmm_domain::agent_update::ResolvedAgentUpdate>,
|
||||
>,
|
||||
script_revision: Option<ScriptRevisionReference>,
|
||||
) -> Result<Value> {
|
||||
scope(p, tenant, true)?;
|
||||
let now = Utc::now();
|
||||
@@ -716,6 +721,7 @@ async fn plan_resolved(
|
||||
halt_after_failures: input.rollout.halt_after_failures,
|
||||
recipe_references,
|
||||
artifact_references,
|
||||
script_revision,
|
||||
};
|
||||
crate::windows_msi_catalog::validate_plan_bindings(&payload)?;
|
||||
crate::agent_updates::validate_plan_bindings(&payload)?;
|
||||
@@ -1085,11 +1091,7 @@ pub async fn operation(
|
||||
"needs_attention"
|
||||
} else if c("succeeded") == n {
|
||||
"succeeded"
|
||||
} else if c("succeeded")
|
||||
+ c("failed")
|
||||
+ c("cancelled")
|
||||
+ c("expired")
|
||||
+ c("closed_unknown")
|
||||
} else if c("succeeded") + c("failed") + c("cancelled") + c("expired") + c("closed_unknown")
|
||||
== n
|
||||
{
|
||||
if c("succeeded") > 0 {
|
||||
@@ -1240,13 +1242,12 @@ pub async fn close_unknown(
|
||||
}
|
||||
let mut tx = rmm_persistence::tenant_tx(&state.pool, tenant).await?;
|
||||
crate::permissions::require_principal(&mut tx, p, "plans:approve").await?;
|
||||
let row = sqlx::query(
|
||||
"SELECT attempt_id,state,revision,result FROM jobs WHERE job_id=$1 FOR UPDATE",
|
||||
)
|
||||
.bind(id)
|
||||
.fetch_optional(&mut *tx)
|
||||
.await?
|
||||
.ok_or_else(missing)?;
|
||||
let row =
|
||||
sqlx::query("SELECT attempt_id,state,revision,result FROM jobs WHERE job_id=$1 FOR UPDATE")
|
||||
.bind(id)
|
||||
.fetch_optional(&mut *tx)
|
||||
.await?
|
||||
.ok_or_else(missing)?;
|
||||
if row.get::<Uuid, _>("attempt_id") != input.attempt_id
|
||||
|| row.get::<i64, _>("revision") != input.revision
|
||||
{
|
||||
@@ -1286,9 +1287,11 @@ pub async fn close_unknown(
|
||||
.bind(tenant)
|
||||
.bind(Uuid::new_v4())
|
||||
.bind(&p.name)
|
||||
.bind(json!({"job_id":id,"attempt_id":input.attempt_id,"grant_id":grant,"closure_id":closure,
|
||||
.bind(
|
||||
json!({"job_id":id,"attempt_id":input.attempt_id,"grant_id":grant,"closure_id":closure,
|
||||
"original_revision":input.revision,"reason":input.reason,"session_hash":session,
|
||||
"approval_origin":p.approval_origin(),"testsimulation":p.testsimulation}))
|
||||
"approval_origin":p.approval_origin(),"testsimulation":p.testsimulation}),
|
||||
)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
tx.commit().await?;
|
||||
@@ -1569,6 +1572,8 @@ mod windows_contract_tests {
|
||||
crate::job_signer::JobSigner::load_or_create(&temp.join("key.pem")).unwrap(),
|
||||
),
|
||||
};
|
||||
crate::script_library::tests::revision_plan_contract(&state, &principal, assets[0], assets[1])
|
||||
.await;
|
||||
let mut request = input();
|
||||
request.targets.asset_ids = assets.clone();
|
||||
let view = plan(&state, &principal, tenant, request.clone())
|
||||
|
||||
Reference in New Issue
Block a user