From a66a3d9b5ced0a663f7d68394b69174352673472 Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Thu, 26 Nov 2026 18:45:52 -0700 Subject: [PATCH 1/2] feat(graphql): removed deprecated get config by key (PR6) --- src/api-docs/paths/path-oauth.js | 20 +------- src/api-docs/schemas/oauth.js | 22 --------- src/middleware/auth.js | 8 ---- src/routers/config.js | 25 +--------- src/services/config.js | 35 -------------- tests/config.test.js | 79 -------------------------------- tests/oauth.test.js | 10 ---- 7 files changed, 2 insertions(+), 197 deletions(-) diff --git a/src/api-docs/paths/path-oauth.js b/src/api-docs/paths/path-oauth.js index 3b6c909..dcb077f 100644 --- a/src/api-docs/paths/path-oauth.js +++ b/src/api-docs/paths/path-oauth.js @@ -1,4 +1,4 @@ -import { pathParameter, queryParameter } from '../schemas/common.js'; +import { queryParameter } from '../schemas/common.js'; import { commonSchemaContent } from './common.js'; export default { @@ -77,23 +77,5 @@ export default { } } } - }, - '/config/key/{key}': { - get: { - tags: ['Config'], - description: 'Get Config by key and domain name', - security: [{ bearerAuth: [] }], - parameters: [ - pathParameter('key', 'Config key', true), - queryParameter('domain', 'Domain name', true), - queryParameter('environment', 'Environment name', false) - ], - responses: { - 200: { - description: 'Config', - content: commonSchemaContent('ConfigByKeyResponse') - } - } - } } }; diff --git a/src/api-docs/schemas/oauth.js b/src/api-docs/schemas/oauth.js index 6cebb6d..2d6b130 100644 --- a/src/api-docs/schemas/oauth.js +++ b/src/api-docs/schemas/oauth.js @@ -1,4 +1,3 @@ -import { config } from './config.js'; const oauthMetadata = { type: 'object', @@ -184,26 +183,5 @@ export default { }, ...oauthMetadata.properties } - }, - ConfigByKeyResponse: { - ...config({ - type: 'array', - description: 'The component IDs that can use the Swichter', - items: { - type: 'string' - } - }), - properties: { - ...config({ - type: 'array', - description: 'The component IDs that can use the Swichter', - items: { - type: 'string' - } - }).properties, - enabled: { - type: 'boolean' - } - } } }; diff --git a/src/middleware/auth.js b/src/middleware/auth.js index 6df6869..65d903e 100644 --- a/src/middleware/auth.js +++ b/src/middleware/auth.js @@ -71,14 +71,6 @@ export async function auth(req, res, next) { * falling through to the other strategy. If neither strategy succeeds * (and it wasn't an expiry), the request fails with a generic 401 * `Please authenticate.`. - * - * Use `authAny` only for routes that must be reachable by both - * switcher-management (JWT) **and** MCP/OAuth clients - as of this - * writing: `GET /domain`, `GET /domain/collaboration`, `GET /environment`, - * `GET /config/key/:key`, and `/adm-graphql` (OAuth tokens limited to the - * `configuration` query via `restrictOAuthGraphQL`). Don't default new routes to `authAny`; - * keep using plain `auth` unless the route is a deliberate MCP tool - * target (see `docs/copilot/switcher-mcp/MCP_DEVELOPMENT.md`). */ export async function authAny(req, res, next) { const token = getBearerToken(req); diff --git a/src/routers/config.js b/src/routers/config.js index 0898a72..677686a 100644 --- a/src/routers/config.js +++ b/src/routers/config.js @@ -1,7 +1,7 @@ import express from 'express'; import { body, check, query } from 'express-validator'; import { relayOptions } from '../models/config.js'; -import { auth, authAny } from '../middleware/auth.js'; +import { auth } from '../middleware/auth.js'; import { ActionTypes, RouterTypes } from '../models/permission.js'; import { responseException } from '../exceptions/index.js'; import { @@ -13,7 +13,6 @@ import { getHistory, deleteHistory } from '../services/history.js'; import { getGroupConfigById } from '../services/group-config.js'; import { SwitcherKeys } from '../external/switcher-api-facade.js'; import { getFields } from './common/index.js'; -import { EnvType } from '../models/environment.js'; const router = new express.Router(); @@ -66,28 +65,6 @@ router.get('/config', auth, [ } }); -router.get('/config/key/:key', authAny, [ - check('key').isLength({ min: 3, max: 50 }), - query('domain').isString(), - query('environment').optional().isString() -], validate, async (req, res) => { - try { - let config = await Services.getConfigByKey( - req.params.key, req.query.domain, req.query.environment, true); - config = await verifyOwnership(req.admin, config, config.domain, ActionTypes.READ, RouterTypes.CONFIG, true); - - const environment = req.query.environment || EnvType.DEFAULT; - const response = config.toJSON(); - response.enabled = config.activated?.has(environment) ? - config.activated.get(environment) === true : - config.activated?.get(EnvType.DEFAULT) === true; - - res.send(response); - } catch (e) { - responseException(res, e, 500); - } -}); - // GET /config/ID?resolveComponents=true router.get('/config/:id', auth, [ check('id').isMongoId() diff --git a/src/services/config.js b/src/services/config.js index 0221c08..7307dc7 100644 --- a/src/services/config.js +++ b/src/services/config.js @@ -1,10 +1,8 @@ import { response } from './common.js'; import { Config } from '../models/config.js'; -import Domain from '../models/domain.js'; import { formatInput, verifyOwnership, checkEnvironmentStatusRemoval } from '../helpers/index.js'; import { ActionTypes, RouterTypes } from '../models/permission.js'; import { getDomainById, updateDomainVersion } from './domain.js'; -import { getEnvironmentByName } from './environment.js'; import { getGroupConfigById } from './group-config.js'; import { checkSwitcher } from '../external/switcher-api-facade.js'; import { BadRequestError, NotFoundError } from '../exceptions/index.js'; @@ -28,39 +26,6 @@ export async function getConfigById(id, populateAdmin = false) { return response(config, 'Config not found'); } -export async function getConfigByKey(key, domainName, environmentName, populateAdmin = false) { - const formattedKey = formatInput(key, { toUpper: true, autoUnderscore: true }); - const domain = await Domain.findOne({ name: domainName.toString() }).exec(); - - if (!domain) { - throw new Error('Domain not found'); - } - - if (environmentName) { - const environment = await getEnvironmentByName(domain._id, environmentName); - - if (!environment) { - throw new Error('Environment not found'); - } - } - - let config = await Config.findOne({ - key: formattedKey, - domain: domain._id.toString() - }).exec(); - - if (!config) { - throw new Error('Config not found'); - } - - if (populateAdmin) { - await config.populate({ path: 'admin', select: 'name' }); - await config.populate({ path: 'configStrategy' }); - } - - return config; -} - export async function getConfig(where) { const query = Config.findOne(); diff --git a/tests/config.test.js b/tests/config.test.js index 61ab287..6980222 100644 --- a/tests/config.test.js +++ b/tests/config.test.js @@ -200,85 +200,6 @@ describe('Testing fetch configuration info', () => { }); }); -describe('Testing fetch configuration by key', () => { - beforeAll(setupDatabase); - - test('CONFIG_SUITE - Should get Config by key', async () => { - const response = await request(app) - .get(`/config/key/${config1Document.key}?domain=Domain`) - .set('Authorization', `Bearer ${adminMasterAccountToken}`) - .send().expect(200); - - expect(String(response.body._id)).toEqual(String(config1Document._id)); - expect(response.body.key).toEqual(config1Document.key); - expect(response.body.enabled).toEqual(true); - }); - - test('CONFIG_SUITE - Should get Config by key - case insensitive', async () => { - const response = await request(app) - .get(`/config/key/${config1Document.key.toLowerCase()}?domain=Domain`) - .set('Authorization', `Bearer ${adminMasterAccountToken}`) - .send().expect(200); - - expect(response.body.key).toEqual(config1Document.key); - }); - - test('CONFIG_SUITE - Should get Config by key - environment reflected in enabled flag', async () => { - const response = await request(app) - .get(`/config/key/${config1Document.key}?domain=Domain&environment=dev`) - .set('Authorization', `Bearer ${adminMasterAccountToken}`) - .send().expect(200); - - // config1Document only has activation for the default environment - // therefore, the request should fall back to the default environment - expect(response.body.enabled).toEqual(true); - }); - - test('CONFIG_SUITE - Should NOT get Config by key - invalid key length', async () => { - const responseInvalidKey = await request(app) - .get('/config/key/AB?domain=Domain') - .set('Authorization', `Bearer ${adminMasterAccountToken}`) - .send().expect(422); - - expect(responseInvalidKey.body.error).not.toBeNull(); - }); - - test('CONFIG_SUITE - Should NOT get Config by key - domain not found', async () => { - const responseDomainNotFound = await request(app) - .get(`/config/key/${config1Document.key}?domain=UNKNOWN_DOMAIN`) - .set('Authorization', `Bearer ${adminMasterAccountToken}`) - .send().expect(500); - - expect(responseDomainNotFound.body.error).not.toBeNull(); - }); - - test('CONFIG_SUITE - Should NOT get Config by key - environment not found', async () => { - const responseEnvironmentNotFound = await request(app) - .get(`/config/key/${config1Document.key}?domain=Domain&environment=UNKNOWN_ENV`) - .set('Authorization', `Bearer ${adminMasterAccountToken}`) - .send().expect(500); - - expect(responseEnvironmentNotFound.body.error).not.toBeNull(); - }); - - test('CONFIG_SUITE - Should NOT get Config by key - key not found', async () => { - const responseKeyNotFound = await request(app) - .get('/config/key/UNKNOWN_CONFIG_KEY?domain=Domain') - .set('Authorization', `Bearer ${adminMasterAccountToken}`) - .send().expect(500); - - expect(responseKeyNotFound.body.error).not.toBeNull(); - }); - - test('CONFIG_SUITE - Should NOT get Config by key - unauthenticated', async () => { - const responseUnauthenticated = await request(app) - .get(`/config/key/${config1Document.key}?domain=Domain`) - .send().expect(401); - - expect(responseUnauthenticated.body.error).not.toBeNull(); - }); -}); - describe('Testing configuration deletion', () => { beforeAll(setupDatabase); diff --git a/tests/oauth.test.js b/tests/oauth.test.js index 08678f9..bd13b26 100644 --- a/tests/oauth.test.js +++ b/tests/oauth.test.js @@ -803,16 +803,6 @@ describe('Testing protected resource access using an OAuth access token', () => expect(response.body.length).toBeGreaterThan(0); }); - test('OAUTH_SUITE - Should get a Config by key using an OAuth access token', async () => { - const response = await request(app) - .get(`/config/key/${config1Document.key}?domain=Domain`) - .set('Authorization', `Bearer ${accessToken}`) - .send().expect(200); - - expect(response.body.key).toEqual(config1Document.key); - expect(response.body.enabled).toEqual(true); - }); - test('OAUTH_SUITE - Should query configuration on /adm-graphql using an OAuth access token', async () => { const response = await request(app) .post('/adm-graphql') From 31e9b1928d324df53ee263f8d062c31d6b7e5e0b Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Thu, 26 Nov 2026 18:50:42 -0700 Subject: [PATCH 2/2] chore(docs): updated postman with MCP aggregator schema sample --- requests/Switcher API.postman_collection.json | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/requests/Switcher API.postman_collection.json b/requests/Switcher API.postman_collection.json index 8dfb6fb..2542d44 100644 --- a/requests/Switcher API.postman_collection.json +++ b/requests/Switcher API.postman_collection.json @@ -6051,6 +6051,30 @@ }, "response": [] }, + { + "name": "Configuration - MCP", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "graphql", + "graphql": { + "query": "query Configuration(\r\n $domain: String!, \r\n $group: String,\r\n $key: String,\r\n $environment: String) {\r\n configuration(domain: $domain, group: $group, key: $key, environment: $environment) {\r\n domain {\r\n id: _id\r\n version\r\n name\r\n activated\r\n }\r\n group {\r\n _id\r\n name\r\n activated\r\n }\r\n config {\r\n _id\r\n key\r\n activated\r\n components\r\n relay {\r\n type\r\n method\r\n endpoint\r\n description\r\n activated\r\n }\r\n }\r\n strategies {\r\n description\r\n strategy\r\n operation\r\n values\r\n activated\r\n }\r\n }\r\n}", + "variables": "{\r\n \"domain\": \"{{doaminid}}\",\r\n \"key\": \"{{switcher_key}}\",\r\n // \"group\": \"{{group}}\",\r\n \"environment\": \"{{environment}}\"\r\n}" + } + }, + "url": { + "raw": "{{url}}/adm-graphql", + "host": [ + "{{url}}" + ], + "path": [ + "adm-graphql" + ] + } + }, + "response": [] + }, { "name": "Permission - By Router Switcher", "request": {