From 212a24348aa199edfc325e3cd010d6ffde1317cb Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 8 Oct 2020 10:56:32 +0100 Subject: [PATCH] hitting deployment success endpoint --- .../server/src/api/controllers/deploy/aws.js | 21 +++++++++++++++++++ .../src/api/controllers/deploy/index.js | 7 ++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/server/src/api/controllers/deploy/aws.js b/packages/server/src/api/controllers/deploy/aws.js index 6b73751695..b56d3c7788 100644 --- a/packages/server/src/api/controllers/deploy/aws.js +++ b/packages/server/src/api/controllers/deploy/aws.js @@ -21,6 +21,27 @@ async function invalidateCDN(cfDistribution, appId) { .promise() } +exports.updateDeploymentQuota = async function(quota) { + const response = await fetch( + `${process.env.DEPLOYMENT_CREDENTIALS_URL}/deploy/success`, + { + method: "POST", + body: JSON.stringify({ + apiKey: process.env.BUDIBASE_API_KEY, + quota, + }), + } + ) + + if (response.status !== 200) { + throw new Error(`Error updating deployment quota for app`) + } + + const json = await response.json() + + return json +} + /** * Verifies the users API key and * Verifies that the deployment fits within the quota of the user, diff --git a/packages/server/src/api/controllers/deploy/index.js b/packages/server/src/api/controllers/deploy/index.js index a155fbbf81..c5d1169962 100644 --- a/packages/server/src/api/controllers/deploy/index.js +++ b/packages/server/src/api/controllers/deploy/index.js @@ -3,7 +3,7 @@ const PouchDB = require("../../../db") const { uploadAppAssets, verifyDeployment, - determineDeploymentAllowed, + updateDeploymentQuota, } = require("./aws") const { getRecordParams } = require("../../db/utils") @@ -85,6 +85,11 @@ exports.deployApp = async function(ctx) { credentials: credentials.couchDbCreds, }) + const deployedInstanceQuota = await getCurrentInstanceQuota( + ctx.user.instanceId + ) + updateDeploymentQuota(deployedInstanceQuota) + ctx.body = { status: "SUCCESS", completed: Date.now(),