mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-19 00:02:03 +00:00
fix(deno-client): add approver
This commit is contained in:
@@ -1317,6 +1317,7 @@ pub async fn create_job_signature(
|
||||
let mut mac = HmacSha256::new_from_slice(key.as_bytes()).map_err(to_anyhow)?;
|
||||
mac.update(job_id.as_bytes());
|
||||
mac.update(resume_id.to_be_bytes().as_ref());
|
||||
tracing::info!("approver: {:?}", approver.approver);
|
||||
if let Some(approver) = approver.approver {
|
||||
mac.update(approver.as_bytes());
|
||||
}
|
||||
|
||||
@@ -3202,7 +3202,7 @@ def main():
|
||||
const job = Deno.env.get('WM_JOB_ID');
|
||||
const token = Deno.env.get('WM_TOKEN');
|
||||
const r = await fetch(
|
||||
`http://localhost:${port}/api/w/test-workspace/jobs/job_signature/${job}/0?token=${token}`,\
|
||||
`http://localhost:${port}/api/w/test-workspace/jobs/job_signature/${job}/0?token=${token}&approver=ruben`,\
|
||||
{\
|
||||
method: 'GET',\
|
||||
headers: { 'Authorization': `Bearer ${token}` }\
|
||||
@@ -3212,7 +3212,7 @@ def main():
|
||||
const secret = await r.text();\
|
||||
console.log('Secret: ' + secret + ' ' + job + ' ' + token);\
|
||||
const r2 = await fetch(
|
||||
`http://localhost:${port}/api/w/test-workspace/jobs/${op}/${job}/0/${secret}`,\
|
||||
`http://localhost:${port}/api/w/test-workspace/jobs/${op}/${job}/0/${secret}?approver=ruben`,\
|
||||
{\
|
||||
method: 'POST',\
|
||||
body: JSON.stringify('from job'),\
|
||||
@@ -3288,7 +3288,7 @@ def main():
|
||||
|
||||
let token = create_token_for_owner(&db, "test-workspace", "u/test-user", "", 100, "").await.unwrap();
|
||||
let secret = reqwest::get(format!(
|
||||
"http://localhost:{port}/api/w/test-workspace/jobs/job_signature/{second}/0?token={token}"
|
||||
"http://localhost:{port}/api/w/test-workspace/jobs/job_signature/{second}/0?token={token}&approver=ruben"
|
||||
))
|
||||
.await
|
||||
.unwrap()
|
||||
@@ -3299,7 +3299,7 @@ def main():
|
||||
|
||||
/* ImZyb20gdGVzdCIK = base64 "from test" */
|
||||
reqwest::get(format!(
|
||||
"http://localhost:{port}/api/w/test-workspace/jobs/resume/{second}/0/{secret}?payload=ImZyb20gdGVzdCIK"
|
||||
"http://localhost:{port}/api/w/test-workspace/jobs/resume/{second}/0/{secret}?payload=ImZyb20gdGVzdCIK&approver=ruben"
|
||||
))
|
||||
.await
|
||||
.unwrap()
|
||||
@@ -3354,7 +3354,7 @@ def main():
|
||||
server.close().await.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
json!({"error": "Job canceled: approval request disapproved by unknown" }),
|
||||
json!({"error": "Job canceled: approval request disapproved by ruben" }),
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
+3
-1
@@ -147,12 +147,13 @@ export interface NonceAndHmac {
|
||||
* Get HMAC and nonce needed for approval script
|
||||
* @param workspace workspace name
|
||||
* @param jobId
|
||||
* @param approver approver name
|
||||
* @returns HMAC and nonce needed to authorize approval script actions
|
||||
*/
|
||||
export async function genNounceAndHmac(workspace: string, jobId: string, approver?: string): Promise<NonceAndHmac> {
|
||||
const nonce = Math.floor(Math.random() * 4294967295);
|
||||
const sig = await fetch(Deno.env.get("WM_BASE_URL") +
|
||||
`/api/w/${workspace}/jobs/job_signature/${jobId}/${nonce}?token=${Deno.env.get("WM_TOKEN")}`)
|
||||
`/api/w/${workspace}/jobs/job_signature/${jobId}/${nonce}?token=${Deno.env.get("WM_TOKEN")}${approver ? `&approver=${approver}` : ''}`)
|
||||
return {
|
||||
nonce,
|
||||
signature: await sig.text()
|
||||
@@ -167,6 +168,7 @@ export interface ResumeEndpoints {
|
||||
|
||||
/**
|
||||
* Get URLs needed for approval script
|
||||
* @param approver approver name
|
||||
* @returns approval page UI URL, resume and cancel API URLs for approval script
|
||||
*/
|
||||
export async function getResumeEndpoints(approver?: string): Promise<ResumeEndpoints> {
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
workspace: $page.params.workspace,
|
||||
id: $page.params.job,
|
||||
resumeId: new Number($page.params.resume).valueOf(),
|
||||
signature: $page.params.hmac
|
||||
signature: $page.params.hmac,
|
||||
approver: $page.url.searchParams.get('approver') ?? undefined
|
||||
})
|
||||
job = suspendedJobFlow.job
|
||||
currentApprovers = suspendedJobFlow.approvers
|
||||
@@ -28,6 +29,7 @@
|
||||
id: $page.params.job,
|
||||
resumeId: new Number($page.params.resume).valueOf(),
|
||||
signature: $page.params.hmac,
|
||||
approver: $page.url.searchParams.get('approver') ?? undefined,
|
||||
requestBody: {}
|
||||
})
|
||||
sendUserToast('Flow approved')
|
||||
@@ -39,6 +41,7 @@
|
||||
id: $page.params.job,
|
||||
resumeId: new Number($page.params.resume).valueOf(),
|
||||
signature: $page.params.hmac,
|
||||
approver: $page.url.searchParams.get('approver') ?? undefined,
|
||||
requestBody: {}
|
||||
})
|
||||
sendUserToast('Flow disapproved!')
|
||||
|
||||
Reference in New Issue
Block a user