wallet-core-embedded: added Anastasis policy discovery

This commit is contained in:
Iván Ávalos 2023-08-07 11:14:00 +02:00
parent a204105b5b
commit d33b70b069
No known key found for this signature in database
GPG Key ID: AC47C0E4F348CE33

View File

@ -45,6 +45,8 @@ import {
reduceAction, reduceAction,
getBackupStartState, getBackupStartState,
getRecoveryStartState, getRecoveryStartState,
discoverPolicies,
mergeDiscoveryAggregate,
ReducerState, ReducerState,
} from "@gnu-taler/anastasis-core"; } from "@gnu-taler/anastasis-core";
import { import {
@ -195,18 +197,33 @@ async function handleAnastasisRequest(
}; };
}; };
let req = args ?? {};
switch (operation) { switch (operation) {
case "anastasisReduce": case "anastasisReduce":
// TODO: do some input validation here // TODO: do some input validation here
let req = args ?? {}; let reduceRes = await reduceAction(req.state, req.action, req.args ?? {});
let res = await reduceAction(req.state, req.action, req.args ?? {});
// For now, this will return "success" even if the wrapped Anastasis // For now, this will return "success" even if the wrapped Anastasis
// response is a ReducerStateError. // response is a ReducerStateError.
return wrapSuccessResponse(res); return wrapSuccessResponse(reduceRes);
case "anastasisStartBackup": case "anastasisStartBackup":
return wrapSuccessResponse(await getBackupStartState()); return wrapSuccessResponse(await getBackupStartState());
case "anastasisStartRecovery": case "anastasisStartRecovery":
return wrapSuccessResponse(await getRecoveryStartState()); return wrapSuccessResponse(await getRecoveryStartState());
case "anastasisDiscoverPolicies":
let discoverRes = await discoverPolicies(req.state, req.cursor);
let aggregatedPolicies = mergeDiscoveryAggregate(
discoverRes.policies ?? [],
req.state.discoveryState?.aggregatedPolicies ?? [],
);
return wrapSuccessResponse({
...req.state,
discoveryState: {
state: "finished",
aggregatedPolicies,
cursor: discoverRes.cursor,
},
});
} }
} }