From f6d0db4c4b607fc5084e54e2c7242669ae3e4533 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 2 Aug 2021 12:09:03 +0100 Subject: [PATCH] Updating API endpoints, to include the new system one, updating hosting envoy yaml to cover these. --- hosting/envoy.dev.yaml.hbs | 8 ++++++++ hosting/envoy.yaml | 10 +++++++++- packages/builder/src/stores/portal/admin.js | 2 +- .../src/api/controllers/{global => system}/flags.js | 0 .../src/api/controllers/{global => system}/tenants.js | 0 packages/worker/src/api/routes/global/flags.js | 8 -------- packages/worker/src/api/routes/global/tenants.js | 11 ----------- packages/worker/src/api/routes/index.js | 4 ++-- packages/worker/src/api/routes/system/flags.js | 8 ++++++++ packages/worker/src/api/routes/system/tenants.js | 11 +++++++++++ 10 files changed, 39 insertions(+), 23 deletions(-) rename packages/worker/src/api/controllers/{global => system}/flags.js (100%) rename packages/worker/src/api/controllers/{global => system}/tenants.js (100%) delete mode 100644 packages/worker/src/api/routes/global/flags.js delete mode 100644 packages/worker/src/api/routes/global/tenants.js create mode 100644 packages/worker/src/api/routes/system/flags.js create mode 100644 packages/worker/src/api/routes/system/tenants.js diff --git a/hosting/envoy.dev.yaml.hbs b/hosting/envoy.dev.yaml.hbs index 5e876a2369..01d5a09efa 100644 --- a/hosting/envoy.dev.yaml.hbs +++ b/hosting/envoy.dev.yaml.hbs @@ -26,6 +26,14 @@ static_resources: cluster: couchdb-service prefix_rewrite: "/" + - match: { prefix: "/api/system/" } + route: + cluster: worker-dev + + - match: { prefix: "/api/admin/" } + route: + cluster: worker-dev + - match: { prefix: "/api/global/" } route: cluster: worker-dev diff --git a/hosting/envoy.yaml b/hosting/envoy.yaml index dc90f11056..d5f9ebee28 100644 --- a/hosting/envoy.yaml +++ b/hosting/envoy.yaml @@ -37,11 +37,19 @@ static_resources: route: cluster: app-service - # special case for worker admin API + # special cases for worker admin (deprecated), global and system API - match: { prefix: "/api/global/" } route: cluster: worker-service + - match: { prefix: "/api/admin/" } + route: + cluster: worker-service + + - match: { prefix: "/api/system/" } + route: + cluster: worker-service + - match: { path: "/" } route: cluster: app-service diff --git a/packages/builder/src/stores/portal/admin.js b/packages/builder/src/stores/portal/admin.js index cec869eb02..0699daf8dc 100644 --- a/packages/builder/src/stores/portal/admin.js +++ b/packages/builder/src/stores/portal/admin.js @@ -41,7 +41,7 @@ export function createAdminStore() { async function multiTenancyEnabled() { let enabled = false try { - const response = await api.get(`/api/global/flags`) + const response = await api.get(`/api/system/flags`) const json = await response.json() enabled = json.multiTenancy } catch (err) { diff --git a/packages/worker/src/api/controllers/global/flags.js b/packages/worker/src/api/controllers/system/flags.js similarity index 100% rename from packages/worker/src/api/controllers/global/flags.js rename to packages/worker/src/api/controllers/system/flags.js diff --git a/packages/worker/src/api/controllers/global/tenants.js b/packages/worker/src/api/controllers/system/tenants.js similarity index 100% rename from packages/worker/src/api/controllers/global/tenants.js rename to packages/worker/src/api/controllers/system/tenants.js diff --git a/packages/worker/src/api/routes/global/flags.js b/packages/worker/src/api/routes/global/flags.js deleted file mode 100644 index a1367f4a82..0000000000 --- a/packages/worker/src/api/routes/global/flags.js +++ /dev/null @@ -1,8 +0,0 @@ -const Router = require("@koa/router") -const controller = require("../../controllers/global/flags") - -const router = Router() - -router.get("/api/global/flags", controller.fetch) - -module.exports = router diff --git a/packages/worker/src/api/routes/global/tenants.js b/packages/worker/src/api/routes/global/tenants.js deleted file mode 100644 index 432e327115..0000000000 --- a/packages/worker/src/api/routes/global/tenants.js +++ /dev/null @@ -1,11 +0,0 @@ -const Router = require("@koa/router") -const controller = require("../../controllers/global/tenants") -const adminOnly = require("../../../middleware/adminOnly") - -const router = Router() - -router - .get("/api/global/tenants/:tenantId/exists", controller.exists) - .get("/api/global/tenants", adminOnly, controller.fetch) - -module.exports = router diff --git a/packages/worker/src/api/routes/index.js b/packages/worker/src/api/routes/index.js index 6341dffeb7..a4ed4d7da4 100644 --- a/packages/worker/src/api/routes/index.js +++ b/packages/worker/src/api/routes/index.js @@ -2,12 +2,12 @@ const userRoutes = require("./global/users") const configRoutes = require("./global/configs") const workspaceRoutes = require("./global/workspaces") const templateRoutes = require("./global/templates") -const tenantsRoutes = require("./global/tenants") const emailRoutes = require("./global/email") const authRoutes = require("./global/auth") const roleRoutes = require("./global/roles") const sessionRoutes = require("./global/sessions") -const flagRoutes = require("./global/flags") +const flagRoutes = require("./system/flags") +const tenantsRoutes = require("./system/tenants") const appRoutes = require("./app") exports.routes = [ diff --git a/packages/worker/src/api/routes/system/flags.js b/packages/worker/src/api/routes/system/flags.js new file mode 100644 index 0000000000..f2f5c5712f --- /dev/null +++ b/packages/worker/src/api/routes/system/flags.js @@ -0,0 +1,8 @@ +const Router = require("@koa/router") +const controller = require("../../controllers/system/flags") + +const router = Router() + +router.get("/api/system/flags", controller.fetch) + +module.exports = router diff --git a/packages/worker/src/api/routes/system/tenants.js b/packages/worker/src/api/routes/system/tenants.js new file mode 100644 index 0000000000..223ba9f26e --- /dev/null +++ b/packages/worker/src/api/routes/system/tenants.js @@ -0,0 +1,11 @@ +const Router = require("@koa/router") +const controller = require("../../controllers/system/tenants") +const adminOnly = require("../../../middleware/adminOnly") + +const router = Router() + +router + .get("/api/system/tenants/:tenantId/exists", controller.exists) + .get("/api/system/tenants", adminOnly, controller.fetch) + +module.exports = router