@@ -3,7 +3,12 @@ import type { RequestHandler } from 'express';
33import { omit , toString } from 'lodash' ;
44import { lastValueFrom , toArray } from 'rxjs' ;
55
6- import { loadBackend } from '../command/utils' ;
6+ import {
7+ fillLabels ,
8+ filterConfiguration ,
9+ filterResourceType ,
10+ loadBackend ,
11+ } from '../command/utils' ;
712import { DifferV3 } from '../differ/differv3' ;
813import { check } from '../linter' ;
914import { SyncInput , type SyncInputType } from './schema' ;
@@ -13,29 +18,44 @@ export const syncHandler: RequestHandler<
1318 unknown ,
1419 SyncInputType
1520> = async ( req , res ) => {
16- const parsedInput = SyncInput . safeParse ( req . body ) ;
17- if ( ! parsedInput . success )
18- return res . status ( 400 ) . json ( {
19- message : parsedInput . error . message ,
20- errors : parsedInput . error . issues ,
21- } ) ;
22- const { task } = parsedInput . data ;
23-
24- // load local configuration and validate it
25- const local = task . config as ADCSDK . Configuration ;
26- if ( task . opts . lint ) {
27- const result = check ( local ) ;
28- if ( ! result . success )
21+ try {
22+ const parsedInput = SyncInput . safeParse ( req . body ) ;
23+ if ( ! parsedInput . success )
2924 return res . status ( 400 ) . json ( {
30- message : result . error . message ,
31- errors : result . error . issues ,
25+ message : parsedInput . error . message ,
26+ errors : parsedInput . error . issues ,
3227 } ) ;
33- }
28+ const { task } = parsedInput . data ;
3429
35- try {
36- // load remote configuration and diff with local
30+ // load local configuration and validate it
31+ //TODO: merged with the listr task
32+ const local = filterResourceType (
33+ task . config ,
34+ task . opts . includeResourceType ,
35+ task . opts . excludeResourceType ,
36+ ) as ADCSDK . Configuration ;
37+ if ( task . opts . lint ) {
38+ const result = check ( local ) ;
39+ if ( ! result . success )
40+ return res . status ( 400 ) . json ( {
41+ message : result . error . message ,
42+ errors : result . error . issues ,
43+ } ) ;
44+ }
45+ fillLabels ( local , task . opts . labelSelector ) ;
46+
47+ // load and filter remote configuration
48+ //TODO: merged with the listr task
3749 const backend = loadBackend ( task . opts . backend , { ...task . opts } ) ;
38- const remote = await lastValueFrom ( backend . dump ( ) ) ;
50+ let remote = await lastValueFrom ( backend . dump ( ) ) ;
51+ remote = filterResourceType (
52+ remote ,
53+ task . opts . includeResourceType ,
54+ task . opts . excludeResourceType ,
55+ ) ;
56+ [ remote ] = filterConfiguration ( remote , task . opts . labelSelector ) ;
57+
58+ // diff local and remote configuration
3959 const diff = DifferV3 . diff ( local , remote , await backend . defaultValue ( ) ) ;
4060
4161 // sync the diff
0 commit comments