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
38 changes: 38 additions & 0 deletions requests/Switcher API.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -5672,6 +5672,44 @@
},
"response": []
},
{
"name": "GitOps Push - Delete Relay",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{gitopsToken}}",
"type": "string"
}
]
},
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"environment\": \"default\",\r\n \"changes\": [\r\n {\r\n \"action\": \"DELETED\",\r\n \"diff\": \"RELAY\",\r\n \"path\": [\r\n \"New Group\",\r\n \"NEW_SWITCHER_RELAY\"\r\n ]\r\n }\r\n ]\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{url}}/gitops/v1/push",
"host": [
"{{url}}"
],
"path": [
"gitops",
"v1",
"push"
]
}
},
"response": []
},
{
"name": "GitOps Push - Delete Switcher",
"request": {
Expand Down
1 change: 1 addition & 0 deletions src/middleware/gitops.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const PATH_CONSTRAINTS_DELETED = {
GROUP: 1,
CONFIG: 2,
STRATEGY: 3,
RELAY: 2,
COMPONENT: 2
};

Expand Down
5 changes: 4 additions & 1 deletion src/models/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ function hasRelayEndpointUpdates(config, modifiedField) {

if (hasUpdate.length) {
const environment = hasUpdate[0].split('.')[2];
config.relay.verified.set(environment, false);

if (config.relay.endpoint.get(environment)) {
config.relay.verified.set(environment, false);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/routers/gitops.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ router.post('/gitops/v1/push', gitopsAuth, featureFlag, [
.custom(value => ['NEW', 'CHANGED', 'DELETED'].includes(value))
.withMessage('Request has invalid type of action'),
body('changes.*.diff')
.custom(value => ['GROUP', 'CONFIG', 'STRATEGY', 'COMPONENT'].includes(value))
.custom(value => ['GROUP', 'CONFIG', 'STRATEGY', 'RELAY', 'COMPONENT'].includes(value))
.withMessage('Request has invalid type of diff'),
], validate, validateChanges, async (req, res) => {
try {
Expand Down
12 changes: 11 additions & 1 deletion src/services/gitops/push-deleted.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { getComponents } from '../component.js';
import { deleteStrategy, getStrategies } from '../config-strategy.js';
import { deleteConfig, getConfig, removeComponent } from '../config.js';
import { deleteConfig, getConfig, removeComponent, removeRelay } from '../config.js';
import { deleteGroup, getGroupConfig } from '../group-config.js';
import { ADMIN_EMAIL } from './index.js';

const DIFF_PROCESSES = Object.freeze({
GROUP: processGroupDeleted,
CONFIG: processConfigDeleted,
STRATEGY: processStrategyDeleted,
RELAY: processRelayDeleted,
COMPONENT: processComponentDeleted
});

Expand Down Expand Up @@ -44,6 +45,15 @@ async function processStrategyDeleted(domain, change, environment) {
await deleteStrategy(strategy._id, admin);
}

async function processRelayDeleted(domain, change, environment) {
const path = change.path;
const admin = { _id: domain.owner, email: ADMIN_EMAIL };
const group = await getGroupConfig({ domain: domain._id, name: path[0] });
const config = await getConfig({ domain: domain._id, group: group._id, key: path[1] });

await removeRelay(config._id, environment, admin);
}

async function processComponentDeleted(domain, change) {
const path = change.path;
const content = change.content;
Expand Down
26 changes: 26 additions & 0 deletions tests/gitops.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,32 @@ describe('GitOps - Push Deleted', () => {
expect(strategy).toBeNull();
});

test('GITOPS_SUITE - Should push changes - Deleted Relay', async () => {
const token = generateToken('30s');

const lastUpdate = Date.now();
const req = await request(app)
.post('/gitops/v1/push')
.set('Authorization', `Bearer ${token}`)
.send({
environment: EnvType.DEFAULT,
changes: [{
action: 'DELETED',
diff: 'RELAY',
path: ['Group Test', 'TEST_CONFIG_KEY'],
content: null
}]
})
.expect(200);

expect(req.body.message).toBe('Changes applied successfully');
expect(req.body.version).toBeGreaterThan(lastUpdate);

// Check if the changes were applied
const config = await Config.findOne({ key: 'TEST_CONFIG_KEY', domain: domainId }).lean().exec();
expect(config.relay).toBeUndefined();
});

test('GITOPS_SUITE - Should push changes - Deleted Switcher', async () => {
const token = generateToken('30s');

Expand Down