From 7985b0a33ffc3e258da5d73f4056384c38e626fe Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 23 Feb 2023 00:52:10 +0100 Subject: taler-harness: deployment tooling for tipping --- packages/taler-harness/src/harness/harness.ts | 54 ++++++++++++++++++++++ .../taler-harness/src/harness/libeufin-apis.ts | 7 +-- 2 files changed, 56 insertions(+), 5 deletions(-) (limited to 'packages/taler-harness/src/harness') diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts index 6168ea0b7..5733e776b 100644 --- a/packages/taler-harness/src/harness/harness.ts +++ b/packages/taler-harness/src/harness/harness.ts @@ -1436,12 +1436,20 @@ export interface MerchantServiceInterface { readonly name: string; } +export interface DeleteTippingReserveArgs { + reservePub: string; + purge?: boolean; +} + export class MerchantApiClient { constructor( private baseUrl: string, public readonly auth: MerchantAuthConfiguration, ) {} + // FIXME: Migrate everything to this in favor of axios + http = createPlatformHttpLib(); + async changeAuth(auth: MerchantAuthConfiguration): Promise { const url = new URL("private/auth", this.baseUrl); await axios.post(url.href, auth, { @@ -1449,6 +1457,51 @@ export class MerchantApiClient { }); } + async deleteTippingReserve(req: DeleteTippingReserveArgs): Promise { + const url = new URL(`private/reserves/${req.reservePub}`, this.baseUrl); + if (req.purge) { + url.searchParams.set("purge", "YES"); + } + const resp = await axios.delete(url.href, { + headers: this.makeAuthHeader(), + }); + logger.info(`delete status: ${resp.status}`); + return; + } + + async createTippingReserve( + req: CreateMerchantTippingReserveRequest, + ): Promise { + const url = new URL("private/reserves", this.baseUrl); + const resp = await axios.post(url.href, req, { + headers: this.makeAuthHeader(), + }); + // FIXME: validate + return resp.data; + } + + async getPrivateInstanceInfo(): Promise { + console.log(this.makeAuthHeader()); + const url = new URL("private", this.baseUrl); + logger.info(`request url ${url.href}`); + const resp = await this.http.fetch(url.href, { + method: "GET", + headers: this.makeAuthHeader(), + }); + return await resp.json(); + } + + async getPrivateTipReserves(): Promise { + console.log(this.makeAuthHeader()); + const url = new URL("private/reserves", this.baseUrl); + const resp = await this.http.fetch(url.href, { + method: "GET", + headers: this.makeAuthHeader(), + }); + // FIXME: Validate! + return await resp.json(); + } + async deleteInstance(instanceId: string) { const url = new URL(`management/instances/${instanceId}`, this.baseUrl); await axios.delete(url.href, { @@ -1578,6 +1631,7 @@ export namespace MerchantPrivateApi { `private/reserves`, merchantService.makeInstanceBaseUrl(instance), ); + // FIXME: Don't use axios! const resp = await axios.post(reqUrl.href, req); // FIXME: validate return resp.data; diff --git a/packages/taler-harness/src/harness/libeufin-apis.ts b/packages/taler-harness/src/harness/libeufin-apis.ts index a6abe3466..4ef588fb5 100644 --- a/packages/taler-harness/src/harness/libeufin-apis.ts +++ b/packages/taler-harness/src/harness/libeufin-apis.ts @@ -7,7 +7,8 @@ import axiosImp from "axios"; const axios = axiosImp.default; -import { Logger, URL } from "@gnu-taler/taler-util"; +import { AmountString, Logger, URL } from "@gnu-taler/taler-util"; +import { createPlatformHttpLib } from "@gnu-taler/taler-util/http"; export interface LibeufinSandboxServiceInterface { baseUrl: string; @@ -163,10 +164,6 @@ export interface LibeufinSandboxAddIncomingRequest { direction: string; } -function getRandomString(): string { - return Math.random().toString(36).substring(2); -} - /** * APIs spread across Legacy and Access, it is therefore * the "base URL" relative to which API every call addresses. -- cgit v1.2.3