-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GitOps- added sync push deleted (#524)
- Loading branch information
Showing
6 changed files
with
295 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { getDomainById, updateDomainVersion } from '../domain.js'; | ||
import { processChanged } from './push-changed.js'; | ||
import { processDeleted } from './push-deleted.js'; | ||
import { processNew } from './push-new.js'; | ||
|
||
export const ADMIN_EMAIL = '[email protected]'; | ||
|
@@ -14,16 +15,15 @@ export async function pushChanges(domainId, environment, changes) { | |
case 'CHANGED': | ||
await processChanged(domain, change, environment); | ||
break; | ||
case 'DELETED': | ||
await processDeleted(domain, change, environment); | ||
break; | ||
} | ||
}; | ||
|
||
domain = await updateDomainVersion(domainId); | ||
return successResponse('Changes applied successfully', domain.lastUpdate); | ||
} | ||
|
||
function successResponse(message, version) { | ||
return { | ||
message, | ||
version | ||
message: 'Changes applied successfully', | ||
version: domain.lastUpdate | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { getComponents } from '../component.js'; | ||
import { deleteStrategy, getStrategies, removeVal } from '../config-strategy.js'; | ||
import { deleteConfig, getConfig, removeComponent } from '../config.js'; | ||
import { deleteGroup, getGroupConfig } from '../group-config.js'; | ||
import { ADMIN_EMAIL } from './index.js'; | ||
|
||
export async function processDeleted(domain, change, environment) { | ||
switch (change.diff) { | ||
case 'GROUP': | ||
await processGroupDeleted(domain, change); | ||
break; | ||
case 'CONFIG': | ||
await processConfigDeleted(domain, change); | ||
break; | ||
case 'STRATEGY': | ||
await processStrategyDeleted(domain, change, environment); | ||
break; | ||
case 'STRATEGY_VALUE': | ||
await processStrategyValueDeleted(domain, change, environment); | ||
break; | ||
case 'COMPONENT': | ||
await processComponentDeleted(domain, change); | ||
break; | ||
} | ||
} | ||
|
||
async function processGroupDeleted(domain, change) { | ||
const path = change.path; | ||
const admin = { _id: domain.owner, email: ADMIN_EMAIL }; | ||
const group = await getGroupConfig({ domain: domain._id, name: path[0] }); | ||
|
||
await deleteGroup(group._id, admin); | ||
} | ||
|
||
async function processConfigDeleted(domain, change) { | ||
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 deleteConfig(config._id, admin); | ||
} | ||
|
||
async function processStrategyDeleted(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] }); | ||
|
||
const strategies = await getStrategies({ config: config._id }); | ||
const strategy = strategies.find(strategy => strategy.strategy === path[2] && strategy.activated.get(environment)); | ||
|
||
await deleteStrategy(strategy._id, admin); | ||
} | ||
|
||
async function processStrategyValueDeleted(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] }); | ||
|
||
const strategies = await getStrategies({ config: config._id }); | ||
const strategy = strategies.find(strategy => strategy.strategy === path[2] && strategy.activated.get(environment)); | ||
|
||
for (const value of change.content) { | ||
if (strategy.values.includes(value)) { | ||
await removeVal(strategy._id, { value }, admin); | ||
} | ||
} | ||
} | ||
|
||
async function processComponentDeleted(domain, change) { | ||
const path = change.path; | ||
const content = change.content; | ||
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] }); | ||
|
||
const components = await getComponents({ domain: domain._id, name: { $in: content } }); | ||
const componentIds = components.map(component => component._id); | ||
|
||
for (const id of componentIds) { | ||
if (config.components.includes(id)) { | ||
await removeComponent(config._id, { component: id }, admin); | ||
} | ||
} | ||
} |
Oops, something went wrong.