1+ import { KeycloakOIDCAuth } from "./util.js" ;
2+ import { config , updateConfig } from "./config.js" ;
3+
4+ export async function main ( opts : { agg ?: string , svc ?: string } = { } ) {
5+ const aggId = opts . agg ?? config . activeAggregator ;
6+ if ( ! aggId ) throw new Error ( "No active aggregator. Use --agg or run `agg set-active`." ) ;
7+
8+ const agg = config . aggregators [ aggId ] ;
9+ if ( ! agg ) throw new Error ( `Aggregator "${ aggId } " not found.` ) ;
10+
11+ const svcName = opts . svc ?? config . service . name ;
12+ if ( ! svcName ) throw new Error ( "No service name provided. Use --svc" ) ;
13+
14+ const svc = agg . services [ svcName ] ;
15+ if ( ! svc ) throw new Error ( `Service "${ svcName } " not found on Aggregator "${ aggId } "` ) ;
16+
17+ const SERVICE_ENDPOINT = `${ agg . id } /${ svc . name } ` ;
18+
19+ console . log ( "=== Initializing Keycloak Authentication ===" ) ;
20+ const auth = new KeycloakOIDCAuth ( ) ;
21+ await auth . init ( config . auth . idp ) ;
22+ await auth . login ( config . auth . username , config . auth . password , config . auth . clientId , config . auth . clientSecret ) ;
23+ console . log ( "🔐 Auth initialized successfully." ) ;
24+ const umaFetch = auth . createUMAFetch ( ) ;
25+
26+ console . log ( "\n=== Deleting service ===" ) ;
27+ console . log ( `➡️ Endpoint: ${ SERVICE_ENDPOINT } \n` ) ;
28+
29+ try {
30+ const response = await umaFetch ( SERVICE_ENDPOINT , { method : "DELETE" } ) ;
31+ console . log ( `📡 Response status: ${ response . status } ` ) ;
32+ console . log ( "📄 Response body:\n" ) ;
33+ console . log ( await response . text ( ) || "(empty response)" ) ;
34+
35+ if ( response . ok ) {
36+ const { [ svcName ] : _ , ...remainingServices } = agg . services ;
37+ const updatedAgg = { ...agg , services : remainingServices } ;
38+ updateConfig ( { aggregators : { ...config . aggregators , [ aggId ] : updatedAgg } } ) ;
39+ console . log ( `✅ Service "${ svcName } " removed from aggregator "${ aggId } " in config.` ) ;
40+ }
41+ } catch ( err : any ) {
42+ console . error ( "\n❌ Failed to delete service:" ) ;
43+ console . error ( err ?. message || err ) ;
44+ }
45+
46+ console . log ( "\n=== Done ===" ) ;
47+ }
0 commit comments