Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 0 additions & 67 deletions requests/Switcher API.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -4786,34 +4786,6 @@
},
"response": []
},
{
"name": "Slack - Feature Availability",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"feature\": \"SLACK_INTEGRATION\"\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{url}}/slack/v1/availability",
"host": [
"{{url}}"
],
"path": [
"slack",
"v1",
"availability"
]
}
},
"response": []
},
{
"name": "Slack - Ticket History Reset",
"request": {
Expand Down Expand Up @@ -5741,45 +5713,6 @@
}
]
},
{
"name": "API Management",
"item": [
{
"name": "Management - Feature",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"feature\": \"FEATURE\",\n\t\"parameters\": {\n \"value\": \"test\"\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{url}}/api-management/feature",
"host": [
"{{url}}"
],
"path": [
"api-management",
"feature"
]
}
},
"response": []
}
]
},
{
"name": "API Check",
"event": [
Expand Down
43 changes: 0 additions & 43 deletions src/api-docs/paths/path-api-management.js

This file was deleted.

40 changes: 0 additions & 40 deletions src/api-docs/paths/path-slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,6 @@ import { pathParameter, queryParameter } from '../schemas/common';
import { commonSchemaContent } from './common';

export default {
'/slack/v1/availability': {
post: {
tags: ['Switcher Slack App'],
description: 'Check if the feature is available',
security: [{ bearerAuth: [] }],
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
properties: {
feature: {
type: 'string',
description: 'The feature to check'
}
}
}
}
}
},
responses: {
200: {
description: 'The feature is available',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
result: {
type: 'boolean',
description: 'The feature is available'
}
}
}
}
}
}
}
}
},
'/slack/v1/installation': {
post: {
tags: ['Slack App'],
Expand Down
4 changes: 1 addition & 3 deletions src/api-docs/swagger-document.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import pathPermission from './paths/path-permission';
import pathMetric from './paths/path-metric';
import pathSlack from './paths/path-slack';
import pathClient from './paths/path-client';
import pathApiManagement from './paths/path-api-management';

import { commonSchema } from './schemas/common';
import adminSchema from './schemas/admin';
Expand Down Expand Up @@ -91,7 +90,6 @@ export default {
...pathPermission,
...pathMetric,
...pathClient,
...pathSlack,
...pathApiManagement
...pathSlack
}
};
2 changes: 0 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import metricRouter from './routers/metric';
import teamRouter from './routers/team';
import permissionRouter from './routers/permission';
import slackRouter from './routers/slack';
import apiManagementRouter from './routers/api-management';
import schema from './client/schema';
import { appAuth, auth, resourcesAuth, slackAuth } from './middleware/auth';
import { clientLimiter, defaultLimiter } from './middleware/limiter';
Expand Down Expand Up @@ -51,7 +50,6 @@ app.use(metricRouter);
app.use(teamRouter);
app.use(permissionRouter);
app.use(slackRouter);
app.use(apiManagementRouter);

/**
* GraphQL Routes
Expand Down
39 changes: 2 additions & 37 deletions src/external/switcher-api-facade.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Switcher, checkValue, checkPayload, checkRegex } from 'switcher-client';
import { EnvType } from '../models/environment';
import { BadRequestError, FeatureUnavailableError } from '../exceptions';
import { FeatureUnavailableError } from '../exceptions';
import { getDomainById, getTotalDomainsByOwner } from '../services/domain';
import { getTotalGroupsByDomainId } from '../services/group-config';
import { getTotalConfigsByDomainId } from '../services/config';
Expand All @@ -25,7 +25,6 @@ export const SwitcherKeys = Object.freeze({
ACCOUNT_IN_NOTIFY: 'ACCOUNT_IN_NOTIFY',
ACCOUNT_OUT_NOTIFY: 'ACCOUNT_OUT_NOTIFY',
SLACK_INTEGRATION: 'SLACK_INTEGRATION',
SLACK_UPDATE: 'SLACK_UPDATE',
RATE_LIMIT: 'RATE_LIMIT',
HTTPS_AGENT: 'HTTPS_AGENT'
});
Expand All @@ -36,13 +35,8 @@ function switcherFlagResult(flag, message) {
}
}

export async function checkFeature(feature, params, restrictTo = SwitcherKeys) {
async function checkFeature(feature, params) {
const switcher = Switcher.factory();
const key = Object.values(restrictTo).find(element => element === feature);

if (!key)
throw new BadRequestError('Invalid feature');

return switcher.isItOn(feature, params, true);
}

Expand Down Expand Up @@ -191,21 +185,6 @@ export async function checkSlackIntegration(value) {
]), 'Slack Integration is not available.');
}

export async function checkSlackAvailability(admin, feature) {
if (process.env.SWITCHER_API_ENABLE != 'true')
return true;

if (!process.env.SWITCHER_SLACK_JWT_SECRET)
return false;

const result = await checkFeature(feature, [checkValue(admin._id)], [
SwitcherKeys.SLACK_INTEGRATION,
SwitcherKeys.SLACK_UPDATE
]);

return result;
}

export function notifyAcCreation(adminid) {
if (process.env.SWITCHER_API_ENABLE != 'true')
return;
Expand Down Expand Up @@ -247,18 +226,4 @@ export async function checkHttpsAgent(value) {
return;

return checkFeature(SwitcherKeys.HTTPS_AGENT, [checkRegex(value)]);
}

export async function checkManagementFeature(feature, params) {
if (process.env.SWITCHER_API_ENABLE != 'true')
return true;

const switcher = Switcher.factory();
const entries = [];

if (params?.value) {
entries.push(checkValue(params.value));
}

return switcher.isItOn(feature, entries);
}
23 changes: 0 additions & 23 deletions src/routers/api-management.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/routers/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,6 @@ const createTicketContent = (req) => {
};
};

router.post('/slack/v1/availability', auth, async (req, res) => {
try {
const result = await Services.checkAvailability(req.admin, req.body.feature);
res.send({ result });
} catch (e) {
responseException(res, e, 400, req.body.feature);
}
});

router.post('/slack/v1/installation', slackAuth, [
check('installation_payload').exists(),
check('bot_payload').exists()
Expand Down
6 changes: 1 addition & 5 deletions src/services/slack.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Slack from '../models/slack';
import { TicketStatusType, SLACK_SUB, TicketValidationType } from '../models/slack_ticket';
import { BadRequestError, NotFoundError, PermissionError } from '../exceptions';
import { checkSlackIntegration, checkSlackAvailability } from '../external/switcher-api-facade';
import { checkSlackIntegration } from '../external/switcher-api-facade';
import { getConfig } from './config';
import { getDomainById } from './domain';
import { getEnvironment } from './environment';
Expand Down Expand Up @@ -68,10 +68,6 @@ export async function getSlack(where) {
return query.exec();
}

export async function checkAvailability(admin, feature) {
return checkSlackAvailability(admin, feature);
}

export async function createSlackInstallation(args) {
await checkSlackIntegration(args.team_id);

Expand Down
Loading