wallet-core: only allow enabling dev mode via separate request

This commit is contained in:
Florian Dold 2022-10-13 15:24:47 +02:00
parent 83d4a1addc
commit ca8da4ed38
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
7 changed files with 78 additions and 67 deletions

View File

@ -20,11 +20,6 @@
"typescript.format.placeOpenBraceOnNewLineForFunctions": false, "typescript.format.placeOpenBraceOnNewLineForFunctions": false,
// Defines whether an open brace is put onto a new line for control blocks or not // Defines whether an open brace is put onto a new line for control blocks or not
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": false, "typescript.format.placeOpenBraceOnNewLineForControlBlocks": false,
"typescript.preferences.autoImportFileExcludePatterns": [
"index.*.js",
"index.ts",
"index.*.ts"
],
// Files hidden in the explorer // Files hidden in the explorer
"files.exclude": { "files.exclude": {
// include the defaults from VS Code // include the defaults from VS Code

View File

@ -1684,6 +1684,15 @@ export interface AcceptPeerPullPaymentRequest {
peerPullPaymentIncomingId: string; peerPullPaymentIncomingId: string;
} }
export interface SetDevModeRequest {
devModeEnabled: boolean;
}
export const codecForSetDevModeRequest = (): Codec<SetDevModeRequest> =>
buildCodecForObject<SetDevModeRequest>()
.property("devModeEnabled", codecForBoolean())
.build("SetDevModeRequest");
export interface ApplyDevExperimentRequest { export interface ApplyDevExperimentRequest {
devExperimentUri: string; devExperimentUri: string;
} }

View File

@ -1018,6 +1018,30 @@ advancedCli
}); });
}); });
advancedCli
.subcommand("enableDevMode", "enable-dev-mode", {
help: "Enable developer mode (dangerous!)",
})
.action(async (args) => {
await withWallet(args, async (wallet) => {
await wallet.client.call(WalletApiOperation.SetDevMode, {
devModeEnabled: true,
});
});
});
advancedCli
.subcommand("disableDevMode", "disable-dev-mode", {
help: "Disable developer mode",
})
.action(async (args) => {
await withWallet(args, async (wallet) => {
await wallet.client.call(WalletApiOperation.SetDevMode, {
devModeEnabled: false,
});
});
});
const coinPubListCodec = codecForList(codecForString()); const coinPubListCodec = codecForList(codecForString());
advancedCli advancedCli

View File

@ -36,6 +36,35 @@ import {
const logger = new Logger("dev-experiments.ts"); const logger = new Logger("dev-experiments.ts");
export async function setDevMode(
ws: InternalWalletState,
enabled: boolean,
): Promise<void> {
if (enabled) {
logger.info("enabling devmode");
await ws.db
.mktx((x) => [x.config])
.runReadWrite(async (tx) => {
tx.config.put({
key: ConfigRecordKey.DevMode,
value: true,
});
});
await maybeInitDevMode(ws);
} else {
logger.info("disabling devmode");
await ws.db
.mktx((x) => [x.config])
.runReadWrite(async (tx) => {
tx.config.put({
key: ConfigRecordKey.DevMode,
value: false,
});
});
await leaveDevMode(ws);
}
}
/** /**
* Apply a dev experiment to the wallet database / state. * Apply a dev experiment to the wallet database / state.
*/ */
@ -49,32 +78,6 @@ export async function applyDevExperiment(
logger.info("unable to parse dev experiment URI"); logger.info("unable to parse dev experiment URI");
return; return;
} }
if (parsedUri.devExperimentId == "enable-devmode") {
logger.info("enabling devmode");
await ws.db
.mktx((x) => [x.config])
.runReadWrite(async (tx) => {
tx.config.put({
key: ConfigRecordKey.DevMode,
value: true,
});
});
await maybeInitDevMode(ws);
return;
}
if (parsedUri.devExperimentId === "disable-devmode") {
logger.info("disabling devmode");
await ws.db
.mktx((x) => [x.config])
.runReadWrite(async (tx) => {
tx.config.put({
key: ConfigRecordKey.DevMode,
value: false,
});
});
await leaveDevMode(ws);
return;
}
if (!ws.devModeActive) { if (!ws.devModeActive) {
throw Error( throw Error(
"can't handle devmode URI (other than enable-devmode) unless devmode is active", "can't handle devmode URI (other than enable-devmode) unless devmode is active",

View File

@ -67,6 +67,7 @@ import {
RecoveryLoadRequest, RecoveryLoadRequest,
RetryTransactionRequest, RetryTransactionRequest,
SetCoinSuspendedRequest, SetCoinSuspendedRequest,
SetDevModeRequest,
SetWalletDeviceIdRequest, SetWalletDeviceIdRequest,
TestPayArgs, TestPayArgs,
TestPayResult, TestPayResult,
@ -140,6 +141,7 @@ export enum WalletApiOperation {
AcceptPeerPullPayment = "acceptPeerPullPayment", AcceptPeerPullPayment = "acceptPeerPullPayment",
ClearDb = "clearDb", ClearDb = "clearDb",
Recycle = "recycle", Recycle = "recycle",
SetDevMode = "setDevMode",
ApplyDevExperiment = "applyDevExperiment", ApplyDevExperiment = "applyDevExperiment",
} }
@ -529,6 +531,12 @@ export type ApplyDevExperimentOp = {
response: {}; response: {};
}; };
export type SetDevModeOp = {
op: WalletApiOperation.SetDevMode;
request: SetDevModeRequest;
response: {};
};
/** /**
* Run a simple integration test on a test deployment * Run a simple integration test on a test deployment
* of the exchange and merchant. * of the exchange and merchant.
@ -676,6 +684,7 @@ export type WalletOperations = {
[WalletApiOperation.ClearDb]: ClearDbOp; [WalletApiOperation.ClearDb]: ClearDbOp;
[WalletApiOperation.Recycle]: RecycleOp; [WalletApiOperation.Recycle]: RecycleOp;
[WalletApiOperation.ApplyDevExperiment]: ApplyDevExperimentOp; [WalletApiOperation.ApplyDevExperiment]: ApplyDevExperimentOp;
[WalletApiOperation.SetDevMode]: SetDevModeOp;
}; };
export type RequestType< export type RequestType<

View File

@ -94,6 +94,7 @@ import {
URL, URL,
WalletCoreVersion, WalletCoreVersion,
WalletNotification, WalletNotification,
codecForSetDevModeRequest,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { TalerCryptoInterface } from "./crypto/cryptoImplementation.js"; import { TalerCryptoInterface } from "./crypto/cryptoImplementation.js";
import { import {
@ -111,7 +112,7 @@ import {
importDb, importDb,
WalletStoresV1, WalletStoresV1,
} from "./db.js"; } from "./db.js";
import { applyDevExperiment, maybeInitDevMode } from "./dev-experiments.js"; import { applyDevExperiment, maybeInitDevMode, setDevMode } from "./dev-experiments.js";
import { getErrorDetailFromException, TalerError } from "./errors.js"; import { getErrorDetailFromException, TalerError } from "./errors.js";
import { import {
ActiveLongpollInfo, ActiveLongpollInfo,
@ -1334,6 +1335,11 @@ async function dispatchRequestInternal(
await applyDevExperiment(ws, req.devExperimentUri); await applyDevExperiment(ws, req.devExperimentUri);
return {}; return {};
} }
case "setDevMode": {
const req = codecForSetDevModeRequest().decode(payload);
await setDevMode(ws, req.devModeEnabled);
return {};
}
case "getVersion": { case "getVersion": {
const version: WalletCoreVersion = { const version: WalletCoreVersion = {
hash: GIT_HASH, hash: GIT_HASH,

View File

@ -92,29 +92,21 @@ importers:
packages/idb-bridge: packages/idb-bridge:
specifiers: specifiers:
'@rollup/plugin-commonjs': ^22.0.2
'@rollup/plugin-json': ^4.1.0
'@rollup/plugin-node-resolve': ^13.3.0
'@types/node': ^18.8.5 '@types/node': ^18.8.5
ava: ^4.3.3 ava: ^4.3.3
esm: ^3.2.25 esm: ^3.2.25
prettier: ^2.5.1 prettier: ^2.5.1
rimraf: ^3.0.2 rimraf: ^3.0.2
rollup: ^2.79.0
tslib: ^2.4.0 tslib: ^2.4.0
typescript: ^4.8.4 typescript: ^4.8.4
dependencies: dependencies:
tslib: 2.4.0 tslib: 2.4.0
devDependencies: devDependencies:
'@rollup/plugin-commonjs': 22.0.2_rollup@2.79.0
'@rollup/plugin-json': 4.1.0_rollup@2.79.0
'@rollup/plugin-node-resolve': 13.3.0_rollup@2.79.0
'@types/node': 18.8.5 '@types/node': 18.8.5
ava: 4.3.3 ava: 4.3.3
esm: 3.2.25 esm: 3.2.25
prettier: 2.5.1 prettier: 2.5.1
rimraf: 3.0.2 rimraf: 3.0.2
rollup: 2.79.0
typescript: 4.8.4 typescript: 4.8.4
packages/pogen: packages/pogen:
@ -130,29 +122,6 @@ importers:
po2json: 0.4.5 po2json: 0.4.5
typescript: 4.8.4 typescript: 4.8.4
packages/taler-config-lib:
specifiers:
'@types/node': ^18.8.5
ava: ^4.3.3
big-integer: ^1.6.51
esbuild: ^0.14.21
jed: ^1.1.1
prettier: ^2.5.1
rimraf: ^3.0.2
tslib: ^2.4.0
typescript: ^4.8.4
dependencies:
big-integer: 1.6.51
jed: 1.1.1
tslib: 2.4.0
devDependencies:
'@types/node': 18.8.5
ava: 4.3.3
esbuild: 0.14.21
prettier: 2.5.1
rimraf: 3.0.2
typescript: 4.8.4
packages/taler-util: packages/taler-util:
specifiers: specifiers:
'@types/node': ^18.8.5 '@types/node': ^18.8.5
@ -241,8 +210,6 @@ importers:
po2json: ^0.4.5 po2json: ^0.4.5
prettier: ^2.5.1 prettier: ^2.5.1
rimraf: ^3.0.2 rimraf: ^3.0.2
rollup: ^2.79.0
rollup-plugin-sourcemaps: ^0.6.3
source-map-resolve: ^0.6.0 source-map-resolve: ^0.6.0
source-map-support: ^0.5.21 source-map-support: ^0.5.21
tslib: ^2.4.0 tslib: ^2.4.0
@ -274,8 +241,6 @@ importers:
po2json: 0.4.5 po2json: 0.4.5
prettier: 2.5.1 prettier: 2.5.1
rimraf: 3.0.2 rimraf: 3.0.2
rollup: 2.79.0
rollup-plugin-sourcemaps: 0.6.3_n3h7ooyjwm4phuvjpg4pqirc4i
source-map-resolve: 0.6.0 source-map-resolve: 0.6.0
typedoc: 0.23.16_typescript@4.8.4 typedoc: 0.23.16_typescript@4.8.4
typescript: 4.8.4 typescript: 4.8.4